Authcache fix

This commit is contained in:
Vladimir Dubrovin 2026-07-04 11:38:47 +03:00
parent c462963d8e
commit 4f99443750
2 changed files with 15 additions and 13 deletions

View File

@ -72,31 +72,32 @@ int alwaysauth(struct clientparam * param){
int cacheauth(struct clientparam * param){ int cacheauth(struct clientparam * param){
struct authcache ac; struct authcache ac;
uint32_t ttl; uint32_t ttl;
unsigned type = param->srv->authcachetype;
if( if(
((conf.authcachetype & 2) && !param->username) || ((type & 2) && !param->username) ||
((conf.authcachetype & 4) && !param->password) || ((type & 4) && !param->password) ||
( (
(conf.authcachetype & 1) && *SAFAMILY(&param->sincr) != AF_INET (type & 1) && *SAFAMILY(&param->sincr) != AF_INET
#ifndef NOIPv6 #ifndef NOIPv6
&& *SAFAMILY(&param->sincr) != AF_INET6 && *SAFAMILY(&param->sincr) != AF_INET6
#endif #endif
) || (!hashresolv(&auth_table, param, &ac, &ttl))) { ) || (!hashresolv(&auth_table, param, &ac, &ttl))) {
return 4; return 4;
} }
if((conf.authcachetype & 1) &&(conf.authcachetype & 8) && if((type & 1) &&(type & 8) &&
(ac.sincr_family != *SAFAMILY(&param->sincr) || (ac.sincr_family != *SAFAMILY(&param->sincr) ||
memcmp(ac.sincr_addr, SAADDR(&param->sincr), SAADDRLEN(&param->sincr)) memcmp(ac.sincr_addr, SAADDR(&param->sincr), SAADDRLEN(&param->sincr))
)) { )) {
return 10; return 10;
} }
if(!(conf.authcachetype&2) && *ac.username){ if(!(type&2) && *ac.username){
if(param->username) free(param->username); if(param->username) free(param->username);
param->username = (unsigned char *)strdup((char *)ac.username); param->username = (unsigned char *)strdup((char *)ac.username);
} }
if((conf.authcachetype & 32)){ if((type & 32)){
memset(&param->sinsl, 0, sizeof(param->sinsl)); memset(&param->sinsl, 0, sizeof(param->sinsl));
*(SAFAMILY(&param->sinsl)) = ac.sinsl_family; *(SAFAMILY(&param->sinsl)) = ac.sinsl_family;
memcpy(SAADDR(&param->sinsl), ac.sinsl_addr, SAADDRLEN(&param->sinsl)); memcpy(SAADDR(&param->sinsl), ac.sinsl_addr, SAADDRLEN(&param->sinsl));
@ -116,7 +117,7 @@ int doauth(struct clientparam * param){
if(authfuncs->authorize && if(authfuncs->authorize &&
(res = (*authfuncs->authorize)(param))) (res = (*authfuncs->authorize)(param)))
return res; 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=""}; struct authcache ac={.username=""};
if(param->username) { if(param->username) {

View File

@ -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){ 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; blake2b_state S;
struct clientparam *param = (struct clientparam *)index; struct clientparam *param = (struct clientparam *)index;
unsigned type = param->srv->authcachetype; 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(&param->srv->intsa), 2); if((type & 2048))blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_final(&S, hash, ht->hash_size); blake2b_final(&S, hash, ht->hash_size);
} }
} memcpy(param->hash, 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);
} }
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){ static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){