X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_smtp.c;h=ed491638993cdb0598e0c8d1c7b9c74dad492e76;hb=refs%2Fheads%2Fsh%2Fcheck_pgsql;hp=d3e4f42e12fedda023b9f7895158b67e0c041efc;hpb=6c4468a728788676621d4c5948ae018fc9d7c917;p=nagiosplug.git diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index d3e4f42..ed49163 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -5,8 +5,6 @@ * License: GPL * Copyright (c) 2000-2007 Nagios Plugins Development Team * -* Last Modified: $Date$ -* * Description: * * This file contains the check_smtp plugin @@ -27,22 +25,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * -* $Id$ * *****************************************************************************/ const char *progname = "check_smtp"; -const char *revision = "$Revision$"; const char *copyright = "2000-2007"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; -#include - #include "common.h" #include "netutils.h" #include "utils.h" #include "base64.h" +#include + #ifdef HAVE_SSL int check_cert = FALSE; int days_till_exp; @@ -137,6 +133,9 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + /* Parse extra opts if any */ + argv=np_extra_opts (&argc, argv, progname); + if (process_arguments (argc, argv) == ERROR) usage4 (_("Could not parse arguments")); @@ -165,7 +164,7 @@ main (int argc, char **argv) if (verbose && smtp_use_dummycmd) printf ("FROM CMD: %s", cmd_str); - + /* initialize alarm signal handling */ (void) signal (SIGALRM, socket_timeout_alarm_handler); @@ -184,7 +183,7 @@ main (int argc, char **argv) /* return a WARNING status if we couldn't read any data */ if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) { printf (_("recv() failed\n")); - result = STATE_WARNING; + return STATE_WARNING; } else { if (verbose) @@ -194,11 +193,11 @@ main (int argc, char **argv) /* make sure we find the response we are looking for */ if (!strstr (buffer, server_expect)) { if (server_port == SMTP_PORT) - printf (_("Invalid SMTP response received from host\n")); + printf (_("Invalid SMTP response received from host: %s\n"), buffer); else - printf (_("Invalid SMTP response received from host on port %d\n"), - server_port); - result = STATE_WARNING; + printf (_("Invalid SMTP response received from host on port %d: %s\n"), + server_port, buffer); + return STATE_WARNING; } } @@ -282,7 +281,7 @@ main (int argc, char **argv) # endif /* USE_OPENSSL */ } #endif - + /* sendmail will syslog a "NOQUEUE" error if session does not attempt * to do something useful. This can be prevented by giving a command * even if syntax is illegal (MAIL requires a FROM:<...> argument) @@ -290,7 +289,6 @@ main (int argc, char **argv) * According to rfc821 you can include a null reversepath in the from command * - but a log message is generated on the smtp server. * - * You can disable sending mail_command with '--nocommand' * Use the -f option to provide a FROM address */ if (smtp_use_dummycmd) { @@ -366,7 +364,8 @@ main (int argc, char **argv) } /* encode authuser with base64 */ - abuf = base64 (authuser, strlen(authuser)); + base64_encode_alloc (authuser, strlen(authuser), &abuf); + /* FIXME: abuf shouldn't have enough space to strcat a '\r\n' into it. */ strcat (abuf, "\r\n"); my_send(abuf, strlen(abuf)); if (verbose) @@ -386,7 +385,8 @@ main (int argc, char **argv) break; } /* encode authpass with base64 */ - abuf = base64 (authpass, strlen(authpass)); + base64_encode_alloc (authpass, strlen(authpass), &abuf); + /* FIXME: abuf shouldn't have enough space to strcat a '\r\n' into it. */ strcat (abuf, "\r\n"); my_send(abuf, strlen(abuf)); if (verbose) { @@ -469,7 +469,6 @@ process_arguments (int argc, char **argv) {"authpass", required_argument, 0, 'P'}, {"command", required_argument, 0, 'C'}, {"response", required_argument, 0, 'R'}, - {"nocommand", required_argument, 0, 'n'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"use-ipv4", no_argument, 0, '4'}, @@ -615,7 +614,7 @@ process_arguments (int argc, char **argv) #endif break; case 'V': /* version */ - print_revision (progname, revision); + print_revision (progname, NP_VERSION); exit (STATE_OK); case 'h': /* help */ print_help (); @@ -741,7 +740,7 @@ recvlines(char *buf, size_t bufsize) } -int +int my_close (void) { #ifdef HAVE_SSL @@ -757,7 +756,7 @@ print_help (void) char *myport; asprintf (&myport, "%d", SMTP_PORT); - print_revision (progname, revision); + print_revision (progname, NP_VERSION); printf ("Copyright (c) 1999-2001 Ethan Galstad \n"); printf (COPYRIGHT, copyright, email); @@ -768,22 +767,23 @@ print_help (void) print_usage (); - printf (_(UT_HELP_VRSN)); + printf (UT_HELP_VRSN); + printf (UT_EXTRA_OPTS); - printf (_(UT_HOST_PORT), 'p', myport); + printf (UT_HOST_PORT, 'p', myport); - printf (_(UT_IPv46)); + printf (UT_IPv46); printf (" %s\n", "-e, --expect=STRING"); printf (_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT); - printf (" %s\n", "-n, nocommand"); - printf (" %s\n", _("Suppress SMTP command")); printf (" %s\n", "-C, --command=STRING"); printf (" %s\n", _("SMTP command (may be used repeatedly)")); printf (" %s\n", "-R, --command=STRING"); printf (" %s\n", _("Expected response to command (may be used repeatedly)")); printf (" %s\n", "-f, --from=STRING"); printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), + printf (" %s\n", "-F, --fqdn=STRING"); + printf (" %s\n", _("FQDN used for HELO")); #ifdef HAVE_SSL printf (" %s\n", "-D, --certificate=INTEGER"); printf (" %s\n", _("Minimum number of days a certificate has to be valid.")); @@ -798,11 +798,11 @@ print_help (void) printf (" %s\n", "-P, --authpass=STRING"); printf (" %s\n", _("SMTP AUTH password")); - printf (_(UT_WARN_CRIT)); + printf (UT_WARN_CRIT); - printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); + printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); - printf (_(UT_VERBOSE)); + printf (UT_VERBOSE); printf("\n"); printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return")); @@ -810,7 +810,7 @@ print_help (void) printf ("%s\n", _("connects, but incorrect reponse messages from the host result in")); printf ("%s\n", _("STATE_WARNING return values.")); - printf (_(UT_SUPPORT)); + printf (UT_SUPPORT); } @@ -818,9 +818,9 @@ print_help (void) void print_usage (void) { - printf (_("Usage:")); - printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname); + printf ("%s\n", _("Usage:")); + printf ("%s -H host [-p port] [-e expect] [-C command] [-f from addr]", progname); printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout]\n"); - printf ("[-S] [-D days] [-n] [-v] [-4|-6]\n"); + printf ("[-F fqdn] [-S] [-D days] [-v] [-4|-6]\n"); }