summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-09-02 18:47:07 +0000
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-09-02 18:47:07 +0000
commite0b39ddb7bf047e83b2b743e4de5287757dd0884 (patch)
tree5d7f21d487ab143af87d5b36658f11e5686aceb5 /plugins
parenta3e09d0d2ba2cdeda2713276b6b322946dea5929 (diff)
downloadmonitoring-plugins-e0b39ddb7bf047e83b2b743e4de5287757dd0884.tar.gz
new -f option for adding a FROM address for RFC correctness
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@87 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_smtp.c48
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);
67int server_port = SMTP_PORT; 70int server_port = SMTP_PORT;
68char *server_address = NULL; 71char *server_address = NULL;
69char *server_expect = NULL; 72char *server_expect = NULL;
73char *from_arg = " ";
70int warning_time = 0; 74int warning_time = 0;
71int check_warning_time = FALSE; 75int check_warning_time = FALSE;
72int critical_time = 0; 76int 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
388print_usage (void) 416print_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}