[sr-dev] git:master:d948ca56: auth_db: fixed is_subscriber() when load_credentials is not set

Daniel-Constantin Mierla miconda at gmail.com
Wed Dec 17 23:35:16 CET 2014


Module: kamailio
Branch: master
Commit: d948ca564b4f669905485e040e295f54bd3f36a2
URL: https://github.com/kamailio/kamailio/commit/d948ca564b4f669905485e040e295f54bd3f36a2

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2014-12-17T23:30:29+01:00

auth_db: fixed is_subscriber() when load_credentials is not set

- the flag parameter can be also explicit on skipping the credentials

---

Modified: modules/auth_db/authdb_mod.c
Modified: modules/auth_db/authorize.c
Modified: modules/auth_db/authorize.h

---

Diff:  https://github.com/kamailio/kamailio/commit/d948ca564b4f669905485e040e295f54bd3f36a2.diff
Patch: https://github.com/kamailio/kamailio/commit/d948ca564b4f669905485e040e295f54bd3f36a2.patch

---

diff --git a/modules/auth_db/authdb_mod.c b/modules/auth_db/authdb_mod.c
index c21d36b..ec44e67 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 b3700f2..13c1044 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 f716480..3746fd6 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




More information about the sr-dev mailing list