summaryrefslogtreecommitdiffstats
path: root/plugins/check_ssh.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-02-22 22:14:17 +0100
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-07 23:38:50 +0100
commit665e2f91306fa9b38044a382e4b7571a0c8c0c5f (patch)
tree66a10f452b026a8958bec21fd4da069a8afee454 /plugins/check_ssh.c
parent4173d724a4e780cde281d8952f3468d403c19f2e (diff)
downloadmonitoring-plugins-665e2f91306fa9b38044a382e4b7571a0c8c0c5f.tar.gz
clang-format
Diffstat (limited to 'plugins/check_ssh.c')
-rw-r--r--plugins/check_ssh.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index 42a88cf9..a50ca530 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -64,8 +64,9 @@ int main(int argc, char **argv) {
64 /* Parse extra opts if any */ 64 /* Parse extra opts if any */
65 argv = np_extra_opts(&argc, argv, progname); 65 argv = np_extra_opts(&argc, argv, progname);
66 66
67 if (process_arguments(argc, argv) == ERROR) 67 if (process_arguments(argc, argv) == ERROR) {
68 usage4(_("Could not parse arguments")); 68 usage4(_("Could not parse arguments"));
69 }
69 70
70 /* initialize alarm signal handling */ 71 /* initialize alarm signal handling */
71 signal(SIGALRM, socket_timeout_alarm_handler); 72 signal(SIGALRM, socket_timeout_alarm_handler);
@@ -95,20 +96,24 @@ int process_arguments(int argc, char **argv) {
95 {"remote-protocol", required_argument, 0, 'P'}, 96 {"remote-protocol", required_argument, 0, 'P'},
96 {0, 0, 0, 0}}; 97 {0, 0, 0, 0}};
97 98
98 if (argc < 2) 99 if (argc < 2) {
99 return ERROR; 100 return ERROR;
101 }
100 102
101 for (int i = 1; i < argc; i++) 103 for (int i = 1; i < argc; i++) {
102 if (strcmp("-to", argv[i]) == 0) 104 if (strcmp("-to", argv[i]) == 0) {
103 strcpy(argv[i], "-t"); 105 strcpy(argv[i], "-t");
106 }
107 }
104 108
105 int option_char; 109 int option_char;
106 while (true) { 110 while (true) {
107 int option = 0; 111 int option = 0;
108 option_char = getopt_long(argc, argv, "+Vhv46t:r:H:p:P:", longopts, &option); 112 option_char = getopt_long(argc, argv, "+Vhv46t:r:H:p:P:", longopts, &option);
109 113
110 if (option_char == -1 || option_char == EOF) 114 if (option_char == -1 || option_char == EOF) {
111 break; 115 break;
116 }
112 117
113 switch (option_char) { 118 switch (option_char) {
114 case '?': /* help */ 119 case '?': /* help */
@@ -123,10 +128,11 @@ int process_arguments(int argc, char **argv) {
123 verbose = true; 128 verbose = true;
124 break; 129 break;
125 case 't': /* timeout period */ 130 case 't': /* timeout period */
126 if (!is_integer(optarg)) 131 if (!is_integer(optarg)) {
127 usage2(_("Timeout interval must be a positive integer"), optarg); 132 usage2(_("Timeout interval must be a positive integer"), optarg);
128 else 133 } else {
129 socket_timeout = atoi(optarg); 134 socket_timeout = atoi(optarg);
135 }
130 break; 136 break;
131 case '4': 137 case '4':
132 address_family = AF_INET; 138 address_family = AF_INET;
@@ -145,8 +151,9 @@ int process_arguments(int argc, char **argv) {
145 remote_protocol = optarg; 151 remote_protocol = optarg;
146 break; 152 break;
147 case 'H': /* host */ 153 case 'H': /* host */
148 if (!is_host(optarg)) 154 if (!is_host(optarg)) {
149 usage2(_("Invalid hostname/address"), optarg); 155 usage2(_("Invalid hostname/address"), optarg);
156 }
150 server_name = optarg; 157 server_name = optarg;
151 break; 158 break;
152 case 'p': /* port */ 159 case 'p': /* port */
@@ -178,10 +185,12 @@ int process_arguments(int argc, char **argv) {
178} 185}
179 186
180int validate_arguments(void) { 187int validate_arguments(void) {
181 if (server_name == NULL) 188 if (server_name == NULL) {
182 return ERROR; 189 return ERROR;
183 if (port == -1) /* funky, but allows -p to override stray integer in args */ 190 }
191 if (port == -1) { /* funky, but allows -p to override stray integer in args */
184 port = SSH_DFL_PORT; 192 port = SSH_DFL_PORT;
193 }
185 return OK; 194 return OK;
186} 195}
187 196
@@ -198,8 +207,9 @@ int ssh_connect(char *haddr, int hport, char *remote_version, char *remote_proto
198 int socket; 207 int socket;
199 int result = my_tcp_connect(haddr, hport, &socket); 208 int result = my_tcp_connect(haddr, hport, &socket);
200 209
201 if (result != STATE_OK) 210 if (result != STATE_OK) {
202 return result; 211 return result;
212 }
203 213
204 char *output = (char *)calloc(BUFF_SZ + 1, sizeof(char)); 214 char *output = (char *)calloc(BUFF_SZ + 1, sizeof(char));
205 char *buffer = NULL; 215 char *buffer = NULL;
@@ -259,8 +269,9 @@ int ssh_connect(char *haddr, int hport, char *remote_version, char *remote_proto
259 * - RFC 4253:4.2 269 * - RFC 4253:4.2
260 */ 270 */
261 strip(version_control_string); 271 strip(version_control_string);
262 if (verbose) 272 if (verbose) {
263 printf("%s\n", version_control_string); 273 printf("%s\n", version_control_string);
274 }
264 275
265 char *ssh_proto = version_control_string + 4; 276 char *ssh_proto = version_control_string + 4;
266 277
@@ -297,8 +308,9 @@ int ssh_connect(char *haddr, int hport, char *remote_version, char *remote_proto
297 static char *rev_no = VERSION; 308 static char *rev_no = VERSION;
298 xasprintf(&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no); 309 xasprintf(&buffer, "SSH-%s-check_ssh_%s\r\n", ssh_proto, rev_no);
299 send(socket, buffer, strlen(buffer), MSG_DONTWAIT); 310 send(socket, buffer, strlen(buffer), MSG_DONTWAIT);
300 if (verbose) 311 if (verbose) {
301 printf("%s\n", buffer); 312 printf("%s\n", buffer);
313 }
302 314
303 if (remote_version && strcmp(remote_version, ssh_server)) { 315 if (remote_version && strcmp(remote_version, ssh_server)) {
304 printf(_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"), ssh_server, ssh_proto, remote_version); 316 printf(_("SSH CRITICAL - %s (protocol %s) version mismatch, expected '%s'\n"), ssh_server, ssh_proto, remote_version);