Merge upstream/dev (3 commits) [upstream-sync]

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-12-03 11:50:55 +01:00
commit 7e911aa17d
7 files changed
+135 -28

No files matched your search

+15 -7
View File
@@ -181,7 +181,7 @@ void ClientACL::save(FILESYSTEM* fs, bool (*filter)(ClientInfo*)) {
for (int i = 0; i < num_clients; i++) {
auto c = &clients[i];
if (c->permissions == 0 || (filter && !filter(c))) continue; // skip deleted entries, or by filter function
if (c->permissions == 0 || c->shared_login || (filter && !filter(c))) continue; // skip deleted/transient entries, or by filter function
bool success = (file.write(c->id.pub_key, 32) == 32);
success = success && (file.write((uint8_t *) &c->permissions, 1) == 1);
@@ -218,12 +218,18 @@ ClientInfo* ClientACL::getClient(const uint8_t* pubkey, int key_len) {
return NULL; // not found
}
ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
uint32_t min_time = 0xFFFFFFFF;
ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms, bool shared_login) {
uint32_t min_time = 0xFFFFFFFF, min_unsaved_time = 0xFFFFFFFF;
ClientInfo* oldest = NULL;
ClientInfo* oldest_unsaved = NULL;
for (int i = 0; i < num_clients; i++) {
if (id.matches(clients[i].id)) return &clients[i]; // already known
if (!clients[i].isAdmin() && clients[i].last_activity < min_time) {
if (clients[i].isAdmin()) continue;
if ((clients[i].permissions == 0 || clients[i].shared_login) && clients[i].last_activity < min_unsaved_time) {
oldest_unsaved = &clients[i];
min_unsaved_time = oldest_unsaved->last_activity;
}
if (clients[i].last_activity < min_time) {
oldest = &clients[i];
min_time = oldest->last_activity;
}
@@ -233,12 +239,13 @@ ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
if (num_clients < MAX_CLIENTS) {
c = &clients[num_clients++];
} else {
if (oldest == NULL) return NULL; // every entry is an admin, so don't evict
c = oldest; // evict least active contact
orphanTimestamp(c);
c = oldest_unsaved ? oldest_unsaved : (shared_login ? NULL : oldest); // evict unsaved entries first, shared logins never evict saved ones
if (c == NULL) return NULL; // every entry is an admin (or saved), so don't evict
orphanTimestamp(c); // CUSTOM (TeTeHacko): keep the evicted client's replay floor
}
memset(c, 0, sizeof(*c));
c->permissions = init_perms;
c->shared_login = shared_login;
c->id = id;
c->out_path_len = OUT_PATH_UNKNOWN;
for (int i = 0; i < _num_ts_orphans; i++) { // known before: its replay floor comes back
@@ -273,6 +280,7 @@ bool ClientACL::applyPermissions(const mesh::LocalIdentity& self_id, const uint8
if (c == NULL) return false; // couldn't put client
c->permissions = perms; // update their permissions
c->shared_login = false;
self_id.calcSharedSecret(c->shared_secret, pubkey);
}
return true;
+2 -1
View File
@@ -22,6 +22,7 @@ struct ClientInfo {
uint32_t saved_timestamp; // last_timestamp as last written to /s_acl_ts*
uint32_t last_req_timestamp; // REQ only (upstream split); restored from saved_timestamp too
uint32_t last_activity; // by OUR clock (transient)
bool shared_login; // logged in with a guest or read-only password, never saved (transient)
union {
struct {
uint32_t sync_since; // sync messages SINCE this timestamp (by OUR clock)
@@ -87,7 +88,7 @@ public:
void persistTimestamp(ClientInfo* c, uint32_t sender_timestamp, uint32_t now);
ClientInfo* getClient(const uint8_t* pubkey, int key_len);
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms); // returns NULL if table is full and all entries are admins
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms, bool shared_login=false); // returns NULL if table is full and all entries are admins (or saved, if shared_login)
bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms);
int getNumClients() const { return num_clients; }
+31 -7
View File
@@ -370,10 +370,16 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
}
} else if (memcmp(command, "password ", 9) == 0) {
// change admin password
StrHelper::strncpy(_prefs->password, &command[9], sizeof(_prefs->password));
savePrefs();
sprintf(reply, "password now: ");
StrHelper::strncpy(&reply[14], _prefs->password, 160-15); // echo back just to let admin know for sure!!
char pw[sizeof(_prefs->password)];
StrHelper::strncpy(pw, &command[9], sizeof(pw));
if (strcmp(pw, _prefs->guest_password) == 0 || (_prefs->ro_password[0] && strcmp(pw, _prefs->ro_password) == 0)) {
strcpy(reply, "Error, must differ from guest and ro passwords");
} else {
strcpy(_prefs->password, pw);
savePrefs();
sprintf(reply, "password now: ");
StrHelper::strncpy(&reply[14], _prefs->password, 160-15); // echo back just to let admin know for sure!!
}
} else if (memcmp(command, "clear stats", 11) == 0) {
_callbacks->clearStats();
strcpy(reply, "(OK - stats reset)");
@@ -698,9 +704,25 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
strcpy(reply, "Error, invalid policy");
}
} else if (memcmp(config, "guest.password ", 15) == 0) {
StrHelper::strncpy(_prefs->guest_password, &config[15], sizeof(_prefs->guest_password));
savePrefs();
strcpy(reply, "OK");
char pw[sizeof(_prefs->guest_password)];
StrHelper::strncpy(pw, &config[15], sizeof(pw));
if (pw[0] && (strcmp(pw, _prefs->password) == 0 || strcmp(pw, _prefs->ro_password) == 0)) {
strcpy(reply, "Error, must differ from admin and ro passwords");
} else {
strcpy(_prefs->guest_password, pw);
savePrefs();
strcpy(reply, "OK");
}
} else if (memcmp(config, "ro.password", 11) == 0 && (config[11] == 0 || config[11] == ' ')) {
char pw[sizeof(_prefs->ro_password)];
StrHelper::strncpy(pw, config[11] ? &config[12] : "", sizeof(pw)); // no value clears it
if (pw[0] && (strcmp(pw, _prefs->password) == 0 || strcmp(pw, _prefs->guest_password) == 0)) {
strcpy(reply, "Error, must differ from admin and guest passwords");
} else {
strcpy(_prefs->ro_password, pw); // blank disables read-only logins
savePrefs();
strcpy(reply, "OK");
}
} else if (memcmp(config, "prv.key ", 8) == 0) {
uint8_t prv_key[PRV_KEY_SIZE];
bool success = mesh::Utils::fromHex(prv_key, PRV_KEY_SIZE, &config[8]);
@@ -996,6 +1018,8 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
}
} else if (memcmp(config, "guest.password", 14) == 0) {
sprintf(reply, "> %s", _prefs->guest_password);
} else if (memcmp(config, "ro.password", 11) == 0) {
sprintf(reply, "> %s", _prefs->ro_password);
} else if (sender_timestamp == 0 && memcmp(config, "prv.key", 7) == 0) { // from serial command line only
uint8_t prv_key[PRV_KEY_SIZE];
int len = _callbacks->getSelfId().writeTo(prv_key, PRV_KEY_SIZE);
+3
View File
@@ -38,6 +38,7 @@ public:
float rx_delay_base = 0;
float tx_delay_factor = 0;
char guest_password[16];
char ro_password[16];
float direct_tx_delay_factor = 0;
uint32_t guard;
uint8_t sf = 0;
@@ -306,6 +307,7 @@ protected:
def("name", node_name, sizeof(node_name));
def("pass", password, sizeof(password));
def("guest", guest_password, sizeof(guest_password));
def("ro_pass", ro_password, sizeof(ro_password));
def("owner", owner_info, sizeof(owner_info));
def("adv_int", advert_interval);
def("f_adv_int", flood_advert_interval);
@@ -325,6 +327,7 @@ public:
node_name[0] = 0;
password[0] = 0;
guest_password[0] = 0;
ro_password[0] = 0;
bridge_secret[0] = 0;
owner_info[0] = 0;
filter_deny[0] = 0;