diff -r 99a34860c105 -r d938228c382e src/server/daemon/auth.c --- a/src/server/daemon/auth.c Wed Nov 02 19:19:01 2022 +0100 +++ b/src/server/daemon/auth.c Sun Nov 06 15:53:32 2022 +0100 @@ -31,7 +31,7 @@ #include #include -#include +#include #include "../public/nsapi.h" #include "../util/atomic.h" @@ -52,7 +52,7 @@ cache.trail = NULL; } -User* auth_cache_get(char *authdb, char *user) { +User* auth_cache_get(char *authdb, const char *user) { //printf("auth_cache_get: %s\n", user); /* * create the key to access the map @@ -62,12 +62,12 @@ size_t userlen = strlen(user); size_t keylen = authdblen + userlen + 1; - char *key = malloc(keylen); + unsigned char *key = malloc(keylen); memcpy(key, authdb, authdblen); key[authdblen] = 0; memcpy(key + authdblen + 1, user, userlen); - UcxKey mapkey = ucx_key(key, keylen); + CxHashKey mapkey = cx_hash_key_bytes(key, keylen); // get cached user from map time_t now = time(NULL); @@ -84,7 +84,7 @@ if(elm) { // compare the key data to be sure it is the correct user int n = (mapkey.len > elm->key.len) ? elm->key.len : mapkey.len; - if (!memcmp(elm->key.data, mapkey.data, n)) { + if (!memcmp(elm->key.data.cbytes, mapkey.data.cbytes, n)) { // elm is now the correct UserCacheElm // TODO: use configuration for expire time if(now - elm->created > 120) { @@ -119,8 +119,8 @@ void auth_cache_add( char *authdb, User *user, - char *password, - char **groups, + const char *password, + const char **groups, size_t numgroups) { //printf("auth_cache_add: %s\n", user->name); @@ -140,10 +140,10 @@ cusr->authdb = strdup(authdb); cusr->password = strdup(password); - cusr->groups = numgroups ? calloc(numgroups, sizeof(sstr_t)) : NULL; + cusr->groups = numgroups ? calloc(numgroups, sizeof(cxmutstr)) : NULL; cusr->numgroups = numgroups; for(int i=0;igroups[i] = sstrdup(sstr(groups[i])); + cusr->groups[i] = cx_strdup(cx_str(groups[i])); } cusr->ref = 1; @@ -164,13 +164,13 @@ size_t authdblen = strlen(authdb); size_t userlen = strlen(user->name); size_t keylen = authdblen + userlen + 1; - char *key = malloc(keylen); + unsigned char *key = malloc(keylen); memcpy(key, authdb, authdblen); key[authdblen] = 0; memcpy(key + authdblen + 1, user->name, userlen); - UcxKey mapkey = ucx_key(key, keylen); + CxHashKey mapkey = cx_hash_key_bytes(key, keylen); - elm->key.data = key; + elm->key.data.bytes = key; elm->key.len = mapkey.len; elm->key.hash = mapkey.hash; elm->slot = mapkey.hash%cache.size; @@ -237,14 +237,14 @@ cache.map[elm->slot] = elm->next_elm; } - free(elm->key.data); + free(elm->key.data.bytes); cached_user_unref(elm->user); free(elm); cache.count--; } -int cached_user_verify_password(CachedUser *user, char *password) { +int cached_user_verify_password(CachedUser *user, const char *password) { if(!strcmp(user->password, password)) { return 1; } else { @@ -252,10 +252,10 @@ } } -int cached_user_check_group(CachedUser *user, char *group) { - sstr_t grp = sstr(group); +int cached_user_check_group(CachedUser *user, const char *group) { + cxstring grp = cx_str(group); for(int i=0;inumgroups;i++) { - if(!sstrcmp(user->groups[i], grp)) { + if(!cx_strcmp(cx_strcast(user->groups[i]), grp)) { return 1; } } @@ -283,7 +283,7 @@ * from public/auth.h */ -User* authdb_get_user(AuthDB *db, char *user) { +User* authdb_get_user(AuthDB *db, const char *user) { if(db->use_cache) { User *u = auth_cache_get(db->name, user); if(u) { @@ -293,7 +293,7 @@ return db->get_user(db, user); } -User* authdb_get_and_verify(AuthDB *db, char *user, char *password, int *pw) { +User* authdb_get_and_verify(AuthDB *db, const char *user, const char *password, int *pw) { User *u = NULL; // try getting the user from the cache if(db->use_cache) {