Browse code

auth_db: fixed is_subscriber() when load_credentials is not set

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

Daniel-Constantin Mierla authored on 17/12/2014 22:30:29
Showing 3 changed files
... ...
@@ -274,8 +274,9 @@ static int w_is_subscriber(sip_msg_t *msg, char *_uri, char* _table,
274 274
 
275 275
 	LM_DBG("uri [%.*s] table [%.*s] flags [%d]\n", suri.len, suri.s,
276 276
 			stable.len,  stable.s, iflags);
277
-	ret = fetch_credentials(msg, &puri.user, (iflags==1)?&puri.host:NULL,
278
-			&stable);
277
+	ret = fetch_credentials(msg, &puri.user,
278
+				(iflags&AUTH_DB_SUBS_USE_DOMAIN)?&puri.host:NULL,
279
+				&stable, iflags);
279 280
 
280 281
 	if(ret>=0)
281 282
 		return 1;
... ...
@@ -50,9 +50,10 @@
50 50
 #include "../../mem/mem.h"
51 51
 #include "api.h"
52 52
 #include "authdb_mod.h"
53
+#include "authorize.h"
53 54
 
54 55
 
55
-int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table)
56
+int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table, int flags)
56 57
 {
57 58
 	pv_elem_t *cred;
58 59
 	db_key_t keys[2];
... ...
@@ -62,11 +63,17 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table)
62 62
 
63 63
 	int n, nc;
64 64
 
65
-	col = pkg_malloc(sizeof(*col) * (credentials_n + 1));
65
+	if(flags&AUTH_DB_SUBS_SKIP_CREDENTIALS) {
66
+		nc = 1;
67
+	} else {
68
+		nc = credentials_n;
69
+	}
70
+	col = pkg_malloc(sizeof(*col) * (nc+1));
66 71
 	if (col == NULL) {
67 72
 		LM_ERR("no more pkg memory\n");
68 73
 		return -1;
69 74
 	}
75
+	col[0] = &user_column;
70 76
 
71 77
 	keys[0] = &user_column;
72 78
 	keys[1] = &domain_column;
... ...
@@ -86,7 +93,6 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table)
86 86
 		n = 2;
87 87
 	}
88 88
 
89
-	nc = credentials_n;
90 89
 	if (auth_dbf.use_table(auth_db_handle, table) < 0) {
91 90
 		LM_ERR("failed to use_table\n");
92 91
 		pkg_free(col);
... ...
@@ -110,6 +116,10 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table)
110 110
 				table->len, table->s);
111 111
 		return -2;
112 112
 	}
113
+	if(flags&AUTH_DB_SUBS_SKIP_CREDENTIALS) {
114
+		/* there is a result and flag to skip loading credentials is set */
115
+		goto done;
116
+	}
113 117
 	for (cred=credentials, n=0; cred; cred=cred->next, n++) {
114 118
 		if (db_val2pv_spec(msg, &RES_ROWS(res)[0].values[n], cred->spec) != 0) {
115 119
 			if(res)
... ...
@@ -119,6 +129,8 @@ int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table)
119 119
 			return -3;
120 120
 		}
121 121
 	}
122
+
123
+done:
122 124
 	if(res)
123 125
 		auth_dbf.free_result(auth_db_handle, res);
124 126
 	return 0;
... ...
@@ -51,10 +51,13 @@ int www_authenticate2(struct sip_msg* _msg, char* _realm, char* _table, char *_m
51 51
  */
52 52
 int auth_check(struct sip_msg* _m, char* _realm, char* _table, char *_flags);
53 53
 
54
+
55
+#define AUTH_DB_SUBS_USE_DOMAIN	1<<0
56
+#define AUTH_DB_SUBS_SKIP_CREDENTIALS	1<<1
54 57
 /*
55 58
  * Fetch credentials for a specific user
56 59
  */
57
-int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table);
60
+int fetch_credentials(sip_msg_t *msg, str *user, str* domain, str *table, int flags);
58 61
 
59 62
 /*
60 63
  * Bind to AUTH_DB API