Radcli library 2.0.2
A simple radius library -- legacy API reference
Loading...
Searching...
No Matches
config.c
1/*
2 * Copyright (C) 1995,1996,1997 Lars Fenneberg
3 *
4 * Copyright 1992 Livingston Enterprises, Inc.
5 *
6 * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan
7 * and Merit Network, Inc. All Rights Reserved
8 *
9 * See the file COPYRIGHT for the respective terms and conditions.
10 * If the file is missing contact me at lf@elemental.net
11 * and I'll send you a copy.
12 *
13 */
14
22
23#include <config.h>
24#include <includes.h>
25#include <radcli/radcli.h>
26#include <options.h>
27#include "util.h"
28#include "tls.h"
29#include "session.h"
30#include "dict_rfc_gen.h"
31
32#ifndef TRUE
33#define TRUE 1
34#define FALSE 0
35#endif
36
37static int rc_conf_int_2(rc_handle const *rh, char const *optname, int complain);
38
39/* The template every rc_handle's config_options[] is memcpy()'d from
40 * (lib/config.c's radcli2_priv_new()/radcli2_priv_read_config()); the per-id enum in
41 * lib/options.h's RC_OPTION_TABLE indexes straight into it/its copies. */
42static const OPTION config_options_default[] = {
43#define RADCLI_OPT_ENTRY(id, name, type) {name, type, ST_UNDEF, NULL},
44 RC_OPTION_TABLE
45#undef RADCLI_OPT_ENTRY
46};
47
48#define NUM_OPTIONS ((sizeof(config_options_default))/(sizeof(config_options_default[0])))
49
50/* Find an option in the option list
51 *
52 * @param rh a handle to parsed configuration.
53 * @param optname the name of the option.
54 * @param type the option type.
55 * @return pointer to option on success, NULL otherwise.
56 */
57/*- Look up optname's OPTION entry, scanning linearly (few enough options
58 * that a binary search isn't worthwhile).
59 *
60 * @param rh a handle to parsed configuration.
61 * @param optname the option name to look up.
62 * @param type a bitmask of acceptable RADCLI_OPT_TYPE_* types for the match.
63 * @return the option's entry, or NULL if optname is unknown or its type
64 * doesn't match type.
65 -*/
66static OPTION *find_option(rc_handle const *rh, char const *optname, unsigned int type)
67{
68 int i;
69
70 /* there're so few options that a binary search seems not necessary */
71 for (i = 0; i < NUM_OPTIONS; i++) {
72 if (!strcmp(rh->config_options[i].name, optname) &&
73 (rh->config_options[i].type & type))
74 {
75 return &rh->config_options[i];
76 }
77 }
78
79 return NULL;
80}
81
82/*- Report whether name is one of RC_IGNORED_OPTION_TABLE's legacy option
83 * names -- accepted for backward compatibility with existing config
84 * files, but never stored (see lib/options.h's RC_IGNORED_OPTION_TABLE
85 * comment).
86 *
87 * @param name the option name to check.
88 * @return nonzero if name is an ignored legacy option, zero otherwise.
89 -*/
90static int rc_ignored_option(char const *name)
91{
92#define X(n) if (!strcmp(name, n)) return 1;
93 RC_IGNORED_OPTION_TABLE
94#undef X
95 return 0;
96}
97
98/* Index-based option lookup for internal callers that already know which
99 * option they want at compile time (an OPT_* from lib/options.h's
100 * RC_OPTION_TABLE) -- skips find_option()'s string scan entirely. Only
101 * ever called with a literal OPT_* id, so id/type pairing is fixed at
102 * compile time; the assert()s below catch a future miswired call site. */
103/*- Look up id's OPTION entry directly by index.
104 *
105 * @param rh a handle to parsed configuration.
106 * @param id the option's compile-time index.
107 * @return the option's entry; never NULL (asserts rh/id are valid).
108 -*/
109static inline OPTION *rc_option_by_id(rc_handle const *rh, rc_option_id id)
110{
111 assert(rh != NULL && rh->config_options != NULL);
112 assert((unsigned)id < NUM_OPTIONS);
113 return &rh->config_options[id];
114}
115
116/*- Get the value of an integer-typed config option by compile-time index.
117 *
118 * @param rh a handle to parsed configuration.
119 * @param id the option's compile-time index; must be RADCLI_OPT_TYPE_INT.
120 * @return config option value, or 0 if unset.
121 -*/
122int rc_conf_int_id(rc_handle const *rh, rc_option_id id)
123{
124 OPTION *option = rc_option_by_id(rh, id);
125
126 assert(option->type & RADCLI_OPT_TYPE_INT);
127
128 if (option->val)
129 return *((int *)option->val);
130
131 rc_log(LOG_INFO, "radcli2_priv_conf_int: config option %s was not set", option->name);
132 return 0;
133}
134
135/*- Get the value of a string-typed config option by compile-time index.
136 *
137 * @param rh a handle to parsed configuration.
138 * @param id the option's compile-time index; must be RADCLI_OPT_TYPE_STR.
139 * @return config option value.
140 -*/
141char *rc_conf_str_id(rc_handle const *rh, rc_option_id id)
142{
143 OPTION *option = rc_option_by_id(rh, id);
144
145 assert(option->type & RADCLI_OPT_TYPE_STR);
146
147 return (char *)option->val;
148}
149
150/*- Get the value of a server-list-typed config option by compile-time index.
151 *
152 * @param rh a handle to parsed configuration.
153 * @param id the option's compile-time index; must be RADCLI_OPT_TYPE_SRV.
154 * @return config option value, or NULL if unset.
155 -*/
156SERVER *rc_conf_srv_id(rc_handle const *rh, rc_option_id id)
157{
158 OPTION *option = rc_option_by_id(rh, id);
159
160 assert(option->type & RADCLI_OPT_TYPE_SRV);
161
162 return (SERVER *)option->val;
163}
164
165/*- Set a string-typed option's value, duplicating p.
166 *
167 * @param filename the name of the config file (for logging purposes).
168 * @param line the line number in the file (for logging purposes).
169 * @param option the option to set.
170 * @param p the value, or NULL to clear it.
171 * @return 0 on success, -1 on allocation failure.
172 -*/
173static int set_option_str(char const *filename, int line, OPTION *option, char const *p)
174{
175 if (p) {
176 option->val = (void *) strdup(p);
177 if (option->val == NULL) {
178 rc_log(LOG_CRIT, "read_config: out of memory");
179 return -1;
180 }
181 } else {
182 option->val = NULL;
183 }
184
185 return 0;
186}
187
188/*- Set an integer-typed option's value, parsing p.
189 *
190 * watchdog-interval carries a floor below which it is refused outright (0
191 * still disables it, unchanged): 1-5 would just mean radcli spends nearly
192 * all its time reconnecting/sending Status-Server packets when
193 * REQ-WATCHDOG-NET-003's 2.5x-interval dead-peer threshold is this close to the
194 * interval itself, RFC 3539 SS3.4's watchdog algorithm assumes Tw is chosen
195 * with meaningful headroom, and TCP-level connection churn that fast is not
196 * useful "liveness" checking. Enforced here, the single choke point both
197 * the config-file reader and radcli_ctx_set_opt_int() (lib/config2.c)
198 * funnel through, so both paths agree.
199 *
200 * @param filename the name of the config file (for logging purposes).
201 * @param line the line number in the file (for logging purposes).
202 * @param option the option to set.
203 * @param p the value text to parse; must be non-NULL.
204 * @return 0 on success, -1 if p is NULL, out of range for option, or on
205 * allocation failure.
206 -*/
207static int set_option_int(char const *filename, int line, OPTION *option, char const *p)
208{
209 int *iptr;
210 int val;
211
212 if (p == NULL) {
213 rc_log(LOG_ERR, "%s: line %d: bogus option value", filename, line);
214 return -1;
215 }
216
217 val = atoi(p);
218
219 if (strcmp(option->name, "watchdog-interval") == 0 && val >= 1 && val <= 5) {
220 rc_log(LOG_ERR, "%s: line %d: watchdog-interval must be 0 (disabled) "
221 "or at least 6 seconds, not %d", filename, line, val);
222 return -1;
223 }
224
225 if ((iptr = malloc(sizeof(*iptr))) == NULL) {
226 rc_log(LOG_CRIT, "read_config: out of memory");
227 return -1;
228 }
229
230 *iptr = val;
231 option->val = (void *) iptr;
232
233 return 0;
234}
235
236/* Shared by set_option_srv()'s parse-failure cleanup and
237 * radcli2_priv_config_free(), which both need to release the same
238 * per-entry allocations. */
239/*- Free serv->name[i]/secret[i] for i in [from, to), nulling each
240 * pointer afterwards.
241 *
242 * @param serv the server list to free entries from.
243 * @param from the first index to free.
244 * @param to one past the last index to free.
245 -*/
246static void server_free_entries(SERVER *serv, unsigned from, unsigned to)
247{
248 unsigned i;
249
250 for (i = from; i < to; i++) {
251 free(serv->name[i]);
252 free(serv->secret[i]);
253 serv->name[i] = NULL;
254 serv->secret[i] = NULL;
255 }
256}
257
258/*- Parse and append server-list entries onto a server-typed option,
259 * accepting a comma-separated "host[:port[:secret]]" list.
260 *
261 * @param rh a handle to parsed configuration.
262 * @param filename the name of the config file (for logging purposes).
263 * @param line the line number in the file (for logging purposes).
264 * @param option the RADCLI_OPT_TYPE_SRV option to append entries to.
265 * @param p the comma-separated server list text.
266 * @return 0 on success, -1 on a parse error or allocation failure.
267 -*/
268static int set_option_srv(rc_handle *rh, char const *filename, int line, OPTION *option, char const *p)
269{
270 SERVER *serv;
271 char *p_pointer;
272 char *p_dupe;
273 char *p_save;
274 char *q;
275 char *s;
276 struct servent *svp;
277 unsigned start_max;
278
279 p_dupe = strdup(p);
280
281 if (p_dupe == NULL) {
282 rc_log(LOG_ERR, "%s: line %d: Invalid option or memory failure", filename, line);
283 return -1;
284 }
285
286 serv = (SERVER *) option->val;
287 if (serv == NULL) {
288 serv = calloc(1, sizeof(*serv));
289 if (serv == NULL) {
290 rc_log(LOG_CRIT, "read_config: out of memory");
291 free(p_dupe);
292 return -1;
293 }
294 serv->max = 0;
295 }
296 start_max = serv->max;
297
298 p_pointer = strtok_r(p_dupe, ", \t", &p_save);
299
300 while(p_pointer != NULL) {
301 if (serv->max >= RC_SERVER_MAX) {
302 DEBUG(rh, LOG_ERR, "cannot set more than %d servers", RC_SERVER_MAX);
303 goto fail;
304 }
305
306 DEBUG(rh, LOG_ERR, "processing server: %s", p_pointer);
307 /* check to see for '[IPv6]:port' syntax */
308 if ((q = strchr(p_pointer,'[')) != NULL) {
309 *q = '\0';
310 q++;
311 p_pointer = q;
312
313 q = strchr(p_pointer, ']');
314 if (q == NULL) {
315 rc_log(LOG_CRIT, "read_config: IPv6 parse error");
316 goto fail;
317 }
318 *q = '\0';
319 q++;
320
321 if (q[0] == ':') {
322 q++;
323 }
324
325 /* Check to see if we have '[IPv6]:port:secret' syntax */
326 if((s=strchr(q, ':')) != NULL) {
327 *s = '\0';
328 s++;
329 serv->secret[serv->max] = strdup(s);
330 if (serv->secret[serv->max] == NULL) {
331 rc_log(LOG_CRIT, "read_config: out of memory");
332 goto fail;
333 }
334 }
335
336 } else /* Check to see if we have 'servername:port' syntax */
337 if ((q = strchr(p_pointer,':')) != NULL) {
338 *q = '\0';
339 q++;
340
341 /* Check to see if we have 'servername:port:secret' syntax */
342 if((s = strchr(q,':')) != NULL) {
343 *s = '\0';
344 s++;
345 serv->secret[serv->max] = strdup(s);
346 if (serv->secret[serv->max] == NULL) {
347 rc_log(LOG_CRIT, "read_config: out of memory");
348 goto fail;
349 }
350 }
351 }
352
353 if(q && strlen(q) > 0) {
354 serv->port[serv->max] = atoi(q);
355 } else {
356 if (!strcmp(option->name,"authserver"))
357 if ((svp = getservbyname ("radius", "udp")) == NULL)
358 serv->port[serv->max] = PW_AUTH_UDP_PORT;
359 else
360 serv->port[serv->max] = ntohs ((unsigned int) svp->s_port);
361 else if (!strcmp(option->name, "acctserver"))
362 if ((svp = getservbyname ("radacct", "udp")) == NULL)
363 serv->port[serv->max] = PW_ACCT_UDP_PORT;
364 else
365 serv->port[serv->max] = ntohs ((unsigned int) svp->s_port);
366 else {
367 rc_log(LOG_ERR, "%s: line %d: no default port for %s", filename, line, option->name);
368 goto fail;
369 }
370 }
371
372 serv->name[serv->max] = strdup(p_pointer);
373 if (serv->name[serv->max] == NULL) {
374 rc_log(LOG_CRIT, "read_config: out of memory");
375 goto fail;
376 }
377
378 serv->max++;
379 p_pointer = strtok_r(NULL, ", \t", &p_save);
380 }
381
382 free(p_dupe);
383 if (option->val == NULL)
384 option->val = (void *)serv;
385
386 return 0;
387 fail:
388 free(p_dupe);
389 /* Release whatever this call already committed (start_max..max),
390 * plus the in-progress entry's secret if it was parsed before the
391 * failure (name[] is only ever set last, right before max++, so
392 * it never needs freeing here). Without this, a config line that
393 * fails partway through (e.g. more than RC_SERVER_MAX servers)
394 * leaks every entry already parsed. */
395 server_free_entries(serv, start_max, serv->max);
396 serv->max = start_max;
397 if (serv->max < RC_SERVER_MAX) {
398 free(serv->secret[serv->max]);
399 serv->secret[serv->max] = NULL;
400 }
401 if (option->val == NULL)
402 free(serv);
403 return -1;
404
405}
406
407/*- Add a config option to rc_handle from inside a program, letting a
408 * program set up a handle without loading a configuration file.
409 *
410 * @param rh a handle to parsed configuration.
411 * @param option_name the name of the option.
412 * @param option_val the value to be added.
413 * @param source typically should be __FILE__ or __func__ for logging purposes.
414 * @param line __LINE__ for logging purposes.
415 * @return 0 on success, -1 on failure.
416 -*/
417int radcli2_priv_add_config(rc_handle *rh, char const *option_name, char const *option_val, char const *source, int line)
418{
419 OPTION *option;
420
421 if ((option = find_option(rh, option_name, OT_ANY)) == NULL)
422 {
423 if (rc_ignored_option(option_name))
424 return 0;
425 rc_log(LOG_ERR, "ERROR: unrecognized option: %s", option_name);
426 return -1;
427 }
428
429 if (option->status != ST_UNDEF)
430 {
431 rc_log(LOG_ERR, "ERROR: duplicate option: %s", option_name);
432 return -1;
433 }
434
435 switch (option->type) {
436 case RADCLI_OPT_TYPE_STR:
437 if (set_option_str(source, line, option, option_val) < 0) {
438 return -1;
439 }
440 break;
441 case RADCLI_OPT_TYPE_INT:
442 if (set_option_int(source, line, option, option_val) < 0) {
443 return -1;
444 }
445 break;
446 case RADCLI_OPT_TYPE_SRV:
447 if (set_option_srv(rh, source, line, option, option_val) < 0) {
448 return -1;
449 }
450 break;
451 default:
452 rc_log(LOG_CRIT, "radcli2_priv_add_config: impossible case branch!");
453 abort();
454 }
455
456 return 0;
457}
458
459/*- Initialise a configuration structure for programmatic configuration.
460 *
461 * Use this when configuring radcli from code rather than from a file. The
462 * full call sequence: radcli2_priv_new(), this function,
463 * radcli2_priv_add_config() per option, then radcli2_priv_apply_config()
464 * to activate.
465 *
466 * @param rh a handle allocated by radcli2_priv_new().
467 * @return rh on success, NULL on failure (rh is freed on failure).
468 -*/
469rc_handle *radcli2_priv_config_init(rc_handle *rh)
470{
471 SERVER *authservers = NULL;
472 SERVER *acctservers;
473 OPTION *acct;
474 OPTION *auth;
475
476 rh->config_options = malloc(sizeof(config_options_default));
477 if (rh->config_options == NULL)
478 {
479 rc_log(LOG_CRIT, "radcli2_priv_config_init: out of memory");
480 radcli2_priv_destroy(rh);
481 return NULL;
482 }
483 memcpy(rh->config_options, &config_options_default, sizeof(config_options_default));
484
485 auth = find_option(rh, "authserver", OT_ANY);
486 if (auth) {
487 authservers = calloc(1, sizeof(SERVER));
488 if(authservers == NULL) {
489 rc_log(LOG_CRIT, "radcli2_priv_config_init: error initializing server structs");
490 radcli2_priv_destroy(rh);
491 return NULL;
492 }
493 auth->val = authservers;
494 }
495
496 acct = find_option(rh, "acctserver", OT_ANY);
497 if (acct) {
498 acctservers = calloc(1, sizeof(SERVER));
499 if(acctservers == NULL) {
500 rc_log(LOG_CRIT, "radcli2_priv_config_init: error initializing server structs");
501 radcli2_priv_destroy(rh);
502 if(authservers) free(authservers);
503 return NULL;
504 }
505 acct->val = acctservers;
506 }
507
508 return rh;
509}
510
511/*- rc_sockets_override.sendto for the plain UDP transport: a thin
512 * sendto(2) wrapper.
513 -*/
514static ssize_t plain_sendto(void *ptr, int sockfd,
515 const void *buf, size_t len, int flags,
516 const struct sockaddr *dest_addr, socklen_t addrlen)
517{
518 return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
519}
520
521/*- rc_sockets_override.recvfrom for the plain UDP transport: a thin
522 * recvfrom(2) wrapper.
523 -*/
524static ssize_t plain_recvfrom(void *ptr, int sockfd,
525 void *buf, size_t len, int flags,
526 struct sockaddr *src_addr, socklen_t * addrlen)
527{
528 return recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
529}
530
531/*- rc_sockets_override.close_fd for the plain UDP transport: a thin
532 * close(2) wrapper.
533 -*/
534static void plain_close_fd(int fd)
535{
536 close(fd);
537}
538
539/*- rc_sockets_override.get_fd for the plain UDP transport: open and bind
540 * a UDP socket at an ephemeral port on our_sockaddr's address/family.
541 *
542 * @param ptr unused; part of the get_fd calling convention.
543 * @param our_sockaddr the local address to bind to (port overwritten with 0).
544 * @return the new socket, or -1 on failure.
545 -*/
546static int plain_get_fd(void *ptr, struct sockaddr *our_sockaddr)
547{
548 int sockfd;
549
550 sockfd = socket(our_sockaddr->sa_family, SOCK_DGRAM, 0);
551 if (sockfd < 0) {
552 return -1;
553 }
554
555 if (our_sockaddr->sa_family == AF_INET)
556 ((struct sockaddr_in *)our_sockaddr)->sin_port = 0;
557 else
558 ((struct sockaddr_in6 *)our_sockaddr)->sin6_port = 0;
559
560 if (bind(sockfd, SA(our_sockaddr), SA_LEN(our_sockaddr)) < 0) {
561 close(sockfd);
562 return -1;
563 }
564 return sockfd;
565}
566
567static const rc_sockets_override default_socket_funcs = {
568 .get_fd = plain_get_fd,
569 .close_fd = plain_close_fd,
570 .sendto = plain_sendto,
571 .recvfrom = plain_recvfrom
572};
573
574/*- Parse ip (IPv4 or IPv6 text) into ss.
575 *
576 * @param ss set to the parsed address on success.
577 * @param ip the address text to parse.
578 * @return 0 on success, -1 if ip is neither a valid IPv4 nor IPv6 address.
579 -*/
580static int set_addr(struct sockaddr_storage *ss, const char *ip)
581{
582 memset(ss, 0, sizeof(*ss));
583 if (inet_pton(AF_INET, ip, &((struct sockaddr_in *)ss)->sin_addr) == 1) {
584 ss->ss_family = AF_INET;
585 } else if (inet_pton(AF_INET6, ip, &((struct sockaddr_in6 *)ss)->sin6_addr) == 1) {
586 ss->ss_family = AF_INET6;
587 } else {
588 rc_log(LOG_CRIT, "invalid IP address for nas-ip: %s", ip);
589 return -1;
590 }
591 return 0;
592}
593
594/* Fills in an authserver/acctserver SERVER's secret[0] from the "secret"
595 * option, but only when that entry has no secret of its own yet -- an
596 * inline host:port:secret (or a legacy "servers" file entry, resolved
597 * later at send time) always takes priority. This is the config-file
598 * counterpart of radcli2.h's radcli_ctx_set_secret(), which instead
599 * overwrites secret[0] unconditionally on an explicit call.
600 *
601 * Harmless but pointless under TLS/DTLS: radcli2_priv_find_server_addr()
602 * doesn't need secret[0] there in the first place (rh->so_type ==
603 * RC_SOCKET_TLS/_DTLS branch), and radcli_transport_exchange()
604 * (lib/sendserver.c) overwrites it with the RFC 6614/7360 fixed secret
605 * before it would ever be used regardless. */
606/*- Fill in a server list's first entry's secret from the "secret"
607 * option, but only when that entry has no secret of its own yet.
608 *
609 * @param rh a handle to parsed configuration.
610 * @param id OPT_AUTHSERVER or OPT_ACCTSERVER.
611 * @param secret the fallback secret to apply.
612 -*/
613static void apply_secret_fallback_one(rc_handle *rh, rc_option_id id, const char *secret)
614{
615 SERVER *serv = rc_conf_srv_id(rh, id);
616 char *dup;
617
618 if (serv == NULL || serv->max == 0)
619 return;
620 if (serv->secret[0] != NULL && serv->secret[0][0] != '\0')
621 return;
622
623 dup = strdup(secret);
624 if (dup == NULL)
625 return;
626
627 free(serv->secret[0]);
628 serv->secret[0] = dup;
629}
630
631/*- Apply the "secret" option as a fallback to authserver/acctserver's
632 * first entry, when they don't already carry their own secret.
633 *
634 * @param rh a handle to parsed configuration.
635 -*/
636static void apply_secret_fallback(rc_handle *rh)
637{
638 const char *secret = rc_conf_str_id(rh, OPT_SECRET);
639
640 if (secret == NULL || secret[0] == '\0')
641 return;
642
643 apply_secret_fallback_one(rh, OPT_AUTHSERVER, secret);
644 apply_secret_fallback_one(rh, OPT_ACCTSERVER, secret);
645}
646
647/*- Materialize optname's default into rh's config table if it was never
648 * explicitly set, so every internal reader can use the default-free,
649 * compile-time-indexed rc_conf_int_id() uniformly afterward (REQ-GEN-STYLE-011)
650 * instead of a runtime string-keyed lookup with an inline default.
651 *
652 * @param rh a handle to parsed configuration.
653 * @param optname the option's name.
654 * @param def the default to materialize if unset.
655 -*/
656static void apply_int_default(rc_handle *rh, char const *optname, int def)
657{
658 OPTION *option = find_option(rh, optname, RADCLI_OPT_TYPE_INT);
659 int *val;
660
661 if (option == NULL || option->val != NULL)
662 return;
663
664 val = malloc(sizeof(*val));
665 if (val == NULL)
666 return;
667
668 *val = def;
669 option->val = val;
670}
671
672/*- Validate the options required for a working request/response cycle or
673 * DAE listener: either an authserver or a configured DAE listener, and
674 * sane radius_timeout/radius_retries. Shared by radcli2_priv_test_config()
675 * (the config-file path, which additionally knows filename for its log
676 * messages) and radcli2_priv_apply_config() itself, so radcli_ctx_apply()
677 * (lib/config2.c) enforces the exact same requirements as
678 * radcli_ctx_read_config() -- per REQ-CONFIG2-CFG-004, the two are meant to
679 * differ only in where the options come from (a file vs.
680 * radcli_ctx_set_opt_*() calls), not in what they require.
681 *
682 * @param rh a handle to parsed configuration.
683 * @param source a label for this handle's origin, used only in log
684 * messages (e.g. the config filename, or the calling function's name).
685 * @return 0 on success, -1 on failure.
686 -*/
687static int radcli2_priv_check_config(rc_handle *rh, char const *source)
688{
689 SERVER *srv;
690
691 /* An RFC 5176 DAE listener (radcli_dae_new(), lib/dae.c) is a
692 * server-side role, independent of ever sending an Access-/
693 * Accounting-Request as a client -- a NAS handling only CoA/
694 * Disconnect need not configure an authserver at all. dae-accept
695 * being set at all (even to "no", or an invalid value later rejected
696 * by radcli_dae_new() itself) is enough to signal that intent here;
697 * this function only gates the cheap, universal requirement, not
698 * dae-accept's own grammar. */
699 srv = rc_conf_srv_id(rh, OPT_AUTHSERVER);
700 if (!srv || !srv->max)
701 {
702 if (rc_conf_str_id(rh, OPT_DAE_ACCEPT) == NULL)
703 {
704 rc_log(LOG_ERR,"%s: no authserver or DAE listener specified", source);
705 return -1;
706 }
707 /* No authserver: a DAE-only context, per the check above. There is
708 * no client role here at all, so "no acctserver specified" (a
709 * client-only concern) would be noise -- skip that check entirely
710 * rather than logging it for a context that was never going to
711 * have one. */
712 }
713 else
714 {
715 srv = rc_conf_srv_id(rh, OPT_ACCTSERVER);
716 if (!srv || !srv->max)
717 {
718 /* it is allowed not to have acct servers under TCP/TLS/DTLS. rh->so_type
719 * isn't set until radcli2_priv_apply_config() runs, so check the
720 * configured serv-type string directly rather than the not-yet-
721 * initialized transport state. */
722 const char *stype = rc_conf_str_id(rh, OPT_SERV_TYPE);
723 if (stype == NULL)
724 stype = rc_conf_str_id(rh, OPT_SERV_AUTH_TYPE);
725 if (stype == NULL ||
726 (strcasecmp(stype, "tcp") != 0 && strcasecmp(stype, "tls") != 0 &&
727 strcasecmp(stype, "dtls") != 0))
728 rc_log(LOG_DEBUG,"%s: no acctserver specified", source);
729 }
730 }
731
732 if (rc_conf_int_id(rh, OPT_RADIUS_TIMEOUT) <= 0)
733 {
734 rc_log(LOG_ERR,"%s: radius_timeout <= 0 is illegal", source);
735 return -1;
736 }
737 if (rc_conf_int_id(rh, OPT_RADIUS_RETRIES) < 0)
738 {
739 rc_log(LOG_ERR,"%s: radius_retries < 0 is illegal", source);
740 return -1;
741 }
742
743 return 0;
744}
745
746/*- Apply configuration and initialise the transport.
747 *
748 * Must be called after all radcli2_priv_add_config() calls when using
749 * programmatic configuration (i.e., without a config file). Validates the
750 * same mandatory options radcli2_priv_test_config() does (REQ-CONFIG2-CFG-004),
751 * then initialises the transport selected by the serv-type option, including
752 * the TLS/DTLS handshake for TLS and DTLS transports. radcli2_priv_read_config()
753 * calls this internally; do not call it again after radcli2_priv_read_config().
754 *
755 * @param rh a handle to parsed configuration.
756 * @return 0 on success, -1 on failure.
757 -*/
758int radcli2_priv_apply_config(rc_handle *rh)
759{
760 const char *txt;
761 int ret;
762
763 if (radcli2_priv_check_config(rh, "radcli2_priv_apply_config") == -1)
764 return -1;
765
766 apply_secret_fallback(rh);
767 apply_int_default(rh, "watchdog-interval", 15);
768 apply_int_default(rh, "dae-max-clock-skew", 300);
769
770 memset(&rh->own_bind_addr, 0, sizeof(rh->own_bind_addr));
771 rh->own_bind_addr_set = 0;
772 rc_own_bind_addr(rh, &rh->own_bind_addr);
773 rh->own_bind_addr_set = 1;
774
775 txt = rc_conf_str_id(rh, OPT_NAS_IP);
776 if (txt != NULL) {
777 if (set_addr(&rh->nas_addr, txt) < 0)
778 return -1;
779 rh->nas_addr_set = 1;
780 }
781
782 txt = rc_conf_str_id(rh, OPT_SERV_TYPE);
783 if (txt == NULL)
784 txt = rc_conf_str_id(rh, OPT_SERV_AUTH_TYPE);
785
786 if (txt == NULL)
787 txt = "udp";
788
789 if (strcasecmp(txt, "udp") == 0) {
790 memset(&rh->so, 0, sizeof(rh->so));
791 rh->so_type = RC_SOCKET_UDP;
792 memcpy(&rh->so, &default_socket_funcs, sizeof(rh->so));
793 ret = 0;
794 } else if (strcasecmp(txt, "tcp") == 0) {
795 ret = radcli2_priv_sess_init_tcp(rh);
796#ifdef HAVE_GNUTLS
797 } else if (strcasecmp(txt, "dtls") == 0) {
798 ret = rc_init_tls(rh, SEC_FLAG_DTLS);
799 } else if (strcasecmp(txt, "tls") == 0) {
800 ret = rc_init_tls(rh, 0);
801#endif
802 } else {
803 rc_log(LOG_CRIT, "unknown server type: %s", txt);
804 return -1;
805 }
806
807 if (ret < 0) {
808 rc_log(LOG_CRIT, "error initializing %s", txt);
809 return -1;
810 }
811
812 return 0;
813
814}
815
816/*- Load the built-in RFC 2865/2866/2869 dictionary into rh. Shared by
817 * radcli2_priv_read_config() and radcli_ctx_new() (lib/config2.c) so both
818 * entry points agree on what "the built-in dictionary" is.
819 *
820 * @param rh a handle allocated by radcli2_priv_new().
821 * @return 0 on success, -1 on failure (rh is left as-is; the caller is
822 * responsible for destroying it).
823 -*/
824int radcli2_priv_load_builtin_dict(rc_handle *rh)
825{
826 if (radcli2_priv_read_dictionary_from_buffer(rh, rc_rfc_dictionary,
827 sizeof(rc_rfc_dictionary) - 1) != 0) {
828 rc_log(LOG_CRIT, "radcli2_priv_load_builtin_dict: failed to load built-in RFC dictionary");
829 return -1;
830 }
831 return 0;
832}
833
834/*- Read the global config file. The full recognised-option reference lives
835 * on the public rc_read_config()'s doc comment (lib/legacy/compat.c),
836 * which this implements.
837 *
838 * @param filename path to the configuration file.
839 * @param skip_builtin_dict nonzero to skip loading the built-in RFC
840 * 2865/2866/2869 dictionary (radcli_ctx_read_config()'s
841 * #RADCLI_CTX_NO_BUILTIN_DICT, translated by lib/config2.c so this
842 * legacy-shared function need not know about radcli2.h's flags enum).
843 * @return new rc_handle on success, NULL on failure.
844 -*/
845rc_handle *radcli2_priv_read_config(char const *filename, int skip_builtin_dict)
846{
847 FILE *configfd;
848 char *buffer = NULL, *p;
849 size_t bufsize = 0;
850 ssize_t nread;
851 OPTION *option;
852 int line;
853 size_t pos;
854 rc_handle *rh;
855
856
857 rh = radcli2_priv_new();
858 if (rh == NULL)
859 return NULL;
860
861 rh->config_options = malloc(sizeof(config_options_default));
862 if (rh->config_options == NULL) {
863 rc_log(LOG_CRIT, "radcli2_priv_read_config: out of memory");
864 radcli2_priv_destroy(rh);
865 return NULL;
866 }
867 memcpy(rh->config_options, &config_options_default, sizeof(config_options_default));
868
869 if ((configfd = fopen(filename,"r")) == NULL)
870 {
871 rc_log(LOG_ERR,"radcli2_priv_read_config: can't open %s: %s", filename, strerror(errno));
872 radcli2_priv_destroy(rh);
873 return NULL;
874 }
875
876 line = 0;
877 while ((nread = getline(&buffer, &bufsize, configfd)) != -1)
878 {
879 line++;
880
881 if (nread > 0 && buffer[nread-1] == '\n')
882 buffer[--nread] = '\0';
883
884 p = buffer;
885
886 if ((*p == '#') || (*p == '\0'))
887 continue;
888
889 if ((pos = strcspn(p, "\t ")) == 0) {
890 rc_log(LOG_ERR, "%s: line %d: bogus format: %s", filename, line, p);
891 goto error;
892 }
893
894 p[pos] = '\0';
895
896 if ((option = find_option(rh, p, OT_ANY)) == NULL) {
897 if (rc_ignored_option(p)) {
898 rc_log(LOG_INFO, "%s: line %d: option '%s' is no longer used, ignoring", filename, line, p);
899 continue;
900 }
901 rc_log(LOG_ERR, "%s: line %d: unrecognized keyword: %s", filename, line, p);
902 goto error;
903 }
904
905 if (option->status != ST_UNDEF) {
906 rc_log(LOG_ERR, "%s: line %d: duplicate option line: %s", filename, line, p);
907 goto error;
908 }
909
910 p += pos+1;
911 while (isspace(*p))
912 p++;
913 if (*p != '\0') {
914 pos = strlen(p) - 1;
915 while (pos != 0 && isspace(p[pos]))
916 pos--;
917 p[pos + 1] = '\0';
918 }
919
920 switch (option->type) {
921 case RADCLI_OPT_TYPE_STR:
922 if (set_option_str(filename, line, option, p) < 0)
923 goto error;
924 break;
925 case RADCLI_OPT_TYPE_INT:
926 if (set_option_int(filename, line, option, p) < 0)
927 goto error;
928 break;
929 case RADCLI_OPT_TYPE_SRV:
930 if (set_option_srv(rh, filename, line, option, p) < 0)
931 goto error;
932 break;
933 default:
934 rc_log(LOG_CRIT, "radcli2_priv_read_config: impossible case branch!");
935 abort();
936 }
937 }
938 free(buffer);
939 fclose(configfd);
940
941 if (radcli2_priv_test_config(rh, filename) == -1) {
942 radcli2_priv_destroy(rh);
943 return NULL;
944 }
945
946 {
947 int clientdebug = rc_conf_int_2(rh, "clientdebug", FALSE);
948 if(clientdebug > 0) {
949 rh->debug = clientdebug;
950 }
951 }
952
953 /* Load the built-in RFC 2865/2866/2869 dictionary first so that
954 * applications need not ship a dictionary file for standard attributes,
955 * unless the caller asked to skip it. */
956 if (!skip_builtin_dict && radcli2_priv_load_builtin_dict(rh) != 0) {
957 radcli2_priv_destroy(rh);
958 return NULL;
959 }
960
961 p = rc_conf_str_id(rh, OPT_DICTIONARY);
962 if (p != NULL) {
963 if (radcli2_priv_read_dictionary(rh, p) != 0) {
964 rc_log(LOG_CRIT, "could not load dictionary");
965 radcli2_priv_destroy(rh);
966 return NULL;
967 }
968 }
969
970 return rh;
971
972error:
973 free(buffer);
974 fclose(configfd);
975 radcli2_priv_destroy(rh);
976 return NULL;
977}
978
979/*- Get the value of a string-typed config option.
980 *
981 * @param rh a handle to parsed configuration.
982 * @param optname the name of an option.
983 * @return config option value.
984 -*/
985char *radcli2_priv_conf_str(rc_handle const *rh, char const *optname)
986{
987 OPTION *option;
988
989 option = find_option(rh, optname, RADCLI_OPT_TYPE_STR);
990
991 if (option != NULL) {
992 return (char *)option->val;
993 } else {
994 rc_log(LOG_CRIT, "radcli2_priv_conf_str: unknown config option requested: %s", optname);
995 return NULL;
996 }
997}
998
999/*- Get the value of an integer-typed config option, optionally logging
1000 * when it was never set.
1001 *
1002 * @param rh a handle to parsed configuration.
1003 * @param optname the name of an option.
1004 * @param complain nonzero to log an error when optname was not set.
1005 * @return config option value, or 0 if not found, not an integer, or unset.
1006 -*/
1007static int rc_conf_int_2(rc_handle const *rh, char const *optname, int complain)
1008{
1009 OPTION *option;
1010
1011 option = find_option(rh, optname, RADCLI_OPT_TYPE_INT);
1012
1013 if (option != NULL) {
1014 if (option->val) {
1015 return *((int *)option->val);
1016 } else if(complain) {
1017 rc_log(LOG_ERR, "radcli2_priv_conf_int: config option %s was not set", optname);
1018 }
1019 return 0;
1020 } else {
1021 rc_log(LOG_CRIT, "radcli2_priv_conf_int: unknown config option requested: %s", optname);
1022 return 0;
1023 }
1024}
1025
1026/*- Get the value of an integer-typed config option.
1027 *
1028 * @param rh a handle to parsed configuration.
1029 * @param optname the name of an option.
1030 * @return config option value, or 0 if not found or not an integer.
1031 -*/
1032int radcli2_priv_conf_int(rc_handle const *rh, char const *optname)
1033{
1034 return rc_conf_int_2(rh, optname, TRUE);
1035}
1036
1037/*- Get the value of a server-list-typed config option.
1038 *
1039 * @param rh a handle to parsed configuration.
1040 * @param optname the name of an option.
1041 * @return config option value.
1042 -*/
1043SERVER *radcli2_priv_conf_srv(rc_handle const *rh, char const *optname)
1044{
1045 OPTION *option;
1046
1047 option = find_option(rh, optname, RADCLI_OPT_TYPE_SRV);
1048
1049 if (option != NULL) {
1050 return (SERVER *)option->val;
1051 } else {
1052 rc_log(LOG_CRIT, "radcli2_priv_conf_srv: unknown config option requested: %s", optname);
1053 return NULL;
1054 }
1055}
1056
1057/*- Test the configuration the user supplied.
1058 *
1059 * @param rh a handle to parsed configuration.
1060 * @param filename a name of a configuration file.
1061 * @return 0 on success, -1 when failure.
1062 -*/
1063int radcli2_priv_test_config(rc_handle *rh, char const *filename)
1064{
1065 if (radcli2_priv_check_config(rh, filename) == -1)
1066 return -1;
1067
1068 if (radcli2_priv_apply_config(rh) == -1) {
1069 return -1;
1070 }
1071
1072 return 0;
1073}
1074
1075/*- Report whether any address in addr matches any address in hostname.
1076 *
1077 * @param addr a struct addrinfo chain.
1078 * @param hostname a struct addrinfo chain to compare against.
1079 * @return 0 if a match is found, -1 otherwise.
1080 -*/
1081static int find_match (const struct addrinfo* addr, const struct addrinfo *hostname)
1082{
1083 const struct addrinfo *ptr, *ptr2;
1084 unsigned len1, len2;
1085
1086 ptr = addr;
1087 while(ptr) {
1088 ptr2 = hostname;
1089 while(ptr2) {
1090 len1 = SA_GET_INLEN(ptr->ai_addr);
1091 len2 = SA_GET_INLEN(ptr2->ai_addr);
1092
1093 if (len1 > 0 &&
1094 len1 == len2 &&
1095 memcmp(SA_GET_INADDR(ptr->ai_addr), SA_GET_INADDR(ptr2->ai_addr), len1) == 0) {
1096 return 0;
1097 }
1098 ptr2 = ptr2->ai_next;
1099 }
1100 ptr = ptr->ai_next;
1101 }
1102 return -1;
1103}
1104
1105/*- Report whether addr is a local address, by attempting to bind it.
1106 *
1107 * @param addr an AF_INET or AF_INET6 address.
1108 * @return 0 if local, 1 if not local, -1 on failure.
1109 -*/
1110static int rc_ipaddr_local(const struct sockaddr *addr)
1111{
1112 int temp_sock, res, serrno;
1113 struct sockaddr_storage tmpaddr;
1114
1115 memcpy(&tmpaddr, addr, SA_LEN(addr));
1116
1117 temp_sock = socket(addr->sa_family, SOCK_DGRAM, 0);
1118 if (temp_sock == -1)
1119 return -1;
1120
1121 if (addr->sa_family == AF_INET) {
1122 ((struct sockaddr_in*)&tmpaddr)->sin_port = 0;
1123 } else {
1124 ((struct sockaddr_in6*)&tmpaddr)->sin6_port = 0;
1125 }
1126 res = bind(temp_sock, SA(&tmpaddr), SS_LEN(&tmpaddr));
1127 serrno = errno;
1128 close(temp_sock);
1129 if (res == 0)
1130 return 0;
1131 if (serrno == EADDRNOTAVAIL)
1132 return 1;
1133 return -1;
1134}
1135
1136/*- Report whether info refers to one of our own local addresses.
1137 *
1138 * @param info a struct addrinfo chain of the host to check.
1139 * @return 0 if yes, 1 if no, -1 on failure.
1140 -*/
1141static int rc_is_myname(const struct addrinfo *info)
1142{
1143 const struct addrinfo *p;
1144 int res;
1145
1146 p = info;
1147 while(p != NULL) {
1148 res = rc_ipaddr_local(p->ai_addr);
1149 if (res == 0 || res == -1) {
1150 return res;
1151 }
1152 p = p->ai_next;
1153 }
1154 return 1;
1155}
1156
1157/*- Locate a server in the rh config or, if not found, check for a
1158 * servers file.
1159 *
1160 * @param rh a handle to parsed configuration.
1161 * @param server_name the name of the server.
1162 * @param info set to a pointer to the resolved addrinfo.
1163 * @param secret set to the server's secret (buffer of MAX_SECRET_LENGTH).
1164 * @param type AUTH or ACCT.
1165 * @return 0 on success, -1 on failure.
1166 -*/
1167int radcli2_priv_find_server_addr (rc_handle const *rh, char const *server_name,
1168 struct addrinfo** info, char *secret, rc_type type)
1169{
1170 int result = 0;
1171 FILE *clientfd;
1172 char *h;
1173 char *s;
1174 char *buffer = NULL;
1175 size_t bufsize = 0;
1176 char hostnm[AUTH_ID_LEN + 1];
1177 char *buffer_save;
1178 char *hostnm_save;
1179 SERVER *servers;
1180 struct addrinfo *tmpinfo = NULL;
1181 const char *fservers;
1182
1183 /* Lookup the IP address of the radius server */
1184 if ((*info = rc_getaddrinfo (server_name, type==AUTH?PW_AI_AUTH:PW_AI_ACCT)) == NULL)
1185 return -1;
1186
1187 switch (type)
1188 {
1189 case AUTH: servers = rc_conf_srv_id(rh, OPT_AUTHSERVER); break;
1190 case ACCT: servers = rc_conf_srv_id(rh, OPT_ACCTSERVER); break;
1191 default: servers = NULL;
1192 }
1193
1194 if (servers != NULL)
1195 {
1196 /* Check to see if the server secret is defined in the rh config */
1197 unsigned servernum;
1198 for (servernum = 0; servernum < servers->max; servernum++)
1199 {
1200 if( (strcmp(server_name, servers->name[servernum]) == 0) &&
1201 (servers->secret[servernum] != NULL) )
1202 {
1203 memset(secret, '\0', MAX_SECRET_LENGTH);
1204 strlcpy(secret, servers->secret[servernum], MAX_SECRET_LENGTH);
1205 return 0;
1206 }
1207 }
1208 }
1209
1210 /* We didn't find it in the rh_config or the servername is too long so look for a
1211 * servers file to define the secret(s)
1212 */
1213
1214 fservers = rc_conf_str_id(rh, OPT_SERVERS);
1215 if (fservers != NULL) {
1216 if ((clientfd = fopen (fservers, "r")) == NULL)
1217 {
1218 rc_log(LOG_ERR, "rc_find_server: couldn't open file: %s: %s", strerror(errno), fservers);
1219 goto fail;
1220 }
1221
1222 while (getline (&buffer, &bufsize, clientfd) != -1)
1223 {
1224 if (*buffer == '#')
1225 continue;
1226
1227 if ((h = strtok_r(buffer, " \t\n", &buffer_save)) == NULL) /* first hostname */
1228 continue;
1229
1230 strlcpy (hostnm, h, AUTH_ID_LEN);
1231
1232 if ((s = strtok_r (NULL, " \t\n", &buffer_save)) == NULL) /* and secret field */
1233 continue;
1234
1235 strlcpy (secret, s, MAX_SECRET_LENGTH);
1236
1237 if (!strchr (hostnm, '/')) /* If single name form */
1238 {
1239 tmpinfo = rc_getaddrinfo(hostnm, 0);
1240 if (tmpinfo)
1241 {
1242 result = find_match (*info, tmpinfo);
1243 if (result == 0)
1244 {
1245 result++;
1246 break;
1247 }
1248
1249 freeaddrinfo(tmpinfo);
1250 tmpinfo = NULL;
1251 }
1252 }
1253 else /* <name1>/<name2> "paired" form */
1254 {
1255 strtok_r(hostnm, "/", &hostnm_save);
1256 tmpinfo = rc_getaddrinfo(hostnm, 0);
1257 if (tmpinfo)
1258 {
1259 if (rc_is_myname(tmpinfo) == 0)
1260 { /* If we're the 1st name, target is 2nd */
1261 if (find_match (*info, tmpinfo) == 0)
1262 {
1263 result++;
1264 break;
1265 }
1266 }
1267 else /* If we were 2nd name, target is 1st name */
1268 {
1269 if (find_match (*info, tmpinfo) == 0)
1270 {
1271 result++;
1272 break;
1273 }
1274 }
1275 freeaddrinfo(tmpinfo);
1276 tmpinfo = NULL;
1277 }
1278 }
1279 }
1280 fclose (clientfd);
1281 }
1282 if (result == 0)
1283 {
1284 /* Under TLS/DTLS, this function's whole secret-lookup half (the
1285 * server's :secret suffix, or a legacy "servers" file) is moot:
1286 * radcli_transport_exchange() (lib/sendserver.c) unconditionally
1287 * overwrites whatever secret is returned here with the RFC 6614/
1288 * 7360 fixed string (rh->so.static_secret) immediately after
1289 * calling this function, since the shared secret for that
1290 * transport is a protocol constant, not something an operator
1291 * configures per server. Requiring a real secret to be found
1292 * here anyway made every ordinary request over a TLS/DTLS
1293 * authserver configured the normal way (no inline :secret, since
1294 * none is needed) fail outright before ever reaching that
1295 * override -- the address above was already resolved
1296 * successfully, which is all this transport actually needs from
1297 * this function. */
1298 if (rh->so_type == RC_SOCKET_TLS || rh->so_type == RC_SOCKET_DTLS) {
1299 memset(secret, '\0', MAX_SECRET_LENGTH);
1300 result = 0;
1301 goto cleanup;
1302 }
1303 memset (secret, '\0', MAX_SECRET_LENGTH);
1304 rc_log(LOG_ERR, "rc_find_server: couldn't find RADIUS server %s in %s",
1305 server_name, rc_conf_str_id(rh, OPT_SERVERS));
1306 goto fail;
1307 }
1308
1309 result = 0;
1310 goto cleanup;
1311
1312 fail:
1313 freeaddrinfo(*info);
1314 result = -1;
1315
1316 cleanup:
1317 if (tmpinfo)
1318 freeaddrinfo(tmpinfo);
1319 free(buffer);
1320
1321 return result;
1322}
1323
1324/*- Free allocated config values. For legacy compatibility reasons this
1325 * will not release any dictionary entries -- use radcli2_priv_destroy()
1326 * to release all memory from the handle.
1327 *
1328 * @param rh a handle to parsed configuration.
1329 -*/
1330void radcli2_priv_config_free(rc_handle *rh)
1331{
1332 int i;
1333 SERVER *serv;
1334
1335 if (rh->config_options == NULL)
1336 return;
1337
1338 for (i = 0; i < NUM_OPTIONS; i++) {
1339 if (rh->config_options[i].val == NULL)
1340 continue;
1341 if (rh->config_options[i].type == RADCLI_OPT_TYPE_SRV) {
1342 serv = (SERVER *)rh->config_options[i].val;
1343 server_free_entries(serv, 0, serv->max);
1344 free(serv);
1345 } else {
1346 free(rh->config_options[i].val);
1347 }
1348 }
1349 free(rh->config_options);
1350 free(rh->first_dict_read);
1351 rh->config_options = NULL;
1352 rh->first_dict_read = NULL;
1353}
1354
1355/*- Initialise a new Radius client handle.
1356 *
1357 * @return a new rc_handle (free with radcli2_priv_destroy()), or NULL on
1358 * allocation failure.
1359 -*/
1360rc_handle *radcli2_priv_new(void)
1361{
1362 rc_handle *rh;
1363
1364 rh = calloc(1, sizeof(*rh));
1365 if (rh == NULL) {
1366 rc_log(LOG_CRIT, "radcli2_priv_new: out of memory");
1367 return NULL;
1368 }
1369 rh->req_fd = -1; /* REQ-NET2-SEND-016: 0 (calloc's default) is a valid
1370 * fd (stdin) -- must not be mistaken for "unset". */
1371 rh->watchdog_slot = -1;
1372 return rh;
1373}
1374
1375/*- Destroy a Radius client handle, reclaiming all memory.
1376 *
1377 * @param rh the handle to free.
1378 -*/
1379void radcli2_priv_destroy(rc_handle *rh)
1380{
1381 radcli2_priv_dict_free(rh);
1382 radcli2_priv_sess_deinit(rh);
1383 radcli2_priv_config_free(rh);
1384 /* REQ-NET2-SEND-016: ctx's persistent request socket/registry, never
1385 * touched by radcli2_priv_config_free() (which only frees config
1386 * state) -- closed/freed only here, at ctx's own end of life. */
1387 if (rh->req_fd != -1 && rh->so.close_fd)
1388 rh->so.close_fd(rh->req_fd);
1389 free(rh->reqreg);
1390 free(rh->tls_psk_identity);
1391 free(rh->tls_psk_key);
1392 free(rh);
1393}
1394
1395 /*
1396 * Local Variables:
1397 * c-basic-offset:8
1398 * c-style: whitesmith
1399 * End:
1400 */
rc_type
Definition radcli.h:81
@ ACCT
Request for accounting server.
Definition radcli.h:83
@ AUTH
Request for authentication server.
Definition radcli.h:82
@ RC_SOCKET_UDP
Plain UDP socket.
Definition radcli.h:113
@ RC_SOCKET_DTLS
DTLS socket.
Definition radcli.h:115
@ RC_SOCKET_TLS
TLS socket.
Definition radcli.h:114