[Nagiosplug-checkins] CVS: nagiosplug/plugins check_smtp.c,1.21,1.22

Karl DeBisschop kdebisschop at users.sourceforge.net
Fri Feb 27 22:58:01 CET 2004


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11394

Modified Files:
	check_smtp.c 
Log Message:
work in progress to accept multiple command/expect pairs


Index: check_smtp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_smtp.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** check_smtp.c	19 Nov 2003 06:00:53 -0000	1.21
--- check_smtp.c	28 Feb 2004 06:48:05 -0000	1.22
***************
*** 41,47 ****
  char *server_address = NULL;
  char *server_expect = NULL;
! int smtp_use_dummycmd = 1;
! char *mail_command;
! char *from_arg;
  int warning_time = 0;
  int check_warning_time = FALSE;
--- 41,53 ----
  char *server_address = NULL;
  char *server_expect = NULL;
! int smtp_use_dummycmd = 0;
! char *mail_command = NULL;
! char *from_arg = NULL;
! int ncommands=0;
! int command_size=0;
! int nresponses=0;
! int response_size=0;
! char **commands = NULL;
! char **responses = NULL;
  int warning_time = 0;
  int check_warning_time = FALSE;
***************
*** 59,67 ****
  {
  	int sd;
  	double elapsed_time;
  	long microsec;
  	int result = STATE_UNKNOWN;
  	char buffer[MAX_INPUT_BUFFER];
! 	char *from_str = NULL;
  	char *helocmd = NULL;
  	struct timeval tv;
--- 65,74 ----
  {
  	int sd;
+ 	int n = 0;
  	double elapsed_time;
  	long microsec;
  	int result = STATE_UNKNOWN;
  	char buffer[MAX_INPUT_BUFFER];
! 	char *cmd_str = NULL;
  	char *helocmd = NULL;
  	struct timeval tv;
***************
*** 83,90 ****
  
  	/* initialize the MAIL command with optional FROM command  */
! 	asprintf (&from_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
  
! 	if (verbose)
! 		printf ("FROMCMD: %s\n", from_str);
  	
  	/* initialize alarm signal handling */
--- 90,97 ----
  
  	/* initialize the MAIL command with optional FROM command  */
! 	asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
  
! 	if (verbose && smtp_use_dummycmd)
! 		printf ("FROM CMD: %s", cmd_str);
  	
  	/* initialize alarm signal handling */
***************
*** 100,105 ****
  	result = my_tcp_connect (server_address, server_port, &sd);
  
! 	/* we connected, so close connection before exiting */
! 	if (result == STATE_OK) {
  
  		/* watch for the SMTP connection string and */
--- 107,111 ----
  	result = my_tcp_connect (server_address, server_port, &sd);
  
! 	if (result == STATE_OK) { /* we connected */
  
  		/* watch for the SMTP connection string and */
***************
*** 110,113 ****
--- 116,121 ----
  		}
  		else {
+ 			if (verbose)
+ 				printf ("%s", buffer);
  			/* strip the buffer of carriage returns */
  			strip (buffer);
***************
*** 140,153 ****
  		 */
  		if (smtp_use_dummycmd) {
! 
! 			send(sd, from_str, strlen(from_str), 0);
! 
! 			/* allow for response to mail_command to reach us */
  			recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
- 
  			if (verbose) 
! 				printf(_("DUMMYCMD: %s\n%s\n"),from_str,buffer);
  
! 		} /* smtp_use_dummycmd */
  
  		/* tell the server we're done */
--- 148,170 ----
  		 */
  		if (smtp_use_dummycmd) {
! 			send(sd, cmd_str, strlen(cmd_str), 0);
  			recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
  			if (verbose) 
! 				printf("%s", buffer);
! 		}
  
! 		while (n < ncommands) {
! 			asprintf (&cmd_str, "%s%s", commands[n], "\r\n");
! 			send(sd, cmd_str, strlen(cmd_str), 0);
! 			recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
! 			if (verbose) 
! 				printf("%s", buffer);
! 			strip (buffer);
! 			if (n < nresponses && strstr(buffer, responses[n])!=buffer) {
! 				result = STATE_WARNING;
! 				printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
! 			}
! 			n++;
! 		}
  
  		/* tell the server we're done */
***************
*** 201,204 ****
--- 218,222 ----
  		{"from", required_argument, 0, 'f'},
  		{"command", required_argument, 0, 'C'},
+ 		{"response", required_argument, 0, 'R'},
  		{"nocommand", required_argument, 0, 'n'},
  		{"verbose", no_argument, 0, 'v'},
***************
*** 223,227 ****
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:",
  		                 longopts, &option);
  
--- 241,245 ----
  
  	while (1) {
! 		c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:",
  		                 longopts, &option);
  
***************
*** 246,259 ****
  		case 'f':									/* from argument */
  			from_arg = optarg;
  			break;
  		case 'e':									/* server expect string on 220  */
  			server_expect = optarg;
  			break;
! 		case 'C':									/* server expect string on 220  */
! 			mail_command = optarg;
! 			smtp_use_dummycmd = 1;
  			break;
! 		case 'n':									/* server expect string on 220  */
! 			smtp_use_dummycmd = 0;
  			break;
  		case 'c':									/* critical time threshold */
--- 264,291 ----
  		case 'f':									/* from argument */
  			from_arg = optarg;
+ 			smtp_use_dummycmd = 1;
  			break;
  		case 'e':									/* server expect string on 220  */
  			server_expect = optarg;
  			break;
! 		case 'C':									/* commands  */
! 			if (ncommands >= command_size) {
! 				commands = realloc (commands, command_size+8);
! 				if (commands == NULL)
! 					die (STATE_UNKNOWN,
! 					     _("Could not realloc() units [%d]\n"), ncommands);
! 			}
! 			commands[ncommands] = optarg;
! 			ncommands++;
  			break;
! 		case 'R':									/* server responses */
! 			if (nresponses >= response_size) {
! 				responses = realloc (responses, response_size+8);
! 				if (responses == NULL)
! 					die (STATE_UNKNOWN,
! 					     _("Could not realloc() units [%d]\n"), nresponses);
! 			}
! 			responses[nresponses] = optarg;
! 			nresponses++;
  			break;
  		case 'c':									/* critical time threshold */





More information about the Commits mailing list