diff options
Diffstat (limited to 'plugins/check_radius.c')
| -rw-r--r-- | plugins/check_radius.c | 553 |
1 files changed, 284 insertions, 269 deletions
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index d9ff8fa7..d26f7cf3 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
| @@ -1,32 +1,32 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * Monitoring check_radius plugin | 3 | * Monitoring check_radius plugin |
| 4 | * | 4 | * |
| 5 | * License: GPL | 5 | * License: GPL |
| 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
| 7 | * | 7 | * |
| 8 | * Description: | 8 | * Description: |
| 9 | * | 9 | * |
| 10 | * This file contains the check_radius plugin | 10 | * This file contains the check_radius plugin |
| 11 | * | 11 | * |
| 12 | * Tests to see if a radius server is accepting connections. | 12 | * Tests to see if a radius server is accepting connections. |
| 13 | * | 13 | * |
| 14 | * | 14 | * |
| 15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
| 18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
| 19 | * | 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
| 24 | * | 24 | * |
| 25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | * | 27 | * |
| 28 | * | 28 | * |
| 29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
| 30 | 30 | ||
| 31 | const char *progname = "check_radius"; | 31 | const char *progname = "check_radius"; |
| 32 | const char *copyright = "2000-2024"; | 32 | const char *copyright = "2000-2024"; |
| @@ -35,64 +35,58 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 35 | #include "common.h" | 35 | #include "common.h" |
| 36 | #include "utils.h" | 36 | #include "utils.h" |
| 37 | #include "netutils.h" | 37 | #include "netutils.h" |
| 38 | #include "states.h" | ||
| 39 | #include "check_radius.d/config.h" | ||
| 38 | 40 | ||
| 39 | #if defined(HAVE_LIBRADCLI) | 41 | #if defined(HAVE_LIBRADCLI) |
| 40 | #include <radcli/radcli.h> | 42 | # include <radcli/radcli.h> |
| 41 | #elif defined(HAVE_LIBFREERADIUS_CLIENT) | 43 | #elif defined(HAVE_LIBFREERADIUS_CLIENT) |
| 42 | #include <freeradius-client.h> | 44 | # include <freeradius-client.h> |
| 43 | #elif defined(HAVE_LIBRADIUSCLIENT_NG) | 45 | #elif defined(HAVE_LIBRADIUSCLIENT_NG) |
| 44 | #include <radiusclient-ng.h> | 46 | # include <radiusclient-ng.h> |
| 45 | #else | 47 | #else |
| 46 | #include <radiusclient.h> | 48 | # include <radiusclient.h> |
| 47 | #endif | 49 | #endif |
| 48 | 50 | ||
| 49 | static int process_arguments (int /*argc*/, char ** /*argv*/); | 51 | typedef struct { |
| 50 | static void print_help (void); | 52 | int errorcode; |
| 51 | void print_usage (void); | 53 | check_radius_config config; |
| 52 | 54 | } check_radius_config_wrapper; | |
| 53 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) | 55 | static check_radius_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); |
| 54 | #define my_rc_conf_str(a) rc_conf_str(rch,a) | 56 | static void print_help(void); |
| 55 | #if defined(HAVE_LIBRADCLI) | 57 | void print_usage(void); |
| 56 | #define my_rc_send_server(a,b) rc_send_server(rch,a,b,AUTH) | 58 | |
| 57 | #else | 59 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \ |
| 58 | #define my_rc_send_server(a,b) rc_send_server(rch,a,b) | 60 | defined(HAVE_LIBRADCLI) |
| 59 | #endif | 61 | # define my_rc_conf_str(a) rc_conf_str(rch, a) |
| 60 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADCLI) | 62 | # if defined(HAVE_LIBRADCLI) |
| 61 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,(a)->secret,e,f) | 63 | # define my_rc_send_server(a, b) rc_send_server(rch, a, b, AUTH) |
| 64 | # else | ||
| 65 | # define my_rc_send_server(a, b) rc_send_server(rch, a, b) | ||
| 66 | # endif | ||
| 67 | # if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADCLI) | ||
| 68 | # define my_rc_buildreq(a, b, c, d, e, f) rc_buildreq(rch, a, b, c, d, (a)->secret, e, f) | ||
| 69 | # else | ||
| 70 | # define my_rc_buildreq(a, b, c, d, e, f) rc_buildreq(rch, a, b, c, d, e, f) | ||
| 71 | # endif | ||
| 72 | # define my_rc_avpair_add(a, b, c, d) rc_avpair_add(rch, a, b, c, -1, d) | ||
| 73 | # define my_rc_read_dictionary(a) rc_read_dictionary(rch, a) | ||
| 62 | #else | 74 | #else |
| 63 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f) | 75 | # define my_rc_conf_str(a) rc_conf_str(a) |
| 64 | #endif | 76 | # define my_rc_send_server(a, b) rc_send_server(a, b) |
| 65 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(rch,a,b,c,-1,d) | 77 | # define my_rc_buildreq(a, b, c, d, e, f) rc_buildreq(a, b, c, d, e, f) |
| 66 | #define my_rc_read_dictionary(a) rc_read_dictionary(rch, a) | 78 | # define my_rc_avpair_add(a, b, c, d) rc_avpair_add(a, b, c, d) |
| 67 | #else | 79 | # define my_rc_read_dictionary(a) rc_read_dictionary(a) |
| 68 | #define my_rc_conf_str(a) rc_conf_str(a) | ||
| 69 | #define my_rc_send_server(a,b) rc_send_server(a, b) | ||
| 70 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(a,b,c,d,e,f) | ||
| 71 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d) | ||
| 72 | #define my_rc_read_dictionary(a) rc_read_dictionary(a) | ||
| 73 | #endif | 80 | #endif |
| 74 | 81 | ||
| 75 | /* REJECT_RC is only defined in some version of radiusclient. It has | 82 | /* REJECT_RC is only defined in some version of radiusclient. It has |
| 76 | * been reported from radiusclient-ng 0.5.6 on FreeBSD 7.2-RELEASE */ | 83 | * been reported from radiusclient-ng 0.5.6 on FreeBSD 7.2-RELEASE */ |
| 77 | #ifndef REJECT_RC | 84 | #ifndef REJECT_RC |
| 78 | #define REJECT_RC BADRESP_RC | 85 | # define REJECT_RC BADRESP_RC |
| 79 | #endif | 86 | #endif |
| 80 | 87 | ||
| 81 | static int my_rc_read_config(char * /*a*/); | 88 | static int my_rc_read_config(char * /*a*/, rc_handle ** /*rch*/); |
| 82 | |||
| 83 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) | ||
| 84 | static rc_handle *rch = NULL; | ||
| 85 | #endif | ||
| 86 | 89 | ||
| 87 | static char *server = NULL; | ||
| 88 | static char *username = NULL; | ||
| 89 | static char *password = NULL; | ||
| 90 | static char *nasid = NULL; | ||
| 91 | static char *nasipaddress = NULL; | ||
| 92 | static char *expect = NULL; | ||
| 93 | static char *config_file = NULL; | ||
| 94 | static unsigned short port = PW_AUTH_UDP_PORT; | ||
| 95 | static int retries = 1; | ||
| 96 | static bool verbose = false; | 90 | static bool verbose = false; |
| 97 | 91 | ||
| 98 | /****************************************************************************** | 92 | /****************************************************************************** |
| @@ -148,149 +142,171 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. | |||
| 148 | -@@ | 142 | -@@ |
| 149 | ******************************************************************************/ | 143 | ******************************************************************************/ |
| 150 | 144 | ||
| 145 | int main(int argc, char **argv) { | ||
| 146 | setlocale(LC_ALL, ""); | ||
| 147 | bindtextdomain(PACKAGE, LOCALEDIR); | ||
| 148 | textdomain(PACKAGE); | ||
| 151 | 149 | ||
| 150 | /* Parse extra opts if any */ | ||
| 151 | argv = np_extra_opts(&argc, argv, progname); | ||
| 152 | |||
| 153 | check_radius_config_wrapper tmp_config = process_arguments(argc, argv); | ||
| 154 | |||
| 155 | if (tmp_config.errorcode == ERROR) { | ||
| 156 | usage4(_("Could not parse arguments")); | ||
| 157 | } | ||
| 158 | |||
| 159 | check_radius_config config = tmp_config.config; | ||
| 160 | |||
| 161 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \ | ||
| 162 | defined(HAVE_LIBRADCLI) | ||
| 163 | rc_handle *rch = NULL; | ||
| 164 | #endif | ||
| 165 | |||
| 166 | char *str = strdup("dictionary"); | ||
| 167 | if ((config.config_file && my_rc_read_config(config.config_file, &rch)) || | ||
| 168 | my_rc_read_dictionary(my_rc_conf_str(str))) { | ||
| 169 | die(STATE_UNKNOWN, _("Config file error\n")); | ||
| 170 | } | ||
| 171 | |||
| 172 | uint32_t service = PW_AUTHENTICATE_ONLY; | ||
| 173 | |||
| 174 | SEND_DATA data; | ||
| 175 | memset(&data, 0, sizeof(data)); | ||
| 176 | if (!(my_rc_avpair_add(&data.send_pairs, PW_SERVICE_TYPE, &service, 0) && | ||
| 177 | my_rc_avpair_add(&data.send_pairs, PW_USER_NAME, config.username, 0) && | ||
| 178 | my_rc_avpair_add(&data.send_pairs, PW_USER_PASSWORD, config.password, 0))) { | ||
| 179 | die(STATE_UNKNOWN, _("Out of Memory?\n")); | ||
| 180 | } | ||
| 181 | |||
| 182 | if (config.nas_id != NULL) { | ||
| 183 | if (!(my_rc_avpair_add(&data.send_pairs, PW_NAS_IDENTIFIER, config.nas_id, 0))) { | ||
| 184 | die(STATE_UNKNOWN, _("Invalid NAS-Identifier\n")); | ||
| 185 | } | ||
| 186 | } | ||
| 152 | 187 | ||
| 153 | int | ||
| 154 | main (int argc, char **argv) | ||
| 155 | { | ||
| 156 | struct sockaddr_storage ss; | ||
| 157 | char name[HOST_NAME_MAX]; | 188 | char name[HOST_NAME_MAX]; |
| 189 | if (config.nas_ip_address == NULL) { | ||
| 190 | if (gethostname(name, sizeof(name)) != 0) { | ||
| 191 | die(STATE_UNKNOWN, _("gethostname() failed!\n")); | ||
| 192 | } | ||
| 193 | config.nas_ip_address = name; | ||
| 194 | } | ||
| 195 | |||
| 196 | struct sockaddr_storage radius_server_socket; | ||
| 197 | if (!dns_lookup(config.nas_ip_address, &radius_server_socket, AF_UNSPEC)) { | ||
| 198 | die(STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 199 | } | ||
| 200 | |||
| 201 | uint32_t client_id = ntohl(((struct sockaddr_in *)&radius_server_socket)->sin_addr.s_addr); | ||
| 202 | if (my_rc_avpair_add(&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL) { | ||
| 203 | die(STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 204 | } | ||
| 205 | |||
| 206 | my_rc_buildreq(&data, PW_ACCESS_REQUEST, config.server, config.port, (int)timeout_interval, | ||
| 207 | config.retries); | ||
| 208 | |||
| 158 | #ifdef RC_BUFFER_LEN | 209 | #ifdef RC_BUFFER_LEN |
| 159 | char msg[RC_BUFFER_LEN]; | 210 | char msg[RC_BUFFER_LEN]; |
| 160 | #else | 211 | #else |
| 161 | char msg[BUFFER_LEN]; | 212 | char msg[BUFFER_LEN]; |
| 162 | #endif | 213 | #endif |
| 163 | SEND_DATA data; | ||
| 164 | int result = STATE_UNKNOWN; | ||
| 165 | uint32_t client_id, service; | ||
| 166 | char *str; | ||
| 167 | 214 | ||
| 168 | setlocale (LC_ALL, ""); | 215 | int result = my_rc_send_server(&data, msg); |
| 169 | bindtextdomain (PACKAGE, LOCALEDIR); | 216 | rc_avpair_free(data.send_pairs); |
| 170 | textdomain (PACKAGE); | 217 | if (data.receive_pairs) { |
| 171 | 218 | rc_avpair_free(data.receive_pairs); | |
| 172 | /* Parse extra opts if any */ | 219 | } |
| 173 | argv=np_extra_opts (&argc, argv, progname); | ||
| 174 | 220 | ||
| 175 | if (process_arguments (argc, argv) == ERROR) | 221 | if (result == TIMEOUT_RC) { |
| 176 | usage4 (_("Could not parse arguments")); | 222 | printf("Timeout\n"); |
| 223 | exit(STATE_CRITICAL); | ||
| 224 | } | ||
| 177 | 225 | ||
| 178 | str = strdup ("dictionary"); | 226 | if (result == ERROR_RC) { |
| 179 | if ((config_file && my_rc_read_config (config_file)) || | 227 | printf(_("Auth Error\n")); |
| 180 | my_rc_read_dictionary (my_rc_conf_str (str))) | 228 | exit(STATE_CRITICAL); |
| 181 | die (STATE_UNKNOWN, _("Config file error\n")); | 229 | } |
| 182 | 230 | ||
| 183 | service = PW_AUTHENTICATE_ONLY; | 231 | if (result == REJECT_RC) { |
| 232 | printf(_("Auth Failed\n")); | ||
| 233 | exit(STATE_WARNING); | ||
| 234 | } | ||
| 184 | 235 | ||
| 185 | memset (&data, 0, sizeof(data)); | 236 | if (result == BADRESP_RC) { |
| 186 | if (!(my_rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) && | 237 | printf(_("Bad Response\n")); |
| 187 | my_rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) && | 238 | exit(STATE_WARNING); |
| 188 | my_rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0) | 239 | } |
| 189 | )) | ||
| 190 | die (STATE_UNKNOWN, _("Out of Memory?\n")); | ||
| 191 | 240 | ||
| 192 | if (nasid != NULL) { | 241 | if (config.expect && !strstr(msg, config.expect)) { |
| 193 | if (!(my_rc_avpair_add (&data.send_pairs, PW_NAS_IDENTIFIER, nasid, 0))) | 242 | printf("%s\n", msg); |
| 194 | die (STATE_UNKNOWN, _("Invalid NAS-Identifier\n")); | 243 | exit(STATE_WARNING); |
| 195 | } | 244 | } |
| 196 | 245 | ||
| 197 | if (nasipaddress == NULL) { | 246 | if (result == OK_RC) { |
| 198 | if (gethostname (name, sizeof(name)) != 0) | 247 | printf(_("Auth OK\n")); |
| 199 | die (STATE_UNKNOWN, _("gethostname() failed!\n")); | 248 | exit(STATE_OK); |
| 200 | nasipaddress = name; | ||
| 201 | } | 249 | } |
| 202 | if (!dns_lookup (nasipaddress, &ss, AF_INET)) /* TODO: Support IPv6. */ | 250 | |
| 203 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 204 | client_id = ntohl (((struct sockaddr_in *)&ss)->sin_addr.s_addr); | ||
| 205 | if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL) | ||
| 206 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 207 | |||
| 208 | my_rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval, | ||
| 209 | retries); | ||
| 210 | |||
| 211 | result = my_rc_send_server (&data, msg); | ||
| 212 | rc_avpair_free (data.send_pairs); | ||
| 213 | if (data.receive_pairs) | ||
| 214 | rc_avpair_free (data.receive_pairs); | ||
| 215 | |||
| 216 | if (result == TIMEOUT_RC) | ||
| 217 | die (STATE_CRITICAL, _("Timeout\n")); | ||
| 218 | if (result == ERROR_RC) | ||
| 219 | die (STATE_CRITICAL, _("Auth Error\n")); | ||
| 220 | if (result == REJECT_RC) | ||
| 221 | die (STATE_WARNING, _("Auth Failed\n")); | ||
| 222 | if (result == BADRESP_RC) | ||
| 223 | die (STATE_WARNING, _("Bad Response\n")); | ||
| 224 | if (expect && !strstr (msg, expect)) | ||
| 225 | die (STATE_WARNING, "%s\n", msg); | ||
| 226 | if (result == OK_RC) | ||
| 227 | die (STATE_OK, _("Auth OK\n")); | ||
| 228 | (void)snprintf(msg, sizeof(msg), _("Unexpected result code %d"), result); | 251 | (void)snprintf(msg, sizeof(msg), _("Unexpected result code %d"), result); |
| 229 | die (STATE_UNKNOWN, "%s\n", msg); | 252 | printf("%s\n", msg); |
| 253 | exit(STATE_UNKNOWN); | ||
| 230 | } | 254 | } |
| 231 | 255 | ||
| 232 | |||
| 233 | |||
| 234 | /* process command-line arguments */ | 256 | /* process command-line arguments */ |
| 235 | int | 257 | check_radius_config_wrapper process_arguments(int argc, char **argv) { |
| 236 | process_arguments (int argc, char **argv) | ||
| 237 | { | ||
| 238 | int c; | ||
| 239 | |||
| 240 | int option = 0; | ||
| 241 | static struct option longopts[] = { | 258 | static struct option longopts[] = { |
| 242 | {"hostname", required_argument, 0, 'H'}, | 259 | {"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'P'}, |
| 243 | {"port", required_argument, 0, 'P'}, | 260 | {"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, |
| 244 | {"username", required_argument, 0, 'u'}, | 261 | {"nas-id", required_argument, 0, 'n'}, {"nas-ip-address", required_argument, 0, 'N'}, |
| 245 | {"password", required_argument, 0, 'p'}, | 262 | {"filename", required_argument, 0, 'F'}, {"expect", required_argument, 0, 'e'}, |
| 246 | {"nas-id", required_argument, 0, 'n'}, | 263 | {"retries", required_argument, 0, 'r'}, {"timeout", required_argument, 0, 't'}, |
| 247 | {"nas-ip-address", required_argument, 0, 'N'}, | 264 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, |
| 248 | {"filename", required_argument, 0, 'F'}, | 265 | {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; |
| 249 | {"expect", required_argument, 0, 'e'}, | 266 | |
| 250 | {"retries", required_argument, 0, 'r'}, | 267 | check_radius_config_wrapper result = { |
| 251 | {"timeout", required_argument, 0, 't'}, | 268 | .errorcode = OK, |
| 252 | {"verbose", no_argument, 0, 'v'}, | 269 | .config = check_radius_config_init(), |
| 253 | {"version", no_argument, 0, 'V'}, | ||
| 254 | {"help", no_argument, 0, 'h'}, | ||
| 255 | {0, 0, 0, 0} | ||
| 256 | }; | 270 | }; |
| 257 | 271 | ||
| 258 | while (1) { | 272 | while (true) { |
| 259 | c = getopt_long (argc, argv, "+hVvH:P:F:u:p:n:N:t:r:e:", longopts, | 273 | int option = 0; |
| 260 | &option); | 274 | int option_index = getopt_long(argc, argv, "+hVvH:P:F:u:p:n:N:t:r:e:", longopts, &option); |
| 261 | 275 | ||
| 262 | if (c == -1 || c == EOF || c == 1) | 276 | if (option_index == -1 || option_index == EOF || option_index == 1) { |
| 263 | break; | 277 | break; |
| 278 | } | ||
| 264 | 279 | ||
| 265 | switch (c) { | 280 | switch (option_index) { |
| 266 | case '?': /* print short usage statement if args not parsable */ | 281 | case '?': /* print short usage statement if args not parsable */ |
| 267 | usage5 (); | 282 | usage5(); |
| 268 | case 'h': /* help */ | 283 | case 'h': /* help */ |
| 269 | print_help (); | 284 | print_help(); |
| 270 | exit (STATE_UNKNOWN); | 285 | exit(STATE_UNKNOWN); |
| 271 | case 'V': /* version */ | 286 | case 'V': /* version */ |
| 272 | print_revision (progname, NP_VERSION); | 287 | print_revision(progname, NP_VERSION); |
| 273 | exit (STATE_UNKNOWN); | 288 | exit(STATE_UNKNOWN); |
| 274 | case 'v': /* verbose mode */ | 289 | case 'v': /* verbose mode */ |
| 275 | verbose = true; | 290 | verbose = true; |
| 276 | break; | 291 | break; |
| 277 | case 'H': /* hostname */ | 292 | case 'H': /* hostname */ |
| 278 | if (!is_host (optarg)) { | 293 | if (!is_host(optarg)) { |
| 279 | usage2 (_("Invalid hostname/address"), optarg); | 294 | usage2(_("Invalid hostname/address"), optarg); |
| 280 | } | 295 | } |
| 281 | server = optarg; | 296 | result.config.server = optarg; |
| 282 | break; | 297 | break; |
| 283 | case 'P': /* port */ | 298 | case 'P': /* port */ |
| 284 | if (is_intnonneg (optarg)) | 299 | if (is_intnonneg(optarg)) { |
| 285 | port = (unsigned short)atoi (optarg); | 300 | result.config.port = (unsigned short)atoi(optarg); |
| 286 | else | 301 | } else { |
| 287 | usage4 (_("Port must be a positive integer")); | 302 | usage4(_("Port must be a positive integer")); |
| 303 | } | ||
| 288 | break; | 304 | break; |
| 289 | case 'u': /* username */ | 305 | case 'u': /* username */ |
| 290 | username = optarg; | 306 | result.config.username = optarg; |
| 291 | break; | 307 | break; |
| 292 | case 'p': /* password */ | 308 | case 'p': /* password */ |
| 293 | password = strdup(optarg); | 309 | result.config.password = strdup(optarg); |
| 294 | 310 | ||
| 295 | /* Delete the password from process list */ | 311 | /* Delete the password from process list */ |
| 296 | while (*optarg != '\0') { | 312 | while (*optarg != '\0') { |
| @@ -298,119 +314,118 @@ process_arguments (int argc, char **argv) | |||
| 298 | optarg++; | 314 | optarg++; |
| 299 | } | 315 | } |
| 300 | break; | 316 | break; |
| 301 | case 'n': /* nas id */ | 317 | case 'n': /* nas id */ |
| 302 | nasid = optarg; | 318 | result.config.nas_id = optarg; |
| 303 | break; | 319 | break; |
| 304 | case 'N': /* nas ip address */ | 320 | case 'N': /* nas ip address */ |
| 305 | nasipaddress = optarg; | 321 | result.config.nas_ip_address = optarg; |
| 306 | break; | 322 | break; |
| 307 | case 'F': /* configuration file */ | 323 | case 'F': /* configuration file */ |
| 308 | config_file = optarg; | 324 | result.config.config_file = optarg; |
| 309 | break; | 325 | break; |
| 310 | case 'e': /* expect */ | 326 | case 'e': /* expect */ |
| 311 | expect = optarg; | 327 | result.config.expect = optarg; |
| 312 | break; | 328 | break; |
| 313 | case 'r': /* retries */ | 329 | case 'r': /* retries */ |
| 314 | if (is_intpos (optarg)) | 330 | if (is_intpos(optarg)) { |
| 315 | retries = atoi (optarg); | 331 | result.config.retries = atoi(optarg); |
| 316 | else | 332 | } else { |
| 317 | usage4 (_("Number of retries must be a positive integer")); | 333 | usage4(_("Number of retries must be a positive integer")); |
| 334 | } | ||
| 318 | break; | 335 | break; |
| 319 | case 't': /* timeout */ | 336 | case 't': /* timeout */ |
| 320 | if (is_intpos (optarg)) | 337 | if (is_intpos(optarg)) { |
| 321 | timeout_interval = (unsigned)atoi (optarg); | 338 | timeout_interval = (unsigned)atoi(optarg); |
| 322 | else | 339 | } else { |
| 323 | usage2 (_("Timeout interval must be a positive integer"), optarg); | 340 | usage2(_("Timeout interval must be a positive integer"), optarg); |
| 341 | } | ||
| 324 | break; | 342 | break; |
| 325 | } | 343 | } |
| 326 | } | 344 | } |
| 327 | 345 | ||
| 328 | if (server == NULL) | 346 | if (result.config.server == NULL) { |
| 329 | usage4 (_("Hostname was not supplied")); | 347 | usage4(_("Hostname was not supplied")); |
| 330 | if (username == NULL) | 348 | } |
| 331 | usage4 (_("User not specified")); | 349 | if (result.config.username == NULL) { |
| 332 | if (password == NULL) | 350 | usage4(_("User not specified")); |
| 333 | usage4 (_("Password not specified")); | 351 | } |
| 334 | if (config_file == NULL) | 352 | if (result.config.password == NULL) { |
| 335 | usage4 (_("Configuration file not specified")); | 353 | usage4(_("Password not specified")); |
| 354 | } | ||
| 355 | if (result.config.config_file == NULL) { | ||
| 356 | usage4(_("Configuration file not specified")); | ||
| 357 | } | ||
| 336 | 358 | ||
| 337 | return OK; | 359 | return result; |
| 338 | } | 360 | } |
| 339 | 361 | ||
| 340 | 362 | void print_help(void) { | |
| 341 | |||
| 342 | void | ||
| 343 | print_help (void) | ||
| 344 | { | ||
| 345 | char *myport; | 363 | char *myport; |
| 346 | xasprintf (&myport, "%d", PW_AUTH_UDP_PORT); | 364 | xasprintf(&myport, "%d", PW_AUTH_UDP_PORT); |
| 347 | 365 | ||
| 348 | print_revision (progname, NP_VERSION); | 366 | print_revision(progname, NP_VERSION); |
| 349 | 367 | ||
| 350 | printf ("Copyright (c) 1999 Robert August Vincent II\n"); | 368 | printf("Copyright (c) 1999 Robert August Vincent II\n"); |
| 351 | printf (COPYRIGHT, copyright, email); | 369 | printf(COPYRIGHT, copyright, email); |
| 352 | 370 | ||
| 353 | printf("%s\n", _("Tests to see if a RADIUS server is accepting connections.")); | 371 | printf("%s\n", _("Tests to see if a RADIUS server is accepting connections.")); |
| 354 | 372 | ||
| 355 | printf ("\n\n"); | 373 | printf("\n\n"); |
| 356 | 374 | ||
| 357 | print_usage (); | 375 | print_usage(); |
| 358 | 376 | ||
| 359 | printf (UT_HELP_VRSN); | 377 | printf(UT_HELP_VRSN); |
| 360 | printf (UT_EXTRA_OPTS); | 378 | printf(UT_EXTRA_OPTS); |
| 361 | 379 | ||
| 362 | printf (UT_HOST_PORT, 'P', myport); | 380 | printf(UT_HOST_PORT, 'P', myport); |
| 363 | 381 | ||
| 364 | printf (" %s\n", "-u, --username=STRING"); | 382 | printf(" %s\n", "-u, --username=STRING"); |
| 365 | printf (" %s\n", _("The user to authenticate")); | 383 | printf(" %s\n", _("The user to authenticate")); |
| 366 | printf (" %s\n", "-p, --password=STRING"); | 384 | printf(" %s\n", "-p, --password=STRING"); |
| 367 | printf (" %s\n", _("Password for authentication (SECURITY RISK)")); | 385 | printf(" %s\n", _("Password for authentication (SECURITY RISK)")); |
| 368 | printf (" %s\n", "-n, --nas-id=STRING"); | 386 | printf(" %s\n", "-n, --nas-id=STRING"); |
| 369 | printf (" %s\n", _("NAS identifier")); | 387 | printf(" %s\n", _("NAS identifier")); |
| 370 | printf (" %s\n", "-N, --nas-ip-address=STRING"); | 388 | printf(" %s\n", "-N, --nas-ip-address=STRING"); |
| 371 | printf (" %s\n", _("NAS IP Address")); | 389 | printf(" %s\n", _("NAS IP Address")); |
| 372 | printf (" %s\n", "-F, --filename=STRING"); | 390 | printf(" %s\n", "-F, --filename=STRING"); |
| 373 | printf (" %s\n", _("Configuration file")); | 391 | printf(" %s\n", _("Configuration file")); |
| 374 | printf (" %s\n", "-e, --expect=STRING"); | 392 | printf(" %s\n", "-e, --expect=STRING"); |
| 375 | printf (" %s\n", _("Response string to expect from the server")); | 393 | printf(" %s\n", _("Response string to expect from the server")); |
| 376 | printf (" %s\n", "-r, --retries=INTEGER"); | 394 | printf(" %s\n", "-r, --retries=INTEGER"); |
| 377 | printf (" %s\n", _("Number of times to retry a failed connection")); | 395 | printf(" %s\n", _("Number of times to retry a failed connection")); |
| 378 | 396 | ||
| 379 | printf (UT_CONN_TIMEOUT, timeout_interval); | 397 | printf(UT_CONN_TIMEOUT, timeout_interval); |
| 380 | 398 | ||
| 381 | printf ("\n"); | 399 | printf("\n"); |
| 382 | printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); | 400 | printf("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); |
| 383 | printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user")); | 401 | printf("%s\n", _("The server to test must be specified in the invocation, as well as a user")); |
| 384 | printf ("%s\n", _("name and password. A configuration file must be present. The format of")); | 402 | printf("%s\n", _("name and password. A configuration file must be present. The format of")); |
| 385 | printf ("%s\n", _("the configuration file is described in the radiusclient library sources.")); | 403 | printf("%s\n", _("the configuration file is described in the radiusclient library sources.")); |
| 386 | printf ("%s\n", _("The password option presents a substantial security issue because the")); | 404 | printf("%s\n", _("The password option presents a substantial security issue because the")); |
| 387 | printf ("%s\n", _("password can possibly be determined by careful watching of the command line")); | 405 | printf("%s\n", |
| 388 | printf ("%s\n", _("in a process listing. This risk is exacerbated because the plugin will")); | 406 | _("password can possibly be determined by careful watching of the command line")); |
| 389 | printf ("%s\n", _("typically be executed at regular predictable intervals. Please be sure that")); | 407 | printf("%s\n", _("in a process listing. This risk is exacerbated because the plugin will")); |
| 390 | printf ("%s\n", _("the password used does not allow access to sensitive system resources.")); | 408 | printf("%s\n", |
| 391 | 409 | _("typically be executed at regular predictable intervals. Please be sure that")); | |
| 392 | printf (UT_SUPPORT); | 410 | printf("%s\n", _("the password used does not allow access to sensitive system resources.")); |
| 411 | |||
| 412 | printf(UT_SUPPORT); | ||
| 393 | } | 413 | } |
| 394 | 414 | ||
| 395 | 415 | void print_usage(void) { | |
| 396 | 416 | printf("%s\n", _("Usage:")); | |
| 397 | void | 417 | printf("%s -H host -F config_file -u username -p password\n\ |
| 398 | print_usage (void) | ||
| 399 | { | ||
| 400 | printf ("%s\n", _("Usage:")); | ||
| 401 | printf ("%s -H host -F config_file -u username -p password\n\ | ||
| 402 | [-P port] [-t timeout] [-r retries] [-e expect]\n\ | 418 | [-P port] [-t timeout] [-r retries] [-e expect]\n\ |
| 403 | [-n nas-id] [-N nas-ip-addr]\n", progname); | 419 | [-n nas-id] [-N nas-ip-addr]\n", |
| 420 | progname); | ||
| 404 | } | 421 | } |
| 405 | 422 | ||
| 406 | 423 | int my_rc_read_config(char *config_file_name, rc_handle **rch) { | |
| 407 | 424 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \ | |
| 408 | int my_rc_read_config(char * a) | 425 | defined(HAVE_LIBRADCLI) |
| 409 | { | 426 | *rch = rc_read_config(config_file_name); |
| 410 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) | ||
| 411 | rch = rc_read_config(a); | ||
| 412 | return (rch == NULL) ? 1 : 0; | 427 | return (rch == NULL) ? 1 : 0; |
| 413 | #else | 428 | #else |
| 414 | return rc_read_config(a); | 429 | return rc_read_config(config_file_name); |
| 415 | #endif | 430 | #endif |
| 416 | } | 431 | } |
