summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 794d341)
raw | patch | inline | side by side (parent: 794d341)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Wed, 30 Oct 2002 18:29:07 +0000 (18:29 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Wed, 30 Oct 2002 18:29:07 +0000 (18:29 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@165 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_smtp.c | patch | blob | history |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 4e5d3c81c80ce9ad501403d3bdc4ee151d9dc157..5afb694123fa2645c932f97e1e9f8c4fd3a8512e 100644 (file)
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
#define SMTP_QUIT "QUIT\r\n"
int process_arguments (int, char **);
-int call_getopt (int, char **);
int validate_arguments (void);
-int check_disk (int usp, int free_disk);
void print_help (void);
void print_usage (void);
int
main (int argc, char **argv)
{
- int sd;
+ int sd, c;
int result;
char buffer[MAX_INPUT_BUFFER] = "";
- char helocmd[255] = SMTP_HELO ;
- char from_str[255] = SMTP_DUMMYCMD ;
- char myhostname[248];
-
+ char *from_str = NULL;
+ char *helocmd = NULL;
if (process_arguments (argc, argv) != OK)
usage ("Invalid command arguments supplied\n");
/* initialize the HELO command with the localhostname */
- gethostname(myhostname, sizeof(myhostname));
- strcat(helocmd, myhostname);
- strcat(helocmd, "\r\n");
+#ifndef HOST_MAX_BYTES
+#define HOST_MAX_BYTES 255
+#endif
+ helocmd = malloc (HOST_MAX_BYTES);
+ gethostname(helocmd, HOST_MAX_BYTES);
+ asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n");
/* initialize the MAIL command with optional FROM command */
- if (from_arg) {
- strcat(from_str, "FROM: ");
- strcat(from_str, from_arg);
- }
- /* terminate line with a CRLF */
- strcat(from_str, "\r\n");
-
- if (verbose == TRUE){
- printf ("FROMCMD: %s\n", from_str);
- }
+ asprintf (&from_str, "%sFROM: %s%s", SMTP_DUMMYCMD, from_arg, "\r\n");
-
+ if (verbose == TRUE)
+ printf ("FROMCMD: %s\n", from_str);
/* initialize alarm signal handling */
signal (SIGALRM, socket_timeout_alarm_handler);
}
/* close the connection */
+
/* first send the HELO command */
- send(sd,helocmd,strlen(helocmd),0);
+ send(sd, helocmd, strlen(helocmd), 0);
+
/* allow for response to helo command to reach us */
- recv(sd,buffer,MAX_INPUT_BUFFER-1,0);
+ recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
#ifdef SMTP_USE_DUMMYCMD
- send(sd,from_str,strlen(from_str),0);
+ send(sd, from_str, strlen(from_str), 0);
+
/* allow for response to DUMMYCMD to reach us */
- recv(sd,buffer,MAX_INPUT_BUFFER-1,0);
+ recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
+
if (verbose == TRUE)
- printf("DUMMYCMD: %s\n%s\n",from_str,buffer);
+ printf("DUMMYCMD: %s\n%s\n",from_str,buffer);
#endif /* SMTP_USE_DUMMYCMD */
- /* finally close the connection */
+ /* tell the server we're done */
send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
+
+ /* finally close the connection */
close (sd);
}
{
int c;
- if (argc < 2)
- return ERROR;
-
- for (c = 1; c < argc; c++) {
- if (strcmp ("-to", argv[c]) == 0)
- strcpy (argv[c], "-t");
- else if (strcmp ("-wt", argv[c]) == 0)
- strcpy (argv[c], "-w");
- else if (strcmp ("-ct", argv[c]) == 0)
- strcpy (argv[c], "-c");
- }
-
-
-
- c = 0;
- while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
-
- if (is_option (argv[c]))
- continue;
-
- if (server_address == NULL) {
- if (is_host (argv[c])) {
- server_address = argv[c];
- }
- else {
- usage ("Invalid host name");
- }
- }
- }
-
- if (server_address == NULL)
- server_address = strscpy (NULL, "127.0.0.1");
-
- if (server_expect == NULL)
- server_expect = strscpy (NULL, SMTP_EXPECT);
-
- return validate_arguments ();
-}
-
-
-
-
-
-
-int
-call_getopt (int argc, char **argv)
-{
- int c, i = 0;
-
#ifdef HAVE_GETOPT_H
int option_index = 0;
static struct option long_options[] = {
};
#endif
+ if (argc < 2)
+ return ERROR;
+
+ for (c = 1; c < argc; c++) {
+ if (strcmp ("-to", argv[c]) == 0)
+ strcpy (argv[c], "-t");
+ else if (strcmp ("-wt", argv[c]) == 0)
+ strcpy (argv[c], "-w");
+ else if (strcmp ("-ct", argv[c]) == 0)
+ strcpy (argv[c], "-c");
+ }
+
while (1) {
#ifdef HAVE_GETOPT_H
c =
#else
c = getopt (argc, argv, "+?hVvt:p:f:e:c:w:H:");
#endif
-
- i++;
-
- if (c == -1 || c == EOF || c == 1)
+ if (c == -1 || c == EOF)
break;
- switch (c) {
- case 't':
- case 'p':
- case 'e':
- case 'f':
- case 'c':
- case 'w':
- case 'H':
- i++;
- }
-
switch (c) {
case 'H': /* hostname */
if (is_host (optarg)) {
usage ("Invalid argument\n");
}
}
- return i;
+
+ c = optind;
+ if (server_address == NULL) {
+ if (argv[c]) {
+ if (is_host (argv[c]))
+ server_address = argv[c];
+ else
+ usage ("Invalid host name");
+ }
+ else {
+ asprintf (&server_address, "127.0.0.1");
+ }
+ }
+
+ if (server_expect == NULL)
+ asprintf (&server_expect, SMTP_EXPECT);
+
+ return validate_arguments ();
}