Browse code

Merge branch '4.2' into lazedo/4.2.1

* 4.2:
exec: use proper header field iterator to print env variables
core: keep the password only if the user part is set
acc: free extra attributes for db, radius and diameter
modules/pua: do not override send_publish return value at error
nat_traversal: use dedicated function for testing via address against source ip
nathelper: use dedicated function for testing via address against source ip
core: dedicated function to check Via address with source ip

Luis Azedo authored on 07/12/2014 11:55:45
Showing 8 changed files
... ...
@@ -932,8 +932,8 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
932 932
 
933 933
 				if (a->type==SET_USERPASS_T) tmp=0;
934 934
 				else tmp=uri.passwd.s;
935
-				/* passwd */
936
-				if (tmp){
935
+				/* passwd - keep it only if user is set */
936
+				if (user && tmp){
937 937
 					len=uri.passwd.len; if(crt+len+1>end) goto error_uri;
938 938
 					*crt=':'; crt++;
939 939
 					memcpy(crt,tmp,len);crt+=len;
... ...
@@ -238,7 +238,6 @@ int acc_log_request( struct sip_msg *rq)
238 238
 
239 239
 	/* get extra values */
240 240
 	o += extra2strar( log_extra, rq, val_arr+m, int_arr+m, type_arr+m);
241
-
242 241
 	m += o;
243 242
 
244 243
 	for ( i=0,p=log_msg ; i<m ; i++ ) {
... ...
@@ -442,6 +441,7 @@ int acc_db_request( struct sip_msg *rq)
442 442
 	int m;
443 443
 	int n;
444 444
 	int i;
445
+	int o;
445 446
 	struct tm *t;
446 447
 
447 448
 	/* formated database columns */
... ...
@@ -476,14 +476,15 @@ int acc_db_request( struct sip_msg *rq)
476 476
 	}
477 477
 
478 478
 	/* extra columns */
479
-	m += extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);
479
+	o += extra2strar( db_extra, rq, val_arr+m, int_arr+m, type_arr+m);
480
+	m += o;
480 481
 
481 482
 	for( i++ ; i<m; i++)
482 483
 		VAL_STR(db_vals+i) = val_arr[i];
483 484
 
484 485
 	if (acc_dbf.use_table(db_handle, &acc_env.text/*table*/) < 0) {
485 486
 		LM_ERR("error in use_table\n");
486
-		return -1;
487
+		goto error;
487 488
 	}
488 489
 
489 490
 	/* multi-leg columns */
... ...
@@ -491,45 +492,51 @@ int acc_db_request( struct sip_msg *rq)
491 491
 		if(acc_db_insert_mode==1 && acc_dbf.insert_delayed!=NULL) {
492 492
 			if (acc_dbf.insert_delayed(db_handle, db_keys, db_vals, m) < 0) {
493 493
 				LM_ERR("failed to insert delayed into database\n");
494
-				return -1;
494
+				goto error;
495 495
 			}
496 496
 		} else if(acc_db_insert_mode==2 && acc_dbf.insert_async!=NULL) {
497 497
 			if (acc_dbf.insert_async(db_handle, db_keys, db_vals, m) < 0) {
498 498
 				LM_ERR("failed to insert async into database\n");
499
-				return -1;
499
+				goto error;
500 500
 			}
501 501
 		} else {
502 502
 			if (acc_dbf.insert(db_handle, db_keys, db_vals, m) < 0) {
503 503
 				LM_ERR("failed to insert into database\n");
504
-				return -1;
504
+				goto error;
505 505
 			}
506 506
 		}
507 507
 	} else {
508
-  	        n = legs2strar(leg_info,rq,val_arr+m,int_arr+m,type_arr+m,1);
508
+		n = legs2strar(leg_info,rq,val_arr+m,int_arr+m,type_arr+m,1);
509 509
 		do {
510 510
 			for (i=m; i<m+n; i++)
511 511
 				VAL_STR(db_vals+i)=val_arr[i];
512 512
 			if(acc_db_insert_mode==1 && acc_dbf.insert_delayed!=NULL) {
513 513
 				if(acc_dbf.insert_delayed(db_handle,db_keys,db_vals,m+n)<0) {
514 514
 					LM_ERR("failed to insert delayed into database\n");
515
-					return -1;
515
+					goto error;
516 516
 				}
517 517
 			} else if(acc_db_insert_mode==2 && acc_dbf.insert_async!=NULL) {
518 518
 				if(acc_dbf.insert_async(db_handle,db_keys,db_vals,m+n)<0) {
519 519
 					LM_ERR("failed to insert async into database\n");
520
-					return -1;
520
+					goto error;
521 521
 				}
522 522
 			} else {
523 523
 				if (acc_dbf.insert(db_handle, db_keys, db_vals, m+n) < 0) {
524 524
 					LM_ERR("failed to insert into database\n");
525
-					return -1;
525
+					goto error;
526 526
 				}
527 527
 			}
528 528
 		}while ( (n=legs2strar(leg_info,rq,val_arr+m,int_arr+m,
529 529
 				       type_arr+m,0))!=0 );
530 530
 	}
531 531
 
532
+	/* free memory allocated by extra2strar */
533
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
532 534
 	return 1;
535
+error:
536
+	/* free memory allocated by extra2strar */
537
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
538
+	return -1;
533 539
 }
534 540
 
535 541
 #endif
... ...
@@ -651,6 +658,8 @@ int acc_rad_request( struct sip_msg *req )
651 651
 	UINT4 av_type;
652 652
 	int offset;
653 653
 	int i;
654
+	int m;
655
+	int o;
654 656
 
655 657
 	send=NULL;
656 658
 
... ...
@@ -675,8 +684,10 @@ int acc_rad_request( struct sip_msg *req )
675 675
 	ADD_RAD_AVPAIR( RA_TIME_STAMP, &av_type, -1);
676 676
 
677 677
 	/* add extra also */
678
-	attr_cnt += extra2strar(rad_extra, req, val_arr+attr_cnt,
678
+	o = extra2strar(rad_extra, req, val_arr+attr_cnt,
679 679
 				int_arr+attr_cnt, type_arr+attr_cnt);
680
+	attr_cnt += o;
681
+	m = attr_cnt;
680 682
 
681 683
 	/* add the values for the vector - start from 1 instead of
682 684
 	 * 0 to skip the first value which is the METHOD as string */
... ...
@@ -710,10 +721,14 @@ int acc_rad_request( struct sip_msg *req )
710 710
 		goto error;
711 711
 	}
712 712
 	rc_avpair_free(send);
713
+	/* free memory allocated by extra2strar */
714
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
713 715
 	return 1;
714 716
 
715 717
 error:
716 718
 	rc_avpair_free(send);
719
+	/* free memory allocated by extra2strar */
720
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
717 721
 	return -1;
718 722
 }
719 723
 
... ...
@@ -793,6 +808,8 @@ int acc_diam_request( struct sip_msg *req )
793 793
 	int status;
794 794
 	char tmp[2];
795 795
 	unsigned int mid;
796
+	int m;
797
+	int o;
796 798
 
797 799
 	attr_cnt = core2strar( req, val_arr, int_arr, type_arr );
798 800
 	/* last value is not used */
... ...
@@ -803,6 +820,8 @@ int acc_diam_request( struct sip_msg *req )
803 803
 		return -1;
804 804
 	}
805 805
 
806
+	m = 0;
807
+	o = 0;
806 808
 	/* AVP_ACCOUNTIG_RECORD_TYPE */
807 809
 	if( (status = diam_status(req, acc_env.code))<0) {
808 810
 		LM_ERR("status unknown\n");
... ...
@@ -846,7 +865,9 @@ int acc_diam_request( struct sip_msg *req )
846 846
 	}
847 847
 
848 848
 	/* also the extra attributes */
849
-	attr_cnt += extra2strar( dia_extra, req, val_arr, int_arr, type_arr);
849
+	o = extra2strar( dia_extra, req, val_arr, int_arr, type_arr);
850
+	attr_cnt += o;
851
+	m = attr_cnt;
850 852
 
851 853
 	/* add attributes */
852 854
 	for(i=0; i<attr_cnt; i++) {
... ...
@@ -937,10 +958,14 @@ int acc_diam_request( struct sip_msg *req )
937 937
 	}
938 938
 
939 939
 	AAAFreeMessage(&send);
940
+	/* free memory allocated by extra2strar */
941
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
940 942
 	return 1;
941 943
 
942 944
 error:
943 945
 	AAAFreeMessage(&send);
946
+	/* free memory allocated by extra2strar */
947
+	free_strar_mem( &(type_arr[m-o]), &(val_arr[m-o]), o, m);
944 948
 	return -1;
945 949
 }
946 950
 
... ...
@@ -258,21 +258,23 @@ static int print_hf_var(struct hf_wrapper *w, int offset)
258 258
 	memcpy(envvar, w->prefix, w->prefix_len); c=envvar+w->prefix_len;
259 259
 	memcpy(c, hname, hlen ); c+=hlen;
260 260
 	*c=EV_ASSIGN;c++;
261
-	if (exec_bash_safety && !strncmp(w->u.hf->body.s,"() {",MIN(w->u.hf->body.len,4))) {
261
+	if (exec_bash_safety && !strncmp(w->u.hf->body.s, "() {",
262
+				MIN(w->u.hf->body.len,4))) {
262 263
 		memcpy(c, w->u.hf->body.s+offset+2, w->u.hf->body.len-2 );
263 264
 		c+=(w->u.hf->body.len-2);
264 265
 	} else {
265 266
 		memcpy(c, w->u.hf->body.s+offset, w->u.hf->body.len );
266 267
 		c+=w->u.hf->body.len;
267 268
 	}
268
-	for (wi=w->next_same; wi; wi=wi->next_same) {
269
+	for(wi=w->next_same; wi; wi=wi->next_same) {
269 270
 		*c=HF_SEPARATOR;c++;
270
-		if (exec_bash_safety && !strncmp(w->u.hf->body.s,"() {",MIN(w->u.hf->body.len,4))) {
271
-			memcpy(c, w->u.hf->body.s+offset+2, w->u.hf->body.len-2 );
272
-			c+=(w->u.hf->body.len-2);
271
+		if (exec_bash_safety && !strncmp(wi->u.hf->body.s, "() {",
272
+					MIN(w->u.hf->body.len,4))) {
273
+			memcpy(c, wi->u.hf->body.s+offset+2, wi->u.hf->body.len-2 );
274
+			c+=(wi->u.hf->body.len-2);
273 275
 		} else {
274
-			memcpy(c, w->u.hf->body.s+offset, w->u.hf->body.len );
275
-			c+=w->u.hf->body.len;
276
+			memcpy(c, wi->u.hf->body.s+offset, wi->u.hf->body.len );
277
+			c+=wi->u.hf->body.len;
276 278
 		}
277 279
 	}
278 280
 	*c=0; /* zero termination */
... ...
@@ -820,7 +820,7 @@ test_source_address(struct sip_msg *msg)
820 820
     Bool different_ip, different_port;
821 821
     int via1_port;
822 822
 
823
-    different_ip = received_test(msg);
823
+    different_ip = received_via_test(msg);
824 824
     via1_port = (msg->via1->port ? msg->via1->port : SIP_PORT);
825 825
     different_port = (msg->rcv.src_port != via1_port);
826 826
 
... ...
@@ -1556,7 +1556,7 @@ nat_uac_test_f(struct sip_msg* msg, char* str1, char* str2)
1556 1556
 	 * test if source address of signaling is different from
1557 1557
 	 * address advertised in Via
1558 1558
 	 */
1559
-	if ((tests & NAT_UAC_TEST_RCVD) && received_test(msg))
1559
+	if ((tests & NAT_UAC_TEST_RCVD) && received_via_test(msg))
1560 1560
 		return 1;
1561 1561
 	/*
1562 1562
 	 * test for occurrences of RFC1918 addresses in Contact
... ...
@@ -716,7 +716,6 @@ done:
716 716
 	goto finish;
717 717
 
718 718
 error:
719
-	ret = -1;
720 719
 	if(cb_param)
721 720
 		shm_free(cb_param);
722 721
 
... ...
@@ -252,7 +252,8 @@ static int check_via_address(struct ip_addr* ip, str *name,
252 252
 }
253 253
 
254 254
 
255
-/* check if IP address in Via != source IP address of signaling */
255
+/* check if IP address in Via != source IP address of signaling,
256
+ * or the sender requires adding rport or received values */
256 257
 int received_test( struct sip_msg *msg )
257 258
 {
258 259
 	int rcvd;
... ...
@@ -263,6 +264,15 @@ int received_test( struct sip_msg *msg )
263 263
 	return rcvd;
264 264
 }
265 265
 
266
+/* check if IP address in Via != source IP address of signaling */
267
+int received_via_test( struct sip_msg *msg )
268
+{
269
+	int rcvd;
270
+
271
+	rcvd = (check_via_address(&msg->rcv.src_ip, &msg->via1->host,
272
+							msg->via1->port, received_dns)!=0);
273
+	return rcvd;
274
+}
266 275
 
267 276
 static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
268 277
 {
... ...
@@ -129,9 +129,13 @@ int branch_builder( unsigned int hash_index,
129 129
 
130 130
 char* id_builder(struct sip_msg* msg, unsigned int *id_len);
131 131
 
132
-/* check if IP address in Via != source IP address of signaling */
132
+/* check if IP address in Via != source IP address of signaling,
133
+ * or the sender is asking to set the values for rport or received */
133 134
 int received_test( struct sip_msg *msg );
134 135
 
136
+/* check if IP address in Via != source IP address of signaling */
137
+int received_via_test( struct sip_msg *msg );
138
+
135 139
 /* builds a char* buffer from message headers without body
136 140
  * first line is excluded in case of skip_first_line=1
137 141
  */