Code

Fix includes for gettext
[nagiosplug.git] / plugins / check_radius.c
index 1e4fff7a855061ff5c7df113f58554bb44e2e8cf..9e1046865e2e4e0a574db7cb2bdc786e460f37f4 100644 (file)
@@ -14,6 +14,8 @@
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
  ******************************************************************************/
 
 const char *progname = "check_radius";
@@ -24,6 +26,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
 #include "common.h"
 #include "utils.h"
 #include "netutils.h"
+
 #include <radiusclient.h>
 
 int process_arguments (int, char **);
@@ -33,6 +36,7 @@ void print_usage (void);
 char *server = NULL;
 char *username = NULL;
 char *password = NULL;
+char *nasid = NULL;
 char *expect = NULL;
 char *config_file = NULL;
 unsigned short port = PW_AUTH_UDP_PORT;
@@ -93,18 +97,24 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
 -@@
 ******************************************************************************/
 
+
+
 int
 main (int argc, char **argv)
 {
        UINT4 service;
        char msg[BUFFER_LEN];
        SEND_DATA data;
-       int result;
+       int result = STATE_UNKNOWN;
        UINT4 client_id;
        char *str;
 
+       setlocale (LC_ALL, "");
+       bindtextdomain (PACKAGE, LOCALEDIR);
+       textdomain (PACKAGE);
+
        if (process_arguments (argc, argv) == ERROR)
-               usage (_("Could not parse arguments\n"));
+               usage4 (_("Could not parse arguments"));
 
        str = strdup ("dictionary");
        if ((config_file && rc_read_config (config_file)) ||
@@ -115,7 +125,8 @@ main (int argc, char **argv)
 
        if (!(rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) &&
                                rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) &&
-                               rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0)))
+                               rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0) &&
+                               (nasid==NULL || rc_avpair_add (&data.send_pairs, PW_NAS_IDENTIFIER, nasid, 0))))
                die (STATE_UNKNOWN, _("Out of Memory?"));
 
        /* 
@@ -163,6 +174,7 @@ process_arguments (int argc, char **argv)
                {"port", required_argument, 0, 'P'},
                {"username", required_argument, 0, 'u'},
                {"password", required_argument, 0, 'p'},
+               {"nas-id", required_argument, 0, 'n'},
                {"filename", required_argument, 0, 'F'},
                {"expect", required_argument, 0, 'e'},
                {"retries", required_argument, 0, 'r'},
@@ -183,7 +195,7 @@ process_arguments (int argc, char **argv)
                if (is_intpos (argv[4]))
                        timeout_interval = atoi (argv[4]);
                else
-                       usage (_("Timeout interval must be a positive integer"));
+                       usage2 (_("Timeout interval must be a positive integer"), optarg);
                if (is_intpos (argv[5]))
                        retries = atoi (argv[5]);
                else
@@ -192,13 +204,13 @@ process_arguments (int argc, char **argv)
                if (is_intpos (argv[7]))
                        port = atoi (argv[7]);
                else
-                       usage (_("Server port must be a positive integer"));
+                       usage (_("Port must be a positive integer"));
                expect = argv[8];
                return OK;
        }
 
        while (1) {
-               c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", longopts,
+               c = getopt_long (argc, argv, "+hVvH:P:F:u:p:n:t:r:e:", longopts,
                                                                         &option);
 
                if (c == -1 || c == EOF || c == 1)
@@ -220,9 +232,7 @@ process_arguments (int argc, char **argv)
                        break;
                case 'H':                                                                       /* hostname */
                        if (is_host (optarg) == FALSE) {
-                               printf (_("Invalid host name/address\n\n"));
-                               print_usage ();
-                               exit (STATE_UNKNOWN);
+                               usage2 (_("Invalid hostname/address"), optarg);
                        }
                        server = optarg;
                        break;
@@ -230,7 +240,7 @@ process_arguments (int argc, char **argv)
                        if (is_intnonneg (optarg))
                                port = atoi (optarg);
                        else
-                               usage (_("Server port must be a positive integer"));
+                               usage (_("Port must be a positive integer"));
                        break;
                case 'u':                                                                       /* username */
                        username = optarg;
@@ -238,6 +248,9 @@ process_arguments (int argc, char **argv)
                case 'p':                                                                       /* password */
                        password = optarg;
                        break;
+               case 'n':                                                                       /* nas id */
+                       nasid = optarg;
+                       break;
                case 'F':                                                                       /* configuration file */
                        config_file = optarg;
                        break;
@@ -254,7 +267,7 @@ process_arguments (int argc, char **argv)
                        if (is_intpos (optarg))
                                timeout_interval = atoi (optarg);
                        else
-                               usage (_("Timeout interval must be a positive integer"));
+                               usage2 (_("Timeout interval must be a positive integer"), optarg);
                        break;
                }
        }
@@ -263,9 +276,6 @@ process_arguments (int argc, char **argv)
 
 
 
-
-
-\f
 void
 print_help (void)
 {
@@ -274,8 +284,8 @@ print_help (void)
 
        print_revision (progname, revision);
 
-       printf (_("Copyright (c) 1999 Robert August Vincent II\n"));
-       printf (_(COPYRIGHT), copyright, email);
+       printf ("Copyright (c) 1999 Robert August Vincent II\n");
+       printf (COPYRIGHT, copyright, email);
 
        printf(_("Tests to see if a radius server is accepting connections.\n\n"));
 
@@ -290,6 +300,8 @@ print_help (void)
     The user to authenticate\n\
  -p, --password=STRING\n\
     Password for autentication (SECURITY RISK)\n\
+ -n, --nas-id=STRING\n\
+    NAS identifier\n\
  -F, --filename=STRING\n\
     Configuration file\n\
  -e, --expect=STRING\n\
@@ -319,12 +331,10 @@ otherwise compormise could occur.\n"));
 
 
 
-
 void
 print_usage (void)
 {
        printf ("\
-Usage: %s -H host -F config_file -u username -p password [-P port]\n\
-  [-t timeout] [-r retries] [-e expect]\n", progname);
-       printf (_(UT_HLP_VRS), progname, progname);
+Usage: %s -H host -F config_file -u username -p password [-n nas-id] [-P port]\n\
+                  [-t timeout] [-r retries] [-e expect]\n", progname);
 }