Code

1041571: -D option processing corrected (Eric Chen). Changed process_arguments()...
[nagiosplug.git] / plugins / check_tcp.c
1 /*****************************************************************************
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; either version 2 of the License, or
6  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  $Id$
18  
19 *****************************************************************************/
21 /* progname "check_tcp" changes depending on symlink called */
22 char *progname;
23 const char *revision = "$Revision$";
24 const char *copyright = "1999-2004";
25 const char *email = "nagiosplug-devel@lists.sourceforge.net";
27 #include "common.h"
28 #include "netutils.h"
29 #include "utils.h"
31 #ifdef HAVE_SSL_H
32 #  include <rsa.h>
33 #  include <crypto.h>
34 #  include <x509.h>
35 #  include <pem.h>
36 #  include <ssl.h>
37 #  include <err.h>
38 #else
39 #  ifdef HAVE_OPENSSL_SSL_H
40 #    include <openssl/rsa.h>
41 #    include <openssl/crypto.h>
42 #    include <openssl/x509.h>
43 #    include <openssl/pem.h>
44 #    include <openssl/ssl.h>
45 #    include <openssl/err.h>
46 #  endif
47 #endif
49 #ifdef HAVE_SSL
50 int check_cert = FALSE;
51 int days_till_exp;
52 char *randbuff = "";
53 SSL_CTX *ctx;
54 SSL *ssl;
55 X509 *server_cert;
56 int connect_SSL (void);
57 int check_certificate (X509 **);
58 #endif
60 enum {
61         TCP_PROTOCOL = 1,
62         UDP_PROTOCOL = 2,
63         MAXBUF = 1024
64 };
66 int process_arguments (int, char **);
67 int my_recv (void);
68 void print_help (void);
69 void print_usage (void);
71 char *SERVICE = NULL;
72 char *SEND = NULL;
73 char *EXPECT = NULL;
74 char *QUIT = NULL;
75 int PROTOCOL = 0;
76 int PORT = 0;
78 char timestamp[17] = "";
79 int server_port = 0;
80 char *server_address = NULL;
81 char *server_send = NULL;
82 char *server_quit = NULL;
83 char **server_expect = NULL;
84 size_t server_expect_count = 0;
85 int maxbytes = 0;
86 char **warn_codes = NULL;
87 size_t warn_codes_count = 0;
88 char **crit_codes = NULL;
89 size_t crit_codes_count = 0;
90 unsigned int delay = 0;
91 double warning_time = 0;
92 int check_warning_time = FALSE;
93 double critical_time = 0;
94 int check_critical_time = FALSE;
95 int hide_output = FALSE;
96 double elapsed_time = 0;
97 long microsec;
98 int verbose = FALSE;
99 int use_ssl = FALSE;
100 int sd = 0;
101 char *buffer;
105 int
106 main (int argc, char **argv)
108         int result = STATE_UNKNOWN;
109         int i;
110         char *status;
111         struct timeval tv;
113         setlocale (LC_ALL, "");
114         bindtextdomain (PACKAGE, LOCALEDIR);
115         textdomain (PACKAGE);
117         if (strstr (argv[0], "check_udp")) {
118                 progname = strdup ("check_udp");
119                 SERVICE = strdup ("UDP");
120                 SEND = NULL;
121                 EXPECT = NULL;
122                 QUIT = NULL;
123                 PROTOCOL = UDP_PROTOCOL;
124                 PORT = 0;
125         }
126         else if (strstr (argv[0], "check_tcp")) {
127                 progname = strdup ("check_tcp");
128                 SERVICE = strdup ("TCP");
129                 SEND = NULL;
130                 EXPECT = NULL;
131                 QUIT = NULL;
132                 PROTOCOL = TCP_PROTOCOL;
133                 PORT = 0;
134         }
135         else if (strstr (argv[0], "check_ftp")) {
136                 progname = strdup ("check_ftp");
137                 SERVICE = strdup ("FTP");
138                 SEND = NULL;
139                 EXPECT = strdup ("220");
140                 QUIT = strdup ("QUIT\r\n");
141                 PROTOCOL = TCP_PROTOCOL;
142                 PORT = 21;
143         }
144         else if (strstr (argv[0], "check_smtp")) {
145                 progname = strdup ("check_smtp");
146                 SERVICE = strdup ("SMTP");
147                 SEND = NULL;
148                 EXPECT = strdup ("220");
149                 QUIT = strdup ("QUIT\r\n");
150                 PROTOCOL = TCP_PROTOCOL;
151                 PORT = 25;
152         }
153         else if (strstr (argv[0], "check_pop")) {
154                 progname = strdup ("check_pop");
155                 SERVICE = strdup ("POP");
156                 SEND = NULL;
157                 EXPECT = strdup ("+OK");
158                 QUIT = strdup ("QUIT\r\n");
159                 PROTOCOL = TCP_PROTOCOL;
160                 PORT = 110;
161         }
162         else if (strstr (argv[0], "check_imap")) {
163                 progname = strdup ("check_imap");
164                 SERVICE = strdup ("IMAP");
165                 SEND = NULL;
166                 EXPECT = strdup ("* OK");
167                 QUIT = strdup ("a1 LOGOUT\r\n");
168                 PROTOCOL = TCP_PROTOCOL;
169                 PORT = 143;
170         }
171 #ifdef HAVE_SSL
172         else if (strstr(argv[0],"check_simap")) {
173                 progname = strdup ("check_simap");
174                 SERVICE = strdup ("SIMAP");
175                 SEND=NULL;
176                 EXPECT = strdup ("* OK");
177                 QUIT = strdup ("a1 LOGOUT\r\n");
178                 PROTOCOL=TCP_PROTOCOL;
179                 use_ssl=TRUE;
180                 PORT=993;
181         }
182         else if (strstr(argv[0],"check_spop")) {
183                 progname = strdup ("check_spop");
184                 SERVICE = strdup ("SPOP");
185                 SEND=NULL;
186                 EXPECT = strdup ("+OK");
187                 QUIT = strdup ("QUIT\r\n");
188                 PROTOCOL=TCP_PROTOCOL;
189                 use_ssl=TRUE;
190                 PORT=995;
191         }
192         else if (strstr(argv[0],"check_jabber")) {
193                 progname = strdup("check_jabber");
194                 SERVICE = strdup("JABBER");
195                 SEND = strdup("<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n");
196                 EXPECT = strdup("<?xml version=\'1.0\'?><stream:stream xmlns:stream=\'http://etherx.jabber.org/streams\'");
197                 QUIT = strdup("</stream:stream>\n");
198                 PROTOCOL=TCP_PROTOCOL;
199                 use_ssl=TRUE;
200                 PORT = 5222;
201         }
202        else if (strstr (argv[0], "check_nntps")) {
203                 progname = strdup("check_nntps");
204                 SERVICE = strdup("NNTPS");
205                 SEND = NULL;
206                 EXPECT = NULL;
207                 server_expect = realloc (server_expect, ++server_expect_count);
208                 asprintf (&server_expect[server_expect_count - 1], "200");
209                 server_expect = realloc (server_expect, ++server_expect_count);
210                 asprintf (&server_expect[server_expect_count - 1], "201");
211                 QUIT = strdup("QUIT\r\n");
212                 PROTOCOL = TCP_PROTOCOL;
213                 use_ssl=TRUE;
214                 PORT = 563;
217 #endif
218         else if (strstr (argv[0], "check_nntp")) {
219                 progname = strdup ("check_nntp");
220                 SERVICE = strdup ("NNTP");
221                 SEND = NULL;
222                 EXPECT = NULL;
223                 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
224                 asprintf (&server_expect[server_expect_count - 1], "200");
225                 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
226                 asprintf (&server_expect[server_expect_count - 1], "201");
227                 asprintf (&QUIT, "QUIT\r\n");
228                 PROTOCOL = TCP_PROTOCOL;
229                 PORT = 119;
230         }
231         else {
232                 progname = strdup ("check_tcp");
233                 usage (_("CRITICAL - Generic check_tcp called with unknown service\n"));
234         }
236         server_address = strdup ("127.0.0.1");
237         server_port = PORT;
238         server_send = SEND;
239         server_quit = QUIT;
240         status = strdup ("");
242         if (process_arguments (argc, argv) != TRUE)
243                 usage4 (_("Could not parse arguments"));
245         /* use default expect if none listed in process_arguments() */
246         if (EXPECT && server_expect_count == 0) {
247                 server_expect = malloc (sizeof (char *) * (++server_expect_count));
248                 server_expect[server_expect_count - 1] = EXPECT;
249         }
251         /* initialize alarm signal handling */
252         signal (SIGALRM, socket_timeout_alarm_handler);
254         /* set socket timeout */
255         alarm (socket_timeout);
257         /* try to connect to the host at the given port number */
258         gettimeofday (&tv, NULL);
259 #ifdef HAVE_SSL
260         if (use_ssl && check_cert == TRUE) {
261           if (connect_SSL () != OK)
262             die (STATE_CRITICAL,"CRITICAL - Could not make SSL connection\n");
263           if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
264             result = check_certificate (&server_cert);
265             X509_free(server_cert);
266           }
267           else {
268             printf("CRITICAL - Cannot retrieve server certificate.\n");
269             result = STATE_CRITICAL;
270           }
271           SSL_shutdown (ssl);
272           SSL_free (ssl);
273           SSL_CTX_free (ctx);
274           close (sd);
275           return result;
276         }
277         else if (use_ssl)
278                 result = connect_SSL ();
279         else
280 #endif
281                 {
282                         if (PROTOCOL == UDP_PROTOCOL)
283                                 result = my_udp_connect (server_address, server_port, &sd);
284                         else
285                                 /* default is TCP */
286                                 result = my_tcp_connect (server_address, server_port, &sd);
287                 }
289         if (result == STATE_CRITICAL)
290                 return STATE_CRITICAL;
292         if (server_send != NULL) {              /* Something to send? */
293                 asprintf (&server_send, "%s\r\n", server_send);
294 #ifdef HAVE_SSL
295                 if (use_ssl)
296                         SSL_write(ssl, server_send, (int)strlen(server_send));
297                 else
298 #endif
299                         send (sd, server_send, strlen(server_send), 0);
300         }
302         if (delay > 0) {
303                 tv.tv_sec += delay;
304                 sleep (delay);
305         }
307         if (server_send || server_expect_count > 0) {
309                 buffer = malloc (MAXBUF);
310                 memset (buffer, '\0', MAXBUF);
311                 /* watch for the expect string */
312                 while ((i = my_recv ()) > 0) {
313                         buffer[i] = '\0';
314                         asprintf (&status, "%s%s", status, buffer);
315                         if (buffer[i-2] == '\r' && buffer[i-1] == '\n')
316                                 break;
317                         if (maxbytes>0 && strlen(status) >= (unsigned)maxbytes)
318                                 break;
319                 }
321                 /* return a CRITICAL status if we couldn't read any data */
322                 if (strlen(status) == 0)
323                         die (STATE_CRITICAL, _("No data received from host\n"));
325                 strip (status);
327                 if (status && verbose)
328                         printf ("%s\n", status);
330                 if (server_expect_count > 0) {
331                         for (i = 0;; i++) {
332                                 if (verbose)
333                                         printf ("%d %d\n", i, (int)server_expect_count);
334                                 if (i >= (int)server_expect_count)
335                                         die (STATE_WARNING, _("Invalid response from host\n"));
336                                 if (strstr (status, server_expect[i]))
337                                         break;
338                         }
339                 }
340         }
342         if (server_quit != NULL) {
343 #ifdef HAVE_SSL
344                 if (use_ssl) {
345                         SSL_write (ssl, server_quit, (int)strlen(server_quit));
346                         SSL_shutdown (ssl);
347                         SSL_free (ssl);
348                         SSL_CTX_free (ctx);
349                 }
350                 else {
351 #endif
352                         send (sd, server_quit, strlen (server_quit), 0);
353 #ifdef HAVE_SSL
354                 }
355 #endif
356         }
358         /* close the connection */
359         if (sd)
360                 close (sd);
362         microsec = deltime (tv);
363         elapsed_time = (double)microsec / 1.0e6;
365         if (check_critical_time == TRUE && elapsed_time > critical_time)
366                 result = STATE_CRITICAL;
367         else if (check_warning_time == TRUE && elapsed_time > warning_time)
368                 result = STATE_WARNING;
370         /* reset the alarm */
371         alarm (0);
373         printf
374                 (_("%s %s%s - %.3f second response time on port %d"),
375                  SERVICE,
376                  state_text (result),
377                  (was_refused) ? " (refused)" : "",
378                  elapsed_time, server_port);
380         if (hide_output == FALSE && status && strlen(status) > 0)
381                 printf (" [%s]", status);
383         printf (" |%s\n", fperfdata ("time", elapsed_time, "s",
384                 TRUE, warning_time,
385                 TRUE, critical_time,
386                 TRUE, 0,
387                 TRUE, socket_timeout));
389         return result;
394 /* process command-line arguments */
395 int
396 process_arguments (int argc, char **argv)
398         int c;
400         int option = 0;
401         static struct option longopts[] = {
402                 {"hostname", required_argument, 0, 'H'},
403                 {"critical-time", required_argument, 0, 'c'},
404                 {"warning-time", required_argument, 0, 'w'},
405                 {"critical-codes", required_argument, 0, 'C'},
406                 {"warning-codes", required_argument, 0, 'W'},
407                 {"timeout", required_argument, 0, 't'},
408                 {"protocol", required_argument, 0, 'P'},
409                 {"port", required_argument, 0, 'p'},
410                 {"send", required_argument, 0, 's'},
411                 {"expect", required_argument, 0, 'e'},
412                 {"maxbytes", required_argument, 0, 'm'},
413                 {"quit", required_argument, 0, 'q'},
414                 {"jail", required_argument, 0, 'j'},
415                 {"delay", required_argument, 0, 'd'},
416                 {"refuse", required_argument, 0, 'r'},
417                 {"use-ipv4", no_argument, 0, '4'},
418                 {"use-ipv6", no_argument, 0, '6'},
419                 {"verbose", no_argument, 0, 'v'},
420                 {"version", no_argument, 0, 'V'},
421                 {"help", no_argument, 0, 'h'},
422 #ifdef HAVE_SSL
423                 {"ssl", no_argument, 0, 'S'},
424                 {"certificate", required_argument, 0, 'D'},
425 #endif
426                 {0, 0, 0, 0}
427         };
429         if (argc < 2)
430                 usage ("No arguments found\n");
432         /* backwards compatibility */
433         for (c = 1; c < argc; c++) {
434                 if (strcmp ("-to", argv[c]) == 0)
435                         strcpy (argv[c], "-t");
436                 else if (strcmp ("-wt", argv[c]) == 0)
437                         strcpy (argv[c], "-w");
438                 else if (strcmp ("-ct", argv[c]) == 0)
439                         strcpy (argv[c], "-c");
440         }
442         if (!is_option (argv[1])) {
443                 server_address = argv[1];
444                 argv[1] = argv[0];
445                 argv = &argv[1];
446                 argc--;
447         }
449         while (1) {
450                 c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:",
451                                  longopts, &option);
453                 if (c == -1 || c == EOF || c == 1)
454                         break;
456                 switch (c) {
457                 case '?':                 /* print short usage statement if args not parsable */
458                         printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
459                         print_usage ();
460                         exit (STATE_UNKNOWN);
461                 case 'h':                 /* help */
462                         print_help ();
463                         exit (STATE_OK);
464                 case 'V':                 /* version */
465                         print_revision (progname, "$Revision$");
466                         exit (STATE_OK);
467                 case 'v':                 /* verbose mode */
468                         verbose = TRUE;
469                         break;
470                 case '4':
471                         address_family = AF_INET;
472                         break;
473                 case '6':
474 #ifdef USE_IPV6
475                         address_family = AF_INET6;
476 #else
477                         usage (_("IPv6 support not available\n"));
478 #endif
479                         break;
480                 case 'H':                 /* hostname */
481                         if (is_host (optarg) == FALSE)
482                                 usage2 (_("invalid hostname/address"), optarg);
483                         server_address = optarg;
484                         break;
485                 case 'c':                 /* critical */
486                         if (!is_intnonneg (optarg))
487                                 usage (_("Critical threshold must be a positive integer\n"));
488                         else
489                                 critical_time = strtod (optarg, NULL);
490                         check_critical_time = TRUE;
491                         break;
492                 case 'j':                 /* hide output */
493                         hide_output = TRUE;
494                         break;
495                 case 'w':                 /* warning */
496                         if (!is_intnonneg (optarg))
497                                 usage (_("Warning threshold must be a positive integer\n"));
498                         else
499                                 warning_time = strtod (optarg, NULL);
500                         check_warning_time = TRUE;
501                         break;
502                 case 'C':
503                         crit_codes = realloc (crit_codes, ++crit_codes_count);
504                         crit_codes[crit_codes_count - 1] = optarg;
505                         break;
506                 case 'W':
507                         warn_codes = realloc (warn_codes, ++warn_codes_count);
508                         warn_codes[warn_codes_count - 1] = optarg;
509                         break;
510                 case 't':                 /* timeout */
511                         if (!is_intpos (optarg))
512                                 usage (_("Timeout interval must be a positive integer\n"));
513                         else
514                                 socket_timeout = atoi (optarg);
515                         break;
516                 case 'p':                 /* port */
517                         if (!is_intpos (optarg))
518                                 usage (_("Port must be a positive integer\n"));
519                         else
520                                 server_port = atoi (optarg);
521                         break;
522                 case 's':
523                         server_send = optarg;
524                         break;
525                 case 'e': /* expect string (may be repeated) */
526                         EXPECT = NULL;
527                         if (server_expect_count == 0)
528                                 server_expect = malloc (sizeof (char *) * (++server_expect_count));
529                         else
530                                 server_expect = realloc (server_expect, sizeof (char *) * (++server_expect_count));
531                         server_expect[server_expect_count - 1] = optarg;
532                         break;
533                 case 'm':
534                         if (!is_intpos (optarg))
535                                 usage (_("Maxbytes must be a positive integer\n"));
536                         else
537                                 maxbytes = atoi (optarg);
538                 case 'q':
539                         asprintf(&server_quit, "%s\r\n", optarg);
540                         break;
541                 case 'r':
542                         if (!strncmp(optarg,"ok",2))
543                                 econn_refuse_state = STATE_OK;
544                         else if (!strncmp(optarg,"warn",4))
545                                 econn_refuse_state = STATE_WARNING;
546                         else if (!strncmp(optarg,"crit",4))
547                                 econn_refuse_state = STATE_CRITICAL;
548                         else
549                                 usage (_("Refuse must be one of ok, warn, crit\n"));
550                         break;
551                 case 'd':
552                         if (is_intpos (optarg))
553                                 delay = atoi (optarg);
554                         else
555                                 usage (_("Delay must be a positive integer\n"));
556                         break;
557                  case 'D': /* Check SSL cert validity - days 'til certificate expiration */
558 #ifdef HAVE_SSL
559                         if (!is_intnonneg (optarg))
560                                 usage2 ("invalid certificate expiration period", optarg);
561                         days_till_exp = atoi (optarg);
562                         check_cert = TRUE;
563                         use_ssl = TRUE;
564                         break;
565                 case 'S':
566                         use_ssl = TRUE;
567 #else
568                         die (STATE_UNKNOWN, "SSL support not available.  Install OpenSSL and recompile.");
569 #endif
570                         break;
571                 }
572         }
574         if (server_address == NULL)
575                 usage (_("You must provide a server address\n"));
577         return TRUE;
582 #ifdef HAVE_SSL
583 int
584 connect_SSL (void)
586   SSL_METHOD *meth;
588   /* Initialize SSL context */
589   SSLeay_add_ssl_algorithms ();
590   meth = SSLv23_client_method ();
591   SSL_load_error_strings ();
592   OpenSSL_add_all_algorithms();
593   if ((ctx = SSL_CTX_new (meth)) == NULL)
594     {
595       printf (_("CRITICAL - Cannot create SSL context.\n"));
596       return STATE_CRITICAL;
597     }
599   /* Initialize alarm signal handling */
600   signal (SIGALRM, socket_timeout_alarm_handler);
602   /* Set socket timeout */
603   alarm (socket_timeout);
605   /* Save start time */
606   time (&start_time);
608   /* Make TCP connection */
609   if (my_tcp_connect (server_address, server_port, &sd) == STATE_OK && was_refused == FALSE)
610     {
611     /* Do the SSL handshake */
612       if ((ssl = SSL_new (ctx)) != NULL)
613       {
614         SSL_set_fd (ssl, sd);
615         if (SSL_connect(ssl) == 1)
616           return OK;
617         /* ERR_print_errors_fp (stderr); */
618         printf (_("CRITICAL - Cannot make  SSL connection "));
619         ERR_print_errors_fp (stdout);
620         /* printf("\n"); */
621       }
622       else
623       {
624         printf (_("CRITICAL - Cannot initiate SSL handshake.\n"));
625       }
626       SSL_free (ssl);
627     }
629   SSL_CTX_free (ctx);
630   close (sd);
632   return STATE_CRITICAL;
634 #endif
638 #ifdef HAVE_SSL
639 int
640 check_certificate (X509 ** certificate)
642   ASN1_STRING *tm;
643   int offset;
644   struct tm stamp;
645   int days_left;
648   /* Retrieve timestamp of certificate */
649   tm = X509_get_notAfter (*certificate);
651   /* Generate tm structure to process timestamp */
652   if (tm->type == V_ASN1_UTCTIME) {
653     if (tm->length < 10) {
654       printf ("CRITICAL - Wrong time format in certificate.\n");
655       return STATE_CRITICAL;
656     }
657     else {
658       stamp.tm_year = (tm->data[0] - '0') * 10 + (tm->data[1] - '0');
659       if (stamp.tm_year < 50)
660         stamp.tm_year += 100;
661       offset = 0;
662     }
663   }
664   else {
665     if (tm->length < 12) {
666       printf ("CRITICAL - Wrong time format in certificate.\n");
667       return STATE_CRITICAL;
668     }
669     else {
670                         stamp.tm_year =
671                           (tm->data[0] - '0') * 1000 + (tm->data[1] - '0') * 100 +
672                           (tm->data[2] - '0') * 10 + (tm->data[3] - '0');
673                         stamp.tm_year -= 1900;
674                         offset = 2;
675     }
676   }
677         stamp.tm_mon =
678           (tm->data[2 + offset] - '0') * 10 + (tm->data[3 + offset] - '0') - 1;
679         stamp.tm_mday =
680           (tm->data[4 + offset] - '0') * 10 + (tm->data[5 + offset] - '0');
681         stamp.tm_hour =
682           (tm->data[6 + offset] - '0') * 10 + (tm->data[7 + offset] - '0');
683         stamp.tm_min =
684           (tm->data[8 + offset] - '0') * 10 + (tm->data[9 + offset] - '0');
685         stamp.tm_sec = 0;
686         stamp.tm_isdst = -1;
688         days_left = (mktime (&stamp) - time (NULL)) / 86400;
689         snprintf
690           (timestamp, 16, "%02d/%02d/%04d %02d:%02d",
691            stamp.tm_mon + 1,
692            stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
694         if (days_left > 0 && days_left <= days_till_exp) {
695           printf ("Certificate expires in %d day(s) (%s).\n", days_left, timestamp);
696           return STATE_WARNING;
697         }
698         if (days_left < 0) {
699           printf ("Certificate expired on %s.\n", timestamp);
700           return STATE_CRITICAL;
701         }
703         if (days_left == 0) {
704           printf ("Certificate expires today (%s).\n", timestamp);
705           return STATE_WARNING;
706         }
708         printf ("Certificate will expire on %s.\n", timestamp);
710         return STATE_OK;
712 #endif
716 int
717 my_recv (void)
719         int i;
721 #ifdef HAVE_SSL
722         if (use_ssl) {
723                 i = SSL_read (ssl, buffer, MAXBUF - 1);
724         }
725         else {
726 #endif
727                 i = read (sd, buffer, MAXBUF - 1);
728 #ifdef HAVE_SSL
729         }
730 #endif
732         return i;
737 void
738 print_help (void)
740         print_revision (progname, revision);
742         printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"));
743         printf (_(COPYRIGHT), copyright, email);
745         printf (_("This plugin tests %s connections with the specified host.\n\n"),
746                 SERVICE);
748         print_usage ();
750         printf (_(UT_HELP_VRSN));
752         printf (_(UT_HOST_PORT), 'p', "none");
754         printf (_(UT_IPv46));
756         printf (_("\
757  -s, --send=STRING\n\
758     String to send to the server\n\
759  -e, --expect=STRING\n\
760     String to expect in server response\n\
761  -q, --quit=STRING\n\
762     String to send server to initiate a clean close of the connection\n"));
764         printf (_("\
765  -r, --refuse=ok|warn|crit\n\
766     Accept tcp refusals with states ok, warn, crit (default: crit)\n\
767  -j, --jail\n\
768     Hide output from TCP socket\n\
769  -m, --maxbytes=INTEGER\n\
770     Close connection once more than this number of bytes are received\n\
771  -d, --delay=INTEGER\n\
772     Seconds to wait between sending string and polling for response\n"));
774 #ifdef HAVE_SSL
775         printf (_("\
776  -D, --certificate=INTEGER\n\
777     Minimum number of days a certificate has to be valid.\n\
778  -S, --ssl\n\
779     Use SSL for the connection.\n"));
780 #endif
782         printf (_(UT_WARN_CRIT));
784         printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
786         printf (_(UT_VERBOSE));
788         printf (_(UT_SUPPORT));
793 void
794 print_usage (void)
796         printf ("\
797 Usage: %s -H host -p port [-w <warning time>] [-c <critical time>]\n\
798           [-s <send string>] [-e <expect string>] [-q <quit string>]\n\
799           [-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
800           [-r <refuse state>] [-v] [-4|-6] [-j] [-D <days to cert expiry>]\n\
801           [-S <use SSL>]\n", progname);