diff --git a/src/auth.c b/src/auth.c index 68b9bdc..cfb04ee 100644 --- a/src/auth.c +++ b/src/auth.c @@ -72,31 +72,32 @@ int alwaysauth(struct clientparam * param){ int cacheauth(struct clientparam * param){ struct authcache ac; uint32_t ttl; + unsigned type = param->srv->authcachetype; if( - ((conf.authcachetype & 2) && !param->username) || - ((conf.authcachetype & 4) && !param->password) || + ((type & 2) && !param->username) || + ((type & 4) && !param->password) || ( - (conf.authcachetype & 1) && *SAFAMILY(¶m->sincr) != AF_INET + (type & 1) && *SAFAMILY(¶m->sincr) != AF_INET #ifndef NOIPv6 && *SAFAMILY(¶m->sincr) != AF_INET6 #endif ) || (!hashresolv(&auth_table, param, &ac, &ttl))) { return 4; } - if((conf.authcachetype & 1) &&(conf.authcachetype & 8) && + if((type & 1) &&(type & 8) && (ac.sincr_family != *SAFAMILY(¶m->sincr) || memcmp(ac.sincr_addr, SAADDR(¶m->sincr), SAADDRLEN(¶m->sincr)) )) { return 10; } - if(!(conf.authcachetype&2) && *ac.username){ + if(!(type&2) && *ac.username){ if(param->username) free(param->username); param->username = (unsigned char *)strdup((char *)ac.username); } - if((conf.authcachetype & 32)){ + if((type & 32)){ memset(¶m->sinsl, 0, sizeof(param->sinsl)); *(SAFAMILY(¶m->sinsl)) = ac.sinsl_family; memcpy(SAADDR(¶m->sinsl), ac.sinsl_addr, SAADDRLEN(¶m->sinsl)); @@ -116,7 +117,7 @@ int doauth(struct clientparam * param){ if(authfuncs->authorize && (res = (*authfuncs->authorize)(param))) return res; - if(conf.authcachetype && authfuncs->authenticate && authfuncs->authenticate != cacheauth && param->username && (!(conf.authcachetype&4) || (!param->pwtype && param->password))){ + if(param->srv->authcachetype && authfuncs->authenticate && authfuncs->authenticate != cacheauth && param->username && (!(param->srv->authcachetype&4) || (!param->pwtype && param->password))){ struct authcache ac={.username=""}; if(param->username) { diff --git a/src/hashtables.c b/src/hashtables.c index eed8022..e46d10b 100644 --- a/src/hashtables.c +++ b/src/hashtables.c @@ -17,6 +17,12 @@ static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *ha } static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){ + struct clientparam *param = (struct clientparam *)index; + + memcpy(hash, param->hash, ht->hash_size); +} + +void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){ blake2b_state S; struct clientparam *param = (struct clientparam *)index; unsigned type = param->srv->authcachetype; @@ -62,12 +68,7 @@ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *has if((type & 2048))blake2b_update(&S, SAPORT(¶m->srv->intsa), 2); blake2b_final(&S, hash, ht->hash_size); } -} - -void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){ - struct clientparam *param = (struct clientparam *)index; - - memcpy(hash, param->hash, ht->hash_size); + memcpy(param->hash, hash, ht->hash_size); } static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){