Add role-based user database administration

This commit is contained in:
2026-08-30 00:56:18 +02:00
parent 0c7b763bec
commit cd235445c7
14 changed files with 2235 additions and 16 deletions
+36
View File
@@ -1,3 +1,5 @@
#include <string.h>
#include "driver/uart.h"
#include "console_completion.h"
#include "esp_console.h"
@@ -26,6 +28,8 @@
#include "system_console.h"
#include "usb_cdc_transport.h"
#include "usb_console.h"
#include "user_console.h"
#include "user_database.h"
#include "web_console.h"
#include "web_security.h"
#include "web_server.h"
@@ -127,6 +131,37 @@ void app_main(void)
web_security_source == WEB_SECURITY_LOAD_STORED ? "stored" : "newly generated");
}
user_database_load_result_t user_database_source = USER_DATABASE_LOAD_EMPTY;
web_security_credentials_t legacy_credentials;
memset(&legacy_credentials, 0, sizeof(legacy_credentials));
user_database_legacy_credentials_t legacy = {0};
const user_database_legacy_credentials_t *legacy_pointer = NULL;
if (web_security_error == ESP_OK &&
web_security_show_credentials(&legacy_credentials) == ESP_OK) {
legacy = (user_database_legacy_credentials_t){
.username = (const uint8_t *)legacy_credentials.username,
.username_length = legacy_credentials.username_length,
.password = (const uint8_t *)legacy_credentials.password,
.password_length = legacy_credentials.password_length,
};
legacy_pointer = &legacy;
}
esp_err_t user_database_error =
user_database_init(legacy_pointer, &user_database_source);
secure_wipe(&legacy_credentials, sizeof(legacy_credentials));
secure_wipe(&legacy, sizeof(legacy));
if (user_database_error != ESP_OK) {
ESP_LOGE(TAG, "User database unavailable: %s; current network authentication remains active",
esp_err_to_name(user_database_error));
} else {
ESP_LOGI(TAG, "Using %s user database",
user_database_source == USER_DATABASE_LOAD_STORED
? "stored"
: (user_database_source == USER_DATABASE_LOAD_MIGRATED_LEGACY
? "newly migrated user-level"
: "new empty"));
}
esp_err_t web_runtime_error = web_server_init();
if (web_runtime_error != ESP_OK) {
ESP_LOGE(TAG, "HTTPS runtime initialization failed: %s",
@@ -261,6 +296,7 @@ void app_main(void)
ESP_ERROR_CHECK(serial_console_register_commands());
ESP_ERROR_CHECK(session_console_register_commands());
ESP_ERROR_CHECK(usb_console_register_commands());
ESP_ERROR_CHECK(user_console_register_commands());
ESP_ERROR_CHECK(wifi_console_register_commands());
ESP_ERROR_CHECK(web_console_register_commands());
ESP_ERROR_CHECK(ssh_console_register_commands());