src/server/daemon/auth.c

changeset 490
d218607f5a7e
parent 467
4d038bc6f86e
equal deleted inserted replaced
489:921f83a8943f 490:d218607f5a7e
82 } 82 }
83 // if we have an elm, the hash is correct 83 // if we have an elm, the hash is correct
84 if(elm) { 84 if(elm) {
85 // compare the key data to be sure it is the correct user 85 // compare the key data to be sure it is the correct user
86 int n = (mapkey.len > elm->key.len) ? elm->key.len : mapkey.len; 86 int n = (mapkey.len > elm->key.len) ? elm->key.len : mapkey.len;
87 if (!memcmp(elm->key.data.cbytes, mapkey.data.cbytes, n)) { 87 if (!memcmp(elm->key.data, mapkey.data, n)) {
88 // elm is now the correct UserCacheElm 88 // elm is now the correct UserCacheElm
89 // TODO: use configuration for expire time 89 // TODO: use configuration for expire time
90 if(now - elm->created > 120) { 90 if(now - elm->created > 120) {
91 // cached user expired 91 // cached user expired
92 // remove all users from the list from the first to this one 92 // remove all users from the list from the first to this one
168 memcpy(key, authdb, authdblen); 168 memcpy(key, authdb, authdblen);
169 key[authdblen] = 0; 169 key[authdblen] = 0;
170 memcpy(key + authdblen + 1, user->name, userlen); 170 memcpy(key + authdblen + 1, user->name, userlen);
171 CxHashKey mapkey = cx_hash_key_bytes(key, keylen); 171 CxHashKey mapkey = cx_hash_key_bytes(key, keylen);
172 172
173 elm->key.data.bytes = key; 173 elm->key.data = key;
174 elm->key.len = mapkey.len; 174 elm->key.len = mapkey.len;
175 elm->key.hash = mapkey.hash; 175 elm->key.hash = mapkey.hash;
176 elm->slot = mapkey.hash%cache.size; 176 elm->slot = mapkey.hash%cache.size;
177 177
178 // add user to list and map 178 // add user to list and map
235 prevelm->next_elm = elm->next_elm; 235 prevelm->next_elm = elm->next_elm;
236 } else { 236 } else {
237 cache.map[elm->slot] = elm->next_elm; 237 cache.map[elm->slot] = elm->next_elm;
238 } 238 }
239 239
240 free(elm->key.data.bytes); 240 free((void*)elm->key.data);
241 cached_user_unref(elm->user); 241 cached_user_unref(elm->user);
242 free(elm); 242 free(elm);
243 243
244 cache.count--; 244 cache.count--;
245 } 245 }

mercurial