summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 74beab3)
raw | patch | inline | side by side (parent: 74beab3)
author | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Mon, 10 Feb 2003 14:18:00 +0000 (14:18 +0000) | ||
committer | Jeremy T. Bouse <undrgrid@users.sourceforge.net> | |
Mon, 10 Feb 2003 14:18:00 +0000 (14:18 +0000) |
netutils.c rather than its own functions.
Corrected code to properly handle input of server hostname and port on
commandline without option flags.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@305 f882894a-f735-0410-b71e-b25c423dba1c
Corrected code to properly handle input of server hostname and port on
commandline without option flags.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@305 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_ssh.c | patch | blob | history |
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index faaead6a36725ef8e27a286067b567a169ec07de..3efc2e625ad9aa12b8db68d013222506cd4c3798 100644 (file)
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
void print_help (void);
void print_usage (void);
-char *ssh_resolve (char *hostname);
int ssh_connect (char *haddr, short hport);
int
alarm (socket_timeout);
/* ssh_connect exits if error is found */
- ssh_connect (ssh_resolve (server_name), port);
+ ssh_connect (server_name, port);
alarm (0);
process_arguments (int argc, char **argv)
{
int c;
+ char *tmp = NULL;
#ifdef HAVE_GETOPT_H
int option_index = 0;
socket_timeout = atoi (optarg);
break;
case 'H': /* host */
+ if (is_host (optarg) == FALSE)
+ usage ("Invalid hostname/address\n");
server_name = optarg;
break;
case 'p': /* port */
c = optind;
if (server_name == NULL && argv[c]) {
- server_name = argv[c++];
+ if (is_host (argv[c])) {
+ server_name = argv[c++];
+ }
}
- else if (port == -1 && argv[c]) {
+
+ if (port == -1 && argv[c]) {
if (is_intpos (argv[c])) {
port = atoi (argv[c++]);
}
}
-/************************************************************************
-*
-* Resolve hostname into IP address
-*
-*-----------------------------------------------------------------------*/
-
-char *
-ssh_resolve (char *hostname)
-{
- struct hostent *host;
-
- host = gethostbyname (hostname);
- if (!host) {
- herror (hostname);
- exit (STATE_CRITICAL);
- }
- return (host->h_addr);
-}
-
-
/************************************************************************
*
* Try to connect to SSH server at specified server and port
int
ssh_connect (char *haddr, short hport)
{
- int s;
- struct sockaddr_in addr;
- int addrlen;
- int len;
+ int sd;
+ int result;
char *output = NULL;
char *buffer = NULL;
char *ssh_proto = NULL;
sscanf ("$Revision$", "$Revision: %[0123456789.]", revision);
- addrlen = sizeof (addr);
- memset (&addr, 0, addrlen);
- addr.sin_port = htons (hport);
- addr.sin_family = AF_INET;
- bcopy (haddr, (void *) &addr.sin_addr.s_addr, 4);
+ result = my_tcp_connect (haddr, hport, &sd);
- s = socket (AF_INET, SOCK_STREAM, 0);
- if (!s) {
- printf ("socket(): %s for %s:%d\n", strerror (errno), server_name, hport);
- exit (STATE_CRITICAL);
- }
-
- if (connect (s, (struct sockaddr *) &addr, addrlen)) {
- printf ("connect(): %s for %s:%d\n", strerror (errno), server_name,
- hport);
- exit (STATE_CRITICAL);
- }
+ if (result != STATE_OK)
+ return result;
output = (char *) malloc (BUFF_SZ + 1);
memset (output, 0, BUFF_SZ + 1);
- recv (s, output, BUFF_SZ, 0);
+ recv (sd, output, BUFF_SZ, 0);
if (strncmp (output, "SSH", 3)) {
printf ("Server answer: %s", output);
exit (STATE_CRITICAL);
("SSH ok - %s (protocol %s)\n",
ssh_server, ssh_proto);
asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
- send (s, buffer, strlen (buffer), MSG_DONTWAIT);
+ send (sd, buffer, strlen (buffer), MSG_DONTWAIT);
if (verbose)
printf ("%s\n", buffer);
exit (STATE_OK);