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 void smtp_quit(void);
78 int my_close(void);
80 #include "regex.h"
81 char regex_expect[MAX_INPUT_BUFFER] = "";
82 regex_t preg;
83 regmatch_t pmatch[10];
84 char timestamp[20] = "";
85 char errbuf[MAX_INPUT_BUFFER];
86 int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
87 int eflags = 0;
88 int errcode, excode;
90 int server_port = SMTP_PORT;
91 char *server_address = NULL;
92 char *server_expect = NULL;
93 int smtp_use_dummycmd = 0;
94 char *mail_command = NULL;
95 char *from_arg = NULL;
96 int ncommands=0;
97 int command_size=0;
98 int nresponses=0;
99 int response_size=0;
100 char **commands = NULL;
101 char **responses = NULL;
102 char *authtype = NULL;
103 char *authuser = NULL;
104 char *authpass = NULL;
105 int warning_time = 0;
106 int check_warning_time = FALSE;
107 int critical_time = 0;
108 int check_critical_time = FALSE;
109 int verbose = 0;
110 int use_ssl = FALSE;
111 short use_ehlo = FALSE;
112 short ssl_established = 0;
113 char *localhostname = NULL;
114 int sd;
115 char buffer[MAX_INPUT_BUFFER];
116 enum {
117 TCP_PROTOCOL = 1,
118 UDP_PROTOCOL = 2,
119 MAXBUF = 1024
120 };
122 /* written by lauri alanko */
123 static char *
124 base64 (const char *bin, size_t len)
125 {
127 char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
128 size_t i = 0, j = 0;
130 char BASE64_END = '=';
131 char base64_table[64];
132 strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
134 while (j < len - 2) {
135 buf[i++] = base64_table[bin[j] >> 2];
136 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
137 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
138 buf[i++] = base64_table[bin[j + 2] & 63];
139 j += 3;
140 }
142 switch (len - j) {
143 case 1:
144 buf[i++] = base64_table[bin[j] >> 2];
145 buf[i++] = base64_table[(bin[j] & 3) << 4];
146 buf[i++] = BASE64_END;
147 buf[i++] = BASE64_END;
148 break;
149 case 2:
150 buf[i++] = base64_table[bin[j] >> 2];
151 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
152 buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
153 buf[i++] = BASE64_END;
154 break;
155 case 0:
156 break;
157 }
159 buf[i] = '\0';
160 return buf;
161 }
163 int
164 main (int argc, char **argv)
165 {
166 short supports_tls=FALSE;
167 int n = 0;
168 double elapsed_time;
169 long microsec;
170 int result = STATE_UNKNOWN;
171 char *cmd_str = NULL;
172 char *helocmd = NULL;
173 char *error_msg = "";
174 struct timeval tv;
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 /* If localhostname not set on command line, use gethostname to set */
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 }
195 if(use_ehlo)
196 asprintf (&helocmd, "%s%s%s", SMTP_EHLO, localhostname, "\r\n");
197 else
198 asprintf (&helocmd, "%s%s%s", SMTP_HELO, localhostname, "\r\n");
200 if (verbose)
201 printf("HELOCMD: %s", helocmd);
203 /* initialize the MAIL command with optional FROM command */
204 asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
206 if (verbose && smtp_use_dummycmd)
207 printf ("FROM CMD: %s", cmd_str);
209 /* initialize alarm signal handling */
210 (void) signal (SIGALRM, socket_timeout_alarm_handler);
212 /* set socket timeout */
213 (void) alarm (socket_timeout);
215 /* start timer */
216 gettimeofday (&tv, NULL);
218 /* try to connect to the host at the given port number */
219 result = my_tcp_connect (server_address, server_port, &sd);
221 if (result == STATE_OK) { /* we connected */
223 /* watch for the SMTP connection string and */
224 /* return a WARNING status if we couldn't read any data */
225 if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) {
226 printf (_("recv() failed\n"));
227 result = STATE_WARNING;
228 }
229 else {
230 if (verbose)
231 printf ("%s", buffer);
232 /* strip the buffer of carriage returns */
233 strip (buffer);
234 /* make sure we find the response we are looking for */
235 if (!strstr (buffer, server_expect)) {
236 if (server_port == SMTP_PORT)
237 printf (_("Invalid SMTP response received from host\n"));
238 else
239 printf (_("Invalid SMTP response received from host on port %d\n"),
240 server_port);
241 result = STATE_WARNING;
242 }
243 }
245 /* send the HELO/EHLO command */
246 send(sd, helocmd, strlen(helocmd), 0);
248 /* allow for response to helo command to reach us */
249 if(read (sd, buffer, MAXBUF - 1) < 0){
250 printf (_("recv() failed\n"));
251 return STATE_WARNING;
252 } else if(use_ehlo){
253 buffer[MAXBUF-1]='\0';
254 if(strstr(buffer, "250 STARTTLS") != NULL ||
255 strstr(buffer, "250-STARTTLS") != NULL){
256 supports_tls=TRUE;
257 }
258 }
260 if(use_ssl && ! supports_tls){
261 printf(_("WARNING - TLS not supported by server\n"));
262 smtp_quit();
263 return STATE_WARNING;
264 }
266 #ifdef HAVE_SSL
267 if(use_ssl) {
268 /* send the STARTTLS command */
269 send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
271 recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
272 if (!strstr (buffer, server_expect)) {
273 printf (_("Server does not support STARTTLS\n"));
274 smtp_quit();
275 return STATE_UNKNOWN;
276 }
277 result = np_net_ssl_init(sd);
278 if(result != STATE_OK) {
279 printf (_("CRITICAL - Cannot create SSL context.\n"));
280 np_net_ssl_cleanup();
281 close(sd);
282 return STATE_CRITICAL;
283 } else {
284 ssl_established = 1;
285 }
287 /*
288 * Resend the EHLO command.
289 *
290 * RFC 3207 (4.2) says: ``The client MUST discard any knowledge
291 * obtained from the server, such as the list of SMTP service
292 * extensions, which was not obtained from the TLS negotiation
293 * itself. The client SHOULD send an EHLO command as the first
294 * command after a successful TLS negotiation.'' For this
295 * reason, some MTAs will not allow an AUTH LOGIN command before
296 * we resent EHLO via TLS.
297 */
298 if (my_send(helocmd, strlen(helocmd)) <= 0) {
299 printf("%s\n", _("SMTP UNKNOWN - Cannot send EHLO command via TLS."));
300 my_close();
301 return STATE_UNKNOWN;
302 }
303 if (verbose)
304 printf(_("sent %s"), helocmd);
305 if ((n = my_recv(buffer, MAX_INPUT_BUFFER - 1)) <= 0) {
306 printf("%s\n", _("SMTP UNKNOWN - Cannot read EHLO response via TLS."));
307 my_close();
308 return STATE_UNKNOWN;
309 }
310 if (verbose) {
311 buffer[n] = '\0';
312 printf("%s", buffer);
313 }
315 # ifdef USE_OPENSSL
316 if ( check_cert ) {
317 result = np_net_ssl_check_cert(days_till_exp);
318 if(result != STATE_OK){
319 printf ("%s\n", _("CRITICAL - Cannot retrieve server certificate."));
320 }
321 my_close();
322 return result;
323 }
324 # endif /* USE_OPENSSL */
325 }
326 #endif
328 /* sendmail will syslog a "NOQUEUE" error if session does not attempt
329 * to do something useful. This can be prevented by giving a command
330 * even if syntax is illegal (MAIL requires a FROM:<...> argument)
331 *
332 * According to rfc821 you can include a null reversepath in the from command
333 * - but a log message is generated on the smtp server.
334 *
335 * You can disable sending mail_command with '--nocommand'
336 * Use the -f option to provide a FROM address
337 */
338 if (smtp_use_dummycmd) {
339 my_send(cmd_str, strlen(cmd_str));
340 my_recv(buffer, MAX_INPUT_BUFFER-1);
341 if (verbose)
342 printf("%s", buffer);
343 }
345 while (n < ncommands) {
346 asprintf (&cmd_str, "%s%s", commands[n], "\r\n");
347 my_send(cmd_str, strlen(cmd_str));
348 my_recv(buffer, MAX_INPUT_BUFFER-1);
349 if (verbose)
350 printf("%s", buffer);
351 strip (buffer);
352 if (n < nresponses) {
353 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
354 errcode = regcomp (&preg, responses[n], cflags);
355 if (errcode != 0) {
356 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
357 printf (_("Could Not Compile Regular Expression"));
358 return ERROR;
359 }
360 excode = regexec (&preg, buffer, 10, pmatch, eflags);
361 if (excode == 0) {
362 result = STATE_OK;
363 }
364 else if (excode == REG_NOMATCH) {
365 result = STATE_WARNING;
366 printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
367 }
368 else {
369 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
370 printf (_("Execute Error: %s\n"), errbuf);
371 result = STATE_UNKNOWN;
372 }
373 }
374 n++;
375 }
377 if (authtype != NULL) {
378 if (strcmp (authtype, "LOGIN") == 0) {
379 char *abuf;
380 int ret;
381 do {
382 if (authuser == NULL) {
383 result = STATE_CRITICAL;
384 asprintf(&error_msg, _("no authuser specified, "));
385 break;
386 }
387 if (authpass == NULL) {
388 result = STATE_CRITICAL;
389 asprintf(&error_msg, _("no authpass specified, "));
390 break;
391 }
393 /* send AUTH LOGIN */
394 my_send(SMTP_AUTH_LOGIN, strlen(SMTP_AUTH_LOGIN));
395 if (verbose)
396 printf (_("sent %s\n"), "AUTH LOGIN");
398 if((ret = my_recv(buffer, MAXBUF - 1)) < 0){
399 asprintf(&error_msg, _("recv() failed after AUTH LOGIN, "));
400 result = STATE_WARNING;
401 break;
402 }
403 buffer[ret] = 0;
404 if (verbose)
405 printf (_("received %s\n"), buffer);
407 if (strncmp (buffer, "334", 3) != 0) {
408 result = STATE_CRITICAL;
409 asprintf(&error_msg, _("invalid response received after AUTH LOGIN, "));
410 break;
411 }
413 /* encode authuser with base64 */
414 abuf = base64 (authuser, strlen(authuser));
415 strcat (abuf, "\r\n");
416 my_send(abuf, strlen(abuf));
417 if (verbose)
418 printf (_("sent %s\n"), abuf);
420 if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
421 result = STATE_CRITICAL;
422 asprintf(&error_msg, _("recv() failed after sending authuser, "));
423 break;
424 }
425 buffer[ret] = 0;
426 if (verbose) {
427 printf (_("received %s\n"), buffer);
428 }
429 if (strncmp (buffer, "334", 3) != 0) {
430 result = STATE_CRITICAL;
431 asprintf(&error_msg, _("invalid response received after authuser, "));
432 break;
433 }
434 /* encode authpass with base64 */
435 abuf = base64 (authpass, strlen(authpass));
436 strcat (abuf, "\r\n");
437 my_send(abuf, strlen(abuf));
438 if (verbose) {
439 printf (_("sent %s\n"), abuf);
440 }
441 if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
442 result = STATE_CRITICAL;
443 asprintf(&error_msg, _("recv() failed after sending authpass, "));
444 break;
445 }
446 buffer[ret] = 0;
447 if (verbose) {
448 printf (_("received %s\n"), buffer);
449 }
450 if (strncmp (buffer, "235", 3) != 0) {
451 result = STATE_CRITICAL;
452 asprintf(&error_msg, _("invalid response received after authpass, "));
453 break;
454 }
455 break;
456 } while (0);
457 } else {
458 result = STATE_CRITICAL;
459 asprintf(&error_msg, _("only authtype LOGIN is supported, "));
460 }
461 }
463 /* tell the server we're done */
464 smtp_quit();
466 /* finally close the connection */
467 close (sd);
468 }
470 /* reset the alarm */
471 alarm (0);
473 microsec = deltime (tv);
474 elapsed_time = (double)microsec / 1.0e6;
476 if (result == STATE_OK) {
477 if (check_critical_time && elapsed_time > (double) critical_time)
478 result = STATE_CRITICAL;
479 else if (check_warning_time && elapsed_time > (double) warning_time)
480 result = STATE_WARNING;
481 }
483 printf (_("SMTP %s - %s%.3f sec. response time%s%s|%s\n"),
484 state_text (result),
485 error_msg,
486 elapsed_time,
487 verbose?", ":"", verbose?buffer:"",
488 fperfdata ("time", elapsed_time, "s",
489 (int)check_warning_time, warning_time,
490 (int)check_critical_time, critical_time,
491 TRUE, 0, FALSE, 0));
493 return result;
494 }
498 /* process command-line arguments */
499 int
500 process_arguments (int argc, char **argv)
501 {
502 int c;
504 int option = 0;
505 static struct option longopts[] = {
506 {"hostname", required_argument, 0, 'H'},
507 {"expect", required_argument, 0, 'e'},
508 {"critical", required_argument, 0, 'c'},
509 {"warning", required_argument, 0, 'w'},
510 {"timeout", required_argument, 0, 't'},
511 {"port", required_argument, 0, 'p'},
512 {"from", required_argument, 0, 'f'},
513 {"fqdn", required_argument, 0, 'F'},
514 {"authtype", required_argument, 0, 'A'},
515 {"authuser", required_argument, 0, 'U'},
516 {"authpass", required_argument, 0, 'P'},
517 {"command", required_argument, 0, 'C'},
518 {"response", required_argument, 0, 'R'},
519 {"nocommand", required_argument, 0, 'n'},
520 {"verbose", no_argument, 0, 'v'},
521 {"version", no_argument, 0, 'V'},
522 {"use-ipv4", no_argument, 0, '4'},
523 {"use-ipv6", no_argument, 0, '6'},
524 {"help", no_argument, 0, 'h'},
525 {"starttls",no_argument,0,'S'},
526 {"certificate",required_argument,0,'D'},
527 {0, 0, 0, 0}
528 };
530 if (argc < 2)
531 return ERROR;
533 for (c = 1; c < argc; c++) {
534 if (strcmp ("-to", argv[c]) == 0)
535 strcpy (argv[c], "-t");
536 else if (strcmp ("-wt", argv[c]) == 0)
537 strcpy (argv[c], "-w");
538 else if (strcmp ("-ct", argv[c]) == 0)
539 strcpy (argv[c], "-c");
540 }
542 while (1) {
543 c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:",
544 longopts, &option);
546 if (c == -1 || c == EOF)
547 break;
549 switch (c) {
550 case 'H': /* hostname */
551 if (is_host (optarg)) {
552 server_address = optarg;
553 }
554 else {
555 usage2 (_("Invalid hostname/address"), optarg);
556 }
557 break;
558 case 'p': /* port */
559 if (is_intpos (optarg))
560 server_port = atoi (optarg);
561 else
562 usage4 (_("Port must be a positive integer"));
563 break;
564 case 'F':
565 /* localhostname */
566 localhostname = strdup(optarg);
567 break;
568 case 'f': /* from argument */
569 from_arg = optarg;
570 smtp_use_dummycmd = 1;
571 break;
572 case 'A':
573 authtype = optarg;
574 break;
575 case 'U':
576 authuser = optarg;
577 break;
578 case 'P':
579 authpass = optarg;
580 break;
581 case 'e': /* server expect string on 220 */
582 server_expect = optarg;
583 break;
584 case 'C': /* commands */
585 if (ncommands >= command_size) {
586 command_size+=8;
587 commands = realloc (commands, sizeof(char *) * command_size);
588 if (commands == NULL)
589 die (STATE_UNKNOWN,
590 _("Could not realloc() units [%d]\n"), ncommands);
591 }
592 commands[ncommands] = (char *) malloc (sizeof(char) * 255);
593 strncpy (commands[ncommands], optarg, 255);
594 ncommands++;
595 break;
596 case 'R': /* server responses */
597 if (nresponses >= response_size) {
598 response_size += 8;
599 responses = realloc (responses, sizeof(char *) * response_size);
600 if (responses == NULL)
601 die (STATE_UNKNOWN,
602 _("Could not realloc() units [%d]\n"), nresponses);
603 }
604 responses[nresponses] = (char *) malloc (sizeof(char) * 255);
605 strncpy (responses[nresponses], optarg, 255);
606 nresponses++;
607 break;
608 case 'c': /* critical time threshold */
609 if (is_intnonneg (optarg)) {
610 critical_time = atoi (optarg);
611 check_critical_time = TRUE;
612 }
613 else {
614 usage4 (_("Critical time must be a positive integer"));
615 }
616 break;
617 case 'w': /* warning time threshold */
618 if (is_intnonneg (optarg)) {
619 warning_time = atoi (optarg);
620 check_warning_time = TRUE;
621 }
622 else {
623 usage4 (_("Warning time must be a positive integer"));
624 }
625 break;
626 case 'v': /* verbose */
627 verbose++;
628 break;
629 case 't': /* timeout */
630 if (is_intnonneg (optarg)) {
631 socket_timeout = atoi (optarg);
632 }
633 else {
634 usage4 (_("Timeout interval must be a positive integer"));
635 }
636 break;
637 case 'S':
638 /* starttls */
639 use_ssl = TRUE;
640 use_ehlo = TRUE;
641 break;
642 case 'D':
643 /* Check SSL cert validity */
644 #ifdef USE_OPENSSL
645 if (!is_intnonneg (optarg))
646 usage2 ("Invalid certificate expiration period",optarg);
647 days_till_exp = atoi (optarg);
648 check_cert = TRUE;
649 #else
650 usage (_("SSL support not available - install OpenSSL and recompile"));
651 #endif
652 break;
653 case '4':
654 address_family = AF_INET;
655 break;
656 case '6':
657 #ifdef USE_IPV6
658 address_family = AF_INET6;
659 #else
660 usage4 (_("IPv6 support not available"));
661 #endif
662 break;
663 case 'V': /* version */
664 print_revision (progname, revision);
665 exit (STATE_OK);
666 case 'h': /* help */
667 print_help ();
668 exit (STATE_OK);
669 case '?': /* help */
670 usage5 ();
671 }
672 }
674 c = optind;
675 if (server_address == NULL) {
676 if (argv[c]) {
677 if (is_host (argv[c]))
678 server_address = argv[c];
679 else
680 usage2 (_("Invalid hostname/address"), argv[c]);
681 }
682 else {
683 asprintf (&server_address, "127.0.0.1");
684 }
685 }
687 if (server_expect == NULL)
688 server_expect = strdup (SMTP_EXPECT);
690 if (mail_command == NULL)
691 mail_command = strdup("MAIL ");
693 if (from_arg==NULL)
694 from_arg = strdup(" ");
696 return validate_arguments ();
697 }
701 int
702 validate_arguments (void)
703 {
704 return OK;
705 }
708 void
709 smtp_quit(void)
710 {
711 int bytes;
713 my_send(SMTP_QUIT, strlen(SMTP_QUIT));
714 if (verbose)
715 printf(_("sent %s\n"), "QUIT");
717 /* read the response but don't care about problems */
718 bytes = my_recv(buffer, MAXBUF - 1);
719 if (verbose) {
720 if (bytes < 0)
721 printf(_("recv() failed after QUIT."));
722 else if (bytes == 0)
723 printf(_("Connection reset by peer."));
724 else {
725 buffer[bytes] = '\0';
726 printf(_("received %s\n"), buffer);
727 }
728 }
729 }
732 int
733 my_close (void)
734 {
735 #ifdef HAVE_SSL
736 np_net_ssl_cleanup();
737 #endif
738 return close(sd);
739 }
742 void
743 print_help (void)
744 {
745 char *myport;
746 asprintf (&myport, "%d", SMTP_PORT);
748 print_revision (progname, revision);
750 printf ("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n");
751 printf (COPYRIGHT, copyright, email);
753 printf("%s\n", _("This plugin will attempt to open an SMTP connection with the host."));
755 printf ("\n\n");
757 print_usage ();
759 printf (_(UT_HELP_VRSN));
761 printf (_(UT_HOST_PORT), 'p', myport);
763 printf (_(UT_IPv46));
765 printf (" %s\n", "-e, --expect=STRING");
766 printf (_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT);
767 printf (" %s\n", "-n, nocommand");
768 printf (" %s\n", _("Suppress SMTP command"));
769 printf (" %s\n", "-C, --command=STRING");
770 printf (" %s\n", _("SMTP command (may be used repeatedly)"));
771 printf (" %s\n", "-R, --command=STRING");
772 printf (" %s\n", _("Expected response to command (may be used repeatedly)"));
773 printf (" %s\n", "-f, --from=STRING");
774 printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")),
775 #ifdef HAVE_SSL
776 printf (" %s\n", "-D, --certificate=INTEGER");
777 printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
778 printf (" %s\n", "-S, --starttls");
779 printf (" %s\n", _("Use STARTTLS for the connection."));
780 #endif
782 printf (" %s\n", "-A, --authtype=STRING");
783 printf (" %s\n", _("SMTP AUTH type to check (default none, only LOGIN supported)"));
784 printf (" %s\n", "-U, --authuser=STRING");
785 printf (" %s\n", _("SMTP AUTH username"));
786 printf (" %s\n", "-P, --authpass=STRING");
787 printf (" %s\n", _("SMTP AUTH password"));
789 printf (_(UT_WARN_CRIT));
791 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
793 printf (_(UT_VERBOSE));
795 printf("\n");
796 printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
797 printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful"));
798 printf ("%s\n", _("connects, but incorrect reponse messages from the host result in"));
799 printf ("%s\n", _("STATE_WARNING return values."));
801 printf (_(UT_SUPPORT));
802 }
806 void
807 print_usage (void)
808 {
809 printf (_("Usage:"));
810 printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname);
811 printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n");
812 printf ("[-S] [-D days] [-n] [-v] [-4|-6]\n");
813 }