Browse code

uid_auth_db: removed history, updated log macros

Daniel-Constantin Mierla authored on 11/09/2017 21:16:39
Showing 5 changed files
... ...
@@ -39,8 +39,8 @@
39 39
  * Parse list of tokens separated by some char and put each token
40 40
  * into result array. Caller frees result array!
41 41
  */
42
-static inline int
43
-parse_token_list(char *p, char *pend, char separator, str **result)
42
+static inline int parse_token_list(char *p, char *pend, char separator,
43
+		str **result)
44 44
 {
45 45
 	int i;
46 46
 
... ...
@@ -63,29 +63,27 @@ parse_token_list(char *p, char *pend, char separator, str **result)
63 63
  * Parse the list of AVP names separated by '|' into an array
64 64
  * of names, each element of the array is str string
65 65
  */
66
-static int
67
-aaa_avps_init(str *avp_list, str **parsed_avps, int *avps_n)
66
+static int aaa_avps_init(str *avp_list, str **parsed_avps, int *avps_n)
68 67
 {
69 68
 	int errcode, i;
70 69
 	char *cp;
71 70
 
72 71
 	if (!avp_list->s || !avp_list->len) {
73
-		     /* AVPs disabled, nothing to do */
72
+		/* AVPs disabled, nothing to do */
74 73
 		*avps_n = 0;
75 74
 		return 1;
76 75
 	}
77 76
 
78 77
 	cp = pkg_malloc(avp_list->len + 1);
79 78
 	if (cp == NULL) {
80
-		LOG(L_ERR, "aaa_avps::aaa_avps_init(): can't allocate memory\n");
79
+		LM_ERR("can't allocate memory\n");
81 80
 		errcode = -1;
82 81
 		goto bad;
83 82
 	}
84 83
 	memcpy(cp, avp_list->s, avp_list->len);
85 84
 	*avps_n = parse_token_list(cp, cp + avp_list->len, '|', parsed_avps);
86 85
 	if (*avps_n == -1) {
87
-		LOG(L_ERR, "aaa_avps::aaa_avps_init(): can't parse avps_column_int "
88
-		    "parameter\n");
86
+		LM_ERR("can't parse avps_column_int parameter\n");
89 87
 		errcode = -2;
90 88
 		pkg_free(cp);
91 89
 		goto bad;
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Digest Authentication - Database support
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -22,16 +20,10 @@
22 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 21
  * GNU General Public License for more details.
24 22
  *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
27 25
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 26
  *
29
- * history:
30
- * ---------
31
- * 2003-02-28 scratchpad compatibility abandoned
32
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
33
- * 2004-06-06 updated to the new DB api, added auth_db_{init,bind,close,ver}
34
- *             (andrei)
35 27
  */
36 28
 
37 29
 
... ...
@@ -57,31 +49,31 @@
57 49
 #define IS_NULL(f)	((f).flags & DB_NULL)
58 50
 
59 51
 static inline int get_ha1(struct username* username, str* did, str* realm,
60
-			  authdb_table_info_t *table_info, char* ha1, db_res_t** res, db_rec_t** row)
52
+		authdb_table_info_t *table_info, char* ha1, db_res_t** res, db_rec_t** row)
61 53
 {
62 54
 	str result;
63 55
 	db_cmd_t *q = NULL;
64
-   
56
+
65 57
 	if (calc_ha1) {
66 58
 		q = table_info->query_password;
67
-		DBG("querying plain password\n");
59
+		LM_DBG("querying plain password\n");
68 60
 	} else {
69 61
 		if (username->domain.len) {
70 62
 			q = table_info->query_pass2;
71
-			DBG("querying ha1b\n");
63
+			LM_DBG("querying ha1b\n");
72 64
 		} else {
73 65
 			q = table_info->query_pass;
74
-			DBG("querying ha1\n");
66
+			LM_DBG("querying ha1\n");
75 67
 		}
76 68
 	}
77
-    
69
+
78 70
 	q->match[0].v.lstr = username->user;
79 71
 	q->match[1].v.lstr = *realm;
80 72
 
81 73
 	if (use_did) q->match[2].v.lstr = *did;
82 74
 
83 75
 	if (db_exec(res, q) < 0 ) {
84
-		ERR("Error while querying database\n");
76
+		LM_ERR("Error while querying database\n");
85 77
 		return -1;
86 78
 	}
87 79
 
... ...
@@ -89,8 +81,10 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
89 81
 	else *row = NULL;
90 82
 	while (*row) {
91 83
 		if (IS_NULL((*row)->fld[0]) || IS_NULL((*row)->fld[1])) {
92
-			LOG(L_ERR, "auth_db:get_ha1: Credentials for '%.*s'@'%.*s' contain NULL value, skipping\n",
93
-				username->user.len, ZSW(username->user.s), realm->len, ZSW(realm->s));
84
+			LM_ERR("Credentials for '%.*s'@'%.*s' contain NULL value,"
85
+					" skipping\n",
86
+					username->user.len, ZSW(username->user.s),
87
+					realm->len, ZSW(realm->s));
94 88
 		} else {
95 89
 			if ((*row)->fld[1].v.int4 & SRDB_DISABLED) {
96 90
 				/* disabled rows ignored */
... ...
@@ -105,10 +99,11 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
105 99
 	}
106 100
 
107 101
 	if (!*row) {
108
-		DBG("auth_db:get_ha1: Credentials for '%.*s'@'%.*s' not found\n",
109
-			username->user.len, ZSW(username->user.s), realm->len, ZSW(realm->s));
102
+		LM_DBG("Credentials for '%.*s'@'%.*s' not found\n",
103
+				username->user.len, ZSW(username->user.s),
104
+				realm->len, ZSW(realm->s));
110 105
 		return 1;
111
-	}		
106
+	}
112 107
 
113 108
 	result.s = (*row)->fld[0].v.cstr;
114 109
 	result.len = strlen(result.s);
... ...
@@ -117,7 +112,7 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
117 112
 		/* Only plaintext passwords are stored in database,
118 113
 		 * we have to calculate HA1 */
119 114
 		auth_api.calc_HA1(HA_MD5, &username->whole, realm, &result, 0, 0, ha1);
120
-		DBG("auth_db:get_ha1: HA1 string calculated: %s\n", ha1);
115
+		LM_DBG("HA1 string calculated: %s\n", ha1);
121 116
 	} else {
122 117
 		memcpy(ha1, result.s, result.len);
123 118
 		ha1[result.len] = '\0';
... ...
@@ -133,36 +128,36 @@ static inline int get_ha1(struct username* username, str* did, str* realm,
133 128
 static inline int check_response(dig_cred_t* cred, str* method, char* ha1)
134 129
 {
135 130
 	HASHHEX resp, hent;
136
-    
131
+
137 132
 	/*
138 133
 	 * First, we have to verify that the response received has
139 134
 	 * the same length as responses created by us
140 135
 	 */
141 136
 	if (cred->response.len != 32) {
142
-		DBG("auth_db:check_response: Receive response len != 32\n");
137
+		LM_DBG("Receive response len != 32\n");
143 138
 		return 1;
144 139
 	}
145
-    
140
+
146 141
 	/*
147 142
 	 * Now, calculate our response from parameters received
148 143
 	 * from the user agent
149 144
 	 */
150
-	auth_api.calc_response(ha1, &(cred->nonce), 
151
-				  &(cred->nc), &(cred->cnonce), 
152
-				  &(cred->qop.qop_str), cred->qop.qop_parsed == QOP_AUTHINT,
153
-				  method, &(cred->uri), hent, resp);
154
-    
155
-	DBG("auth_db:check_response: Our result = \'%s\'\n", resp);
156
-    
145
+	auth_api.calc_response(ha1, &(cred->nonce),
146
+			&(cred->nc), &(cred->cnonce),
147
+			&(cred->qop.qop_str), cred->qop.qop_parsed == QOP_AUTHINT,
148
+			method, &(cred->uri), hent, resp);
149
+
150
+	LM_DBG("Our result = \'%s\'\n", resp);
151
+
157 152
 	/*
158 153
 	 * And simply compare the strings, the user is
159 154
 	 * authorized if they match
160 155
 	 */
161 156
 	if (!memcmp(resp, cred->response.s, 32)) {
162
-		DBG("auth_db:check_response: Authorization is OK\n");
157
+		LM_DBG("Authorization is OK\n");
163 158
 		return 0;
164 159
 	} else {
165
-		DBG("auth_db:check_response: Authorization failed\n");
160
+		LM_DBG("Authorization failed\n");
166 161
 		return 2;
167 162
 	}
168 163
 }
... ...
@@ -177,7 +172,7 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
177 172
 	int_str iname, ivalue;
178 173
 	str value;
179 174
 	char buf[32];
180
-    
175
+
181 176
 	for (i = 2; i < credentials_n + 2; i++) {
182 177
 		value = row->fld[i].v.lstr;
183 178
 
... ...
@@ -185,18 +180,18 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
185 180
 			continue;
186 181
 
187 182
 		switch (row->fld[i].type) {
188
-		case DB_STR:
189
-			value = row->fld[i].v.lstr;
190
-			break;
191
-
192
-		case DB_INT:
193
-			value.len = sprintf(buf, "%d", row->fld[i].v.int4);
194
-			value.s = buf;
195
-			break;
196
-
197
-		default:
198
-			abort();
199
-			break;
183
+			case DB_STR:
184
+				value = row->fld[i].v.lstr;
185
+				break;
186
+
187
+			case DB_INT:
188
+				value.len = sprintf(buf, "%d", row->fld[i].v.int4);
189
+				value.s = buf;
190
+				break;
191
+
192
+			default:
193
+				abort();
194
+				break;
200 195
 		}
201 196
 
202 197
 		if (value.s == NULL)
... ...
@@ -205,15 +200,16 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
205 200
 		iname.s = credentials[i - 2];
206 201
 		ivalue.s = value;
207 202
 
208
-		if (add_avp(AVP_NAME_STR | AVP_VAL_STR | AVP_CLASS_USER, iname, ivalue) < 0) {
209
-			LOG(L_ERR, "auth_db:generate_avps: Error while creating AVPs\n");
203
+		if (add_avp(AVP_NAME_STR | AVP_VAL_STR | AVP_CLASS_USER,
204
+					iname, ivalue) < 0) {
205
+			LM_ERR("Error while creating AVPs\n");
210 206
 			return -1;
211 207
 		}
212 208
 
213
-		DBG("auth_db:generate_avps: set string AVP \'%.*s = %.*s\'\n",
214
-			iname.s.len, ZSW(iname.s.s), value.len, ZSW(value.s));
209
+		LM_DBG("set string AVP \'%.*s = %.*s\'\n",
210
+				iname.s.len, ZSW(iname.s.s), value.len, ZSW(value.s));
215 211
 	}
216
-    
212
+
217 213
 	return 0;
218 214
 }
219 215
 
... ...
@@ -226,32 +222,32 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
226 222
  * WARNING: if -1 is returned res _must_ _not_ be freed (it's empty)
227 223
  *
228 224
  */
229
-static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr, 
230
-		dig_cred_t* dig, str* method, str* did, str* realm, 
231
-		authdb_table_info_t *table_info, db_res_t** res) 
225
+static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
226
+		dig_cred_t* dig, str* method, str* did, str* realm,
227
+		authdb_table_info_t *table_info, db_res_t** res)
232 228
 {
233 229
 	char ha1[256];
234 230
 	db_rec_t *row;
235 231
 	str result;
236 232
 	db_cmd_t *q;
237
-   
233
+
238 234
 	if (calc_ha1) {
239 235
 		q = table_info->query_password;
240
-		DBG("querying plain password\n");
236
+		LM_DBG("querying plain password\n");
241 237
 	}
242 238
 	else {
243
-	    if (dig->username.domain.len) {
239
+		if (dig->username.domain.len) {
244 240
 			q = table_info->query_pass2;
245
-			DBG("querying ha1b\n");
241
+			LM_DBG("querying ha1b\n");
246 242
 		}
247 243
 		else {
248 244
 			q = table_info->query_pass;
249
-			DBG("querying ha1\n");
245
+			LM_DBG("querying ha1\n");
250 246
 		}
251 247
 	}
252
-    
248
+
253 249
 	q->match[0].v.lstr = dig->username.user;
254
-	if (dig->username.domain.len) 
250
+	if (dig->username.domain.len)
255 251
 		q->match[1].v.lstr = dig->username.domain;
256 252
 	else
257 253
 		q->match[1].v.lstr = *realm;
... ...
@@ -259,15 +255,17 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
259 255
 	if (use_did) q->match[2].v.lstr = *did;
260 256
 
261 257
 	if (db_exec(res, q) < 0 ) {
262
-		ERR("Error while querying database\n");
258
+		LM_ERR("Error while querying database\n");
263 259
 	}
264 260
 
265 261
 	if (*res) row = db_first(*res);
266 262
 	else row = NULL;
267 263
 	while (row) {
268 264
 		if (IS_NULL(row->fld[0]) || IS_NULL(row->fld[1])) {
269
-			LOG(L_ERR, "auth_db:check_all_ha1: Credentials for '%.*s'@'%.*s' contain NULL value, skipping\n",
270
-			    dig->username.user.len, ZSW(dig->username.user.s), realm->len, ZSW(realm->s));
265
+			LM_ERR("Credentials for '%.*s'@'%.*s' contain NULL value,"
266
+					" skipping\n",
267
+					dig->username.user.len, ZSW(dig->username.user.s),
268
+					realm->len, ZSW(realm->s));
271 269
 		}
272 270
 		else {
273 271
 			if (row->fld[1].v.int4 & SRDB_DISABLED) {
... ...
@@ -278,17 +276,19 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
278 276
 					result.s = row->fld[0].v.cstr;
279 277
 					result.len = strlen(result.s);
280 278
 					if (calc_ha1) {
281
-						 /* Only plaintext passwords are stored in database,
282
-						  * we have to calculate HA1 */
283
-						auth_api.calc_HA1(HA_MD5, &(dig->username.whole), realm, &result, 0, 0, ha1);
284
-						DBG("auth_db:check_all_ha1: HA1 string calculated: %s\n", ha1);
279
+						/* Only plaintext passwords are stored in database,
280
+						 * we have to calculate HA1 */
281
+						auth_api.calc_HA1(HA_MD5, &(dig->username.whole),
282
+								realm, &result, 0, 0, ha1);
283
+						LM_DBG("HA1 string calculated: %s\n", ha1);
285 284
 					} else {
286 285
 						memcpy(ha1, result.s, result.len);
287 286
 						ha1[result.len] = '\0';
288 287
 					}
289 288
 
290 289
 					if (!check_response(dig, method, ha1)) {
291
-						if (auth_api.post_auth(msg, hdr, ha1) == AUTHENTICATED) {
290
+						if (auth_api.post_auth(msg, hdr, ha1)
291
+								== AUTHENTICATED) {
292 292
 							generate_avps(*res, row);
293 293
 							return 0;
294 294
 						}
... ...
@@ -300,9 +300,10 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
300 300
 	}
301 301
 
302 302
 	if (!row) {
303
-		DBG("auth_db:check_all_ha1: Credentials for '%.*s'@'%.*s' not found",
304
-		    dig->username.user.len, ZSW(dig->username.user.s), realm->len, ZSW(realm->s));
305
-	}		
303
+		LM_DBG("Credentials for '%.*s'@'%.*s' not found",
304
+				dig->username.user.len, ZSW(dig->username.user.s),
305
+				realm->len, ZSW(realm->s));
306
+	}
306 307
 	return 1;
307 308
 
308 309
 
... ...
@@ -317,7 +318,8 @@ static inline int check_all_ha1(struct sip_msg* msg, struct hdr_field* hdr,
317 318
  *      -1 -- Authentication failed
318 319
  *       1 -- Authentication successful
319 320
  */
320
-static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_info_t *table, hdr_types_t hftype)
321
+static inline int authenticate(struct sip_msg* msg, str* realm,
322
+		authdb_table_info_t *table, hdr_types_t hftype)
321 323
 {
322 324
 	char ha1[256];
323 325
 	int res, ret;
... ...
@@ -326,51 +328,51 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
326 328
 	auth_body_t* cred;
327 329
 	db_res_t* result;
328 330
 	str did;
329
-    
331
+
330 332
 	cred = 0;
331 333
 	result = 0;
332 334
 	ret = -1;
333
-    
335
+
334 336
 	switch(auth_api.pre_auth(msg, realm, hftype, &h, NULL)) {
335
-	case NONCE_REUSED:
336
-		LM_DBG("nonce reused");
337
-		ret = AUTH_NONCE_REUSED;
338
-		goto end;
339
-	case STALE_NONCE:
340
-		LM_DBG("stale nonce\n");
341
-		ret = AUTH_STALE_NONCE;
342
-		goto end;
343
-	case NO_CREDENTIALS:
344
-		LM_DBG("no credentials\n");
345
-		ret = AUTH_NO_CREDENTIALS;
346
-		goto end;
347
-	case ERROR:
348
-	case BAD_CREDENTIALS:
349
-		ret = -3;
350
-		goto end;
351
-	case CREATE_CHALLENGE:
352
-		ERR("auth_db:authenticate: CREATE_CHALLENGE is not a valid state\n");
353
-		ret = -2;
354
-		goto end;
355
-	case DO_RESYNCHRONIZATION:
356
-		ERR("auth_db:authenticate: DO_RESYNCHRONIZATION is not a valid state\n");
357
-		ret = -2;
358
-		goto end;
359
-		
360
-	case NOT_AUTHENTICATED: 
361
-		ret = -1;
362
-		goto end;
363
-		
364
-	case DO_AUTHENTICATION: 
365
-		break;
366
-		
367
-	case AUTHENTICATED:
368
-		ret = 1; 
369
-		goto end;
337
+		case NONCE_REUSED:
338
+			LM_DBG("nonce reused");
339
+			ret = AUTH_NONCE_REUSED;
340
+			goto end;
341
+		case STALE_NONCE:
342
+			LM_DBG("stale nonce\n");
343
+			ret = AUTH_STALE_NONCE;
344
+			goto end;
345
+		case NO_CREDENTIALS:
346
+			LM_DBG("no credentials\n");
347
+			ret = AUTH_NO_CREDENTIALS;
348
+			goto end;
349
+		case ERROR:
350
+		case BAD_CREDENTIALS:
351
+			ret = -3;
352
+			goto end;
353
+		case CREATE_CHALLENGE:
354
+			LM_ERR("CREATE_CHALLENGE is not a valid state\n");
355
+			ret = -2;
356
+			goto end;
357
+		case DO_RESYNCHRONIZATION:
358
+			LM_ERR("DO_RESYNCHRONIZATION is not a valid state\n");
359
+			ret = -2;
360
+			goto end;
361
+
362
+		case NOT_AUTHENTICATED:
363
+			ret = -1;
364
+			goto end;
365
+
366
+		case DO_AUTHENTICATION:
367
+			break;
368
+
369
+		case AUTHENTICATED:
370
+			ret = 1;
371
+			goto end;
370 372
 	}
371
-    
373
+
372 374
 	cred = (auth_body_t*)h->parsed;
373
-	
375
+
374 376
 	if (use_did) {
375 377
 		if (msg->REQ_METHOD == METHOD_REGISTER) {
376 378
 			ret = get_to_did(&did, msg);
... ...
@@ -384,11 +386,12 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
384 386
 	} else {
385 387
 		did.len = 0;
386 388
 		did.s = 0;
387
-	}	
388
-    
389
+	}
390
+
389 391
 
390 392
 	if (check_all) {
391
-		res = check_all_ha1(msg, h, &(cred->digest), &msg->first_line.u.request.method, &did, realm, table, &result);
393
+		res = check_all_ha1(msg, h, &(cred->digest),
394
+				&msg->first_line.u.request.method, &did, realm, table, &result);
392 395
 		if (res < 0) {
393 396
 			ret = -2;
394 397
 			goto end;
... ...
@@ -401,8 +404,9 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
401 404
 			ret = 1;
402 405
 			goto end;
403 406
 		}
404
-    	} else {
405
-		res = get_ha1(&cred->digest.username, &did, realm, table, ha1, &result, &row);
407
+	} else {
408
+		res = get_ha1(&cred->digest.username, &did, realm, table, ha1,
409
+				&result, &row);
406 410
 		if (res < 0) {
407 411
 			ret = -2;
408 412
 			goto end;
... ...
@@ -411,39 +415,41 @@ static inline int authenticate(struct sip_msg* msg, str* realm, authdb_table_inf
411 415
 			/* Username not found in the database */
412 416
 			ret = -1;
413 417
 			goto end;
414
-        	}
415
-    	}
416
-    
418
+		}
419
+	}
420
+
417 421
 	/* Recalculate response, it must be same to authorize successfully */
418
-	if (!check_response(&(cred->digest), &msg->first_line.u.request.method, ha1)) {
422
+	if (!check_response(&(cred->digest), &msg->first_line.u.request.method,
423
+				ha1)) {
419 424
 		switch(auth_api.post_auth(msg, h, ha1)) {
420
-		case ERROR:
421
-		case BAD_CREDENTIALS:
422
-			ret = -2; 
423
-			break;
424
-			
425
-		case NOT_AUTHENTICATED: 
426
-			ret = -1; 
427
-			break;
428
-			
429
-		case AUTHENTICATED:
430
-			generate_avps(result, row);
431
-			ret = 1;
432
-			break;
433
-			
434
-		default:
435
-			ret = -1;
436
-			break;
425
+			case ERROR:
426
+			case BAD_CREDENTIALS:
427
+				ret = -2;
428
+				break;
429
+
430
+			case NOT_AUTHENTICATED:
431
+				ret = -1;
432
+				break;
433
+
434
+			case AUTHENTICATED:
435
+				generate_avps(result, row);
436
+				ret = 1;
437
+				break;
438
+
439
+			default:
440
+				ret = -1;
441
+				break;
437 442
 		}
438 443
 	} else {
439 444
 		ret = -1;
440 445
 	}
441 446
 
442
- end:
447
+end:
443 448
 	if (result) db_res_free(result);
444 449
 	if (ret < 0) {
445
-		if (auth_api.build_challenge(msg, (cred ? cred->stale : 0), realm, NULL, NULL, hftype) < 0) {
446
-			ERR("Error while creating challenge\n");
450
+		if (auth_api.build_challenge(msg, (cred ? cred->stale : 0), realm,
451
+					NULL, NULL, hftype) < 0) {
452
+			LM_ERR("Error while creating challenge\n");
447 453
 			ret = -2;
448 454
 		}
449 455
 	}
... ...
@@ -459,7 +465,8 @@ int proxy_authenticate(struct sip_msg* msg, char* p1, char* p2)
459 465
 	str realm;
460 466
 
461 467
 	if (get_str_fparam(&realm, msg, (fparam_t*)p1) < 0) {
462
-		ERR("Cannot obtain digest realm from parameter '%s'\n", ((fparam_t*)p1)->orig);
468
+		LM_ERR("Cannot obtain digest realm from parameter '%s'\n",
469
+				((fparam_t*)p1)->orig);
463 470
 		return -1;
464 471
 	}
465 472
 
... ...
@@ -475,9 +482,11 @@ int www_authenticate(struct sip_msg* msg, char* p1, char* p2)
475 482
 	str realm;
476 483
 
477 484
 	if (get_str_fparam(&realm, msg, (fparam_t*)p1) < 0) {
478
-		ERR("Cannot obtain digest realm from parameter '%s'\n", ((fparam_t*)p1)->orig);
485
+		LM_ERR("Cannot obtain digest realm from parameter '%s'\n",
486
+				((fparam_t*)p1)->orig);
479 487
 		return -1;
480 488
 	}
481 489
 
482
-	return authenticate(msg, &realm, (authdb_table_info_t*)p2, HDR_AUTHORIZATION_T);
490
+	return authenticate(msg, &realm, (authdb_table_info_t*)p2,
491
+			HDR_AUTHORIZATION_T);
483 492
 }
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Digest Authentication - Database support
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -22,8 +20,8 @@
22 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 21
  * GNU General Public License for more details.
24 22
  *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
27 25
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 26
  */
29 27
 
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Digest Authentication Module
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -26,14 +24,6 @@
26 24
  * along with this program; if not, write to the Free Software
27 25
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 26
  *
29
- * History:
30
- * --------
31
- * 2003-02-26: checks and group moved to separate modules (janakj)
32
- * 2003-03-11: New module interface (janakj)
33
- * 2003-03-16: flags export parameter added (janakj)
34
- * 2003-03-19  all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei)
35
- * 2003-04-05: default_uri #define used (jiri)
36
- * 2004-06-06  cleanup: static & auth_db_{init,bind,close.ver} used (andrei)
37 27
  */
38 28
 
39 29
 #include <stdio.h>
... ...
@@ -113,11 +103,11 @@ int credentials_n;         /* Number of credentials in the list */
113 103
  * Exported functions
114 104
  */
115 105
 static cmd_export_t cmds[] = {
116
-    {"www_authenticate",   www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
117
-    {"www_authorize",      www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
118
-    {"proxy_authenticate", proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
119
-    {"proxy_authorize",    proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
120
-    {0, 0, 0, 0, 0}
106
+	{"www_authenticate",   www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
107
+	{"www_authorize",      www_authenticate,    2, authdb_fixup, REQUEST_ROUTE},
108
+	{"proxy_authenticate", proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
109
+	{"proxy_authorize",    proxy_authenticate,  2, authdb_fixup, REQUEST_ROUTE},
110
+	{0, 0, 0, 0, 0}
121 111
 };
122 112
 
123 113
 
... ...
@@ -125,19 +115,19 @@ static cmd_export_t cmds[] = {
125 115
  * Exported parameters
126 116
  */
127 117
 static param_export_t params[] = {
128
-    {"db_url",            PARAM_STRING, &db_url          },
129
-    {"username_column",   PARAM_STR,    &username_column },
130
-    {"did_column",        PARAM_STR,    &did_column      },
131
-    {"realm_column",      PARAM_STR,    &realm_column    },
132
-    {"password_column",   PARAM_STR,    &pass_column     },
133
-    {"password_column_2", PARAM_STR,    &pass_column_2   },
134
-    {"plain_password_column",   PARAM_STR,    &plain_password_column },
135
-    {"flags_column",      PARAM_STR,    &flags_column    },
136
-    {"calculate_ha1",     PARAM_INT,    &calc_ha1        },
137
-    {"load_credentials",  PARAM_STR,    &credentials_list},
138
-    {"use_did",           PARAM_INT,    &use_did         },
139
-    {"check_all_ha1",     PARAM_INT,    &check_all       },
140
-    {0, 0, 0}
118
+	{"db_url",            PARAM_STRING, &db_url          },
119
+	{"username_column",   PARAM_STR,    &username_column },
120
+	{"did_column",        PARAM_STR,    &did_column      },
121
+	{"realm_column",      PARAM_STR,    &realm_column    },
122
+	{"password_column",   PARAM_STR,    &pass_column     },
123
+	{"password_column_2", PARAM_STR,    &pass_column_2   },
124
+	{"plain_password_column",   PARAM_STR,    &plain_password_column },
125
+	{"flags_column",      PARAM_STR,    &flags_column    },
126
+	{"calculate_ha1",     PARAM_INT,    &calc_ha1        },
127
+	{"load_credentials",  PARAM_STR,    &credentials_list},
128
+	{"use_did",           PARAM_INT,    &use_did         },
129
+	{"check_all_ha1",     PARAM_INT,    &check_all       },
130
+	{0, 0, 0}
141 131
 };
142 132
 
143 133
 
... ...
@@ -145,15 +135,15 @@ static param_export_t params[] = {
145 135
  * Module interface
146 136
  */
147 137
 struct module_exports exports = {
148
-    "uid_auth_db",
149
-    cmds,       /* Exported functions */
150
-    0,          /* RPC methods */
151
-    params,     /* Exported parameters */
152
-    mod_init,   /* module initialization function */
153
-    0,          /* response function */
154
-    destroy,    /* destroy function */
155
-    0,          /* oncancel function */
156
-    child_init  /* child initialization function */
138
+	"uid_auth_db",
139
+	cmds,       /* Exported functions */
140
+	0,          /* RPC methods */
141
+	params,     /* Exported parameters */
142
+	mod_init,   /* module initialization function */
143
+	0,          /* response function */
144
+	destroy,    /* destroy function */
145
+	0,          /* oncancel function */
146
+	child_init  /* child initialization function */
157 147
 };
158 148
 
159 149
 static authdb_table_info_t *registered_tables = NULL;
... ...
@@ -161,14 +151,14 @@ static authdb_table_info_t *registered_tables = NULL;
161 151
 static int generate_queries(authdb_table_info_t *info)
162 152
 {
163 153
 	db_fld_t match_with_did[] = {
164
-		{ .name = username_column.s, .type = DB_STR }, 
165
-		{ .name = realm_column.s, .type = DB_STR }, 
166
-		{ .name = did_column.s, .type = DB_STR }, 
154
+		{ .name = username_column.s, .type = DB_STR },
155
+		{ .name = realm_column.s, .type = DB_STR },
156
+		{ .name = did_column.s, .type = DB_STR },
167 157
 		{ .name = NULL }
168 158
 	};
169 159
 	db_fld_t match_without_did[] = {
170
-		{ .name = username_column.s, .type = DB_STR }, 
171
-		{ .name = realm_column.s, .type = DB_STR }, 
160
+		{ .name = username_column.s, .type = DB_STR },
161
+		{ .name = realm_column.s, .type = DB_STR },
172 162
 		{ .name = NULL }
173 163
 	};
174 164
 	db_fld_t *result_cols = NULL;
... ...
@@ -184,7 +174,7 @@ static int generate_queries(authdb_table_info_t *info)
184 174
 
185 175
 	result_cols[0].name = pass_column.s;
186 176
 	result_cols[0].type = DB_CSTR;
187
-	
177
+
188 178
 	result_cols[1].name = flags_column.s;
189 179
 	result_cols[1].type = DB_INT;
190 180
 	for (i = 0; i < credentials_n; i++) {
... ...
@@ -194,23 +184,23 @@ static int generate_queries(authdb_table_info_t *info)
194 184
 	result_cols[2 + i].name = NULL;
195 185
 
196 186
 	if (use_did) {
197
-		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s, 
187
+		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s,
198 188
 				result_cols, match_with_did, NULL);
199 189
 		result_cols[0].name = pass_column_2.s;
200
-		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s, 
190
+		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s,
201 191
 				result_cols, match_with_did, NULL);
202 192
 		result_cols[0].name = plain_password_column.s;
203
-		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s, 
193
+		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s,
204 194
 				result_cols, match_with_did, NULL);
205 195
 	}
206 196
 	else {
207
-		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s, 
197
+		info->query_pass = db_cmd(DB_GET, auth_db_handle, info->table.s,
208 198
 				result_cols, match_without_did, NULL);
209 199
 		result_cols[0].name = pass_column_2.s;
210
-		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s, 
200
+		info->query_pass2 = db_cmd(DB_GET, auth_db_handle, info->table.s,
211 201
 				result_cols, match_without_did, NULL);
212 202
 		result_cols[0].name = plain_password_column.s;
213
-		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s, 
203
+		info->query_password = db_cmd(DB_GET, auth_db_handle, info->table.s,
214 204
 				result_cols, match_without_did, NULL);
215 205
 	}
216 206
 
... ...
@@ -235,12 +225,12 @@ static int child_init(int rank)
235 225
 	i = registered_tables;
236 226
 	while (i) {
237 227
 		if (generate_queries(i) < 0) {
238
-			ERR("can't prepare queries\n");
228
+			LM_ERR("can't prepare queries\n");
239 229
 			return -1;
240 230
 		}
241 231
 		i = i->next;
242 232
 	}
243
-    
233
+
244 234
 	return 0;
245 235
 
246 236
 err:
... ...
@@ -250,56 +240,56 @@ err:
250 240
 		db_ctx_free(auth_db_handle);
251 241
 	}
252 242
 
253
-	ERR("Error while initializing database layer\n");
243
+	LM_ERR("Error while initializing database layer\n");
254 244
 	return -1;
255 245
 }
256 246
 
257 247
 
258 248
 static int mod_init(void)
259 249
 {
260
-    bind_auth_s_t bind_auth;
261
-    
262
-    DBG("auth_db module - initializing\n");
263
-    
264
-    bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
265
-    if (!bind_auth) {
266
-	LOG(L_ERR, "auth_db:mod_init: Unable to find bind_auth function\n");
267
-	return -1;
268
-    }
269
-    if (bind_auth(&auth_api) < 0) {
270
-	LOG(L_ERR, "auth_db:child_init: Unable to bind auth module\n");
271
-	return -3;
272
-    }
273
-    
274
-    if (aaa_avps_init(&credentials_list, &credentials, &credentials_n)) {
275
-	return -1;
276
-    }
277
-    
278
-    return 0;
250
+	bind_auth_s_t bind_auth;
251
+
252
+	LM_DBG("auth_db module - initializing\n");
253
+
254
+	bind_auth = (bind_auth_s_t)find_export("bind_auth_s", 0, 0);
255
+	if (!bind_auth) {
256
+		LM_ERR("Unable to find bind_auth function\n");
257
+		return -1;
258
+	}
259
+	if (bind_auth(&auth_api) < 0) {
260
+		LM_ERR("Unable to bind auth module\n");
261
+		return -3;
262
+	}
263
+
264
+	if (aaa_avps_init(&credentials_list, &credentials, &credentials_n)) {
265
+		return -1;
266
+	}
267
+
268
+	return 0;
279 269
 }
280 270
 
281 271
 
282 272
 static void destroy(void)
283 273
 {
284
-    if (auth_db_handle) {
274
+	if (auth_db_handle) {
285 275
 		db_ctx_free(auth_db_handle);
286 276
 		auth_db_handle = NULL;
287
-    }
277
+	}
288 278
 }
289 279
 
290 280
 static int str_case_equals(const str *a, const str *b)
291 281
 {
292 282
 	/* ugly hack: taken from libcds */
293 283
 	int i;
294
-	
284
+
295 285
 	if (!a) {
296 286
 		if (!b) return 0;
297 287
 		else return (b->len == 0) ? 0 : 1;
298 288
 	}
299 289
 	if (!b) return (a->len == 0) ? 0 : 1;
300 290
 	if (a->len != b->len) return 1;
301
-	
302
-	for (i = 0; i < a->len; i++) 
291
+
292
+	for (i = 0; i < a->len; i++)
303 293
 		if (a->s[i] != b->s[i]) return 1;
304 294
 	return 0;
305 295
 }
... ...
@@ -307,9 +297,9 @@ static int str_case_equals(const str *a, const str *b)
307 297
 static authdb_table_info_t *find_table_info(str *table)
308 298
 {
309 299
 	authdb_table_info_t *i = registered_tables;
310
-	
300
+
311 301
 	/* sequential search is OK because it is called only in child init */
312
-	while (i) { 
302
+	while (i) {
313 303
 		if (str_case_equals(&i->table, table) == 0) return i;
314 304
 		i = i->next;
315 305
 	}
... ...
@@ -323,9 +313,10 @@ static authdb_table_info_t *register_table(str *table)
323 313
 	info = find_table_info(table);
324 314
 	if (info) return info; /* queries for this table already exist */
325 315
 
326
-	info = (authdb_table_info_t*)pkg_malloc(sizeof(authdb_table_info_t) + table->len + 1);
316
+	info = (authdb_table_info_t*)pkg_malloc(sizeof(authdb_table_info_t)
317
+			+ table->len + 1);
327 318
 	if (!info) {
328
-		ERR("can't allocate pkg mem\n");
319
+		LM_ERR("can't allocate pkg mem\n");
329 320
 		return NULL;
330 321
 	}
331 322
 
... ...
@@ -359,11 +350,12 @@ static int authdb_fixup(void** param, int param_no)
359 350
 				return -1;
360 351
 			}
361 352
 		} else {
362
-			ERR("Non-string value of table with credentials is not allowed.\n");
353
+			LM_ERR("Non-string value of table with credentials"
354
+					" is not allowed.\n");
363 355
 			/* TODO: allow this too */
364 356
 			return -1;
365 357
 		}
366 358
 	}
367 359
 
368
-    return 0;
360
+	return 0;
369 361
 }
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Digest Authentication - Database support
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -22,8 +20,8 @@
22 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 21
  * GNU General Public License for more details.
24 22
  *
25
- * You should have received a copy of the GNU General Public License 
26
- * along with this program; if not, write to the Free Software 
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program; if not, write to the Free Software
27 25
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
28 26
  */
29 27
 
... ...
@@ -45,8 +43,8 @@ extern str did_column;      /* 'did' column name */
45 43
 extern str realm_column;    /* 'realm' column name */
46 44
 extern str pass_column;     /* 'password' column name */
47 45
 extern str pass_column_2;   /* Column containing HA1 string constructed
48
-			     * of user@domain username
49
-			     */
46
+							 * of user@domain username
47
+							 */
50 48
 extern str flags_column;    /* Flags column in credentials table */
51 49
 
52 50
 extern int calc_ha1;          /* if set to 1, ha1 is calculated by the server */