diff options
Diffstat (limited to 'web/attachments/41928-check_ssh.diff')
| -rw-r--r-- | web/attachments/41928-check_ssh.diff | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/web/attachments/41928-check_ssh.diff b/web/attachments/41928-check_ssh.diff new file mode 100644 index 0000000..fce5ad2 --- /dev/null +++ b/web/attachments/41928-check_ssh.diff | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | Index: plugins/check_ssh.c | ||
| 2 | =================================================================== | ||
| 3 | RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ssh.c,v | ||
| 4 | retrieving revision 1.4 | ||
| 5 | diff -u -r1.4 check_ssh.c | ||
| 6 | --- plugins/check_ssh.c 13 Jan 2003 12:15:16 -0000 1.4 | ||
| 7 | +++ plugins/check_ssh.c 9 Feb 2003 19:32:30 -0000 | ||
| 8 | @@ -34,7 +34,6 @@ | ||
| 9 | void print_help (void); | ||
| 10 | void print_usage (void); | ||
| 11 | |||
| 12 | -char *ssh_resolve (char *hostname); | ||
| 13 | int ssh_connect (char *haddr, short hport); | ||
| 14 | |||
| 15 | int | ||
| 16 | @@ -49,7 +48,7 @@ | ||
| 17 | alarm (socket_timeout); | ||
| 18 | |||
| 19 | /* ssh_connect exits if error is found */ | ||
| 20 | - ssh_connect (ssh_resolve (server_name), port); | ||
| 21 | + ssh_connect (server_name, port); | ||
| 22 | |||
| 23 | alarm (0); | ||
| 24 | |||
| 25 | @@ -62,6 +61,7 @@ | ||
| 26 | process_arguments (int argc, char **argv) | ||
| 27 | { | ||
| 28 | int c; | ||
| 29 | + char *tmp = NULL; | ||
| 30 | |||
| 31 | #ifdef HAVE_GETOPT_H | ||
| 32 | int option_index = 0; | ||
| 33 | @@ -109,6 +109,8 @@ | ||
| 34 | socket_timeout = atoi (optarg); | ||
| 35 | break; | ||
| 36 | case 'H': /* host */ | ||
| 37 | + if (is_host (optarg) == FALSE) | ||
| 38 | + usage ("Invalid hostname/address\n"); | ||
| 39 | server_name = optarg; | ||
| 40 | break; | ||
| 41 | case 'p': /* port */ | ||
| 42 | @@ -125,9 +127,12 @@ | ||
| 43 | |||
| 44 | c = optind; | ||
| 45 | if (server_name == NULL && argv[c]) { | ||
| 46 | - server_name = argv[c++]; | ||
| 47 | + if (is_host (argv[c])) { | ||
| 48 | + server_name = argv[c++]; | ||
| 49 | + } | ||
| 50 | } | ||
| 51 | - else if (port == -1 && argv[c]) { | ||
| 52 | + | ||
| 53 | + if (port == -1 && argv[c]) { | ||
| 54 | if (is_intpos (argv[c])) { | ||
| 55 | port = atoi (argv[c++]); | ||
| 56 | } | ||
| 57 | @@ -153,26 +158,6 @@ | ||
| 58 | |||
| 59 | /************************************************************************ | ||
| 60 | * | ||
| 61 | -* Resolve hostname into IP address | ||
| 62 | -* | ||
| 63 | -*-----------------------------------------------------------------------*/ | ||
| 64 | - | ||
| 65 | -char * | ||
| 66 | -ssh_resolve (char *hostname) | ||
| 67 | -{ | ||
| 68 | - struct hostent *host; | ||
| 69 | - | ||
| 70 | - host = gethostbyname (hostname); | ||
| 71 | - if (!host) { | ||
| 72 | - herror (hostname); | ||
| 73 | - exit (STATE_CRITICAL); | ||
| 74 | - } | ||
| 75 | - return (host->h_addr); | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | - | ||
| 79 | -/************************************************************************ | ||
| 80 | -* | ||
| 81 | * Try to connect to SSH server at specified server and port | ||
| 82 | * | ||
| 83 | *-----------------------------------------------------------------------*/ | ||
| 84 | @@ -180,39 +165,24 @@ | ||
| 85 | int | ||
| 86 | ssh_connect (char *haddr, short hport) | ||
| 87 | { | ||
| 88 | - int s; | ||
| 89 | - struct sockaddr_in addr; | ||
| 90 | - int addrlen; | ||
| 91 | - int len; | ||
| 92 | + int sock; | ||
| 93 | + int result; | ||
| 94 | char *output = NULL; | ||
| 95 | char *buffer = NULL; | ||
| 96 | char *ssh_proto = NULL; | ||
| 97 | char *ssh_server = NULL; | ||
| 98 | char revision[20]; | ||
| 99 | |||
| 100 | - sscanf ("$Revision: 1.4 $", "$Revision: %[0123456789.]", revision); | ||
| 101 | + sscanf ("$Revision: 1.4 $", "$Revision: %[0-9.]", revision); | ||
| 102 | |||
| 103 | - addrlen = sizeof (addr); | ||
| 104 | - memset (&addr, 0, addrlen); | ||
| 105 | - addr.sin_port = htons (hport); | ||
| 106 | - addr.sin_family = AF_INET; | ||
| 107 | - bcopy (haddr, (void *) &addr.sin_addr.s_addr, 4); | ||
| 108 | - | ||
| 109 | - s = socket (AF_INET, SOCK_STREAM, 0); | ||
| 110 | - if (!s) { | ||
| 111 | - printf ("socket(): %s for %s:%d\n", strerror (errno), server_name, hport); | ||
| 112 | - exit (STATE_CRITICAL); | ||
| 113 | - } | ||
| 114 | + result = my_tcp_connect (haddr, hport, &sock); | ||
| 115 | |||
| 116 | - if (connect (s, (struct sockaddr *) &addr, addrlen)) { | ||
| 117 | - printf ("connect(): %s for %s:%d\n", strerror (errno), server_name, | ||
| 118 | - hport); | ||
| 119 | - exit (STATE_CRITICAL); | ||
| 120 | - } | ||
| 121 | + if (result != STATE_OK) | ||
| 122 | + return result; | ||
| 123 | |||
| 124 | output = (char *) malloc (BUFF_SZ + 1); | ||
| 125 | memset (output, 0, BUFF_SZ + 1); | ||
| 126 | - recv (s, output, BUFF_SZ, 0); | ||
| 127 | + recv (sock, output, BUFF_SZ, 0); | ||
| 128 | if (strncmp (output, "SSH", 3)) { | ||
| 129 | printf ("Server answer: %s", output); | ||
| 130 | exit (STATE_CRITICAL); | ||
| 131 | @@ -228,7 +198,7 @@ | ||
| 132 | ("SSH ok - %s (protocol %s)\n", | ||
| 133 | ssh_server, ssh_proto); | ||
| 134 | asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision); | ||
| 135 | - send (s, buffer, strlen (buffer), MSG_DONTWAIT); | ||
| 136 | + send (sock, buffer, strlen (buffer), MSG_DONTWAIT); | ||
| 137 | if (verbose) | ||
| 138 | printf ("%s\n", buffer); | ||
| 139 | exit (STATE_OK); | ||
