fix bug where a login from a new identity silently removes an admin
This commit is contained in:
1 parent
505ae195dd
commit
6ae61bbb40
5 files changed
+8
-2
No files matched your search
@@ -96,7 +96,7 @@ ClientInfo* ClientACL::getClient(const uint8_t* pubkey, int key_len) {
|
||||
|
||||
ClientInfo* ClientACL::putClient(const mesh::Identity& id, uint8_t init_perms) {
|
||||
uint32_t min_time = 0xFFFFFFFF;
|
||||
ClientInfo* oldest = &clients[MAX_CLIENTS - 1];
|
||||
ClientInfo* oldest = 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) {
|
||||
@@ -109,6 +109,7 @@ 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
|
||||
}
|
||||
memset(c, 0, sizeof(*c));
|
||||
@@ -135,6 +136,7 @@ bool ClientACL::applyPermissions(const mesh::LocalIdentity& self_id, const uint8
|
||||
|
||||
mesh::Identity id(pubkey);
|
||||
c = putClient(id, 0);
|
||||
if (c == NULL) return false; // couldn't put client
|
||||
|
||||
c->permissions = perms; // update their permissions
|
||||
self_id.calcSharedSecret(c->shared_secret, pubkey);
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
bool clear();
|
||||
|
||||
ClientInfo* getClient(const uint8_t* pubkey, int key_len);
|
||||
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms);
|
||||
ClientInfo* putClient(const mesh::Identity& id, uint8_t init_perms); // returns NULL if table is full and all entries are admins
|
||||
bool applyPermissions(const mesh::LocalIdentity& self_id, const uint8_t* pubkey, int key_len, uint8_t perms);
|
||||
|
||||
int getNumClients() const { return num_clients; }
|
||||
|
||||
Reference in new issue
Block a user