Code

Fix bug #1632072 pointer error in plugins/netutils.c. Add changelog entry for previou...
[nagiosplug.git] / plugins / check_smtp.c
1 /******************************************************************************
2 *
3 * Nagios check_smtp plugin
4 *
5 * License: GPL
6 * Copyright (c) 1999-2006 nagios-plugins team
7 *
8 * Last Modified: $Date$
9 *
10 * Description:
11 *
12 * This file contains the check_smtp plugin
13 *
14 *  This plugin will attempt to open an SMTP connection with the host.
15 *
16 *
17 * License Information:
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 *
33 *
34 * $Id$
35
36 ******************************************************************************/
38 const char *progname = "check_smtp";
39 const char *revision = "$Revision$";
40 const char *copyright = "2000-2006";
41 const char *email = "nagiosplug-devel@lists.sourceforge.net";
43 #include "common.h"
44 #include "netutils.h"
45 #include "utils.h"
47 #ifdef HAVE_SSL
48 int check_cert = FALSE;
49 int days_till_exp;
50 #  define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
51 #  define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
52 #else /* ifndef HAVE_SSL */
53 #  define my_recv(buf, len) read(sd, buf, len)
54 #  define my_send(buf, len) send(sd, buf, len, 0)
55 #endif
57 enum {
58         SMTP_PORT       = 25
59 };
60 #define SMTP_EXPECT "220"
61 #define SMTP_HELO "HELO "
62 #define SMTP_EHLO "EHLO "
63 #define SMTP_QUIT "QUIT\r\n"
64 #define SMTP_STARTTLS "STARTTLS\r\n"
65 #define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
67 #ifndef HOST_MAX_BYTES
68 #define HOST_MAX_BYTES 255
69 #endif
71 #define EHLO_SUPPORTS_STARTTLS 1
73 int process_arguments (int, char **);
74 int validate_arguments (void);
75 void print_help (void);
76 void print_usage (void);
77 int my_close(void);
79 #include "regex.h"
80 char regex_expect[MAX_INPUT_BUFFER] = "";
81 regex_t preg;
82 regmatch_t pmatch[10];
83 char timestamp[20] = "";
84 char errbuf[MAX_INPUT_BUFFER];
85 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
86 int eflags = 0;
87 int errcode, excode;
89 int server_port = SMTP_PORT;
90 char *server_address = NULL;
91 char *server_expect = NULL;
92 int smtp_use_dummycmd = 0;
93 char *mail_command = NULL;
94 char *from_arg = NULL;
95 int ncommands=0;
96 int command_size=0;
97 int nresponses=0;
98 int response_size=0;
99 char **commands = NULL;
100 char **responses = NULL;
101 char *authtype = NULL;
102 char *authuser = NULL;
103 char *authpass = NULL;
104 int warning_time = 0;
105 int check_warning_time = FALSE;
106 int critical_time = 0;
107 int check_critical_time = FALSE;
108 int verbose = 0;
109 int use_ssl = FALSE;
110 short use_ehlo = FALSE;
111 short ssl_established = 0;
112 char *localhostname = NULL;
113 int sd;
114 char buffer[MAX_INPUT_BUFFER];
115 enum {
116   TCP_PROTOCOL = 1,
117   UDP_PROTOCOL = 2,
118   MAXBUF = 1024
119 };
121 /* written by lauri alanko */
122 static char *
123 base64 (const char *bin, size_t len)
126         char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
127         size_t i = 0, j = 0;
129         char BASE64_END = '=';
130         char base64_table[64];
131         strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
133         while (j < len - 2) {
134                 buf[i++] = base64_table[bin[j] >> 2];
135                 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
136                 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
137                 buf[i++] = base64_table[bin[j + 2] & 63];
138                 j += 3;
139         }
141         switch (len - j) {
142         case 1:
143                 buf[i++] = base64_table[bin[j] >> 2];
144                 buf[i++] = base64_table[(bin[j] & 3) << 4];
145                 buf[i++] = BASE64_END;
146                 buf[i++] = BASE64_END;
147                 break;
148         case 2:
149                 buf[i++] = base64_table[bin[j] >> 2];
150                 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
151                 buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
152                 buf[i++] = BASE64_END;
153                 break;
154         case 0:
155                 break;
156         }
158         buf[i] = '\0';
159         return buf;
162 int
163 main (int argc, char **argv)
165         short supports_tls=FALSE;
166         int n = 0;
167         double elapsed_time;
168         long microsec;
169         int result = STATE_UNKNOWN;
170         char *cmd_str = NULL;
171         char *helocmd = NULL;
172         char *error_msg = NULL;
173         struct timeval tv;
174         struct hostent *hp;
176         setlocale (LC_ALL, "");
177         bindtextdomain (PACKAGE, LOCALEDIR);
178         textdomain (PACKAGE);
180         if (process_arguments (argc, argv) == ERROR)
181                 usage4 (_("Could not parse arguments"));
183         /* initialize the HELO command with the localhostname */
184         if(! localhostname){
185                 localhostname = malloc (HOST_MAX_BYTES);
186                 if(!localhostname){
187                         printf(_("malloc() failed!\n"));
188                         return STATE_CRITICAL;
189                 }
190                 if(gethostname(localhostname, HOST_MAX_BYTES)){
191                         printf(_("gethostname() failed!\n"));
192                         return STATE_CRITICAL;
193                 }
194                 hp = gethostbyname(localhostname);
195                 if(!hp) helocmd = localhostname;
196                 else helocmd = hp->h_name;
197         } else {
198                 helocmd = localhostname;
199         }
200         if(use_ehlo)
201                 asprintf (&helocmd, "%s%s%s", SMTP_EHLO, helocmd, "\r\n");
202         else
203                 asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n");
205         /* initialize the MAIL command with optional FROM command  */
206         asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
208         if (verbose && smtp_use_dummycmd)
209                 printf ("FROM CMD: %s", cmd_str);
210         
211         /* initialize alarm signal handling */
212         (void) signal (SIGALRM, socket_timeout_alarm_handler);
214         /* set socket timeout */
215         (void) alarm (socket_timeout);
217         /* start timer */
218         gettimeofday (&tv, NULL);
220         /* try to connect to the host at the given port number */
221         result = my_tcp_connect (server_address, server_port, &sd);
223         if (result == STATE_OK) { /* we connected */
225                 /* watch for the SMTP connection string and */
226                 /* return a WARNING status if we couldn't read any data */
227                 if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) {
228                         printf (_("recv() failed\n"));
229                         result = STATE_WARNING;
230                 }
231                 else {
232                         if (verbose)
233                                 printf ("%s", buffer);
234                         /* strip the buffer of carriage returns */
235                         strip (buffer);
236                         /* make sure we find the response we are looking for */
237                         if (!strstr (buffer, server_expect)) {
238                                 if (server_port == SMTP_PORT)
239                                         printf (_("Invalid SMTP response received from host\n"));
240                                 else
241                                         printf (_("Invalid SMTP response received from host on port %d\n"),
242                                                                         server_port);
243                                 result = STATE_WARNING;
244                         }
245                 }
247                 /* send the HELO/EHLO command */
248                 send(sd, helocmd, strlen(helocmd), 0);
250                 /* allow for response to helo command to reach us */
251                 if(read (sd, buffer, MAXBUF - 1) < 0){
252                         printf (_("recv() failed\n"));
253                         return STATE_WARNING;
254                 } else if(use_ehlo){
255                         buffer[MAXBUF-1]='\0';
256                         if(strstr(buffer, "250 STARTTLS") != NULL ||
257                            strstr(buffer, "250-STARTTLS") != NULL){
258                                 supports_tls=TRUE;
259                         }
260                 }
262                 if(use_ssl && ! supports_tls){
263                         printf(_("WARNING - TLS not supported by server\n"));
264                         send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
265                         return STATE_WARNING;
266                 }
268 #ifdef HAVE_SSL
269                 if(use_ssl) {
270                   /* send the STARTTLS command */
271                   send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
273                   recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
274                   if (!strstr (buffer, server_expect)) {
275                     printf (_("Server does not support STARTTLS\n"));
276                     send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
277                     return STATE_UNKNOWN;
278                   }
279                   result = np_net_ssl_init(sd);
280                   if(result != STATE_OK) {
281                     printf (_("CRITICAL - Cannot create SSL context.\n"));
282                     np_net_ssl_cleanup();
283                     close(sd);
284                     return STATE_CRITICAL;
285                   } else {
286                         ssl_established = 1;
287                   }
289                 /*
290                  * Resend the EHLO command.
291                  *
292                  * RFC 3207 (4.2) says: ``The client MUST discard any knowledge
293                  * obtained from the server, such as the list of SMTP service
294                  * extensions, which was not obtained from the TLS negotiation
295                  * itself.  The client SHOULD send an EHLO command as the first
296                  * command after a successful TLS negotiation.''  For this
297                  * reason, some MTAs will not allow an AUTH LOGIN command before
298                  * we resent EHLO via TLS.
299                  */
300                 if (my_send(helocmd, strlen(helocmd)) <= 0) {
301                         printf(_("SMTP UNKNOWN - Cannot send EHLO command via TLS.\n"));
302                         my_close();
303                         return STATE_UNKNOWN;
304                 }
305                 if (verbose)
306                         printf(_("sent %s"), helocmd);
307                 if ((n = my_recv(buffer, MAX_INPUT_BUFFER - 1)) <= 0) {
308                         printf(_("SMTP UNKNOWN - Cannot read EHLO response via TLS.\n"));
309                         my_close();
310                         return STATE_UNKNOWN;
311                 }
312                 if (verbose) {
313                         buffer[n] = '\0';
314                         printf("%s", buffer);
315                 }
317 #  ifdef USE_OPENSSL
318                   if ( check_cert ) {
319                     result = np_net_ssl_check_cert(days_till_exp);
320                     if(result != STATE_OK){
321                       printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
322                     }
323                     my_close();
324                     return result;
325                   }
326 #  endif /* USE_OPENSSL */
327                 }
328 #endif
329                                 
330                 /* sendmail will syslog a "NOQUEUE" error if session does not attempt
331                  * to do something useful. This can be prevented by giving a command
332                  * even if syntax is illegal (MAIL requires a FROM:<...> argument)
333                  *
334                  * According to rfc821 you can include a null reversepath in the from command
335                  * - but a log message is generated on the smtp server.
336                  *
337                  * You can disable sending mail_command with '--nocommand'
338                  * Use the -f option to provide a FROM address
339                  */
340                 if (smtp_use_dummycmd) {
341                   my_send(cmd_str, strlen(cmd_str));
342                   my_recv(buffer, MAX_INPUT_BUFFER-1);
343                   if (verbose) 
344                     printf("%s", buffer);
345                 }
347                 while (n < ncommands) {
348                         asprintf (&cmd_str, "%s%s", commands[n], "\r\n");
349                         my_send(cmd_str, strlen(cmd_str));
350                         my_recv(buffer, MAX_INPUT_BUFFER-1);
351                         if (verbose) 
352                                 printf("%s", buffer);
353                         strip (buffer);
354                         if (n < nresponses) {
355                                 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
356                                 errcode = regcomp (&preg, responses[n], cflags);
357                                 if (errcode != 0) {
358                                         regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
359                                         printf (_("Could Not Compile Regular Expression"));
360                                         return ERROR;
361                                 }
362                                 excode = regexec (&preg, buffer, 10, pmatch, eflags);
363                                 if (excode == 0) {
364                                         result = STATE_OK;
365                                 }
366                                 else if (excode == REG_NOMATCH) {
367                                         result = STATE_WARNING;
368                                         printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
369                                 }
370                                 else {
371                                         regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
372                                         printf (_("Execute Error: %s\n"), errbuf);
373                                         result = STATE_UNKNOWN;
374                                 }
375                         }
376                         n++;
377                 }
379                 if (authtype != NULL) {
380                         if (strcmp (authtype, "LOGIN") == 0) {
381                                 char *abuf;
382                                 int ret;
383                                 do {
384                                         if (authuser == NULL) {
385                                                 result = STATE_CRITICAL;
386                                                 error_msg = _("no authuser specified, ");
387                                                 break;
388                                         }
389                                         if (authpass == NULL) {
390                                                 result = STATE_CRITICAL;
391                                                 error_msg = _("no authpass specified, ");
392                                                 break;
393                                         }
395                                         /* send AUTH LOGIN */
396                                         my_send(SMTP_AUTH_LOGIN, strlen(SMTP_AUTH_LOGIN));
397                                         if (verbose)
398                                                 printf (_("sent %s\n"), "AUTH LOGIN");
400                                         if((ret = my_recv(buffer, MAXBUF - 1)) < 0){
401                                                 error_msg = _("recv() failed after AUTH LOGIN, \n");
402                                                 result = STATE_WARNING;
403                                                 break;
404                                         }
405                                         buffer[ret] = 0;
406                                         if (verbose)
407                                                 printf (_("received %s\n"), buffer);
409                                         if (strncmp (buffer, "334", 3) != 0) {
410                                                 result = STATE_CRITICAL;
411                                                 error_msg = _("invalid response received after AUTH LOGIN, ");
412                                                 break;
413                                         }
415                                         /* encode authuser with base64 */
416                                         abuf = base64 (authuser, strlen(authuser));
417                                         strcat (abuf, "\r\n");
418                                         my_send(abuf, strlen(abuf));
419                                         if (verbose)
420                                                 printf (_("sent %s\n"), abuf);
422                                         if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
423                                                 result = STATE_CRITICAL;
424                                                 error_msg = _("recv() failed after sending authuser, ");
425                                                 break;
426                                         }
427                                         buffer[ret] = 0;
428                                         if (verbose) {
429                                                 printf (_("received %s\n"), buffer);
430                                         }
431                                         if (strncmp (buffer, "334", 3) != 0) {
432                                                 result = STATE_CRITICAL;
433                                                 error_msg = _("invalid response received after authuser, ");
434                                                 break;
435                                         }
436                                         /* encode authpass with base64 */
437                                         abuf = base64 (authpass, strlen(authpass));
438                                         strcat (abuf, "\r\n");
439                                         my_send(abuf, strlen(abuf));
440                                         if (verbose) {
441                                                 printf (_("sent %s\n"), abuf);
442                                         }
443                                         if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
444                                                 result = STATE_CRITICAL;
445                                                 error_msg = _("recv() failed after sending authpass, ");
446                                                 break;
447                                         }
448                                         buffer[ret] = 0;
449                                         if (verbose) {
450                                                 printf (_("received %s\n"), buffer);
451                                         }
452                                         if (strncmp (buffer, "235", 3) != 0) {
453                                                 result = STATE_CRITICAL;
454                                                 error_msg = _("invalid response received after authpass, ");
455                                                 break;
456                                         }
457                                         break;
458                                 } while (0);
459                         } else {
460                                 result = STATE_CRITICAL;
461                                 error_msg = _("only authtype LOGIN is supported, ");
462                         }
463                 }
465                 /* tell the server we're done */
466                 my_send (SMTP_QUIT, strlen (SMTP_QUIT));
468                 /* finally close the connection */
469                 close (sd);
470         }
472         /* reset the alarm */
473         alarm (0);
475         microsec = deltime (tv);
476         elapsed_time = (double)microsec / 1.0e6;
478         if (result == STATE_OK) {
479                 if (check_critical_time && elapsed_time > (double) critical_time)
480                         result = STATE_CRITICAL;
481                 else if (check_warning_time && elapsed_time > (double) warning_time)
482                         result = STATE_WARNING;
483         }
485         printf (_("SMTP %s - %s%.3f sec. response time%s%s|%s\n"),
486                         state_text (result),
487                         (error_msg == NULL ? "" : error_msg),
488                         elapsed_time,
489                         verbose?", ":"", verbose?buffer:"",
490                         fperfdata ("time", elapsed_time, "s",
491                                 (int)check_warning_time, warning_time,
492                                 (int)check_critical_time, critical_time,
493                                 TRUE, 0, FALSE, 0));
495         return result;
500 /* process command-line arguments */
501 int
502 process_arguments (int argc, char **argv)
504         int c;
506         int option = 0;
507         static struct option longopts[] = {
508                 {"hostname", required_argument, 0, 'H'},
509                 {"expect", required_argument, 0, 'e'},
510                 {"critical", required_argument, 0, 'c'},
511                 {"warning", required_argument, 0, 'w'},
512                 {"timeout", required_argument, 0, 't'},
513                 {"port", required_argument, 0, 'p'},
514                 {"from", required_argument, 0, 'f'},
515                 {"fqdn", required_argument, 0, 'F'},
516                 {"authtype", required_argument, 0, 'A'},
517                 {"authuser", required_argument, 0, 'U'},
518                 {"authpass", required_argument, 0, 'P'},
519                 {"command", required_argument, 0, 'C'},
520                 {"response", required_argument, 0, 'R'},
521                 {"nocommand", required_argument, 0, 'n'},
522                 {"verbose", no_argument, 0, 'v'},
523                 {"version", no_argument, 0, 'V'},
524                 {"use-ipv4", no_argument, 0, '4'},
525                 {"use-ipv6", no_argument, 0, '6'},
526                 {"help", no_argument, 0, 'h'},
527                 {"starttls",no_argument,0,'S'},
528                 {"certificate",required_argument,0,'D'},
529                 {0, 0, 0, 0}
530         };
532         if (argc < 2)
533                 return ERROR;
535         for (c = 1; c < argc; c++) {
536                 if (strcmp ("-to", argv[c]) == 0)
537                         strcpy (argv[c], "-t");
538                 else if (strcmp ("-wt", argv[c]) == 0)
539                         strcpy (argv[c], "-w");
540                 else if (strcmp ("-ct", argv[c]) == 0)
541                         strcpy (argv[c], "-c");
542         }
544         while (1) {
545                 c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:",
546                                  longopts, &option);
548                 if (c == -1 || c == EOF)
549                         break;
551                 switch (c) {
552                 case 'H':                                                                       /* hostname */
553                         if (is_host (optarg)) {
554                                 server_address = optarg;
555                         }
556                         else {
557                                 usage2 (_("Invalid hostname/address"), optarg);
558                         }
559                         break;
560                 case 'p':                                                                       /* port */
561                         if (is_intpos (optarg))
562                                 server_port = atoi (optarg);
563                         else
564                                 usage4 (_("Port must be a positive integer"));
565                         break;
566                 case 'F':
567                 /* localhostname */
568                         localhostname = strdup(optarg);
569                         break;
570                 case 'f':                                                                       /* from argument */
571                         from_arg = optarg;
572                         smtp_use_dummycmd = 1;
573                         break;
574                 case 'A':
575                         authtype = optarg;
576                         break;
577                 case 'U':
578                         authuser = optarg;
579                         break;
580                 case 'P':
581                         authpass = optarg;
582                         break;
583                 case 'e':                                                                       /* server expect string on 220  */
584                         server_expect = optarg;
585                         break;
586                 case 'C':                                                                       /* commands  */
587                         if (ncommands >= command_size) {
588                                 commands = realloc (commands, command_size+8);
589                                 if (commands == NULL)
590                                         die (STATE_UNKNOWN,
591                                              _("Could not realloc() units [%d]\n"), ncommands);
592                         }
593                         commands[ncommands] = optarg;
594                         ncommands++;
595                         break;
596                 case 'R':                                                                       /* server responses */
597                         if (nresponses >= response_size) {
598                                 responses = realloc (responses, response_size+8);
599                                 if (responses == NULL)
600                                         die (STATE_UNKNOWN,
601                                              _("Could not realloc() units [%d]\n"), nresponses);
602                         }
603                         responses[nresponses] = optarg;
604                         nresponses++;
605                         break;
606                 case 'c':                                                                       /* critical time threshold */
607                         if (is_intnonneg (optarg)) {
608                                 critical_time = atoi (optarg);
609                                 check_critical_time = TRUE;
610                         }
611                         else {
612                                 usage4 (_("Critical time must be a positive integer"));
613                         }
614                         break;
615                 case 'w':                                                                       /* warning time threshold */
616                         if (is_intnonneg (optarg)) {
617                                 warning_time = atoi (optarg);
618                                 check_warning_time = TRUE;
619                         }
620                         else {
621                                 usage4 (_("Warning time must be a positive integer"));
622                         }
623                         break;
624                 case 'v':                                                                       /* verbose */
625                         verbose++;
626                         break;
627                 case 't':                                                                       /* timeout */
628                         if (is_intnonneg (optarg)) {
629                                 socket_timeout = atoi (optarg);
630                         }
631                         else {
632                                 usage4 (_("Timeout interval must be a positive integer"));
633                         }
634                         break;
635                 case 'S':
636                 /* starttls */
637                         use_ssl = TRUE;
638                         use_ehlo = TRUE;
639                         break;
640                 case 'D':
641                 /* Check SSL cert validity */
642 #ifdef USE_OPENSSL
643                         if (!is_intnonneg (optarg))
644                                 usage2 ("Invalid certificate expiration period",optarg);
645                                 days_till_exp = atoi (optarg);
646                                 check_cert = TRUE;
647 #else
648                                 usage (_("SSL support not available - install OpenSSL and recompile"));
649 #endif
650                         break;
651                 case '4':
652                         address_family = AF_INET;
653                         break;
654                 case '6':
655 #ifdef USE_IPV6
656                         address_family = AF_INET6;
657 #else
658                         usage4 (_("IPv6 support not available"));
659 #endif
660                         break;
661                 case 'V':                                                                       /* version */
662                         print_revision (progname, revision);
663                         exit (STATE_OK);
664                 case 'h':                                                                       /* help */
665                         print_help ();
666                         exit (STATE_OK);
667                 case '?':                                                                       /* help */
668                         usage2 (_("Unknown argument"), optarg);
669                 }
670         }
672         c = optind;
673         if (server_address == NULL) {
674                 if (argv[c]) {
675                         if (is_host (argv[c]))
676                                 server_address = argv[c];
677                         else
678                                 usage2 (_("Invalid hostname/address"), argv[c]);
679                 }
680                 else {
681                         asprintf (&server_address, "127.0.0.1");
682                 }
683         }
685         if (server_expect == NULL)
686                 server_expect = strdup (SMTP_EXPECT);
688         if (mail_command == NULL)
689                 mail_command = strdup("MAIL ");
691         if (from_arg==NULL)
692                 from_arg = strdup(" ");
694         return validate_arguments ();
699 int
700 validate_arguments (void)
702         return OK;
706 int 
707 my_close (void)
709 #ifdef HAVE_SSL
710   np_net_ssl_cleanup();
711 #endif
712   return close(sd);
716 void
717 print_help (void)
719         char *myport;
720         asprintf (&myport, "%d", SMTP_PORT);
722         print_revision (progname, revision);
724         printf ("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n");
725         printf (COPYRIGHT, copyright, email);
727         printf("%s\n", _("This plugin will attempt to open an SMTP connection with the host."));
729   printf ("\n\n");
731         print_usage ();
733         printf (_(UT_HELP_VRSN));
735         printf (_(UT_HOST_PORT), 'p', myport);
737         printf (_(UT_IPv46));
739         printf (" %s\n", "-e, --expect=STRING");
740   printf (_("    String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT);
741   printf (" %s\n", "-n, nocommand");
742   printf ("    %s\n", _("Suppress SMTP command"));
743   printf (" %s\n", "-C, --command=STRING");
744   printf ("    %s\n", _("SMTP command (may be used repeatedly)"));
745   printf (" %s\n", "-R, --command=STRING");
746   printf ("    %s\n", _("Expected response to command (may be used repeatedly)"));
747   printf (" %s\n", "-f, --from=STRING");
748   printf ("    %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")),
749 #ifdef HAVE_SSL
750   printf (" %s\n", "-D, --certificate=INTEGER");
751   printf ("    %s\n", _("Minimum number of days a certificate has to be valid."));
752   printf (" %s\n", "-S, --starttls");
753   printf ("    %s\n", _("Use STARTTLS for the connection."));
754 #endif
756         printf (" %s\n", "-A, --authtype=STRING");
757   printf ("    %s\n", _("SMTP AUTH type to check (default none, only LOGIN supported)"));
758   printf (" %s\n", "-U, --authuser=STRING");
759   printf ("    %s\n", _("SMTP AUTH username"));
760   printf (" %s\n", "-P, --authpass=STRING");
761   printf ("    %s\n", _("SMTP AUTH password"));
763         printf (_(UT_WARN_CRIT));
765         printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
767         printf (_(UT_VERBOSE));
769         printf("\n");
770         printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
771   printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN.  Successful"));
772   printf ("%s\n", _("connects, but incorrect reponse messages from the host result in"));
773   printf ("%s\n", _("STATE_WARNING return values."));
775         printf (_(UT_SUPPORT));
780 void
781 print_usage (void)
783   printf (_("Usage:"));
784         printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname);
785   printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n");
786   printf ("[-S] [-D days] [-n] [-v] [-4|-6]\n");