summaryrefslogtreecommitdiffstats
path: root/plugins/check_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_tcp.c')
-rw-r--r--plugins/check_tcp.c132
1 files changed, 69 insertions, 63 deletions
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 5bec2915..62efc8c7 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -1,4 +1,4 @@
1/****************************************************************************** 1/*****************************************************************************
2* 2*
3* This program is free software; you can redistribute it and/or modify 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 4* it under the terms of the GNU General Public License as published by
@@ -51,7 +51,9 @@ const char *options = "\
51 -r, --refuse=ok|warn|crit\n\ 51 -r, --refuse=ok|warn|crit\n\
52 Accept tcp refusals with states ok, warn, crit (default: crit)\n\ 52 Accept tcp refusals with states ok, warn, crit (default: crit)\n\
53 -v\n\ 53 -v\n\
54 Show details for command-line debugging (do not use with nagios server)\n\ 54 Show details for command-line debugging (do not use with nagios server)\n";
55
56const char *standard_options = "\
55 -h, --help\n\ 57 -h, --help\n\
56 Print detailed help screen\n\ 58 Print detailed help screen\n\
57 -V, --version\n\ 59 -V, --version\n\
@@ -63,21 +65,21 @@ const char *options = "\
63#include "utils.h" 65#include "utils.h"
64 66
65#ifdef HAVE_SSL_H 67#ifdef HAVE_SSL_H
66#include <rsa.h> 68# include <rsa.h>
67#include <crypto.h> 69# include <crypto.h>
68#include <x509.h> 70# include <x509.h>
69#include <pem.h> 71# include <pem.h>
70#include <ssl.h> 72# include <ssl.h>
71#include <err.h> 73# include <err.h>
72#endif 74#else
73 75# ifdef HAVE_OPENSSL_SSL_H
74#ifdef HAVE_OPENSSL_SSL_H 76# include <openssl/rsa.h>
75#include <openssl/rsa.h> 77# include <openssl/crypto.h>
76#include <openssl/crypto.h> 78# include <openssl/x509.h>
77#include <openssl/x509.h> 79# include <openssl/pem.h>
78#include <openssl/pem.h> 80# include <openssl/ssl.h>
79#include <openssl/ssl.h> 81# include <openssl/err.h>
80#include <openssl/err.h> 82# endif
81#endif 83#endif
82 84
83#ifdef HAVE_SSL 85#ifdef HAVE_SSL
@@ -134,8 +136,8 @@ main (int argc, char **argv)
134 struct timeval tv; 136 struct timeval tv;
135 137
136 if (strstr (argv[0], "check_udp")) { 138 if (strstr (argv[0], "check_udp")) {
137 asprintf (&progname, "check_udp"); 139 progname = strdup ("check_udp");
138 asprintf (&SERVICE, "UDP"); 140 SERVICE = strdup ("UDP");
139 SEND = NULL; 141 SEND = NULL;
140 EXPECT = NULL; 142 EXPECT = NULL;
141 QUIT = NULL; 143 QUIT = NULL;
@@ -143,8 +145,8 @@ main (int argc, char **argv)
143 PORT = 0; 145 PORT = 0;
144 } 146 }
145 else if (strstr (argv[0], "check_tcp")) { 147 else if (strstr (argv[0], "check_tcp")) {
146 asprintf (&progname, "check_tcp"); 148 progname = strdup ("check_tcp");
147 asprintf (&SERVICE, "TCP"); 149 SERVICE = strdup ("TCP");
148 SEND = NULL; 150 SEND = NULL;
149 EXPECT = NULL; 151 EXPECT = NULL;
150 QUIT = NULL; 152 QUIT = NULL;
@@ -152,66 +154,66 @@ main (int argc, char **argv)
152 PORT = 0; 154 PORT = 0;
153 } 155 }
154 else if (strstr (argv[0], "check_ftp")) { 156 else if (strstr (argv[0], "check_ftp")) {
155 asprintf (&progname, "check_ftp"); 157 progname = strdup ("check_ftp");
156 asprintf (&SERVICE, "FTP"); 158 SERVICE = strdup ("FTP");
157 SEND = NULL; 159 SEND = NULL;
158 asprintf (&EXPECT, "220"); 160 EXPECT = strdup ("220");
159 asprintf (&QUIT, "QUIT\r\n"); 161 QUIT = strdup ("QUIT\r\n");
160 PROTOCOL = TCP_PROTOCOL; 162 PROTOCOL = TCP_PROTOCOL;
161 PORT = 21; 163 PORT = 21;
162 } 164 }
163 else if (strstr (argv[0], "check_smtp")) { 165 else if (strstr (argv[0], "check_smtp")) {
164 asprintf (&progname, "check_smtp"); 166 progname = strdup ("check_smtp");
165 asprintf (&SERVICE, "SMTP"); 167 SERVICE = strdup ("SMTP");
166 SEND = NULL; 168 SEND = NULL;
167 asprintf (&EXPECT, "220"); 169 EXPECT = strdup ("220");
168 asprintf (&QUIT, "QUIT\r\n"); 170 QUIT = strdup ("QUIT\r\n");
169 PROTOCOL = TCP_PROTOCOL; 171 PROTOCOL = TCP_PROTOCOL;
170 PORT = 25; 172 PORT = 25;
171 } 173 }
172 else if (strstr (argv[0], "check_pop")) { 174 else if (strstr (argv[0], "check_pop")) {
173 asprintf (&progname, "check_pop"); 175 progname = strdup ("check_pop");
174 asprintf (&SERVICE, "POP"); 176 SERVICE = strdup ("POP");
175 SEND = NULL; 177 SEND = NULL;
176 asprintf (&EXPECT, "+OK"); 178 EXPECT = strdup ("+OK");
177 asprintf (&QUIT, "QUIT\r\n"); 179 QUIT = strdup ("QUIT\r\n");
178 PROTOCOL = TCP_PROTOCOL; 180 PROTOCOL = TCP_PROTOCOL;
179 PORT = 110; 181 PORT = 110;
180 } 182 }
181 else if (strstr (argv[0], "check_imap")) { 183 else if (strstr (argv[0], "check_imap")) {
182 asprintf (&progname, "check_imap"); 184 progname = strdup ("check_imap");
183 asprintf (&SERVICE, "IMAP"); 185 SERVICE = strdup ("IMAP");
184 SEND = NULL; 186 SEND = NULL;
185 asprintf (&EXPECT, "* OK"); 187 EXPECT = strdup ("* OK");
186 asprintf (&QUIT, "a1 LOGOUT\r\n"); 188 QUIT = strdup ("a1 LOGOUT\r\n");
187 PROTOCOL = TCP_PROTOCOL; 189 PROTOCOL = TCP_PROTOCOL;
188 PORT = 143; 190 PORT = 143;
189 } 191 }
190#ifdef HAVE_SSL 192#ifdef HAVE_SSL
191 else if (strstr(argv[0],"check_simap")) { 193 else if (strstr(argv[0],"check_simap")) {
192 asprintf (&progname, "check_simap"); 194 progname = strdup ("check_simap");
193 asprintf (&SERVICE, "SIMAP"); 195 SERVICE = strdup ("SIMAP");
194 SEND=NULL; 196 SEND=NULL;
195 asprintf (&EXPECT, "* OK"); 197 EXPECT = strdup ("* OK");
196 asprintf (&QUIT, "a1 LOGOUT\r\n"); 198 QUIT = strdup ("a1 LOGOUT\r\n");
197 PROTOCOL=TCP_PROTOCOL; 199 PROTOCOL=TCP_PROTOCOL;
198 use_ssl=TRUE; 200 use_ssl=TRUE;
199 PORT=993; 201 PORT=993;
200 } 202 }
201 else if (strstr(argv[0],"check_spop")) { 203 else if (strstr(argv[0],"check_spop")) {
202 asprintf (&progname, "check_spop"); 204 progname = strdup ("check_spop");
203 asprintf (&SERVICE, "SPOP"); 205 SERVICE = strdup ("SPOP");
204 SEND=NULL; 206 SEND=NULL;
205 asprintf (&EXPECT, "+OK"); 207 EXPECT = strdup ("+OK");
206 asprintf (&QUIT, "QUIT\r\n"); 208 QUIT = strdup ("QUIT\r\n");
207 PROTOCOL=TCP_PROTOCOL; 209 PROTOCOL=TCP_PROTOCOL;
208 use_ssl=TRUE; 210 use_ssl=TRUE;
209 PORT=995; 211 PORT=995;
210 } 212 }
211#endif 213#endif
212 else if (strstr (argv[0], "check_nntp")) { 214 else if (strstr (argv[0], "check_nntp")) {
213 asprintf (&progname, "check_nntp"); 215 progname = strdup ("check_nntp");
214 asprintf (&SERVICE, "NNTP"); 216 SERVICE = strdup ("NNTP");
215 SEND = NULL; 217 SEND = NULL;
216 EXPECT = NULL; 218 EXPECT = NULL;
217 server_expect = realloc (server_expect, ++server_expect_count); 219 server_expect = realloc (server_expect, ++server_expect_count);
@@ -226,7 +228,7 @@ main (int argc, char **argv)
226 usage ("ERROR: Generic check_tcp called with unknown service\n"); 228 usage ("ERROR: Generic check_tcp called with unknown service\n");
227 } 229 }
228 230
229 asprintf (&server_address, "127.0.0.1"); 231 server_address = strdup ("127.0.0.1");
230 server_port = PORT; 232 server_port = PORT;
231 server_send = SEND; 233 server_send = SEND;
232 server_quit = QUIT; 234 server_quit = QUIT;
@@ -312,17 +314,21 @@ main (int argc, char **argv)
312 } 314 }
313 } 315 }
314 316
315 if (server_quit != NULL) 317 if (server_quit != NULL) {
316#ifdef HAVE_SSL 318#ifdef HAVE_SSL
317 if (use_ssl) { 319 if (use_ssl) {
318 SSL_write (ssl, QUIT, strlen (QUIT)); 320 SSL_write (ssl, server_quit, strlen (server_quit));
319 SSL_shutdown (ssl); 321 SSL_shutdown (ssl);
320 SSL_free (ssl); 322 SSL_free (ssl);
321 SSL_CTX_free (ctx); 323 SSL_CTX_free (ctx);
322 } 324 }
323 else 325 else {
326#endif
327 send (sd, server_quit, strlen (server_quit), 0);
328#ifdef HAVE_SSL
329 }
324#endif 330#endif
325 send (sd, server_quit, strlen (server_quit), 0); 331 }
326 332
327 /* close the connection */ 333 /* close the connection */
328 if (sd) 334 if (sd)
@@ -511,23 +517,23 @@ process_arguments (int argc, char **argv)
511void 517void
512print_help (void) 518print_help (void)
513{ 519{
514 print_revision (progname, revision); 520 print_revision (progname, revision);
515 printf ("Copyright (c) %s %s\n\t<%s>\n\n", 521 printf ("Copyright (c) %s %s\n\t<%s>\n\n",
516 copyright, authors, email); 522 copyright, authors, email);
517 printf (summary, SERVICE); 523 printf (summary, SERVICE);
518 print_usage (); 524 print_usage ();
519 printf ("\nOptions:\n"); 525 printf ("\nOptions:\n");
520 printf (options, DEFAULT_SOCKET_TIMEOUT); 526 printf (options, DEFAULT_SOCKET_TIMEOUT);
521 support (); 527 printf (standard_options);
528 support ();
522} 529}
523 530
524void 531void
525print_usage (void) 532print_usage (void)
526{ 533{
527 printf 534 printf ("Usage: %s %s\n", progname, option_summary);
528 ("Usage: %s %s\n" 535 printf (" %s (-h|--help)\n", progname);
529 " %s (-h|--help)\n" 536 printf (" %s (-V|--version)\n", progname);
530 " %s (-V|--version)\n", progname, option_summary, progname, progname);
531} 537}
532 538
533#ifdef HAVE_SSL 539#ifdef HAVE_SSL