Przeglądaj źródła

Host names can now be specified in allowed host list

Ethan Galstad 22 lat temu
rodzic
commit
4e1fd0ec6c
3 zmienionych plików z 51 dodań i 11 usunięć
  1. 5 0
      Changelog
  2. 6 6
      src/dh.h
  3. 40 5
      src/nrpe.c

+ 5 - 0
Changelog

@@ -3,6 +3,11 @@ NRPE Changelog
 **************
 
 
+2.1 - ??/??/2003
+----------------
+- Host names can now be specified in allowed host list
+
+
 2.0 - 09/08/2003
 ----------------
 - Added support for passing arguments to command

+ 6 - 6
src/dh.h

@@ -4,12 +4,12 @@
 DH *get_dh512()
 	{
 	static unsigned char dh512_p[]={
-		0xD7,0x32,0x39,0xB3,0x1F,0x55,0x31,0xD2,0x44,0x1D,0x5D,0xBC,
-		0xF1,0x3B,0x5B,0x70,0xFD,0x2B,0xCF,0x97,0xD8,0xAD,0xA4,0xE2,
-		0x80,0xE4,0x9F,0x5A,0x2B,0xF9,0x63,0xA6,0x0A,0xAE,0xF9,0x64,
-		0xF2,0x89,0xE3,0xC5,0xCD,0x6D,0x37,0xC8,0x94,0xBF,0xE7,0x26,
-		0x9B,0x33,0xCF,0x06,0xA3,0xC4,0x66,0xCE,0x38,0x7B,0x75,0xCA,
-		0x0C,0x34,0x47,0xEB,
+		0x81,0xC3,0x30,0xAC,0x8E,0xF9,0x3D,0x54,0x19,0xF8,0x85,0x93,
+		0xF8,0x4A,0xE4,0x22,0x7B,0xD4,0x8F,0x25,0xAC,0xDC,0x21,0xE6,
+		0x70,0xB5,0x1D,0x01,0x7C,0x8F,0x75,0xE9,0xEC,0xA2,0x48,0x0A,
+		0xD3,0xFC,0x8B,0xA0,0xFE,0x77,0x21,0x5D,0xDD,0x76,0x4C,0x65,
+		0xAB,0x09,0x0D,0x0D,0x64,0x92,0xFD,0xB3,0xDA,0x37,0xB9,0x0B,
+		0x39,0xDC,0xC6,0x6B,
 		};
 	static unsigned char dh512_g[]={
 		0x02,

+ 40 - 5
src/nrpe.c

@@ -4,7 +4,7 @@
  * Copyright (c) 1999-2003 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  *
- * Last Modified: 09-08-2003
+ * Last Modified: 09-09-2003
  *
  * Command line: nrpe -c <config_file> [--inetd | --daemon]
  *
@@ -643,7 +643,7 @@ void wait_for_connections(void){
 				if(!is_an_allowed_host(connecting_host)){
 
 				        /* log error to syslog facility */
-					syslog(LOG_ERR,"Host %s is not allowed to talk to us!",connecting_host);
+					syslog(LOG_DEBUG,"Host %s is not allowed to talk to us!",connecting_host);
 			                }
 				else{
 
@@ -945,16 +945,51 @@ void handle_connection(int sock){
 int is_an_allowed_host(char *connecting_host){
 	char temp_buffer[MAX_INPUT_BUFFER];
 	char *temp_ptr;
+	int result=0;
+        struct hostent *myhost;
+	char **pptr;
+	char resolved_addr[INET6_ADDRSTRLEN];
 
+	/* try and match IP addresses first */
 	strncpy(temp_buffer,allowed_hosts,sizeof(temp_buffer));
 	temp_buffer[sizeof(temp_buffer)-1]='\x0';
 
 	for(temp_ptr=strtok(temp_buffer,",");temp_ptr!=NULL;temp_ptr=strtok(NULL,",")){
-		if(!strcmp(connecting_host,temp_ptr))
-			return 1;
+
+		if(!strcmp(connecting_host,temp_ptr)){
+			result=1;
+			break;
+		        }
 	        }
 
-	return 0;
+	/* try DNS lookups if needed */
+	if(result==0){
+
+		strncpy(temp_buffer,allowed_hosts,sizeof(temp_buffer));
+		temp_buffer[sizeof(temp_buffer)-1]='\x0';
+
+		for(temp_ptr=strtok(temp_buffer,",");temp_ptr!=NULL;temp_ptr=strtok(NULL,",")){
+
+			myhost=gethostbyname(temp_ptr);
+			if(myhost!=NULL){
+
+				/* check all addresses for the host... */
+				for(pptr=myhost->h_addr_list;*pptr!=NULL;pptr++){
+
+					inet_ntop(myhost->h_addrtype,*pptr,resolved_addr,sizeof(resolved_addr));
+					if(!strcmp(resolved_addr,connecting_host)){
+						result=1;
+						break;
+					        }
+					}
+			        }
+
+			if(result==1)
+				break;
+		        }
+	        }
+
+	return result;
         }