diff options
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index f96db49b..4e5d3c81 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -52,8 +52,11 @@ | |||
52 | * | 52 | * |
53 | * According to rfc821 you can include a null reversepath in the from command | 53 | * According to rfc821 you can include a null reversepath in the from command |
54 | * - but a log message is generated on the smtp server. | 54 | * - but a log message is generated on the smtp server. |
55 | * | ||
56 | * Use the -f option to provide a FROM address | ||
55 | */ | 57 | */ |
56 | #define SMTP_DUMMYCMD "MAIL FROM:<>\r\n" | 58 | |
59 | #define SMTP_DUMMYCMD "MAIL " | ||
57 | #define SMTP_USE_DUMMYCMD 1 | 60 | #define SMTP_USE_DUMMYCMD 1 |
58 | #define SMTP_QUIT "QUIT\r\n" | 61 | #define SMTP_QUIT "QUIT\r\n" |
59 | 62 | ||
@@ -67,6 +70,7 @@ void print_usage (void); | |||
67 | int server_port = SMTP_PORT; | 70 | int server_port = SMTP_PORT; |
68 | char *server_address = NULL; | 71 | char *server_address = NULL; |
69 | char *server_expect = NULL; | 72 | char *server_expect = NULL; |
73 | char *from_arg = " "; | ||
70 | int warning_time = 0; | 74 | int warning_time = 0; |
71 | int check_warning_time = FALSE; | 75 | int check_warning_time = FALSE; |
72 | int critical_time = 0; | 76 | int critical_time = 0; |
@@ -80,16 +84,31 @@ main (int argc, char **argv) | |||
80 | int result; | 84 | int result; |
81 | char buffer[MAX_INPUT_BUFFER] = ""; | 85 | char buffer[MAX_INPUT_BUFFER] = ""; |
82 | char helocmd[255] = SMTP_HELO ; | 86 | char helocmd[255] = SMTP_HELO ; |
87 | char from_str[255] = SMTP_DUMMYCMD ; | ||
83 | char myhostname[248]; | 88 | char myhostname[248]; |
84 | 89 | ||
85 | 90 | ||
86 | if (process_arguments (argc, argv) != OK) | 91 | if (process_arguments (argc, argv) != OK) |
87 | usage ("Invalid command arguments supplied\n"); | 92 | usage ("Invalid command arguments supplied\n"); |
88 | 93 | ||
89 | /* initalize the HELO command with the localhostname */ | 94 | /* initialize the HELO command with the localhostname */ |
90 | gethostname(myhostname, sizeof(myhostname)); | 95 | gethostname(myhostname, sizeof(myhostname)); |
91 | strcat(helocmd, myhostname); | 96 | strcat(helocmd, myhostname); |
92 | strcat(helocmd, "\r\n"); | 97 | strcat(helocmd, "\r\n"); |
98 | |||
99 | /* initialize the MAIL command with optional FROM command */ | ||
100 | if (from_arg) { | ||
101 | strcat(from_str, "FROM: "); | ||
102 | strcat(from_str, from_arg); | ||
103 | } | ||
104 | /* terminate line with a CRLF */ | ||
105 | strcat(from_str, "\r\n"); | ||
106 | |||
107 | if (verbose == TRUE){ | ||
108 | printf ("FROMCMD: %s\n", from_str); | ||
109 | } | ||
110 | |||
111 | |||
93 | 112 | ||
94 | /* initialize alarm signal handling */ | 113 | /* initialize alarm signal handling */ |
95 | signal (SIGALRM, socket_timeout_alarm_handler); | 114 | signal (SIGALRM, socket_timeout_alarm_handler); |
@@ -157,9 +176,11 @@ main (int argc, char **argv) | |||
157 | recv(sd,buffer,MAX_INPUT_BUFFER-1,0); | 176 | recv(sd,buffer,MAX_INPUT_BUFFER-1,0); |
158 | 177 | ||
159 | #ifdef SMTP_USE_DUMMYCMD | 178 | #ifdef SMTP_USE_DUMMYCMD |
160 | send(sd,SMTP_DUMMYCMD,strlen(SMTP_DUMMYCMD),0); | 179 | send(sd,from_str,strlen(from_str),0); |
161 | /* allow for response to DUMMYCMD to reach us */ | 180 | /* allow for response to DUMMYCMD to reach us */ |
162 | recv(sd,buffer,MAX_INPUT_BUFFER-1,0); | 181 | recv(sd,buffer,MAX_INPUT_BUFFER-1,0); |
182 | if (verbose == TRUE) | ||
183 | printf("DUMMYCMD: %s\n%s\n",from_str,buffer); | ||
163 | #endif /* SMTP_USE_DUMMYCMD */ | 184 | #endif /* SMTP_USE_DUMMYCMD */ |
164 | 185 | ||
165 | /* finally close the connection */ | 186 | /* finally close the connection */ |
@@ -240,7 +261,8 @@ call_getopt (int argc, char **argv) | |||
240 | {"expect", required_argument, 0, 'e'}, | 261 | {"expect", required_argument, 0, 'e'}, |
241 | {"critical", required_argument, 0, 'c'}, | 262 | {"critical", required_argument, 0, 'c'}, |
242 | {"warning", required_argument, 0, 'w'}, | 263 | {"warning", required_argument, 0, 'w'}, |
243 | {"port", required_argument, 0, 'P'}, | 264 | {"port", required_argument, 0, 'p'}, |
265 | {"from", required_argument, 0, 'f'}, | ||
244 | {"verbose", no_argument, 0, 'v'}, | 266 | {"verbose", no_argument, 0, 'v'}, |
245 | {"version", no_argument, 0, 'V'}, | 267 | {"version", no_argument, 0, 'V'}, |
246 | {"help", no_argument, 0, 'h'}, | 268 | {"help", no_argument, 0, 'h'}, |
@@ -251,10 +273,10 @@ call_getopt (int argc, char **argv) | |||
251 | while (1) { | 273 | while (1) { |
252 | #ifdef HAVE_GETOPT_H | 274 | #ifdef HAVE_GETOPT_H |
253 | c = | 275 | c = |
254 | getopt_long (argc, argv, "+hVvt:p:e:c:w:H:", long_options, | 276 | getopt_long (argc, argv, "+hVvt:p:f:e:c:w:H:", long_options, |
255 | &option_index); | 277 | &option_index); |
256 | #else | 278 | #else |
257 | c = getopt (argc, argv, "+?hVvt:p:e:c:w:H:"); | 279 | c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:"); |
258 | #endif | 280 | #endif |
259 | 281 | ||
260 | i++; | 282 | i++; |
@@ -266,6 +288,7 @@ call_getopt (int argc, char **argv) | |||
266 | case 't': | 288 | case 't': |
267 | case 'p': | 289 | case 'p': |
268 | case 'e': | 290 | case 'e': |
291 | case 'f': | ||
269 | case 'c': | 292 | case 'c': |
270 | case 'w': | 293 | case 'w': |
271 | case 'H': | 294 | case 'H': |
@@ -289,7 +312,10 @@ call_getopt (int argc, char **argv) | |||
289 | usage ("Server port must be a positive integer\n"); | 312 | usage ("Server port must be a positive integer\n"); |
290 | } | 313 | } |
291 | break; | 314 | break; |
292 | case 'e': /* username */ | 315 | case 'f': /* from argument */ |
316 | from_arg = optarg; | ||
317 | break; | ||
318 | case 'e': /* server expect string on 220 */ | ||
293 | server_expect = optarg; | 319 | server_expect = optarg; |
294 | break; | 320 | break; |
295 | case 'c': /* critical time threshold */ | 321 | case 'c': /* critical time threshold */ |
@@ -364,6 +390,8 @@ print_help (void) | |||
364 | " Make connection on the indicated port (default: %d)\n" | 390 | " Make connection on the indicated port (default: %d)\n" |
365 | " -e, --expect=STRING\n" | 391 | " -e, --expect=STRING\n" |
366 | " String to expect in first line of server response (default: %s)\n" | 392 | " String to expect in first line of server response (default: %s)\n" |
393 | " -f, --from=STRING\n" | ||
394 | " from address to include in MAIL command (default NULL, Exchange2000 requires one)\n" | ||
367 | " -w, --warning=INTEGER\n" | 395 | " -w, --warning=INTEGER\n" |
368 | " Seconds necessary to result in a warning status\n" | 396 | " Seconds necessary to result in a warning status\n" |
369 | " -c, --critical=INTEGER\n" | 397 | " -c, --critical=INTEGER\n" |
@@ -388,7 +416,7 @@ void | |||
388 | print_usage (void) | 416 | print_usage (void) |
389 | { | 417 | { |
390 | printf | 418 | printf |
391 | ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n" | 419 | ("Usage: %s -H host [-e expect] [-p port] [-f from addr] [-w warn] [-c crit] [-t timeout] [-v]\n" |
392 | " %s --help\n" | 420 | " %s --help\n" |
393 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); | 421 | " %s --version\n", PROGNAME, PROGNAME, PROGNAME); |
394 | } | 422 | } |