Browse code

- F_MALLOC - fixed seg. fault when parsing cfg., if tls commands are encountered and no tls support is compiled in

Andrei Pelinescu-Onciul authored on 16/11/2003 16:21:12
Showing 2 changed files
... ...
@@ -278,6 +278,7 @@ DEFS+= $(extra_defs) \
278 278
 	 -DUSE_IPV6 \
279 279
 	 -DUSE_TCP \
280 280
 	 -DDISABLE_NAGLE \
281
+	 -DF_MALLOC \
281 282
 	# -DDBG_QM_MALLOC \
282 283
 	# -DF_MALLOC \
283 284
 	# -DDBG_F_MALLOC \
... ...
@@ -46,9 +46,6 @@
46 46
  * 2003-10-10  added <,>,<=,>=, != operators support
47 47
  *             added msg:len (andrei)
48 48
  * 2003-10-11  if(){} doesn't require a ';' after it anymore (andrei)
49
- * 2003-10-13  added FIFO_DIR & proto:host:port listen/alias support (andrei)
50
- * 2003-10-24  converted to the new socket_info lists (andrei)
51
- * 2003-10-28  added tcp_accept_aliases (andrei)
52 49
  */
53 50
 
54 51
 
... ...
@@ -69,11 +66,9 @@
69 69
 #include "sr_module.h"
70 70
 #include "modparam.h"
71 71
 #include "ip_addr.h"
72
-#include "socket_info.h"
73 72
 #include "name_alias.h"
74 73
 #include "ut.h"
75 74
 
76
-
77 75
 #include "config.h"
78 76
 #ifdef USE_TLS
79 77
 #include "tls/tls_config.h"
... ...
@@ -88,9 +83,7 @@
88 88
 #undef _ALLOCA_H
89 89
 
90 90
 struct id_list{
91
-	char* name;
92
-	int proto;
93
-	int port;
91
+	char* s;
94 92
 	struct id_list* next;
95 93
 };
96 94
 
... ...
@@ -104,7 +97,6 @@ static int rt;  /* Type of route block for find_export */
104 104
 static str* str_tmp;
105 105
 
106 106
 void warn(char* s);
107
-static struct id_list* mk_listen_id(char*, int, int);
108 107
  
109 108
 
110 109
 %}
... ...
@@ -149,7 +141,6 @@ static struct id_list* mk_listen_id(char*, int, int);
149 149
 %token SET_URI
150 150
 %token REVERT_URI
151 151
 %token FORCE_RPORT
152
-%token FORCE_TCP_ALIAS
153 152
 %token IF
154 153
 %token ELSE
155 154
 %token SET_ADV_ADDRESS
... ...
@@ -170,9 +161,6 @@ static struct id_list* mk_listen_id(char*, int, int);
170 170
 %token AF
171 171
 %token MYSELF
172 172
 %token MSGLEN 
173
-%token UDP
174
-%token TCP
175
-%token TLS
176 173
 
177 174
 /* config vars. */
178 175
 %token DEBUG
... ...
@@ -190,9 +178,7 @@ static struct id_list* mk_listen_id(char*, int, int);
190 190
 %token MEMLOG
191 191
 %token SIP_WARNING
192 192
 %token FIFO
193
-%token FIFO_DIR
194 193
 %token FIFO_MODE
195
-%token FIFO_DB_URL
196 194
 %token SERVER_SIGNATURE
197 195
 %token REPLY_TO_VIA
198 196
 %token LOADMODULE
... ...
@@ -204,7 +190,6 @@ static struct id_list* mk_listen_id(char*, int, int);
204 204
 %token WDIR
205 205
 %token MHOMED
206 206
 %token DISABLE_TCP
207
-%token TCP_ACCEPT_ALIASES
208 207
 %token TCP_CHILDREN
209 208
 %token DISABLE_TLS
210 209
 %token TLSLOG
... ...
@@ -257,20 +242,16 @@ static struct id_list* mk_listen_id(char*, int, int);
257 257
 %token SLASH
258 258
 %token DOT
259 259
 %token CR
260
-%token COLON
261
-%token STAR
262 260
 
263 261
 
264 262
 /*non-terminals */
265 263
 %type <expr> exp exp_elem /*, condition*/
266 264
 %type <action> action actions cmd if_cmd stm
267
-%type <ipaddr> ipv4 ipv6 ipv6addr ip
265
+%type <ipaddr> ipv4 ipv6 ip
268 266
 %type <ipnet> ipnet
269 267
 %type <strval> host
270 268
 %type <strval> listen_id
271 269
 %type <idlst>  id_lst
272
-%type <idlst>  phostport
273
-%type <intval> proto port
274 270
 %type <intval> equalop strop intop
275 271
 /*%type <route_el> rules;
276 272
   %type <route_el> rule;
... ...
@@ -331,25 +312,23 @@ listen_id:	ip			{	tmp=ip_addr2a($1);
331 331
 						}
332 332
 	;
333 333
 
334
-proto:	  UDP	{ $$=PROTO_UDP; }
335
-		| TCP	{ $$=PROTO_TCP; }
336
-		| TLS	{ $$=PROTO_TLS; }
337
-		| STAR	{ $$=0; }
338
-		;
339
-
340
-port:	  NUMBER	{ $$=$1; }
341
-		| STAR		{ $$=0; }
342
-;
343
-
344
-phostport:	listen_id				{ $$=mk_listen_id($1, 0, 0); }
345
-			| listen_id COLON port	{ $$=mk_listen_id($1, 0, $3); }
346
-			| proto COLON listen_id	{ $$=mk_listen_id($3, $1, 0); }
347
-			| proto COLON listen_id COLON port	{ $$=mk_listen_id($3, $1, $5);}
348
-			| listen_id COLON error { $$=0; yyerror(" port number expected"); }
349
-			;
350
-
351
-id_lst:		phostport		{  $$=$1 ; }
352
-		| phostport id_lst	{ $$=$1; $$->next=$2; }
334
+id_lst:	  listen_id	{	$$=pkg_malloc(sizeof(struct id_list));
335
+						if ($$==0){
336
+							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
337
+						}else{
338
+							$$->s=$1;
339
+							$$->next=0;
340
+						}
341
+					}
342
+		| listen_id id_lst	{
343
+						$$=pkg_malloc(sizeof(struct id_list));
344
+						if ($$==0){
345
+							LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
346
+						}else{
347
+							$$->s=$1;
348
+							$$->next=$2;
349
+						}
350
+							}
353 351
 		;
354 352
 
355 353
 
... ...
@@ -363,7 +342,10 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
363 363
 		| DNS EQUAL error { yyerror("boolean value expected"); }
364 364
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
365 365
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
366
-		| PORT EQUAL NUMBER   { port_no=$3; }
366
+		| PORT EQUAL NUMBER   { port_no=$3; 
367
+								if (sock_no>0) 
368
+									sock_info[sock_no-1].port_no=port_no;
369
+							  }
367 370
 		| STAT EQUAL STRING {
368 371
 					#ifdef STATS
369 372
 							stat_file=$3;
... ...
@@ -384,12 +366,8 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
384 384
 		| SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
385 385
 		| FIFO EQUAL STRING { fifo=$3; }
386 386
 		| FIFO EQUAL error { yyerror("string value expected"); }
387
-		| FIFO_DIR EQUAL STRING { fifo_dir=$3; }
388
-		| FIFO_DIR EQUAL error { yyerror("string value expected"); }
389 387
 		| FIFO_MODE EQUAL NUMBER { fifo_mode=$3; }
390 388
 		| FIFO_MODE EQUAL error { yyerror("int value expected"); }
391
-		| FIFO_DB_URL EQUAL STRING { fifo_db_url=$3; }
392
-		| FIFO_DB_URL EQUAL error { yyerror("string value expected"); }
393 389
 		| USER EQUAL STRING     { user=$3; }
394 390
 		| USER EQUAL ID         { user=$3; }
395 391
 		| USER EQUAL error      { yyerror("string value expected"); }
... ...
@@ -412,14 +390,6 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
412 412
 									#endif
413 413
 									}
414 414
 		| DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
415
-		| TCP_ACCEPT_ALIASES EQUAL NUMBER {
416
-									#ifdef USE_TCP
417
-										tcp_accept_aliases=$3;
418
-									#else
419
-										warn("tcp support not compiled in");
420
-									#endif
421
-									}
422
-		| TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
423 415
 		| TCP_CHILDREN EQUAL NUMBER {
424 416
 									#ifdef USE_TCP
425 417
 										tcp_children_no=$3;
... ...
@@ -536,13 +506,26 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
536 536
 		| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
537 537
 		| LISTEN EQUAL id_lst {
538 538
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
539
-								if (add_listen_iface(	lst_tmp->name,
540
-														lst_tmp->port,
541
-														lst_tmp->proto,
542
-														0
543
-													)!=0){
544
-									LOG(L_CRIT,  "ERROR: cfg. parser: failed"
545
-											" to add listen address\n");
539
+								if (sock_no < MAX_LISTEN){
540
+									sock_info[sock_no].name.s=(char*)
541
+											pkg_malloc(strlen(lst_tmp->s)+1);
542
+									if (sock_info[sock_no].name.s==0){
543
+										LOG(L_CRIT, "ERROR: cfg. parser:"
544
+													" out of memory.\n");
545
+										break;
546
+									}else{
547
+										strncpy(sock_info[sock_no].name.s,
548
+												lst_tmp->s,
549
+												strlen(lst_tmp->s)+1);
550
+										sock_info[sock_no].name.len=
551
+													strlen(lst_tmp->s);
552
+										sock_info[sock_no].port_no=port_no;
553
+										sock_no++;
554
+									}
555
+								}else{
556
+									LOG(L_CRIT, "ERROR: cfg. parser: "
557
+												"too many listen addresses"
558
+												"(max. %d).\n", MAX_LISTEN);
546 559
 									break;
547 560
 								}
548 561
 							}
... ...
@@ -551,8 +534,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
551 551
 						"expected"); }
552 552
 		| ALIAS EQUAL  id_lst { 
553 553
 							for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next)
554
-								add_alias(lst_tmp->name, strlen(lst_tmp->name),
555
-											lst_tmp->port, lst_tmp->proto);
554
+								add_alias(lst_tmp->s, strlen(lst_tmp->s), 0);
556 555
 							  }
557 556
 		| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
558 557
 		| ADVERTISED_ADDRESS EQUAL listen_id {
... ...
@@ -637,7 +619,7 @@ ipv4:	NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
637 637
 												}
638 638
 	;
639 639
 
640
-ipv6addr:	IPV6ADDR {
640
+ipv6:	IPV6ADDR {
641 641
 					$$=pkg_malloc(sizeof(struct ip_addr));
642 642
 					if ($$==0){
643 643
 						LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
... ...
@@ -657,10 +639,6 @@ ipv6addr:	IPV6ADDR {
657 657
 				}
658 658
 	;
659 659
 
660
-ipv6:	ipv6addr { $$=$1; }
661
-	| LBRACK ipv6addr RBRACK {$$=$2; }
662
-;
663
-
664 660
 
665 661
 route_stm:  ROUTE LBRACE actions RBRACE { push($3, &rlist[DEFAULT_RT]); }
666 662
 
... ...
@@ -769,11 +747,9 @@ exp_elem:	METHOD strop STRING	{$$= mk_elem(	$2, STRING_ST,
769 769
 												DSTPORT_O, (void *) $3 ); }
770 770
 		| DSTPORT intop error { $$=0; yyerror("number expected"); }
771 771
 		| DSTPORT error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
772
-		| PROTO intop proto	{ $$=mk_elem(	$2, NUMBER_ST,
772
+		| PROTO intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
773 773
 												PROTO_O, (void *) $3 ); }
774
-		| PROTO intop error { $$=0;
775
-								yyerror("protocol expected (udp, tcp or tls)");
776
-							}
774
+		| PROTO intop error { $$=0; yyerror("number expected"); }
777 775
 		| PROTO error { $$=0; yyerror("equal/!= operator expected"); }
778 776
 		| AF intop NUMBER	{ $$=mk_elem(	$2, NUMBER_ST,
779 777
 												AF_O, (void *) $3 ); }
... ...
@@ -1103,6 +1079,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1103 1103
 														$3,
1104 1104
 														0);
1105 1105
 										#else
1106
+											$$=0;
1106 1107
 											yyerror("tls support not "
1107 1108
 													"compiled in");
1108 1109
 										#endif
... ...
@@ -1115,6 +1092,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1115 1115
 															$3,
1116 1116
 															0);
1117 1117
 										#else
1118
+											$$=0;
1118 1119
 											yyerror("tls support not "
1119 1120
 													"compiled in");
1120 1121
 										#endif
... ...
@@ -1127,6 +1105,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1127 1127
 															(void*)$3,
1128 1128
 															0);
1129 1129
 										#else
1130
+											$$=0;
1130 1131
 											yyerror("tls support not "
1131 1132
 													"compiled in");
1132 1133
 										#endif
... ...
@@ -1139,6 +1118,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1139 1139
 															$3,
1140 1140
 															(void*)$5);
1141 1141
 										#else
1142
+											$$=0;
1142 1143
 											yyerror("tls support not "
1143 1144
 													"compiled in");
1144 1145
 										#endif
... ...
@@ -1151,6 +1131,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1151 1151
 															$3,
1152 1152
 															(void*)$5);
1153 1153
 										#else
1154
+											$$=0;
1154 1155
 											yyerror("tls support not "
1155 1156
 													"compiled in");
1156 1157
 										#endif
... ...
@@ -1163,6 +1144,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1163 1163
 															 (void*)$3,
1164 1164
 															(void*)$5);
1165 1165
 										#else
1166
+											$$=0;
1166 1167
 											yyerror("tls support not "
1167 1168
 													"compiled in");
1168 1169
 										#endif
... ...
@@ -1175,6 +1157,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1175 1175
 															0,
1176 1176
 															0);
1177 1177
 										#else
1178
+											$$=0;
1178 1179
 											yyerror("tls support not "
1179 1180
 													"compiled in");
1180 1181
 										#endif
... ...
@@ -1189,6 +1172,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1189 1189
 															0,
1190 1190
 															(void*)$5);
1191 1191
 										#else
1192
+											$$=0;
1192 1193
 											yyerror("tls support not "
1193 1194
 													"compiled in");
1194 1195
 										#endif
... ...
@@ -1201,6 +1185,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1201 1201
 															0,
1202 1202
 															0);
1203 1203
 										#else
1204
+											$$=0;
1204 1205
 											yyerror("tls support not "
1205 1206
 													"compiled in");
1206 1207
 										#endif
... ...
@@ -1384,40 +1369,8 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1384 1384
 										"string expected"); }
1385 1385
 		| REVERT_URI LPAREN RPAREN { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1386 1386
 		| REVERT_URI { $$=mk_action( REVERT_URI_T, 0,0,0,0); }
1387
-		| FORCE_RPORT LPAREN RPAREN	{
1388
-							#ifdef USE_TCP
1389
-								$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); 
1390
-							#else
1391
-								yyerror("tcp support not compiled in");
1392
-							#endif
1393
-							}
1387
+		| FORCE_RPORT LPAREN RPAREN	{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1394 1388
 		| FORCE_RPORT				{$$=mk_action(FORCE_RPORT_T,0, 0, 0, 0); }
1395
-		| FORCE_TCP_ALIAS LPAREN NUMBER RPAREN	{
1396
-					#ifdef USE_TCP
1397
-						$$=mk_action(FORCE_TCP_ALIAS_T,NUMBER_ST, 0,
1398
-										(void*)$3, 0);
1399
-					#else
1400
-						yyerror("tcp support not compiled in");
1401
-					#endif
1402
-												}
1403
-		| FORCE_TCP_ALIAS LPAREN RPAREN	{
1404
-					#ifdef USE_TCP
1405
-						$$=mk_action(FORCE_TCP_ALIAS_T,0, 0, 0, 0); 
1406
-					#else
1407
-						yyerror("tcp support not compiled in");
1408
-					#endif
1409
-										}
1410
-		| FORCE_TCP_ALIAS				{
1411
-					#ifdef USE_TCP
1412
-						$$=mk_action(FORCE_TCP_ALIAS_T,0, 0, 0, 0);
1413
-					#else
1414
-						yyerror("tcp support not compiled in");
1415
-					#endif
1416
-										}
1417
-		| FORCE_TCP_ALIAS LPAREN error RPAREN	{$$=0; 
1418
-												yyerror("bad argument,"
1419
-														" number expected");
1420
-												}
1421 1389
 		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1422 1390
 								$$=0;
1423 1391
 								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
... ...
@@ -1534,23 +1487,6 @@ void yyerror(char* s)
1534 1534
 	cfg_errors++;
1535 1535
 }
1536 1536
 
1537
-
1538
-static struct id_list* mk_listen_id(char* host, int proto, int port)
1539
-{
1540
-	struct id_list* l;
1541
-	l=pkg_malloc(sizeof(struct id_list));
1542
-	if (l==0){
1543
-		LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
1544
-	}else{
1545
-		l->name=host;
1546
-		l->port=port;
1547
-		l->proto=proto;
1548
-		l->next=0;
1549
-	}
1550
-	return l;
1551
-}
1552
-
1553
-
1554 1537
 /*
1555 1538
 int main(int argc, char ** argv)
1556 1539
 {