diff --git a/modules/auth_db/authdb_mod.c b/modules/auth_db/authdb_mod.c index c21d36b59a0..ec44e67cdb5 100644 --- a/modules/auth_db/authdb_mod.c +++ b/modules/auth_db/authdb_mod.c @@ -274,8 +274,9 @@ static int w_is_subscriber(sip_msg_t *msg, char *_uri, char* _table, LM_DBG("uri [%.*s] table [%.*s] flags [%d]\n", suri.len, suri.s, stable.len, stable.s, iflags); - ret = fetch_credentials(msg, &puri.user, (iflags==1)?&puri.host:NULL, - &stable); + ret = fetch_credentials(msg, &puri.user, + (iflags&AUTH_DB_SUBS_USE_DOMAIN)?&puri.host:NULL, + &stable, iflags); if(ret>=0) return 1; diff --git a/modules/auth_db/authorize.c b/modules/auth_db/authorize.c index b3700f2daeb..13c1044c138 100644 --- a/modules/auth_db/authorize.c +++ b/modules/auth_db/authorize.c @@ -50,9 +50,10 @@ #include "../../mem/mem.h" #include "api.h" #include "authdb_mod.h" +#include "authorize.h" -int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table) +int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table, int flags) { pv_elem_t *cred; db_key_t keys[2]; @@ -62,11 +63,17 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table) int n, nc; - col = pkg_malloc(sizeof(*col) * (credentials_n + 1)); + if(flags&AUTH_DB_SUBS_SKIP_CREDENTIALS) { + nc = 1; + } else { + nc = credentials_n; + } + col = pkg_malloc(sizeof(*col) * (nc+1)); if (col == NULL) { LM_ERR("no more pkg memory\n"); return -1; } + col[0] = &user_column; keys[0] = &user_column; keys[1] = &domain_column; @@ -86,7 +93,6 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table) n = 2; } - nc = credentials_n; if (auth_dbf.use_table(auth_db_handle, table) < 0) { LM_ERR("failed to use_table\n"); pkg_free(col); @@ -110,6 +116,10 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table) table->len, table->s); return -2; } + if(flags&AUTH_DB_SUBS_SKIP_CREDENTIALS) { + /* there is a result and flag to skip loading credentials is set */ + goto done; + } for (cred=credentials, n=0; cred; cred=cred->next, n++) { if (db_val2pv_spec(msg, &RES_ROWS(res)[0].values[n], cred->spec) != 0) { if(res) @@ -119,6 +129,8 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table) return -3; } } + +done: if(res) auth_dbf.free_result(auth_db_handle, res); return 0; diff --git a/modules/auth_db/authorize.h b/modules/auth_db/authorize.h index f7164803476..3746fd69ebb 100644 --- a/modules/auth_db/authorize.h +++ b/modules/auth_db/authorize.h @@ -51,10 +51,13 @@ int www_authenticate2(struct sip_msg* _msg, char* _realm, char* _table, char *_m */ int auth_check(struct sip_msg* _m, char* _realm, char* _table, char *_flags); + +#define AUTH_DB_SUBS_USE_DOMAIN 1<<0 +#define AUTH_DB_SUBS_SKIP_CREDENTIALS 1<<1 /* * Fetch credentials for a specific user */ -int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table); +int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table, int flags); /* * Bind to AUTH_DB API