2
0
Эх сурвалжийг харах

core: auto_aliases to control rev DNS aliases

- parameter takes boolean value
- if set, rev dns results are added to aliases list
- default is set
Daniel-Constantin Mierla 16 жил өмнө
parent
commit
bb4cd6b049
5 өөрчлөгдсөн 14 нэмэгдсэн , 4 устгасан
  1. 3 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 1 0
      globals.h
  4. 2 0
      main.c
  5. 5 4
      socket_info.c

+ 3 - 0
cfg.lex

@@ -273,6 +273,7 @@ LOGSTDERROR	log_stderror
 LOGFACILITY	log_facility
 LISTEN		listen
 ALIAS		alias
+SR_AUTO_ALIASES	auto_aliases
 DNS		 dns
 REV_DNS	 rev_dns
 DNS_TRY_IPV6	dns_try_ipv6
@@ -550,6 +551,8 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
+<INITIAL>{SR_AUTO_ALIASES}	{ count(); yylval.strval=yytext;
+									return SR_AUTO_ALIASES; }
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
 <INITIAL>{DNS_TRY_IPV6}	{ count(); yylval.strval=yytext;

+ 3 - 0
cfg.y

@@ -333,6 +333,7 @@ static int case_check_default(struct case_stms* stms);
 %token LOGFACILITY
 %token LISTEN
 %token ALIAS
+%token SR_AUTO_ALIASES
 %token DNS
 %token REV_DNS
 %token DNS_TRY_IPV6
@@ -1272,6 +1273,8 @@ assign_stm:
 		free_socket_id_lst($3);
 	}
 	| ALIAS  EQUAL error  { yyerror(" hostname expected"); }
+	| SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
+	| SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
 	| ADVERTISED_ADDRESS EQUAL listen_id {
 		default_global_address.s=$3;
 		default_global_address.len=strlen($3);

+ 1 - 0
globals.h

@@ -117,6 +117,7 @@ extern int sock_gid;
 extern int sock_mode;
 extern char* chroot_dir;
 extern char* working_dir;
+extern int sr_auto_aliases;
 
 #ifdef USE_MCAST
 extern int mcast_loopback;

+ 2 - 0
main.c

@@ -348,6 +348,8 @@ int mhomed=0;
 /* use dns and/or rdns or to see if we need to add
    a ;received=x.x.x.x to via: */
 int received_dns = 0;
+/* add or not the rev dns names to aliases list */
+int sr_auto_aliases=1;
 char* working_dir = 0;
 char* chroot_dir = 0;
 char* user=0;

+ 5 - 4
socket_info.c

@@ -822,7 +822,8 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 	}
 	/* check if we got the official name */
 	if (strcasecmp(he->h_name, name->s)!=0){
-		if (add_alias(name->s, name->len, s->port_no, s->proto)<0){
+		if (sr_auto_aliases && 
+				add_alias(name->s, name->len, s->port_no, s->proto)<0){
 			LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
 		}
 		/* change the official name */
@@ -836,9 +837,9 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 		strncpy(name->s, he->h_name, name->len+1);
 	}
 	/* add the aliases*/
-	for(h=he->h_aliases; h && *h; h++)
+	for(h=he->h_aliases; sr_auto_aliases && h && *h; h++)
 		if (add_alias(*h, strlen(*h), s->port_no, s->proto)<0){
-				LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
+			LOG(L_ERR, "ERROR: fix_hostname: add_alias failed\n");
 		}
 	hostent2ip_addr(address, he, 0); /*convert to ip_addr format*/
 	if (type_flags){
@@ -853,7 +854,7 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
 	strncpy(address_str->s, tmp, strlen(tmp)+1);
 	/* set is_ip (1 if name is an ip address, 0 otherwise) */
 	address_str->len=strlen(tmp);
-	if ((address_str->len==name->len) &&
+	if (sr_auto_aliases && (address_str->len==name->len) &&
 		(strncasecmp(address_str->s, name->s, address_str->len)==0)){
 		*flags|=SI_IS_IP;
 		/* do rev. DNS on it (for aliases)*/