-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathuserManagement.h
More file actions
69 lines (44 loc) · 2.23 KB
/
userManagement.h
File metadata and controls
69 lines (44 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
userManagement.h
This file is part of Multitasking Esp32 HTTP FTP Telnet servers for Arduino project: https://github.com/BojanJurca/Multitasking-Esp32-HTTP-FTP-Telnet-servers-for-Arduino
UNIX-like user management.
April 27, 2026, Bojan Jurca
*/
#pragma once
#ifndef __USER_MANAGEMENT_H__
#define __USER_MANAGEMENT_H__
//#include <cstddef>
#include <mbedtls/md.h>
#include <time.h>
#include <string.h>
#include <Cstring.hpp>
#include <threadSafeFS.h>
// TUNING PARAMETERS
#define USER_PASSWORD_MAX_LENGTH 64
#define MAX_ETC_PASSWD_SIZE (1024 + 512)
#define MAX_ETC_SHADOW_SIZE (1024 + 512)
#define DEFAULT_ROOT_PASSWORD "rootpassword"
#define DEFAULT_ROOT_PASSWORD_SHA "de362bbdf11f2df30d12f318eeed87b8ee9e0c69c8ba61ed9a57695bbd91e481" // = __SHA256__ ("rootpassword")
#define DEFAULT_WEBADMIN_PASSWORD "webadminpassword"
#define DEFAULT_WEBADMIN_PASSWORD_SHA "40c6af3d1540ca2af132e1e93e7f5a5f624280b9d4d552a0bb103afe17c75c53" // = __SHA256__ ("webadminpassword")
#define DEFAULT_USER_PASSWORD "changeimmediatelly"
#define DEFAULT_USER_PASSWORD_SHA "ef286dbce1c8edcb4db441e0b717942a90e7f26264fc46e0a518d446ef8da48c" // = __SHA256__ ("changeimmediatelly")
class userManagement_t {
public:
// Singleton accessor
static userManagement_t &getInstance ();
bool checkUserNameAndPassword (const char *userName, const char *password);
Cstring<255> getHomeDirectory (const char *userName);
bool passwd (const char *userName, const char *newPassword);
const char *userAdd (const char *userName, const char *userHomeDirectory);
const char *userDel (const char *userName);
userManagement_t (threadSafeFS::FS& fileSystem);
private:
threadSafeFS::FS& __fileSystem__;
bool __writePasswd__ (const char *buffer);
bool __readPasswd__ (char *buffer);
bool __writeShadow__ (const char *buffer);
bool __readShadow__ (char *buffer);
static bool __sha256__ (char *buffer, size_t bufferSize, const char *clearText);
};
#endif