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