[Nagios-checkins] CVS: nsca/src Makefile.in,1.1.1.1,1.2 netutils.c,1.1.1.1,1.2 netutils.h,1.1.1.1,1.2 nsca.c,1.1.1.1,1.2 send_nsca.c,1.1.1.1,1.2 utils.c,1.1.1.1,1.2 utils.h,1.1.1.1,1.2

Ethan Galstad egalstad at users.sourceforge.net
Thu Feb 21 19:23:03 UTC 2002


Update of /cvsroot/nagios/nsca/src
In directory usw-pr-cvs1:/tmp/cvs-serv22297/src

Modified Files:
	Makefile.in netutils.c netutils.h nsca.c send_nsca.c utils.c 
	utils.h 
Log Message:
Name and version change

Index: Makefile.in
===================================================================
RCS file: /cvsroot/nagios/nsca/src/Makefile.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** Makefile.in	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- Makefile.in	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 2,6 ****
  # Makefile for NSCA
  #
! # Last Modified: 08-26-2000
  ###############################
  
--- 2,6 ----
  # Makefile for NSCA
  #
! # Last Modified: 12-23-2001
  ###############################
  
***************
*** 26,35 ****
  
  clean:
! 	rm -f core \
! 	nsca send_nsca
! 
! distclean: clean
  	rm -f *~ */*~
  	rm -f Makefile
  
! devclean: distclean
--- 26,34 ----
  
  clean:
! 	rm -f core nsca send_nsca
  	rm -f *~ */*~
  	rm -f Makefile
  
! distclean: clean
! 
! devclean: clean

Index: netutils.c
===================================================================
RCS file: /cvsroot/nagios/nsca/src/netutils.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** netutils.c	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- netutils.c	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 1,9 ****
  /****************************************************************************
   *
!  * NETUTILS.C - NRPE Network Utilities
   * License: GPL
!  * Copyright (c) 1999-2001 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 06-23-2001
   *
   * Description:
--- 1,10 ----
  /****************************************************************************
   *
!  * NETUTILS.C - NSCA Network Utilities
!  *
   * License: GPL
!  * Copyright (c) 1999-2002 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 02-21-2002
   *
   * Description:
***************
*** 32,123 ****
  #include "netutils.h"
  
- extern int socket_timeout;    /* this doesn't have to be used, but it is nice to know how many seconds we timed out after */
- 
- extern int errno;
- 
- 
- /* handles socket timeouts */
- void socket_timeout_alarm_handler(int sig){
- 
- 	printf("Socket timeout after %d seconds\n",socket_timeout);
- 
- 	exit(STATE_CRITICAL);
-         }
- 
- 
- /* connects to a host on a specified TCP port, sends a string, and gets a response */
- int process_tcp_request(char *server_address, int server_port, char *send_buffer, char *recv_buffer, int recv_size){
- 	int result;
- 
- 	result=process_request(server_address,server_port,"tcp",send_buffer,recv_buffer,recv_size);
- 
- 	return result;
-         }
- 
- 
- /* connects to a host on a specified UDP port, sends a string, and gets a response */
- int process_udp_request(char *server_address, int server_port, char *send_buffer, char *recv_buffer, int recv_size){
- 	int result;
- 
- 	result=process_request(server_address,server_port,"udp",send_buffer,recv_buffer,recv_size);
- 
- 	return result;
-         }
- 
- 
- /* connects to a host on a specified port, sends a string, and gets a response */
- int process_request(char *server_address, int server_port, char *proto, char *send_buffer, char *recv_buffer, int recv_size){
- 	int result;
- 	int send_result;
- 	int recv_result;
- 	int sd;
- 	struct timeval tv;
- 	fd_set readfds;
- 
- 	result=STATE_OK;
- 
- 	result=my_connect(server_address,server_port,&sd,proto);
- 	if(result!=STATE_OK)
- 		return STATE_CRITICAL;
- 
- 	send_result=send(sd,send_buffer,strlen(send_buffer),0);
- 	if(send_result!=strlen(send_buffer)){
- 		printf("send() failed\n");
- 		result=STATE_WARNING;
- 	        }
- 
- 	/* wait up to the number of seconds for socket timeout minus one for data from the host */
- 	tv.tv_sec=socket_timeout-1;
- 	tv.tv_usec=0;
- 	FD_ZERO(&readfds);
- 	FD_SET(sd,&readfds);
- 	select(sd+1,&readfds,NULL,NULL,&tv);
- 
- 	/* make sure some data has arrived */
- 	if(!FD_ISSET(sd,&readfds)){
- 		strcpy(recv_buffer,"");
- 		printf("No data was recieved from host!\n");
- 		result=STATE_WARNING;
- 	        }
- 
- 	else{
- 		recv_result=recv(sd,recv_buffer,recv_size-1,0);
- 		if(recv_result==-1){
- 			strcpy(recv_buffer,"");
- 			if(!strcmp(proto,"tcp"))
- 				printf("recv() failed\n");
- 			result=STATE_WARNING;
- 	                }
- 		else
- 			recv_buffer[recv_result]='\x0';
- 
- 		/* terminate returned string */
- 		recv_buffer[recv_size-1]='\x0';
- 	        }
- 
- 	close(sd);
- 
- 	return result;
-         }
  
  
--- 33,36 ----
***************
*** 132,145 ****
  
  
- /* opens a connection to a remote host/udp port */
- int my_udp_connect(char *host_name,int port,int *sd){
- 	int result;
- 
- 	result=my_connect(host_name,port,sd,"udp");
- 
- 	return result;
-         }
- 
- 
  /* opens a tcp or udp connection to a remote host */
  int my_connect(char *host_name,int port,int *sd,char *proto){
--- 45,48 ----
***************
*** 304,305 ****
--- 207,275 ----
          }
  
+ 
+ 
+ /* sends all data - thanks to Beej's Guide to Network Programming */
+ int sendall(int s, char *buf, int *len){
+ 	int total=0;
+ 	int bytesleft=*len;
+ 	int n;
+ 
+ 	while(total<*len){
+ 		n=send(s,buf+total,bytesleft,0);
+ 		if(n==-1)
+ 			break;
+ 		total+=n;
+ 		bytesleft-=n;
+ 	        }
+ 
+ 	/* return number of bytes actually send here */
+ 	*len=total;
+ 
+ 	/* return -1 on failure, 0 on success */
+ 	return n==-1?-1:0;
+         }
+ 
+ 
+ /* receives all data - modelled after sendall() */
+ int recvall(int s, char *buf, int *len, int timeout){
+ 	int total=0;
+ 	int bytesleft=*len;
+ 	int n;
+ 	time_t start_time;
+ 	time_t current_time;
+ 	
+ 	/* clear the receive buffer */
+ 	bzero(buf,*len);
+ 
+ 	time(&start_time);
+ 
+ 	/* receive all data */
+ 	while(total<*len){
+ 
+ 		/* receive some data */
+ 		n=recv(s,buf+total,bytesleft,0);
+ 
+ 		/* no data has arrived yet (non-blocking socket) */
+ 		if(n==-1 && errno==EAGAIN){
+ 			time(&current_time);
+ 			if(current_time-start_time>timeout)
+ 				break;
+ 			sleep(1);
+ 			continue;
+ 		        }
+ 
+ 		/* receive error or client disconnect */
+ 		else if(n<=0)
+ 			break;
+ 
+ 		/* apply bytes we received */
+ 		total+=n;
+ 		bytesleft-=n;
+ 	        }
+ 
+ 	/* return number of bytes actually received here */
+ 	*len=total;
+ 
+ 	/* return <=0 on failure, bytes received on success */
+ 	return (n<=0)?n:total;
+         }

Index: netutils.h
===================================================================
RCS file: /cvsroot/nagios/nsca/src/netutils.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** netutils.h	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- netutils.h	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 1,9 ****
  /************************************************************************************************
   *
!  * NETUTILS.H - NRPE Network Utilities Header File
   * License: GPL
!  * Copyright (c) 1999-2001 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 06-23-2001
   *
   * Description:
--- 1,10 ----
  /************************************************************************************************
   *
!  * NETUTILS.H - NSCA Network Utilities Include File
!  *
   * License: GPL
!  * Copyright (c) 1999-2002 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 02-21-2002
   *
   * Description:
***************
*** 31,45 ****
  #include "../common/config.h"
  
! void socket_timeout_alarm_handler(int);
! 
! int process_tcp_request(char *address,int port,char *sbuffer,char *rbuffer,int rsize);
! int process_udp_request(char *address,int port,char *sbuffer,char *rbuffer,int rsize);
! int process_request(char *address,int port,char *proto,char *sbuffer,char *rbuffer,int rsize);
  
! int my_tcp_connect(char *address,int port,int *sd);
! int my_udp_connect(char *address,int port,int *sd);
! int my_connect(char *address,int port,int *sd,char *proto);
  
! int my_inet_aton(register const char *cp, struct in_addr *addr);
  
  
--- 32,42 ----
  #include "../common/config.h"
  
! int my_tcp_connect(char *,int,int *);
! int my_connect(char *,int,int *,char *);
  
! int my_inet_aton(register const char *,struct in_addr *);
  
! int sendall(int,char *,int *);
! int recvall(int,char *,int *,int);
  
  

Index: nsca.c
===================================================================
RCS file: /cvsroot/nagios/nsca/src/nsca.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** nsca.c	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- nsca.c	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 2,10 ****
   *
   * NSCA.C - Nagios Service Check Acceptor
!  * Copyright (c) 2000-2001 Ethan Galstad (nagios at nagios.org)
!  * Version: 1.2
   * License: GPL
   *
!  * Last Modified: 06-23-2001
   *
   * Command line: NSCA <config_file>
--- 2,9 ----
[...1704 lines suppressed...]
+ 		/* config file */
+ 		else if(!strcmp(argv[x-1],"-c") || x==3){
+ 
+ 			if(!strcmp(argv[x-1],"-c")){
+ 				if(x>=argc)
+ 					return ERROR;
+ 				x++;
+ 			        }
+ 
+ 			/* grab the config file */
+ 			strncpy(config_file,argv[x-1],sizeof(config_file)-1);
+ 			config_file[sizeof(config_file)-1]='\0';
+  		        }
+ 
+  		else
+ 			return ERROR;
+ 	        }
+ 
+ 	return OK;
+         }

Index: send_nsca.c
===================================================================
RCS file: /cvsroot/nagios/nsca/src/send_nsca.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** send_nsca.c	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- send_nsca.c	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 2,10 ****
   *
   * SEND_NSCA.C - NSCA Client
-  * Version: 1.2
   * License: GPL
!  * Copyright (c) 2000-2001 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 06-23-2001
   *
   * Command line: SEND_NSCA <host_address> [-p port] [-to to_sec] [-c config_file]
--- 2,9 ----
   *
   * SEND_NSCA.C - NSCA Client
   * License: GPL
!  * Copyright (c) 2000-2002 Ethan Galstad (nagios at nagios.org)
   *
!  * Last Modified: 02-21-2002
   *
   * Command line: SEND_NSCA <host_address> [-p port] [-to to_sec] [-c config_file]
***************
*** 15,18 ****
--- 14,19 ----
   *********************************************************************************/
  
+ /*#define DEBUG*/
+ 
  #include "../common/common.h"
  #include "../common/config.h"
***************
*** 20,26 ****
  #include "utils.h"
  
- #define PROGRAM_VERSION "1.2"
- #define MODIFICATION_DATE "06-23-2001"
- 
  time_t start_time,end_time;
  
--- 21,24 ----
***************
*** 31,34 ****
--- 29,34 ----
  char delimiter[2]="\t";
  
+ char received_iv[TRANSMITTED_IV_SIZE];
+ 
  int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
  
***************
*** 38,46 ****
--- 38,52 ----
  int check_critical_time=FALSE;
  int encryption_method=ENCRYPT_XOR;
+ time_t packet_timestamp;
+ 
+ int show_help=FALSE;
+ int show_license=FALSE;
  
  
  int process_arguments(int,char **);
  int read_config_file(char *);
+ int read_init_packet(int);
  void alarm_handler(int);
+ void clear_password(void);
  
  
***************
*** 51,56 ****
  	int rc;
  	int result;
! 	packet send_packet;
! 	packet receive_packet;
  	char input_buffer[MAX_INPUT_BUFFER];
  	char *temp_ptr;
--- 57,62 ----
  	int rc;
  	int result;
! 	data_packet send_packet;
! 	int bytes_to_send;
  	char input_buffer[MAX_INPUT_BUFFER];
  	char *temp_ptr;
***************
*** 58,73 ****
  	char svc_description[MAX_DESCRIPTION_LENGTH];
  	char plugin_output[MAX_PLUGINOUTPUT_LENGTH];
- 	int return_code;
  	int total_packets=0;
! 	unsigned long calculated_crc32=0L;
  
  	result=process_arguments(argc,argv);
  
! 	if(result!=OK){
  
! 		printf("Incorrect command line arguments supplied\n");
  		printf("\n");
  		printf("NSCA Client %s\n",PROGRAM_VERSION);
! 		printf("Copyright (c) 2000-2001 Ethan Galstad (nagios at nagios.org)\n");
  		printf("Last Modified: %s\n",MODIFICATION_DATE);
  		printf("License: GPL\n");
--- 64,83 ----
  	char svc_description[MAX_DESCRIPTION_LENGTH];
  	char plugin_output[MAX_PLUGINOUTPUT_LENGTH];
  	int total_packets=0;
! 	int16_t return_code;
! 	u_int32_t calculated_crc32;
!         struct crypt_instance *CI;
! 
  
+ 	/* process command-line arguments */
  	result=process_arguments(argc,argv);
  
! 	if(result!=OK || show_help==TRUE || show_license==TRUE){
  
! 		if(result!=OK)
! 			printf("Incorrect command line arguments supplied\n");
  		printf("\n");
  		printf("NSCA Client %s\n",PROGRAM_VERSION);
! 		printf("Copyright (c) 2000-2002 Ethan Galstad (nagios at nagios.org)\n");
  		printf("Last Modified: %s\n",MODIFICATION_DATE);
  		printf("License: GPL\n");
***************
*** 80,83 ****
--- 90,96 ----
  		printf("\n");
  		printf("\n");
+ 	        }
+ 
+ 	if(result!=OK || show_help==TRUE){
  		printf("Usage: %s <host_address> [-p port] [-to to_sec] [-d delim] [-c config_file]\n",argv[0]);
  		printf("\n");
***************
*** 102,105 ****
--- 115,125 ----
  	        }
  
+ 	if(show_license==TRUE){
+ 
+ 		display_license();
+ 
+ 		return STATE_UNKNOWN;
+ 	        }
+ 
  	/* read the config file */
  	result=read_config_file(config_file);	
***************
*** 114,123 ****
  	generate_crc32_table();
  
- 	/* initialize encryption/decryption routines */
- 	if(encrypt_init(password,encryption_method)!=OK){
- 		printf("Error: Failed to initialize encryption libraries for method %d\n",encryption_method);
- 		return STATE_CRITICAL;
- 	        }
- 
  	/* initialize alarm signal handling */
  	signal(SIGALRM,alarm_handler);
--- 134,137 ----
***************
*** 131,236 ****
  	result=my_tcp_connect(server_name,server_port,&sd);
  
! 	/* we connected! */
! 	if(result==STATE_OK){
  
! 		/* read all data from STDIN until there isn't anymore */
! 		while(fgets(input_buffer,sizeof(input_buffer)-1,stdin)){
  
! 			if(feof(stdin))
! 				break;
  
! 			strip(input_buffer);
! 
! 			if(!strcmp(input_buffer,""))
! 				continue;
! 
! 			/* get the host name */
! 			temp_ptr=strtok(input_buffer,delimiter);
! 			if(temp_ptr==NULL){
! 				printf("Error: Host name is NULL!\n");
! 				continue;
! 			        }
! 			strncpy(host_name,temp_ptr,sizeof(host_name)-1);
! 			host_name[sizeof(host_name)-1]='\x0';
! 
! 			/* get the service description */
! 			temp_ptr=strtok(NULL,delimiter);
! 			if(temp_ptr==NULL){
! 				printf("Error: Service description is NULL!\n");
! 				continue;
! 			        }
! 			strncpy(svc_description,temp_ptr,sizeof(svc_description)-1);
! 			svc_description[sizeof(svc_description)-1]='\x0';
! 
! 			/* get the return code */
! 			temp_ptr=strtok(NULL,delimiter);
! 			if(temp_ptr==NULL){
! 				printf("Error: Return code is NULL!\n");
! 				continue;
! 			        }
! 			return_code=atoi(temp_ptr);
! 
! 			/* get the plugin output */
! 			temp_ptr=strtok(NULL,"\n");
! 			if(temp_ptr==NULL){
! 				printf("Error: Plugin output is NULL!\n");
! 				continue;
! 			        }
! 			strncpy(plugin_output,temp_ptr,sizeof(plugin_output)-1);
! 			plugin_output[sizeof(plugin_output)-1]='\x0';
! 		
  
! 			total_packets++;
  
! 			/* clear the packet buffer */
! 			bzero(&send_packet,sizeof(send_packet));
  
! 			/* fill the packet with semi-random data */
! 			randomize_buffer((char *)&send_packet,sizeof(send_packet));
  
! 			/* copy the data we want to send into the packet */
! 			send_packet.packet_version=htonl(NSCA_PACKET_VERSION_1);
! 			strcpy(&send_packet.host_name[0],host_name);
! 			strcpy(&send_packet.svc_description[0],svc_description);
! 			send_packet.return_code=htonl(return_code);
! 			strcpy(&send_packet.plugin_output[0],plugin_output);
! 
! 			/* calculate the crc 32 value of the packet */
! 			send_packet.crc32_value=0L;
! 			calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet));
! 			send_packet.crc32_value=htonl(calculated_crc32);
! 
! 			/* encrypt the packet */
! 			encrypt_buffer((char *)&send_packet,sizeof(send_packet),password,encryption_method);
! 
! 			/* send the packet */
! 			rc=send(sd,(void *)&send_packet,sizeof(send_packet),0);
! 
! 			/* there was an error sending the packet */
! 			if(rc==-1){
! 				printf("Error: Could not send data to host\n");
! 				close(sd);
! 				return STATE_UNKNOWN;
! 		                }
! 
! 			/* for some reason we didn't send all the bytes we were supposed to */
! 			else if(rc<sizeof(send_packet)){
! 				printf("Warning: Sent only %d of %d bytes to host\n",rc,sizeof(send_packet));
! 				close(sd);
! 				return STATE_UNKNOWN;
! 			        }
  		        }
  
! 		result=STATE_OK;
  
! 		/* close the connection */
! 		close(sd);
  
! 		printf("%d data packet(s) sent to host successfully.\n",total_packets);
  	        }
  
! 	/* we couldn't connect */
! 	else
! 		printf("Error: Could not connect to host %s on port %d\n",server_name,server_port);
  
  	/* reset the alarm */
--- 145,298 ----
  	result=my_tcp_connect(server_name,server_port,&sd);
  
! 	/* we couldn't connect */
! 	if(result!=STATE_OK){
! 
! 		printf("Error: Could not connect to host %s on port %d\n",server_name,server_port);
! 
! 		return STATE_CRITICAL;
! 	        }
  
! #ifdef DEBUG
! 	printf("Connected okay...\n");
! #endif
  
! 	/* read the initialization packet containing the IV and timestamp */
! 	result=read_init_packet(sd);
! 	if(result!=OK){
  
! 		printf("Error: Could not read init packet from server\n");
  
! 		/* close the connection */
! 		close(sd);
! 
! 		return STATE_CRITICAL;
! 	        }
! 
! #ifdef DEBUG
! 	printf("Got init packet from server\n");
! #endif
  
! 	/* initialize encryption/decryption routines with the IV we received from the server */
!         if(encrypt_init(password,encryption_method,received_iv,&CI)!=OK){
  
! 		printf("Error: Failed to initialize encryption libraries for method %d\n",encryption_method);
  
! 		return STATE_CRITICAL;
! 	        }
! 
! 	/* clear password from memory if we can */
! 	if(encryption_method!=ENCRYPT_XOR)
! 		clear_buffer(password,sizeof(password));
! 
! #ifdef DEBUG
! 	printf("Initialized encryption routines\n");
! #endif
! 
! 
! 	/**** WE'RE CONNECTED AND READY TO SEND ****/
! 
! 	/* read all data from STDIN until there isn't anymore */
! 	while(fgets(input_buffer,sizeof(input_buffer)-1,stdin)){
! 
! 		if(feof(stdin))
! 			break;
! 
! 		strip(input_buffer);
! 
! 		if(!strcmp(input_buffer,""))
! 			continue;
! 
! 		/* get the host name */
! 		temp_ptr=strtok(input_buffer,delimiter);
! 		if(temp_ptr==NULL){
! 			printf("Error: Host name is NULL!\n");
! 			continue;
  		        }
+ 		strncpy(host_name,temp_ptr,sizeof(host_name)-1);
+ 		host_name[sizeof(host_name)-1]='\x0';
  
! 		/* get the service description */
! 		temp_ptr=strtok(NULL,delimiter);
! 		if(temp_ptr==NULL){
! 			printf("Error: Service description is NULL!\n");
! 			continue;
! 		        }
! 		strncpy(svc_description,temp_ptr,sizeof(svc_description)-1);
! 		svc_description[sizeof(svc_description)-1]='\x0';
  
! 		/* get the return code */
! 		temp_ptr=strtok(NULL,delimiter);
! 		if(temp_ptr==NULL){
! 			printf("Error: Return code is NULL!\n");
! 			continue;
! 		        }
! 		return_code=atoi(temp_ptr);
! 
! 		/* get the plugin output */
! 		temp_ptr=strtok(NULL,"\n");
! 		if(temp_ptr==NULL){
! 			printf("Error: Plugin output is NULL!\n");
! 			continue;
! 		        }
! 		strncpy(plugin_output,temp_ptr,sizeof(plugin_output)-1);
! 		plugin_output[sizeof(plugin_output)-1]='\x0';
! 		
! 		total_packets++;
! 
! 		/* clear the packet buffer */
! 		bzero(&send_packet,sizeof(send_packet));
  
! 		/* fill the packet with semi-random data */
! 		randomize_buffer((char *)&send_packet,sizeof(send_packet));
! 
! 		/* copy the data we want to send into the packet */
! 		send_packet.packet_version=(int16_t)htons(NSCA_PACKET_VERSION_2);
! 		send_packet.return_code=(int16_t)htons(return_code);
! 		strcpy(&send_packet.host_name[0],host_name);
! 		strcpy(&send_packet.svc_description[0],svc_description);
! 		strcpy(&send_packet.plugin_output[0],plugin_output);
! 
! 		/* use timestamp provided by the server */
! 		send_packet.timestamp=(u_int32_t)htonl(packet_timestamp);
! 
! 		/* calculate the crc 32 value of the packet */
! 		send_packet.crc32_value=(u_int32_t)0L;
! 		calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet));
! 		send_packet.crc32_value=(u_int32_t)htonl(calculated_crc32);
! 
! 		/* encrypt the packet */
! 		encrypt_buffer((char *)&send_packet,sizeof(send_packet),password,encryption_method,CI);
! 
! 		/* send the packet */
! 		bytes_to_send=sizeof(send_packet);
! 		rc=sendall(sd,(char *)&send_packet,&bytes_to_send);
! 
! 		/* there was an error sending the packet */
! 		if(rc==-1){
! 			printf("Error: Could not send data to host\n");
! 			close(sd);
! 			return STATE_UNKNOWN;
! 	                }
! 
! 		/* for some reason we didn't send all the bytes we were supposed to */
! 		else if(bytes_to_send<sizeof(send_packet)){
! 			printf("Warning: Sent only %d of %d bytes to host\n",rc,sizeof(send_packet));
! 			close(sd);
! 			return STATE_UNKNOWN;
! 		        }
  	        }
  
! #ifdef DEBUG
! 	printf("Done sending data\n");
! #endif
! 
! 	/* clear password from memory if we haven't already */
! 	if(encryption_method==ENCRYPT_XOR)
! 		clear_buffer(password,sizeof(password));
! 
! 	/* close the connection */
! 	close(sd);
! 
! 	printf("%d data packet(s) sent to host successfully.\n",total_packets);
  
  	/* reset the alarm */
***************
*** 238,244 ****
  
  	/* encryption/decryption routine cleanup */
! 	encrypt_cleanup(encryption_method);
  
! 	return result;
          }
  
--- 300,345 ----
  
  	/* encryption/decryption routine cleanup */
! 	encrypt_cleanup(encryption_method,CI);
  
! #ifdef DEBUG
! 	printf("Cleaned up encryption routines\n");
! #endif
! 
! 	return STATE_OK;
!         }
! 
! 
! 
! /* reads initialization packet (containing IV and timestamp) from server */
! int read_init_packet(int sock){
!         int rc;
!         init_packet receive_packet;
!         int bytes_to_recv;
! 
!         /* clear the IV and timestamp */
!         bzero(&received_iv,TRANSMITTED_IV_SIZE);
!         packet_timestamp=(time_t)0;
! 
!         /* get the init packet from the server */
!         bytes_to_recv=sizeof(receive_packet);
!         rc=recvall(sock,(char *)&receive_packet,&bytes_to_recv,socket_timeout);
! 
!         /* recv() error or server disconnect */
!         if(rc<=0){
!                 printf("Error: Server closed connection before init packet was received\n");
!                 return ERROR;
!                 }
! 
!         /* we couldn't read the correct amount of data, so bail out */
!         else if(bytes_to_recv!=sizeof(receive_packet)){
!                 printf("Error: Init packet from server was too short (%d bytes received, %d expected)\n",bytes_to_recv,sizeof(receive_packet));
!                 return ERROR;
!                 }
! 
!         /* transfer the IV and timestamp */
!         memcpy(&received_iv,&receive_packet.iv[0],TRANSMITTED_IV_SIZE);
!         packet_timestamp=(time_t)ntohl(receive_packet.timestamp);
! 
!         return OK;
          }
  
***************
*** 250,265 ****
  
  	/* no options were supplied */
! 	if(argc<2)
! 		return ERROR;
  
! 	/* first option is always the server name/address */
! 	strncpy(server_name,argv[1],sizeof(server_name)-1);
! 	server_name[sizeof(server_name)-1]='\x0';
  
! 	/* process all remaining arguments */
! 	for(x=3;x<=argc;x++){
  
  		/* port to connect to */
! 		if(!strcmp(argv[x-1],"-p")){
  			if(x<argc){
  				server_port=atoi(argv[x]);
--- 351,378 ----
  
  	/* no options were supplied */
! 	if(argc<2){
! 		show_help=TRUE;
! 		return OK;
! 	        }
  
! 	/* process arguments (host name is usually 1st argument) */
! 	for(x=2;x<=argc;x++){
  
! 		/* show usage */
! 		if(!strcmp(argv[x-1],"-h") || !strcmp(argv[x-1],"--help"))
! 			show_help=TRUE;
! 
! 		/* show license */
! 		else if(!strcmp(argv[x-1],"-l") || !strcmp(argv[x-1],"--license"))
! 			show_license=TRUE;
! 
! 		/* server name/address */
! 		else if(x==2){
! 			strncpy(server_name,argv[1],sizeof(server_name)-1);
! 			server_name[sizeof(server_name)-1]='\x0';
! 		        }
  
  		/* port to connect to */
! 		else if(!strcmp(argv[x-1],"-p")){
  			if(x<argc){
  				server_port=atoi(argv[x]);

Index: utils.c
===================================================================
RCS file: /cvsroot/nagios/nsca/src/utils.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** utils.c	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- utils.c	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 2,8 ****
   *
   * UTILS.C - Utility functions for NSCA
!  * Copyright (c) 2000-2001 Ethan Galstad (nagios at nagios.org)
   * License: GPL
!  * Last Modified: 06-23-2001
   *
   * Description:
--- 2,10 ----
   *
   * UTILS.C - Utility functions for NSCA
!  *
   * License: GPL
!  * Copyright (c) 2000-2002 Ethan Galstad (nagios at nagios.org)
!  *
!  * Last Modified: 02-21-2002
   *
   * Description:
***************
*** 32,48 ****
  
  
! static unsigned long crc32_table[256];
  
  
- #ifdef HAVE_LIBMCRYPT
- MCRYPT td;
- char *key;
- char block_buffer;
- char *IV;
- int blocksize=1;                   /* block size = 1 byte w/ CFB mode */
- int keysize=7;                     /* default to 56 bit key length */
- char *mcrypt_algorithm="unknown";
- char *mcrypt_mode="cfb";           /* CFB = 8-bit cipher-feedback mode */
- #endif
  
  
--- 34,41 ----
  
  
! /*#define DEBUG*/
  
+ static unsigned long crc32_table[256];
  
  
  
***************
*** 88,217 ****
  
  /* initializes encryption routines */
! int encrypt_init(char *password,int encryption_method){
  #ifdef HAVE_LIBMCRYPT
! 	int i;
! 	int iv_size;
  #endif
  
! 	/* XOR or no encryption */
! 	if(encryption_method==ENCRYPT_NONE || encryption_method==ENCRYPT_XOR)
! 		return OK;
  
  #ifdef HAVE_LIBMCRYPT
  
! 	/* get the name of the mcrypt encryption algorithm to use */
! 	switch(encryption_method){
! 	case ENCRYPT_DES:
! 		mcrypt_algorithm=MCRYPT_DES;
! 		break;
! 	case ENCRYPT_3DES:
! 		mcrypt_algorithm=MCRYPT_3DES;
! 		break;
! 	case ENCRYPT_CAST128:
! 		mcrypt_algorithm=MCRYPT_CAST_128;
! 		break;
! 	case ENCRYPT_CAST256:
! 		mcrypt_algorithm=MCRYPT_CAST_256;
! 		break;
! 	case ENCRYPT_XTEA:
! 		mcrypt_algorithm=MCRYPT_XTEA;
! 		break;
! 	case ENCRYPT_3WAY:
! 		mcrypt_algorithm=MCRYPT_3WAY;
! 		break;
! 	case ENCRYPT_BLOWFISH:
! 		mcrypt_algorithm=MCRYPT_BLOWFISH;
! 		break;
! 	case ENCRYPT_TWOFISH:
! 		mcrypt_algorithm=MCRYPT_TWOFISH;
! 		break;
! 	case ENCRYPT_LOKI97:
! 		mcrypt_algorithm=MCRYPT_LOKI97;
! 		break;
! 	case ENCRYPT_RC2:
! 		mcrypt_algorithm=MCRYPT_RC2;
! 		break;
! 	case ENCRYPT_ARCFOUR:
! 		mcrypt_algorithm=MCRYPT_ARCFOUR;
! 		break;
! 	case ENCRYPT_RIJNDAEL128:
! 		mcrypt_algorithm=MCRYPT_RIJNDAEL_128;
! 		break;
! 	case ENCRYPT_RIJNDAEL192:
! 		mcrypt_algorithm=MCRYPT_RIJNDAEL_192;
! 		break;
! 	case ENCRYPT_RIJNDAEL256:
! 		mcrypt_algorithm=MCRYPT_RIJNDAEL_256;
! 		break;
! 	case ENCRYPT_WAKE:
! 		mcrypt_algorithm=MCRYPT_WAKE;
! 		break;
! 	case ENCRYPT_SERPENT:
! 		mcrypt_algorithm=MCRYPT_SERPENT;
! 		break;
! 	case ENCRYPT_ENIGMA:
! 		mcrypt_algorithm=MCRYPT_ENIGMA;
! 		break;
! 	case ENCRYPT_GOST:
! 		mcrypt_algorithm=MCRYPT_GOST;
! 		break;
! 	case ENCRYPT_SAFER64:
! 		mcrypt_algorithm=MCRYPT_SAFER_SK64;
! 		break;
! 	case ENCRYPT_SAFER128:
! 		mcrypt_algorithm=MCRYPT_SAFER_SK128;
! 		break;
! 	case ENCRYPT_SAFERPLUS:
! 		mcrypt_algorithm=MCRYPT_SAFERPLUS;
! 		break;
! 
! 	default:
! 		mcrypt_algorithm="unknown";
! 		break;
! 	        }
  
! 	/* open encryption module */
! 	if((td=mcrypt_module_open(mcrypt_algorithm,NULL,mcrypt_mode,NULL))==MCRYPT_FAILED){
! 		syslog(LOG_ERR,"Could not open mcrypt algorithm '%s' with mode '%s'",mcrypt_algorithm,mcrypt_mode);
! 		return ERROR;
! 	        }
  
  #ifdef DEBUG
! 	syslog(LOG_INFO,"Using '%s' as crypto algorithm...",mcrypt_algorithm);
  #endif
  
! 	/* allocate memory for IV buffer */
! 	iv_size=mcrypt_enc_get_iv_size(td);
! 	if((IV=(char *)malloc(iv_size))==NULL){
! 		syslog(LOG_ERR,"Could not allocate memory for IV buffer");
! 		return ERROR;
! 	        }
  
! 	/* fill IV buffer with random data - this isn't too random, and should be improved */
! 	srand(time(NULL));
! 	for(i=0;i<iv_size;i++)
! 		IV[i]=rand();
! 
! 	/* get maximum key size for this algorithm */
! 	keysize=mcrypt_enc_get_key_size(td);
! 
! 	/* generate an encryption/decription key using the password */
! 	if((key=(char *)malloc(keysize))==NULL){
! 		syslog(LOG_ERR,"Could not allocate memory for encryption/decryption key");
! 		return ERROR;
! 	        }
! 	bzero(key,keysize);
  
! 	if(keysize<strlen(password))
! 		strncpy(key,password,keysize);
! 	else
! 		strncpy(key,password,strlen(password));
! 	
! 	/* initialize encryption buffers */
! 	mcrypt_generic_init(td,key,keysize,IV);
  
  #endif
  
! 	return OK;
          }
  
--- 81,243 ----
  
  /* initializes encryption routines */
! int encrypt_init(char *password,int encryption_method,char *received_iv,struct crypt_instance **CIptr){
  #ifdef HAVE_LIBMCRYPT
!         int i;
!         int iv_size;
  #endif
+         struct crypt_instance *CI;
+ 
+         CI=malloc(sizeof(struct crypt_instance));
+         *CIptr=CI;
  
!         if(CI==NULL){
!                 syslog(LOG_ERR, "Could not allocate memory for crypt instance");
!                 return ERROR;
!                 }
! 
! 	/* server generates IV used for encryption */
!         if(received_iv==NULL)
!                 generate_transmitted_iv(CI->transmitted_iv);
! 
! 	/* client recieves IV from server */
!         else
!                 memcpy(CI->transmitted_iv,received_iv,TRANSMITTED_IV_SIZE);
  
  #ifdef HAVE_LIBMCRYPT
+         CI->blocksize=1;                        /* block size = 1 byte w/ CFB mode */
+         CI->keysize=7;                          /* default to 56 bit key length */
+         CI->mcrypt_mode="cfb";                  /* CFB = 8-bit cipher-feedback mode */
+         CI->mcrypt_algorithm="unknown";
+ #endif
  
!         /* XOR or no encryption */
!         if(encryption_method==ENCRYPT_NONE || encryption_method==ENCRYPT_XOR)
!                 return OK;
  
! #ifdef HAVE_LIBMCRYPT
! 
!         /* get the name of the mcrypt encryption algorithm to use */
!         switch(encryption_method){
!         case ENCRYPT_DES:
!                 CI->mcrypt_algorithm=MCRYPT_DES;
!                 break;
!         case ENCRYPT_3DES:
!                 CI->mcrypt_algorithm=MCRYPT_3DES;
!                 break;
!         case ENCRYPT_CAST128:
!                 CI->mcrypt_algorithm=MCRYPT_CAST_128;
!                 break;
!         case ENCRYPT_CAST256:
!                 CI->mcrypt_algorithm=MCRYPT_CAST_256;
!                 break;
!         case ENCRYPT_XTEA:
!                 CI->mcrypt_algorithm=MCRYPT_XTEA;
!                 break;
!         case ENCRYPT_3WAY:
!                 CI->mcrypt_algorithm=MCRYPT_3WAY;
!                 break;
!         case ENCRYPT_BLOWFISH:
!                 CI->mcrypt_algorithm=MCRYPT_BLOWFISH;
!                 break;
!         case ENCRYPT_TWOFISH:
!                 CI->mcrypt_algorithm=MCRYPT_TWOFISH;
!                 break;
!         case ENCRYPT_LOKI97:
!                 CI->mcrypt_algorithm=MCRYPT_LOKI97;
!                 break;
!         case ENCRYPT_RC2:
!                 CI->mcrypt_algorithm=MCRYPT_RC2;
!                 break;
!         case ENCRYPT_ARCFOUR:
!                 CI->mcrypt_algorithm=MCRYPT_ARCFOUR;
!                 break;
!         case ENCRYPT_RIJNDAEL128:
!                 CI->mcrypt_algorithm=MCRYPT_RIJNDAEL_128;
!                 break;
!         case ENCRYPT_RIJNDAEL192:
!                 CI->mcrypt_algorithm=MCRYPT_RIJNDAEL_192;
!                 break;
!         case ENCRYPT_RIJNDAEL256:
!                 CI->mcrypt_algorithm=MCRYPT_RIJNDAEL_256;
!                 break;
!         case ENCRYPT_WAKE:
!                 CI->mcrypt_algorithm=MCRYPT_WAKE;
!                 break;
!         case ENCRYPT_SERPENT:
!                 CI->mcrypt_algorithm=MCRYPT_SERPENT;
!                 break;
!         case ENCRYPT_ENIGMA:
!                 CI->mcrypt_algorithm=MCRYPT_ENIGMA;
!                 break;
!         case ENCRYPT_GOST:
!                 CI->mcrypt_algorithm=MCRYPT_GOST;
!                 break;
!         case ENCRYPT_SAFER64:
!                 CI->mcrypt_algorithm=MCRYPT_SAFER_SK64;
!                 break;
!         case ENCRYPT_SAFER128:
!                 CI->mcrypt_algorithm=MCRYPT_SAFER_SK128;
!                 break;
!         case ENCRYPT_SAFERPLUS:
!                 CI->mcrypt_algorithm=MCRYPT_SAFERPLUS;
!                 break;
! 
!         default:
!                 CI->mcrypt_algorithm="unknown";
!                 break;
!                 }
  
  #ifdef DEBUG
!         syslog(LOG_INFO,"Attempting to initialize '%s' crypto algorithm...",CI->mcrypt_algorithm);
  #endif
  
!         /* open encryption module */
!         if((CI->td=mcrypt_module_open(CI->mcrypt_algorithm,NULL,CI->mcrypt_mode,NULL))==MCRYPT_FAILED){
!                 syslog(LOG_ERR,"Could not open mcrypt algorithm '%s' with mode '%s'",CI->mcrypt_algorithm,CI->mcrypt_mode);
!                 return ERROR;
!                 }
  
! #ifdef DEBUG
!         syslog(LOG_INFO,"Using '%s' as crypto algorithm...",CI->mcrypt_algorithm);
! #endif
  
!         /* determine size of IV buffer for this algorithm */
!         iv_size=mcrypt_enc_get_iv_size(CI->td);
!         if(iv_size>TRANSMITTED_IV_SIZE){
!                 syslog(LOG_ERR,"IV size for crypto algorithm exceeds limits");
!                 return ERROR;
!                 }
! 
!         /* allocate memory for IV buffer */
!         if((CI->IV=(char *)malloc(iv_size))==NULL){
!                 syslog(LOG_ERR,"Could not allocate memory for IV buffer");
!                 return ERROR;
!                 }
! 
!         /* fill IV buffer with first bytes of IV that is going to be used to crypt (determined by server) */
!         for(i=0;i<iv_size;i++)
!                 CI->IV[i]=CI->transmitted_iv[i];
! 
!         /* get maximum key size for this algorithm */
!         CI->keysize=mcrypt_enc_get_key_size(CI->td);
! 
!         /* generate an encryption/decription key using the password */
!         if((CI->key=(char *)malloc(CI->keysize))==NULL){
!                 syslog(LOG_ERR,"Could not allocate memory for encryption/decryption key");
!                 return ERROR;
!                 }
!         bzero(CI->key,CI->keysize);
! 
!         if(CI->keysize<strlen(password))
!                 strncpy(CI->key,password,CI->keysize);
!         else
!                 strncpy(CI->key,password,strlen(password));
!         
!         /* initialize encryption buffers */
!         mcrypt_generic_init(CI->td,CI->key,CI->keysize,CI->IV);
  
  #endif
  
!         return OK;
          }
  
***************
*** 219,234 ****
  
  /* encryption routine cleanup */
! void encrypt_cleanup(int encryption_method){
! 
! 	/* XOR or no encryption */
! 	if(encryption_method==ENCRYPT_NONE || encryption_method==ENCRYPT_XOR)
! 		return;
  
  #ifdef HAVE_LIBMCRYPT
! 	/* mcrypt cleanup */
! 	mcrypt_generic_end(td);
  #endif
  
! 	return;
          }
  
--- 245,290 ----
  
  /* encryption routine cleanup */
! void encrypt_cleanup(int encryption_method, struct crypt_instance *CI){
  
  #ifdef HAVE_LIBMCRYPT
!         /* mcrypt cleanup */
!         if(encryption_method!=ENCRYPT_NONE && encryption_method!=ENCRYPT_XOR)
!                 mcrypt_generic_end(CI->td);
  #endif
  
!         free(CI);
! 
!         return;
!         }
! 
! 
! 
! /* generates IV to use for encrypted communications (function is called by server only, client uses IV it receives from server) */
! static void generate_transmitted_iv(char *transmitted_iv){
!         FILE *fp;
!         int x;
!         int seed=0;
! 
!         /*********************************************************/
!         /* fill IV buffer with data that's as random as possible */ 
!         /*********************************************************/
! 
!         /* try to get seed value from /dev/urandom, as its a better source of entropy */
!         fp=fopen("/dev/urandom","r");
!         if(fp!=NULL){
!                 seed=fgetc(fp);
!                 fclose(fp);
!                 }
! 
!         /* else fallback to using the current time as the seed */
!         else
!                 seed=(int)time(NULL);
! 
!         /* generate pseudo-random IV */
!         srand(seed);
!         for(x=0;x<TRANSMITTED_IV_SIZE;x++)
!                 transmitted_iv[x]=(int)((256.0*rand())/(RAND_MAX+1.0));
! 
!         return;
          }
  
***************
*** 236,314 ****
  
  /* encrypt a buffer */
! void encrypt_buffer(char *buffer,int buffer_size, char *password, int encryption_method){
! 	int x;
! 	int y;
! 	int password_length;
  
! 	/* no encryption */
! 	if(encryption_method==ENCRYPT_NONE)
! 		return;
  
! 	/* simple XOR "encryption" - not meant for any real security, just obfuscates data, but its fast... */
! 	else if(encryption_method==ENCRYPT_XOR){
  
! 		password_length=strlen(password);
  
! 		for(y=0,x=0;y<buffer_size;y++,x++){
  
! 			/* keep rotating over password */
! 			if(x>=password_length)
! 				x=0;
  
! 			buffer[y]^=password[x];
! 	                }
! 		return;
! 	        }
  
  #ifdef HAVE_LIBMCRYPT
! 	/* use mcrypt routines */
! 	else{
  
! 		/* encrypt each byte of buffer, one byte at a time (CFB mode) */
! 		for(x=0;x<buffer_size;x++)
! 			mcrypt_generic(td,&buffer[x],1);
! 	        }
  #endif
  
! 	return;
          }
  
  
  /* decrypt a buffer */
! void decrypt_buffer(char *buffer,int buffer_size, char *password, int encryption_method){
! 	int x=0;
  
! 	/* no encryption */
! 	if(encryption_method==ENCRYPT_NONE)
! 		return;
! 
! 	/* XOR decryption is the same as encryption */
! 	else if(encryption_method==ENCRYPT_XOR){
! 		encrypt_buffer(buffer,buffer_size,password,encryption_method);
! 		return;
! 	        }
  
  #ifdef HAVE_LIBMCRYPT
! 	/* use mcrypt routines */
! 	else{
  
! 		/* encrypt each byte of buffer, one byte at a time (CFB mode) */
! 		for(x=0;x<buffer_size;x++)
! 			mdecrypt_generic(td,&buffer[x],1);
! 	        }
  #endif
  
! 	return;
          }
  
  
  /* fill a buffer with semi-random data */
  void randomize_buffer(char *buffer,int buffer_size){
  	int x;
  
! 	/* seed the random number generator */
! 	srand(time(NULL));
  
! 	/* use numbers and alpha characters */
  	for(x=0;x<buffer_size;x++)
  		buffer[x]=(int)'0'+(int)(72.0*rand()/(RAND_MAX+1.0));
--- 292,408 ----
  
  /* encrypt a buffer */
! void encrypt_buffer(char *buffer,int buffer_size, char *password, int encryption_method, struct crypt_instance *CI){
!         int x;
!         int y;
!         int password_length;
  
! #ifdef DEBUG
!         syslog(LOG_INFO,"Encrypting with algorithm #%d",encryption_method);
! #endif
  
!         /* no encryption */
!         if(encryption_method==ENCRYPT_NONE)
!                 return;
  
!         /* simple XOR "encryption" - not meant for any real security, just obfuscates data, but its fast... */
!         else if(encryption_method==ENCRYPT_XOR){
  
!                 /* rotate over IV we received from the server... */
!                 for(y=0,x=0;y<buffer_size;y++,x++){
  
!                         /* keep rotating over IV */
!                         if(x>=TRANSMITTED_IV_SIZE)
!                                 x=0;
  
!                         buffer[y]^=CI->transmitted_iv[x];
!                         }
! 
!                 /* rotate over password... */
!                 password_length=strlen(password);
!                 for(y=0,x=0;y<buffer_size;y++,x++){
! 
!                         /* keep rotating over password */
!                         if(x>=password_length)
!                                 x=0;
! 
!                         buffer[y]^=password[x];
!                         }
! 
!                 return;
!                 }
  
  #ifdef HAVE_LIBMCRYPT
!         /* use mcrypt routines */
!         else{
  
!                 /* encrypt each byte of buffer, one byte at a time (CFB mode) */
!                 for(x=0;x<buffer_size;x++)
!                         mcrypt_generic(CI->td,&buffer[x],1);
!                 }
  #endif
  
!         return;
          }
  
  
  /* decrypt a buffer */
! void decrypt_buffer(char *buffer,int buffer_size, char *password, int encryption_method, struct crypt_instance *CI){
!         int x=0;
  
! #ifdef DEBUG
!         syslog(LOG_INFO,"Decrypting with algorithm #%d",encryption_method);
! #endif
! 
!         /* no encryption */
!         if(encryption_method==ENCRYPT_NONE)
!                 return;
! 
!         /* XOR "decryption" is the same as encryption */
!         else if(encryption_method==ENCRYPT_XOR)
!                 encrypt_buffer(buffer,buffer_size,password,encryption_method,CI);
  
  #ifdef HAVE_LIBMCRYPT
!         /* use mcrypt routines */
!         else{
  
!                 /* encrypt each byte of buffer, one byte at a time (CFB mode) */
!                 for(x=0;x<buffer_size;x++)
!                         mdecrypt_generic(CI->td,&buffer[x],1);
!                 }
  #endif
  
!         return;
          }
  
  
+ 
  /* fill a buffer with semi-random data */
  void randomize_buffer(char *buffer,int buffer_size){
+ 	FILE *fp;
  	int x;
+ 	int seed;
  
! 	/**** FILL BUFFER WITH RANDOM ALPHA-NUMERIC CHARACTERS ****/
  
! 	/***************************************************************
! 	   Only use alpha-numeric characters becase plugins usually
! 	   only generate numbers and letters in their output.  We
! 	   want the buffer to contain the same set of characters as
! 	   plugins, so its harder to distinguish where the real output
! 	   ends and the rest of the buffer (padded randomly) starts.
! 	***************************************************************/
! 
! 	/* try to get seed value from /dev/urandom, as its a better source of entropy */
! 	fp=fopen("/dev/urandom","r");
! 	if(fp!=NULL){
! 		seed=fgetc(fp);
! 		fclose(fp);
! 	        }
! 
! 	/* else fallback to using the current time as the seed */
! 	else
! 		seed=(int)time(NULL);
! 
! 	srand(seed);
  	for(x=0;x<buffer_size;x++)
  		buffer[x]=(int)'0'+(int)(72.0*rand()/(RAND_MAX+1.0));
***************
*** 318,321 ****
--- 412,416 ----
  
  
+ 
  /* strips trailing newlines, carriage returns, spaces, and tabs from a string */
  void strip(char *buffer){
***************
*** 330,333 ****
--- 425,459 ----
  			break;
  	        }
+ 
+ 	return;
+         }
+ 
+ 
+ 
+ /* wipes an area of memory clean */
+ void clear_buffer(char *buffer, int buffer_length){
+ 
+ 	/* NULL all bytes of buffer */
+ 	memset(buffer,'\x0',buffer_length);
+ 
+ 	return;
+         }
+ 
+ 
+ 
+ /* show license */
+ void display_license(void){
+ 
+ 	printf("This program is free software; you can redistribute it and/or modify\n");
+ 	printf("it under the terms of the GNU General Public License as published by\n");
+ 	printf("the Free Software Foundation; either version 2 of the License, or\n");
+ 	printf("(at your option) any later version.\n\n");
+ 	printf("This program is distributed in the hope that it will be useful,\n");
+ 	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+ 	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
+ 	printf("GNU General Public License for more details.\n\n");
+ 	printf("You should have received a copy of the GNU General Public License\n");
+ 	printf("along with this program; if not, write to the Free Software\n");
+ 	printf("Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
  
  	return;

Index: utils.h
===================================================================
RCS file: /cvsroot/nagios/nsca/src/utils.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** utils.h	23 Jun 2001 16:48:53 -0000	1.1.1.1
--- utils.h	22 Feb 2002 01:50:43 -0000	1.2
***************
*** 2,9 ****
   *
   * UTILS.H - Header file for NSCA utility functions
   * License: GPL
!  * Copyright (c) 2000-2001 Ethan Galstad (nagios at nagios.org)
   *
-  * Last Modified: 07-23-2001
   *
   * License Information:
--- 2,13 ----
   *
   * UTILS.H - Header file for NSCA utility functions
+  *
   * License: GPL
!  * Copyright (c) 2000-2002 Ethan Galstad (nagios at nagios.org)
!  *
!  * Last Modified: 02-21-2002
!  *
!  * Description:
   *
   *
   * License Information:
***************
*** 30,45 ****
  #include "../common/config.h"
  
  void generate_crc32_table(void);
  unsigned long calculate_crc32(char *, int);
  
! int encrypt_init(char *,int);
! void encrypt_cleanup(int);
  
! void encrypt_buffer(char *,int,char *,int);
! void decrypt_buffer(char *,int,char *,int);
  
  void randomize_buffer(char *,int);
  
  void strip(char *);
  
  #endif
--- 34,69 ----
  #include "../common/config.h"
  
+ struct crypt_instance {
+ 	char transmitted_iv[TRANSMITTED_IV_SIZE];
+ #ifdef HAVE_LIBMCRYPT
+ 	MCRYPT td;
+ 	char *key;
+ 	char *IV;
+ 	char block_buffer;
+ 	int blocksize;
+ 	int keysize;
+ 	char *mcrypt_algorithm;
+ 	char *mcrypt_mode;
+ #endif
+         };
+ 
  void generate_crc32_table(void);
  unsigned long calculate_crc32(char *, int);
  
! int encrypt_init(char *,int,char *,struct crypt_instance **);
! void encrypt_cleanup(int,struct crypt_instance *);
  
! static void generate_transmitted_iv(char *transmitted_iv);
! 
! void encrypt_buffer(char *,int,char *,int,struct crypt_instance *);
! void decrypt_buffer(char *,int,char *,int,struct crypt_instance *);
  
  void randomize_buffer(char *,int);
  
  void strip(char *);
+ 
+ void clear_buffer(char *,int);
+ 
+ void display_license(void);
  
  #endif





More information about the Nagios-commits mailing list