diff options
Diffstat (limited to 'plugins/check_radius.c')
| -rw-r--r-- | plugins/check_radius.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/plugins/check_radius.c b/plugins/check_radius.c index 03cbb8b0..b1b4938c 100644 --- a/plugins/check_radius.c +++ b/plugins/check_radius.c | |||
| @@ -36,7 +36,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 36 | #include "utils.h" | 36 | #include "utils.h" |
| 37 | #include "netutils.h" | 37 | #include "netutils.h" |
| 38 | 38 | ||
| 39 | #if defined(HAVE_LIBFREERADIUS_CLIENT) | 39 | #if defined(HAVE_LIBRADCLI) |
| 40 | #include <radcli/radcli.h> | ||
| 41 | #elif defined(HAVE_LIBFREERADIUS_CLIENT) | ||
| 40 | #include <freeradius-client.h> | 42 | #include <freeradius-client.h> |
| 41 | #elif defined(HAVE_LIBRADIUSCLIENT_NG) | 43 | #elif defined(HAVE_LIBRADIUSCLIENT_NG) |
| 42 | #include <radiusclient-ng.h> | 44 | #include <radiusclient-ng.h> |
| @@ -48,22 +50,24 @@ int process_arguments (int, char **); | |||
| 48 | void print_help (void); | 50 | void print_help (void); |
| 49 | void print_usage (void); | 51 | void print_usage (void); |
| 50 | 52 | ||
| 51 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) | 53 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) |
| 52 | #define my_rc_conf_str(a) rc_conf_str(rch,a) | 54 | #define my_rc_conf_str(a) rc_conf_str(rch,a) |
| 55 | #if defined(HAVE_LIBRADCLI) | ||
| 56 | #define my_rc_send_server(a,b) rc_send_server(rch,a,b,AUTH) | ||
| 57 | #else | ||
| 53 | #define my_rc_send_server(a,b) rc_send_server(rch,a,b) | 58 | #define my_rc_send_server(a,b) rc_send_server(rch,a,b) |
| 54 | #ifdef HAVE_LIBFREERADIUS_CLIENT | 59 | #endif |
| 60 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADCLI) | ||
| 55 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,(a)->secret,e,f) | 61 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,(a)->secret,e,f) |
| 56 | #else | 62 | #else |
| 57 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f) | 63 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f) |
| 58 | #endif | 64 | #endif |
| 59 | #define my_rc_own_ipaddress() rc_own_ipaddress(rch) | ||
| 60 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(rch,a,b,c,-1,d) | 65 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(rch,a,b,c,-1,d) |
| 61 | #define my_rc_read_dictionary(a) rc_read_dictionary(rch, a) | 66 | #define my_rc_read_dictionary(a) rc_read_dictionary(rch, a) |
| 62 | #else | 67 | #else |
| 63 | #define my_rc_conf_str(a) rc_conf_str(a) | 68 | #define my_rc_conf_str(a) rc_conf_str(a) |
| 64 | #define my_rc_send_server(a,b) rc_send_server(a, b) | 69 | #define my_rc_send_server(a,b) rc_send_server(a, b) |
| 65 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(a,b,c,d,e,f) | 70 | #define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(a,b,c,d,e,f) |
| 66 | #define my_rc_own_ipaddress() rc_own_ipaddress() | ||
| 67 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d) | 71 | #define my_rc_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d) |
| 68 | #define my_rc_read_dictionary(a) rc_read_dictionary(a) | 72 | #define my_rc_read_dictionary(a) rc_read_dictionary(a) |
| 69 | #endif | 73 | #endif |
| @@ -76,7 +80,7 @@ void print_usage (void); | |||
| 76 | 80 | ||
| 77 | int my_rc_read_config(char *); | 81 | int my_rc_read_config(char *); |
| 78 | 82 | ||
| 79 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) | 83 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) |
| 80 | rc_handle *rch = NULL; | 84 | rc_handle *rch = NULL; |
| 81 | #endif | 85 | #endif |
| 82 | 86 | ||
| @@ -90,11 +94,10 @@ char *config_file = NULL; | |||
| 90 | unsigned short port = PW_AUTH_UDP_PORT; | 94 | unsigned short port = PW_AUTH_UDP_PORT; |
| 91 | int retries = 1; | 95 | int retries = 1; |
| 92 | int verbose = FALSE; | 96 | int verbose = FALSE; |
| 93 | ENV *env = NULL; | ||
| 94 | 97 | ||
| 95 | /****************************************************************************** | 98 | /****************************************************************************** |
| 96 | 99 | ||
| 97 | The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 100 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
| 98 | tags in the comments. With in the tags, the XML is assembled sequentially. | 101 | tags in the comments. With in the tags, the XML is assembled sequentially. |
| 99 | You can define entities in tags. You also have all the #defines available as | 102 | You can define entities in tags. You also have all the #defines available as |
| 100 | entities. | 103 | entities. |
| @@ -150,7 +153,13 @@ Please note that all tags must be lowercase to use the DocBook XML DTD. | |||
| 150 | int | 153 | int |
| 151 | main (int argc, char **argv) | 154 | main (int argc, char **argv) |
| 152 | { | 155 | { |
| 156 | struct sockaddr_storage ss; | ||
| 157 | char name[HOST_NAME_MAX]; | ||
| 158 | #ifdef RC_BUFFER_LEN | ||
| 159 | char msg[RC_BUFFER_LEN]; | ||
| 160 | #else | ||
| 153 | char msg[BUFFER_LEN]; | 161 | char msg[BUFFER_LEN]; |
| 162 | #endif | ||
| 154 | SEND_DATA data; | 163 | SEND_DATA data; |
| 155 | int result = STATE_UNKNOWN; | 164 | int result = STATE_UNKNOWN; |
| 156 | uint32_t client_id, service; | 165 | uint32_t client_id, service; |
| @@ -185,15 +194,14 @@ main (int argc, char **argv) | |||
| 185 | die (STATE_UNKNOWN, _("Invalid NAS-Identifier\n")); | 194 | die (STATE_UNKNOWN, _("Invalid NAS-Identifier\n")); |
| 186 | } | 195 | } |
| 187 | 196 | ||
| 188 | if (nasipaddress != NULL) { | 197 | if (nasipaddress == NULL) { |
| 189 | if (rc_good_ipaddr (nasipaddress)) | 198 | if (gethostname (name, sizeof(name)) != 0) |
| 190 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | 199 | die (STATE_UNKNOWN, _("gethostname() failed!\n")); |
| 191 | if ((client_id = rc_get_ipaddr(nasipaddress)) == 0) | 200 | nasipaddress = name; |
| 192 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 193 | } else { | ||
| 194 | if ((client_id = my_rc_own_ipaddress ()) == 0) | ||
| 195 | die (STATE_UNKNOWN, _("Can't find local IP for NAS-IP-Address\n")); | ||
| 196 | } | 201 | } |
| 202 | if (!dns_lookup (nasipaddress, &ss, AF_INET)) /* TODO: Support IPv6. */ | ||
| 203 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | ||
| 204 | client_id = ntohl (((struct sockaddr_in *)&ss)->sin_addr.s_addr); | ||
| 197 | if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL) | 205 | if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) == NULL) |
| 198 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); | 206 | die (STATE_UNKNOWN, _("Invalid NAS-IP-Address\n")); |
| 199 | 207 | ||
| @@ -274,7 +282,7 @@ process_arguments (int argc, char **argv) | |||
| 274 | break; | 282 | break; |
| 275 | case 'P': /* port */ | 283 | case 'P': /* port */ |
| 276 | if (is_intnonneg (optarg)) | 284 | if (is_intnonneg (optarg)) |
| 277 | port = atoi (optarg); | 285 | port = (unsigned short)atoi (optarg); |
| 278 | else | 286 | else |
| 279 | usage4 (_("Port must be a positive integer")); | 287 | usage4 (_("Port must be a positive integer")); |
| 280 | break; | 288 | break; |
| @@ -310,7 +318,7 @@ process_arguments (int argc, char **argv) | |||
| 310 | break; | 318 | break; |
| 311 | case 't': /* timeout */ | 319 | case 't': /* timeout */ |
| 312 | if (is_intpos (optarg)) | 320 | if (is_intpos (optarg)) |
| 313 | timeout_interval = atoi (optarg); | 321 | timeout_interval = (unsigned)atoi (optarg); |
| 314 | else | 322 | else |
| 315 | usage2 (_("Timeout interval must be a positive integer"), optarg); | 323 | usage2 (_("Timeout interval must be a positive integer"), optarg); |
| 316 | break; | 324 | break; |
| @@ -356,7 +364,7 @@ print_help (void) | |||
| 356 | printf (" %s\n", "-u, --username=STRING"); | 364 | printf (" %s\n", "-u, --username=STRING"); |
| 357 | printf (" %s\n", _("The user to authenticate")); | 365 | printf (" %s\n", _("The user to authenticate")); |
| 358 | printf (" %s\n", "-p, --password=STRING"); | 366 | printf (" %s\n", "-p, --password=STRING"); |
| 359 | printf (" %s\n", _("Password for autentication (SECURITY RISK)")); | 367 | printf (" %s\n", _("Password for authentication (SECURITY RISK)")); |
| 360 | printf (" %s\n", "-n, --nas-id=STRING"); | 368 | printf (" %s\n", "-n, --nas-id=STRING"); |
| 361 | printf (" %s\n", _("NAS identifier")); | 369 | printf (" %s\n", _("NAS identifier")); |
| 362 | printf (" %s\n", "-N, --nas-ip-address=STRING"); | 370 | printf (" %s\n", "-N, --nas-ip-address=STRING"); |
| @@ -373,7 +381,7 @@ print_help (void) | |||
| 373 | printf ("\n"); | 381 | printf ("\n"); |
| 374 | printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); | 382 | printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections.")); |
| 375 | printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user")); | 383 | printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user")); |
| 376 | printf ("%s\n", _("name and password. A configuration file may also be present. The format of")); | 384 | printf ("%s\n", _("name and password. A configuration file must be present. The format of")); |
| 377 | printf ("%s\n", _("the configuration file is described in the radiusclient library sources.")); | 385 | printf ("%s\n", _("the configuration file is described in the radiusclient library sources.")); |
| 378 | printf ("%s\n", _("The password option presents a substantial security issue because the")); | 386 | printf ("%s\n", _("The password option presents a substantial security issue because the")); |
| 379 | printf ("%s\n", _("password can possibly be determined by careful watching of the command line")); | 387 | printf ("%s\n", _("password can possibly be determined by careful watching of the command line")); |
| @@ -399,7 +407,7 @@ print_usage (void) | |||
| 399 | 407 | ||
| 400 | int my_rc_read_config(char * a) | 408 | int my_rc_read_config(char * a) |
| 401 | { | 409 | { |
| 402 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) | 410 | #if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI) |
| 403 | rch = rc_read_config(a); | 411 | rch = rc_read_config(a); |
| 404 | return (rch == NULL) ? 1 : 0; | 412 | return (rch == NULL) ? 1 : 0; |
| 405 | #else | 413 | #else |
