summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 8eb2b9b..f80a9dc 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -1,37 +1,49 @@
1/****************************************************************************** 1/*****************************************************************************
2 * 2*
3 * Program: SNMP plugin for Nagios 3* This program is free software; you can redistribute it and/or modify
4 * License: GPL 4* it under the terms of the GNU General Public License as published by
5 * 5* the Free Software Foundation; either version 2 of the License, or
6 * License Information: 6* (at your option) any later version.
7 * 7*
8 * This program is free software; you can redistribute it and/or modify 8* This program is distributed in the hope that it will be useful,
9 * it under the terms of the GNU General Public License as published by 9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * the Free Software Foundation; either version 2 of the License, or 10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * (at your option) any later version. 11* GNU General Public License for more details.
12 * 12*
13 * This program is distributed in the hope that it will be useful, 13* You should have received a copy of the GNU General Public License
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14* along with this program; if not, write to the Free Software
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 * GNU General Public License for more details. 16*
17 * 17*****************************************************************************/
18 * You should have received a copy of the GNU General Public License 18
19 * along with this program; if not, write to the Free Software 19const char *progname = "check_dig";
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20const char *revision = "$Revision$";
21 *****************************************************************************/ 21const char *copyright = "2002-2003";
22const char *authors = "Nagios Plugin Development Team";
23const char *email = "nagiosplug-devel@lists.sourceforge.net";
24const char *summary = "Test the DNS service on the specified host using dig\n";
25
26const char *option_summary = "-H host -l lookup [-t timeout] [-v]";
27
28const char *options = "\
29 -H, --hostname=STRING or IPADDRESS\n\
30 Check server on the indicated host\n\
31 -l, --lookup=STRING\n\
32 machine name to lookup\n\
33 -t, --timeout=INTEGER\n\
34 Seconds before connection attempt times out (default: %d)\n\
35 -v, --verbose\n\
36 Print extra information (command-line use only)\n\
37 -h, --help\n\
38 Print detailed help screen\n\
39 -V, --version\n\
40 Print version information\n\n";
22 41
23#include "config.h" 42#include "config.h"
24#include "common.h" 43#include "common.h"
25#include "utils.h" 44#include "utils.h"
26#include "popen.h" 45#include "popen.h"
27 46
28const char *progname = "check_dig";
29#define REVISION "$Revision$"
30#define COPYRIGHT "2000-2002"
31#define AUTHOR "Karl DeBisschop"
32#define EMAIL "karl@debisschop.net"
33#define SUMMARY "Test the DNS service on the specified host using dig\n"
34
35int process_arguments (int, char **); 47int process_arguments (int, char **);
36int validate_arguments (void); 48int validate_arguments (void);
37void print_help (void); 49void print_help (void);
@@ -210,7 +222,7 @@ process_arguments (int argc, char **argv)
210 } 222 }
211 } 223 }
212 else { 224 else {
213 asprintf (&dns_server, "127.0.0.1"); 225 dns_server = strdup ("127.0.0.1");
214 } 226 }
215 } 227 }
216 228
@@ -234,25 +246,13 @@ validate_arguments (void)
234void 246void
235print_help (void) 247print_help (void)
236{ 248{
237 print_revision (progname, "$Revision$"); 249 print_revision (progname, revision);
238 printf 250 printf
239 ("Copyright (c) %s %s <%s>\n\n%s\n", 251 ("Copyright (c) %s %s <%s>\n\n%s\n",
240 COPYRIGHT, AUTHOR, EMAIL, SUMMARY); 252 copyright, authors, email, summary);
241 print_usage (); 253 print_usage ();
242 printf 254 printf ("\nOptions:\n");
243 ("\nOptions:\n" 255 printf (options, DEFAULT_SOCKET_TIMEOUT);
244 " -H, --hostname=STRING or IPADDRESS\n"
245 " Check server on the indicated host\n"
246 " -l, --lookup=STRING\n"
247 " machine name to lookup\n"
248 " -t, --timeout=INTEGER\n"
249 " Seconds before connection attempt times out (default: %d)\n"
250 " -v, --verbose\n"
251 " Print extra information (command-line use only)\n"
252 " -h, --help\n"
253 " Print detailed help screen\n"
254 " -V, --version\n"
255 " Print version information\n\n", DEFAULT_SOCKET_TIMEOUT);
256 support (); 256 support ();
257} 257}
258 258
@@ -263,8 +263,7 @@ print_help (void)
263void 263void
264print_usage (void) 264print_usage (void)
265{ 265{
266 printf 266 printf ("Usage: %s %s\n", progname, option_summary);
267 ("Usage: %s -H host -l lookup [-t timeout] [-v]\n" 267 printf (" %s (-h|--help)\n", progname);
268 " %s --help\n" 268 printf (" %s (-V|--version)\n", progname);
269 " %s --version\n", progname, progname, progname);
270} 269}
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 5bec291..62efc8c 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
diff --git a/plugins/netutils.c b/plugins/netutils.c
index ce8b428..926547e 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -40,8 +40,10 @@ int was_refused = FALSE;
40void 40void
41socket_timeout_alarm_handler (int sig) 41socket_timeout_alarm_handler (int sig)
42{ 42{
43 43 if (sig == SIGALRM)
44 printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout); 44 printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
45 else
46 printf ("CRITICAL - Abnormal timeout after %d seconds\n", socket_timeout);
45 47
46 exit (STATE_CRITICAL); 48 exit (STATE_CRITICAL);
47} 49}
@@ -99,7 +101,7 @@ process_tcp_request2 (char *server_address, int server_port,
99 return STATE_CRITICAL; 101 return STATE_CRITICAL;
100 102
101 send_result = send (sd, send_buffer, strlen (send_buffer), 0); 103 send_result = send (sd, send_buffer, strlen (send_buffer), 0);
102 if (send_result != strlen (send_buffer)) { 104 if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
103 printf ("send() failed\n"); 105 printf ("send() failed\n");
104 result = STATE_WARNING; 106 result = STATE_WARNING;
105 } 107 }
@@ -177,7 +179,7 @@ process_request (char *server_address, int server_port, int proto,
177 return STATE_CRITICAL; 179 return STATE_CRITICAL;
178 180
179 send_result = send (sd, send_buffer, strlen (send_buffer), 0); 181 send_result = send (sd, send_buffer, strlen (send_buffer), 0);
180 if (send_result != strlen (send_buffer)) { 182 if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
181 printf ("send() failed\n"); 183 printf ("send() failed\n");
182 result = STATE_WARNING; 184 result = STATE_WARNING;
183 } 185 }
@@ -248,7 +250,6 @@ my_connect (char *host_name, int port, int *sd, int proto)
248{ 250{
249 struct addrinfo hints; 251 struct addrinfo hints;
250 struct addrinfo *res; 252 struct addrinfo *res;
251 struct addrinfo *ptrp;
252 char port_str[6]; 253 char port_str[6];
253 int result; 254 int result;
254 255
@@ -267,7 +268,7 @@ my_connect (char *host_name, int port, int *sd, int proto)
267 while (res) { 268 while (res) {
268 /* attempt to create a socket */ 269 /* attempt to create a socket */
269 *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ? 270 *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
270 SOCK_DGRAM : SOCK_STREAM, res->ai_protocol); 271 SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
271 272
272 if (*sd < 0) { 273 if (*sd < 0) {
273 printf ("Socket creation failed\n"); 274 printf ("Socket creation failed\n");
@@ -285,13 +286,13 @@ my_connect (char *host_name, int port, int *sd, int proto)
285 286
286 if (result < 0) { 287 if (result < 0) {
287 switch (errno) { 288 switch (errno) {
288 case ECONNREFUSED: 289 case ECONNREFUSED:
289 switch (econn_refuse_state) { 290 switch (econn_refuse_state) {
290 case STATE_OK: 291 case STATE_OK:
291 case STATE_WARNING: 292 case STATE_WARNING:
292 was_refused = TRUE; 293 was_refused = TRUE;
293 } 294 }
294 break; 295 break;
295 } 296 }
296 } 297 }
297 298
@@ -314,55 +315,56 @@ my_connect (char *host_name, int port, int *sd, int proto)
314int 315int
315is_host (char *address) 316is_host (char *address)
316{ 317{
317 if (is_addr (address) || is_hostname (address)) 318 if (is_addr (address) || is_hostname (address))
318 return (TRUE); 319 return (TRUE);
319 320
320 return (FALSE); 321 return (FALSE);
321} 322}
322 323
323int 324int
324is_addr (char *address) 325is_addr (char *address)
325{ 326{
327 if (is_inet_addr (address))
328 return (TRUE);
329
326#ifdef USE_IPV6 330#ifdef USE_IPV6
327 if (is_inet_addr (address) || is_inet6_addr (address)) 331 if (is_inet6_addr (address))
328#else 332 return (TRUE);
329 if (is_inet_addr (address))
330#endif 333#endif
331 return (TRUE);
332 334
333 return (FALSE); 335 return (FALSE);
334} 336}
335 337
336int 338int
337resolve_host_or_addr (char *address, int family) 339resolve_host_or_addr (char *address, int family)
338{ 340{
339 struct addrinfo hints; 341 struct addrinfo hints;
340 struct addrinfo *res; 342 struct addrinfo *res;
341 int retval; 343 int retval;
342 344
343 memset (&hints, 0, sizeof (hints)); 345 memset (&hints, 0, sizeof (hints));
344 hints.ai_family = family; 346 hints.ai_family = family;
345 retval = getaddrinfo (address, NULL, &hints, &res); 347 retval = getaddrinfo (address, NULL, &hints, &res);
346 348
347 if (retval != 0) 349 if (retval != 0)
348 return FALSE; 350 return FALSE;
349 else { 351 else {
350 freeaddrinfo (res); 352 freeaddrinfo (res);
351 return TRUE; 353 return TRUE;
352 } 354 }
353} 355}
354 356
355int 357int
356is_inet_addr (char *address) 358is_inet_addr (char *address)
357{ 359{
358 return resolve_host_or_addr (address, AF_INET); 360 return resolve_host_or_addr (address, AF_INET);
359} 361}
360 362
361#ifdef USE_IPV6 363#ifdef USE_IPV6
362int 364int
363is_inet6_addr (char *address) 365is_inet6_addr (char *address)
364{ 366{
365 return resolve_host_or_addr (address, AF_INET6); 367 return resolve_host_or_addr (address, AF_INET6);
366} 368}
367#endif 369#endif
368 370
@@ -370,9 +372,9 @@ int
370is_hostname (char *s1) 372is_hostname (char *s1)
371{ 373{
372#ifdef USE_IPV6 374#ifdef USE_IPV6
373 return resolve_host_or_addr (s1, AF_UNSPEC); 375 return resolve_host_or_addr (s1, AF_UNSPEC);
374#else 376#else
375 return resolve_host_or_addr (s1, AF_INET); 377 return resolve_host_or_addr (s1, AF_INET);
376#endif 378#endif
377} 379}
378 380