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_ssh.c b/plugins/check_ssh.c
index d78189f..ed36dd4 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -16,6 +16,7 @@
16#include "utils.h" 16#include "utils.h"
17 17
18#define PROGNAME "check_ssh" 18#define PROGNAME "check_ssh"
19#define REVISION "$Revision$"
19 20
20#ifndef MSG_DONTWAIT 21#ifndef MSG_DONTWAIT
21#define MSG_DONTWAIT 0 22#define MSG_DONTWAIT 0
@@ -63,46 +64,6 @@ process_arguments (int argc, char **argv)
63{ 64{
64 int c; 65 int c;
65 66
66 if (argc < 2)
67 return ERROR;
68
69 for (c = 1; c < argc; c++)
70 if (strcmp ("-to", argv[c]) == 0)
71 strcpy (argv[c], "-t");
72
73 c = 0;
74 while (c += (call_getopt (argc - c, &argv[c]))) {
75 if (argc <= c)
76 break;
77 if (server_name == NULL) {
78 server_name = argv[c];
79 }
80 else if (port == -1) {
81 if (is_intpos (argv[c])) {
82 port = atoi (argv[c]);
83 }
84 else {
85 print_usage ();
86 exit (STATE_UNKNOWN);
87 }
88 }
89 }
90
91 return validate_arguments ();
92}
93
94
95/************************************************************************
96*
97* Run the getopt until we encounter a non-option entry in the arglist
98*
99*-----------------------------------------------------------------------*/
100
101int
102call_getopt (int argc, char **argv)
103{
104 int c, i = 1;
105
106#ifdef HAVE_GETOPT_H 67#ifdef HAVE_GETOPT_H
107 int option_index = 0; 68 int option_index = 0;
108 static struct option long_options[] = { 69 static struct option long_options[] = {
@@ -115,29 +76,27 @@ call_getopt (int argc, char **argv)
115 }; 76 };
116#endif 77#endif
117 78
79 if (argc < 2)
80 return ERROR;
81
82 for (c = 1; c < argc; c++)
83 if (strcmp ("-to", argv[c]) == 0)
84 strcpy (argv[c], "-t");
85
118 while (1) { 86 while (1) {
119#ifdef HAVE_GETOPT_H 87#ifdef HAVE_GETOPT_H
120 c = getopt_long (argc, argv, "+Vhvt:H:p:", long_options, &option_index); 88 c = getopt_long (argc, argv, "+Vhvt:H:p:", long_options, &option_index);
121#else 89#else
122 c = getopt (argc, argv, "+Vhvt:H:p:"); 90 c = getopt (argc, argv, "+Vhvt:H:p:");
123#endif 91#endif
124
125 if (c == -1 || c == EOF) 92 if (c == -1 || c == EOF)
126 break; 93 break;
127 94
128 i++;
129 switch (c) {
130 case 't':
131 case 'H':
132 case 'p':
133 i++;
134 }
135
136 switch (c) { 95 switch (c) {
137 case '?': /* help */ 96 case '?': /* help */
138 usage (""); 97 usage ("");
139 case 'V': /* version */ 98 case 'V': /* version */
140 print_revision (my_basename (argv[0]), "$Revision$"); 99 print_revision (PROGNAME, REVISION);
141 exit (STATE_OK); 100 exit (STATE_OK);
142 case 'h': /* help */ 101 case 'h': /* help */
143 print_help (); 102 print_help ();
@@ -164,7 +123,22 @@ call_getopt (int argc, char **argv)
164 } 123 }
165 124
166 } 125 }
167 return i; 126
127 c = optind;
128 if (server_name == NULL && argv[c]) {
129 server_name = argv[c++];
130 }
131 else if (port == -1 && argv[c]) {
132 if (is_intpos (argv[c])) {
133 port = atoi (argv[c++]);
134 }
135 else {
136 print_usage ();
137 exit (STATE_UNKNOWN);
138 }
139 }
140
141 return validate_arguments ();
168} 142}
169 143
170int 144int
@@ -249,13 +223,12 @@ ssh_connect (char *haddr, short hport)
249 if (verbose) 223 if (verbose)
250 printf ("%s\n", output); 224 printf ("%s\n", output);
251 ssh_proto = output + 4; 225 ssh_proto = output + 4;
252 ssh_server = ssh_proto + strspn (ssh_proto, "0123456789-. "); 226 ssh_server = ssh_proto + strspn (ssh_proto, "-0123456789. ");
253 ssh_proto[strspn (ssh_proto, "0123456789-. ")] = 0; 227 ssh_proto[strspn (ssh_proto, "0123456789. ")] = 0;
254 printf 228 printf
255 ("SSH ok - protocol version %s - server version %s\n", 229 ("SSH ok - %s (protocol %s)\n",
256 ssh_proto, ssh_server); 230 ssh_server, ssh_proto);
257 buffer = 231 asprintf (&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
258 ssprintf (buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, revision);
259 send (s, buffer, strlen (buffer), MSG_DONTWAIT); 232 send (s, buffer, strlen (buffer), MSG_DONTWAIT);
260 if (verbose) 233 if (verbose)
261 printf ("%s\n", buffer); 234 printf ("%s\n", buffer);
@@ -266,7 +239,7 @@ ssh_connect (char *haddr, short hport)
266void 239void
267print_help (void) 240print_help (void)
268{ 241{
269 print_revision (PROGNAME, "$Revision$"); 242 print_revision (PROGNAME, REVISION);
270 printf ("Copyright (c) 1999 Remi Paulmier (remi@sinfomic.fr)\n\n"); 243 printf ("Copyright (c) 1999 Remi Paulmier (remi@sinfomic.fr)\n\n");
271 print_usage (); 244 print_usage ();
272 printf ("by default, port is %d\n", SSH_DFL_PORT); 245 printf ("by default, port is %d\n", SSH_DFL_PORT);