Code

Fix translations when extra-opts aren't enabled
[nagiosplug.git] / plugins / check_smtp.c
index 79c7cd35f004f903b61b5efb18f4cd68d2c954f6..c78b709ce5a71462b803b1a3ca162bd949f2861f 100644 (file)
@@ -1,50 +1,43 @@
-/******************************************************************************
-*
+/*****************************************************************************
+* 
 * Nagios check_smtp plugin
-*
+* 
 * License: GPL
-* Copyright (c) 1999-2006 nagios-plugins team
-*
-* Last Modified: $Date$
-*
+* Copyright (c) 2000-2007 Nagios Plugins Development Team
+* 
 * Description:
-*
+* 
 * This file contains the check_smtp plugin
-*
-*  This plugin will attempt to open an SMTP connection with the host.
-*
-*
-* License Information:
-*
-* This program is free software; you can redistribute it and/or modify
+* 
+* This plugin will attempt to open an SMTP connection with the host.
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
+* the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
-*
+* 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
-*
+* 
 * You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*
-*
-* $Id$
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
 * 
-******************************************************************************/
+*****************************************************************************/
 
 const char *progname = "check_smtp";
-const char *revision = "$Revision$";
-const char *copyright = "2000-2006";
+const char *copyright = "2000-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-#include <ctype.h>
-
 #include "common.h"
 #include "netutils.h"
 #include "utils.h"
+#include "base64.h"
+
+#include <ctype.h>
 
 #ifdef HAVE_SSL
 int check_cert = FALSE;
@@ -122,46 +115,6 @@ enum {
   UDP_PROTOCOL = 2,
 };
 
-/* written by lauri alanko */
-static char *
-base64 (const char *bin, size_t len)
-{
-
-       char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
-       size_t i = 0, j = 0;
-
-       char BASE64_END = '=';
-       char base64_table[64];
-       strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
-
-       while (j < len - 2) {
-               buf[i++] = base64_table[bin[j] >> 2];
-               buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
-               buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
-               buf[i++] = base64_table[bin[j + 2] & 63];
-               j += 3;
-       }
-
-       switch (len - j) {
-       case 1:
-               buf[i++] = base64_table[bin[j] >> 2];
-               buf[i++] = base64_table[(bin[j] & 3) << 4];
-               buf[i++] = BASE64_END;
-               buf[i++] = BASE64_END;
-               break;
-       case 2:
-               buf[i++] = base64_table[bin[j] >> 2];
-               buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
-               buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
-               buf[i++] = BASE64_END;
-               break;
-       case 0:
-               break;
-       }
-
-       buf[i] = '\0';
-       return buf;
-}
 
 int
 main (int argc, char **argv)
@@ -180,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"));
 
@@ -208,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);
 
@@ -237,10 +193,10 @@ 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);
+                                       printf (_("Invalid SMTP response received from host on port %d: %s\n"),
+                                                                       server_port, buffer);
                                result = STATE_WARNING;
                        }
                }
@@ -325,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)
@@ -333,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) {
@@ -409,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)
@@ -429,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) {
@@ -512,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'},
@@ -567,6 +523,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'A':
                        authtype = optarg;
+                       use_ehlo = TRUE;
                        break;
                case 'U':
                        authuser = optarg;
@@ -657,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 ();
@@ -783,7 +740,7 @@ recvlines(char *buf, size_t bufsize)
 }
 
 
-int 
+int
 my_close (void)
 {
 #ifdef HAVE_SSL
@@ -799,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 <nagios@nagios.org>\n");
        printf (COPYRIGHT, copyright, email);
@@ -810,16 +767,15 @@ 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");
@@ -840,11 +796,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"));
@@ -852,7 +808,13 @@ 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));
+#ifdef NP_EXTRA_OPTS
+  printf ("\n");
+  printf ("%s\n", _("Notes:"));
+  printf (UT_EXTRA_OPTS_NOTES);
+#endif
+
+       printf (UT_SUPPORT);
 }
 
 
@@ -863,6 +825,6 @@ print_usage (void)
   printf (_("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 ("[-S] [-D days] [-v] [-4|-6]\n");
 }