The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
proto_control_unix.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: 664567d39a22718b90fbcc0455540879a2163a01 $
19 * @file proto_control_unix.c
20 * @brief Control handler for Unix sockets.
21 *
22 * @copyright 2018 The FreeRADIUS server project.
23 * @copyright 2018 Alan DeKok (aland@deployingradius.com)
24 */
25#include <freeradius-devel/server/main_config.h>
26
27#include <freeradius-devel/io/application.h>
28#include <freeradius-devel/io/listen.h>
29#include <freeradius-devel/io/schedule.h>
30#include <freeradius-devel/server/protocol.h>
31#include <freeradius-devel/util/perm.h>
32#include <freeradius-devel/util/trie.h>
33#include <freeradius-devel/util/file.h>
34
35#include <netdb.h>
36
37#include "proto_control.h"
38
39#include <freeradius-devel/bio/fd.h>
40
41#ifdef HAVE_SYS_STAT_H
42#endif
43
44#include <libgen.h>
45
46typedef struct {
47 char const *name; //!< socket name
48
49 int sockfd;
50
52
53 fr_stats_t stats; //!< statistics for this socket
54
55 fr_io_address_t *connection; //!< for connected sockets.
56
57
58 fr_io_data_read_t read; //!< function to process data *after* reading
59 FILE *stdout_fp;
60 FILE *stderr_fp;
61
63 FILE *misc;
64 fr_cmd_info_t *info; //!< for running commands
65
66 fr_client_t radclient; //!< for faking out clients
68
69typedef struct {
70 CONF_SECTION *cs; //!< our configuration
71
72 char const *filename; //!< filename of control socket
73 char const *uid_name; //!< name of UID to require
74 char const *gid_name; //!< name of GID to require
75 uid_t uid; //!< UID value
76 gid_t gid; //!< GID value
77
78 uint32_t recv_buff; //!< How big the kernel's receive buffer should be.
79
80 uint32_t max_packet_size; //!< for message ring buffer.
81
82 char const *mode_name;
84
85 bool recv_buff_is_set; //!< Whether we were provided with a receive
86 //!< buffer value.
87 char const *peer_uid_name; //!< name of UID to require
88 char const *peer_gid_name; //!< name of GID to require
89 uid_t peer_uid; //!< UID value
90 gid_t peer_gid; //!< GID value
91
93
95 { FR_CONF_OFFSET("uid", proto_control_unix_t, peer_uid_name) },
96 { FR_CONF_OFFSET("gid", proto_control_unix_t, peer_gid_name) },
97
99};
100
103 .dflt = "${run_dir}/radiusd.sock" },
104 { FR_CONF_OFFSET("uid", proto_control_unix_t, uid_name) },
105 { FR_CONF_OFFSET("gid", proto_control_unix_t, gid_name) },
106 { FR_CONF_OFFSET("mode", proto_control_unix_t, mode_name) },
107
108 { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_control_unix_t, recv_buff) },
109
110 { FR_CONF_OFFSET("max_packet_size", proto_control_unix_t, max_packet_size), .dflt = "4096" } ,
111
112 { FR_CONF_POINTER("peercred", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) peercred_config },
113
115};
116
117#define FR_READ (1)
118#define FR_WRITE (2)
119
121 { L("read-only"), FR_READ },
122 { L("read-write"), FR_READ | FR_WRITE },
123 { L("ro"), FR_READ },
124 { L("rw"), FR_READ | FR_WRITE }
125};
127
128#undef INT
129#define INT size_t
130#define SINT ssize_t
131
132static SINT write_stdout(void *instance, char const *buffer, INT buffer_size)
133{
134 proto_control_unix_thread_t *thread = talloc_get_type_abort(instance, proto_control_unix_thread_t);
135
136 return fr_conduit_write(thread->sockfd, FR_CONDUIT_STDOUT, buffer, buffer_size);
137}
138
139static SINT write_stderr(void *instance, char const *buffer, INT buffer_size)
140{
141 proto_control_unix_thread_t *thread = talloc_get_type_abort(instance, proto_control_unix_thread_t)
142;
143 return fr_conduit_write(thread->sockfd, FR_CONDUIT_STDERR, buffer, buffer_size);
144}
145
146static SINT write_misc(void *instance, char const *buffer, INT buffer_size)
147{
148 proto_control_unix_thread_t *thread = talloc_get_type_abort(instance, proto_control_unix_thread_t);
149
150 return fr_conduit_write(thread->sockfd, thread->misc_conduit, buffer, buffer_size);
151}
152
153
154/*
155 * Run a command.
156 */
157static ssize_t mod_read_command(fr_listen_t *li, UNUSED void **packet_ctx, UNUSED fr_time_t *recv_time_p, uint8_t *buffer, UNUSED size_t buffer_len, UNUSED size_t *leftover)
158{
160 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
162 uint32_t status;
163 uint8_t *cmd = buffer + sizeof(*hdr);
164 int rcode;
165 char string[1024];
166
167 hdr->length = ntohl(hdr->length);
168 if (hdr->length >= sizeof(string)) goto fail;
169
170 /*
171 * If the write gives us nothing, send an empty SUCCESS back.
172 */
173 if (!hdr->length) {
174 status = FR_CONDUIT_SUCCESS;
175 goto done;
176 }
177
178 /*
179 * fr_command_run() expects a zero-terminated string...
180 */
181 memcpy(string, cmd, hdr->length);
182 string[hdr->length] = '\0';
183
184 /*
185 * Content is the string we need help for.
186 */
187 if (htons(hdr->conduit) == FR_CONDUIT_HELP) {
188 fr_radmin_help(thread->stdout_fp, string);
189 // @todo - have in-band signalling saying that the help is done?
190 // we want to be able to say that *this* help is done.
191 // the best way to do that is to have a token, and every command
192 // from the other end sends a token, and we echo it back here...
193 // Or, since we currently can't do streaming commands, it's OK?
194 // Or, we assume that origin 0 is for interactive commands,
195 // and that the other origins are for streaming output...
196 status = FR_CONDUIT_SUCCESS;
197 goto done;
198 }
199
200 if (htons(hdr->conduit) == FR_CONDUIT_COMPLETE) {
201 uint16_t start;
202
203 if (hdr->length < 2) goto fail;
204
205 start = (string[0] << 8) | string[1];
206
208
209 fr_radmin_complete(thread->misc, string + 2, start);
211 status = FR_CONDUIT_SUCCESS;
212 goto done;
213 }
214
215 if (htons(hdr->conduit) != FR_CONDUIT_STDIN) {
216 DEBUG("ERROR: Ignoring data which is from wrong input");
217 return 0;
218 }
219
220 DEBUG("radmin-remote> %.*s", (int) hdr->length, cmd);
221
222 rcode = fr_radmin_run(thread->info, thread->stdout_fp, thread->stderr_fp, string, inst->read_only);
223 if (rcode < 0) {
224fail:
225 status = FR_CONDUIT_FAIL;
226
227 } else if (rcode == 0) {
228 /*
229 * The other end should keep track of it's
230 * context, and send us full lines.
231 */
232 (void) fr_command_clear(0, thread->info);
233 status = FR_CONDUIT_PARTIAL;
234 } else {
235 status = FR_CONDUIT_SUCCESS;
236 }
237
238done:
239 status = htonl(status);
240 (void) fr_conduit_write(thread->sockfd, FR_CONDUIT_CMD_STATUS, &status, sizeof(status));
241
242 return 0;
243}
244
245/*
246 * Process an initial connection request.
247 */
248static ssize_t mod_read_init(fr_listen_t *li, UNUSED void **packet_ctx, UNUSED fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, UNUSED size_t *leftover)
249{
250 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
252 uint32_t magic;
253
254 if (htons(hdr->conduit) != FR_CONDUIT_INIT_ACK) {
255 DEBUG("ERROR: Connection is missing initial ACK packet.");
256 return -1;
257 }
258
259 if (buffer_len < sizeof(*hdr)) {
260 DEBUG("ERROR: Initial ACK is malformed");
261 return -1;
262 }
263
264 if (htonl(hdr->length) != 8) {
265 DEBUG("ERROR: Initial ACK has wrong length (%lu).", (size_t) htonl(hdr->length));
266 return -1;
267 }
268
269 memcpy(&magic, buffer + sizeof(*hdr), sizeof(magic));
270 magic = htonl(magic);
271 if (magic != FR_CONDUIT_MAGIC) {
272 DEBUG("ERROR: Connection from incompatible version of radmin.");
273 return -1;
274 }
275
276 /*
277 * Next 4 bytes are zero, we ignore them.
278 */
279 if (write(thread->sockfd, buffer, buffer_len) < (ssize_t) buffer_len) {
280 DEBUG("ERROR: Blocking write to socket... oops");
281 return -1;
282 }
283
284 thread->read = mod_read_command;
285
286 return 0;
287}
288
289static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
290{
291 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
292 ssize_t data_size;
293
294 fr_conduit_type_t conduit;
295 bool want_more;
296
297 /*
298 * Read data into the buffer.
299 */
300 data_size = fr_conduit_read_async(thread->sockfd, &conduit, buffer, buffer_len, leftover, &want_more);
301 if (data_size < 0) {
302 DEBUG2("proto_control_unix got read error %zd: %s", data_size, fr_syserror(errno));
303 return data_size;
304 }
305
306 /*
307 * Note that we return ERROR for all bad packets, as
308 * there's no point in reading packets from a TCP
309 * connection which isn't sending us properly formatted
310 * packets.
311 */
312
313 /*
314 * Not enough for a full packet, ask the caller to read more.
315 */
316 if (want_more) {
317 return 0;
318 }
319
320 // @todo - maybe convert timestamp?
321 *recv_time_p = fr_time();
322 *leftover = 0;
323
324 /*
325 * Print out what we received.
326 */
327 DEBUG3("proto_control_unix - Received command packet length %d on %s",
328 (int) data_size, thread->name);
329
330 /*
331 * Run the state machine to process the rest of the packet.
332 */
333 return thread->read(li, packet_ctx, recv_time_p, buffer, (size_t) data_size, leftover);
334}
335
336
337static ssize_t mod_write(fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time,
338 uint8_t *buffer, size_t buffer_len, size_t written)
339{
340 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
341 ssize_t data_size;
342
343 /*
344 * @todo - share a stats interface with the parent? or
345 * put the stats in the listener, so that proto_control
346 * can update them, too.. <sigh>
347 */
348 thread->stats.total_responses++;
349
350 /*
351 * Only write replies if they're RADIUS packets.
352 * sometimes we want to NOT send a reply...
353 */
354 data_size = write(thread->sockfd, buffer + written, buffer_len - written);
355
356 /*
357 * This socket is dead. That's an error...
358 */
359 if (data_size <= 0) return data_size;
360
361#ifdef __COVERITY__
362 /*
363 * data_size and written have type size_t, so
364 * their sum can at least in theory exceed SSIZE_MAX.
365 * We add this check to placate Coverity.
366 *
367 * When Coverity examines this function it doesn't have
368 * the caller context to see that it's honoring needed
369 * preconditions (buffer_len <=SSIZE_MAX, and the loop
370 * schema needed to use this function).
371 */
372 if (data_size + written > SSIZE_MAX) return -1;
373#endif
374
375 return data_size + written;
376}
377
378
380{
381 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
382
383 thread->connection = connection;
384
385 // @todo - set name to path + peer ID of other end?
386
387 return 0;
388}
389
390static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, UNUSED void *instance)
391{
392 *ipproto = IPPROTO_TCP;
393 *dynamic_clients = false;
394 *trie = NULL;
395}
396
397/** Open a UNIX listener for control sockets
398 *
399 */
400static int mod_open(fr_listen_t *li)
401{
403 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
404
405 CONF_ITEM *ci;
406 CONF_SECTION *server_cs;
407
408 fr_bio_fd_info_t const *info;
410
411 fr_assert(!thread->connection);
412
413 cfg = (fr_bio_fd_config_t) {
415 .socket_type = SOCK_STREAM,
416 .path = inst->filename,
417 .uid = inst->uid,
418 .gid = inst->gid,
419 .perm = 0600,
420 .async = true,
421 };
422
423 thread->fd_bio = fr_bio_fd_alloc(thread, &cfg, 0);
424 if (!thread->fd_bio) {
425 cf_log_err(li->cs, "Failed opening UNIX path %s - %s", inst->filename, fr_strerror());
426 return -1;
427 }
428
429 info = fr_bio_fd_info(thread->fd_bio);
430 fr_assert(info != NULL);
431
432 li->fd = thread->sockfd = info->socket.fd;
433
434 ci = cf_parent(inst->cs); /* listen { ... } */
435 fr_assert(ci != NULL);
436 ci = cf_parent(ci);
437 fr_assert(ci != NULL);
438
439 server_cs = cf_item_to_section(ci);
440
441 thread->name = talloc_typed_asprintf(thread, "control_unix from filename %s", inst->filename);
442
443 /*
444 * Set up the fake client
445 */
446 thread->radclient.longname = inst->filename;
447 thread->radclient.ipaddr.af = AF_INET;
448 thread->radclient.src_ipaddr.af = AF_INET;
449
450 thread->radclient.server_cs = server_cs;
451 fr_assert(thread->radclient.server_cs != NULL);
453
454 return 0;
455}
456
457#if !defined(HAVE_GETPEEREID) && defined(SO_PEERCRED)
458static int getpeereid(int s, uid_t *euid, gid_t *egid)
459{
460 struct ucred cr;
461 socklen_t cl = sizeof(cr);
462
463 if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cr, &cl) < 0) {
464 return -1;
465 }
466
467 *euid = cr.uid;
468 *egid = cr.gid;
469 return 0;
470}
471
472/* we now have getpeereid() in this file */
473#define HAVE_GETPEEREID (1)
474
475#endif /* HAVE_GETPEEREID */
476
478{
479 if (thread->stdout_fp) fclose(thread->stdout_fp);
480 if (thread->stderr_fp) fclose(thread->stderr_fp);
481 if (thread->misc) fclose(thread->misc);
482
483 return 0;
484}
485
486/** Set the file descriptor for this socket.
487 *
488 */
489static int mod_fd_set(fr_listen_t *li, int fd)
490{
492 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
493
495
496#ifdef HAVE_GETPEEREID
497 /*
498 * Perform user authentication.
499 *
500 * @todo - this really belongs in the accept() callback,
501 * so that we don't create an entirely new listener and
502 * then close it.
503 */
504 if (inst->peer_uid || inst->peer_gid) {
505 uid_t uid;
506 gid_t gid;
507
508 if (getpeereid(fd, &uid, &gid) < 0) {
509 ERROR("Failed getting peer credentials for %s: %s",
510 inst->filename, fr_syserror(errno));
511 return -1;
512 }
513
514 /*
515 * Only do UID checking if the caller is
516 * non-root. The superuser can do anything, so
517 * we might as well let them do anything.
518 */
519 if (uid != 0) do {
520 /*
521 * Allow entry if UID or GID matches.
522 */
523 if (inst->peer_uid_name && (inst->peer_uid == uid)) break;
524 if (inst->peer_gid_name && (inst->peer_gid == gid)) break;
525
526 if (inst->peer_uid_name && (inst->peer_uid != uid)) {
527 ERROR("Unauthorized connection to %s from uid %ld",
528 inst->filename, (long int) uid);
529 return -1;
530 }
531
532 if (inst->peer_gid_name && (inst->peer_gid != gid)) {
533 ERROR("Unauthorized connection to %s from gid %ld",
534 inst->filename, (long int) gid);
535 return -1;
536 }
537
538 } while (0);
539
540 thread->name = talloc_typed_asprintf(thread, "proto unix filename %s from peer UID %u GID %u",
541 inst->filename,
542 (unsigned int) uid, (unsigned int) gid);
543 } else
544#endif
545
546
547 thread->name = talloc_typed_asprintf(thread, "proto unix filename %s", inst->filename);
548
549 thread->sockfd = fd;
550 thread->read = mod_read_init;
551
552 /*
553 * These must be set separately as they have different prototypes.
554 */
555 io.read = NULL;
556 io.seek = NULL;
557 io.close = NULL;
558 io.write = write_stdout;
559
560 thread->stdout_fp = fopencookie(thread, "w", io);
561
562 io.write = write_stderr;
563 thread->stderr_fp = fopencookie(thread, "w", io);
564
565 io.write = write_misc;
566 thread->misc = fopencookie(thread, "w", io);
567
568 talloc_set_destructor(thread, _close_cookies);
569
570 /*
571 * @todo - if we move to a binary protocol, then we
572 * should change this to a small (i.e. 1K) buffer. The
573 * data should be sent over to the remote side as quickly
574 * as possible.
575 */
576 (void) setvbuf(thread->stdout_fp, NULL, _IOLBF, 0);
577 (void) setvbuf(thread->stderr_fp, NULL, _IOLBF, 0);
578 (void) setvbuf(thread->misc, NULL, _IOLBF, 0);
579
580 thread->info = talloc_zero(thread, fr_cmd_info_t);
581 fr_command_info_init(thread, thread->info);
582
583 return 0;
584}
585
586static char const *mod_name(fr_listen_t *li)
587{
588 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
589
590 return thread->name;
591}
592
593
594static int mod_instantiate(module_inst_ctx_t const *mctx)
595{
596 proto_control_unix_t *inst = talloc_get_type_abort(mctx->mi->data, proto_control_unix_t);
597 CONF_SECTION *conf = mctx->mi->conf;
598
599 inst->cs = conf;
600
601 if (inst->recv_buff_is_set) {
602 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32);
603 FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, <=, INT_MAX);
604 }
605
606 if (inst->uid_name) {
607 struct passwd *pwd;
608
609 if (fr_perm_getpwnam(conf, &pwd, inst->uid_name) < 0) {
610 PERROR("Failed getting uid for %s", inst->uid_name);
611 return -1;
612 }
613 inst->uid = pwd->pw_uid;
614 talloc_free(pwd);
615
616 } else if (main_config->server_uid) {
617 inst->uid = main_config->server_uid;
618
619 } else {
620 inst->uid = getuid();
621 }
622
623 if (inst->gid_name) {
624 if (fr_perm_gid_from_str(conf, &inst->gid, inst->gid_name) < 0) {
625 PERROR("Failed getting gid for %s", inst->gid_name);
626 return -1;
627 }
628
629 } else if (main_config->server_gid) {
630 inst->gid = main_config->server_gid;
631
632 } else {
633 inst->gid = getgid();
634 }
635
636 /*
637 * And for peer creds
638 */
639 if (inst->peer_uid_name) {
640 struct passwd *pwd;
641
642 if (fr_perm_getpwnam(conf, &pwd, inst->peer_uid_name) < 0) {
643 PERROR("Failed getting peer uid for %s", inst->peer_uid_name);
644 return -1;
645 }
646 inst->peer_uid = pwd->pw_uid;
647 talloc_free(pwd);
648 }
649
650 if (inst->peer_gid_name) {
651 if (fr_perm_gid_from_str(conf, &inst->peer_gid, inst->peer_gid_name) < 0) {
652 PERROR("Failed getting peer gid for %s", inst->peer_gid_name);
653 return -1;
654 }
655 }
656
657 if (!inst->mode_name) {
658 inst->read_only = true;
659 } else {
660 int mode;
661
662 mode = fr_table_value_by_str(mode_names, inst->mode_name, 0);
663 if (!mode) {
664 ERROR("Invalid mode name \"%s\"",
665 inst->mode_name);
666 return -1;
667 }
668
669 if ((mode & FR_WRITE) == 0) {
670 inst->read_only = true;
671 } else {
672 inst->read_only = false;
673 }
674 }
675
676 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 20);
677 FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65536);
678
679 return 0;
680}
681
683{
684 proto_control_unix_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_control_unix_thread_t);
685
686 return &thread->radclient;
687}
688
691 .common = {
692 .magic = MODULE_MAGIC_INIT,
693 .name = "control_unix",
695 .inst_size = sizeof(proto_control_unix_t),
696 .thread_inst_size = sizeof(proto_control_unix_thread_t),
697 .instantiate = mod_instantiate
698 },
699 .default_message_size = 4096,
700
701 .open = mod_open,
702 .read = mod_read,
703 .write = mod_write,
704 .fd_set = mod_fd_set,
705 .connection_set = mod_connection_set,
706 .network_get = mod_network_get,
707 .client_find = mod_client_find,
708 .get_name = mod_name,
709};
static int const char char buffer[256]
Definition acutest.h:576
module_t common
Common fields to all loadable modules.
Definition app_io.h:34
Public structure describing an I/O path for a protocol.
Definition app_io.h:33
int fr_radmin_run(fr_cmd_info_t *info, FILE *fp, FILE *fp_err, char *str, bool read_only)
Run a command from an input string.
Definition radmin.c:1181
void fr_radmin_complete(FILE *fp, const char *text, int start)
Definition radmin.c:1217
void fr_radmin_help(FILE *fp, char const *text)
Definition radmin.c:1212
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:210
#define UNUSED
Definition build.h:318
#define NUM_ELEMENTS(_t)
Definition build.h:340
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:657
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition cf_parse.h:517
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:280
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition cf_parse.h:334
#define FR_CONF_OFFSET_IS_SET(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct,...
Definition cf_parse.h:294
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:268
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:429
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition cf_parse.h:423
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:594
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1184
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:285
#define cf_parent(_cf)
Definition cf_util.h:98
int fr_command_clear(int new_argc, fr_cmd_info_t *info)
Clear out any value boxes etc.
Definition command.c:2377
void fr_command_info_init(TALLOC_CTX *ctx, fr_cmd_info_t *info)
Initialize an fr_cmd_info_t structure.
Definition command.c:2405
ssize_t fr_conduit_write(int fd, fr_conduit_type_t conduit, void const *out, size_t outlen)
Definition conduit.c:227
ssize_t fr_conduit_read_async(int fd, fr_conduit_type_t *pconduit, void *out, size_t outlen, size_t *leftover, bool *want_more)
Definition conduit.c:74
#define FR_CONDUIT_MAGIC
Definition conduit.h:32
uint16_t conduit
Definition conduit.h:77
@ FR_CONDUIT_FAIL
Definition conduit.h:54
@ FR_CONDUIT_PARTIAL
Definition conduit.h:55
@ FR_CONDUIT_SUCCESS
Definition conduit.h:56
uint32_t length
Definition conduit.h:78
fr_conduit_type_t
Definition conduit.h:34
@ FR_CONDUIT_STDOUT
Definition conduit.h:36
@ FR_CONDUIT_HELP
Definition conduit.h:43
@ FR_CONDUIT_STDIN
Definition conduit.h:35
@ FR_CONDUIT_STDERR
Definition conduit.h:37
@ FR_CONDUIT_CMD_STATUS
Definition conduit.h:38
@ FR_CONDUIT_INIT_ACK
Definition conduit.h:39
@ FR_CONDUIT_COMPLETE
Definition conduit.h:44
#define ERROR(fmt,...)
Definition dhcpclient.c:40
#define DEBUG(fmt,...)
Definition dhcpclient.c:38
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
fr_bio_t * fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_fd_config_t const *cfg, size_t offset)
Allocate a FD bio.
Definition fd.c:971
fr_bio_fd_info_t const * fr_bio_fd_info(fr_bio_t *bio)
Returns a pointer to the bio-specific information.
Definition fd.c:1295
fr_socket_t socket
as connected socket
Definition fd.h:132
@ FR_BIO_FD_LISTEN
returns new fd in buffer on fr_bio_read() or fr_bio_fd_accept()
Definition fd.h:69
fr_bio_fd_type_t type
accept, connected, unconnected, etc.
Definition fd.h:81
Configuration for sockets.
Definition fd.h:80
Run-time status of the socket.
Definition fd.h:131
FILE * fopencookie(void *cookie, const char *mode, cookie_io_functions_t io_funcs)
Definition fopencookie.c:99
cookie_close_function_t close
Definition fopencookie.h:55
cookie_seek_function_t seek
Definition fopencookie.h:54
cookie_read_function_t read
Definition fopencookie.h:52
cookie_write_function_t write
Definition fopencookie.h:53
talloc_free(hp)
int af
Address family.
Definition inet.h:63
IPv4/6 prefix.
ssize_t(* fr_io_data_read_t)(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)
Read from a socket.
Definition base.h:176
CONF_SECTION * cs
of this listener
Definition listen.h:41
void const * app_io_instance
I/O path configuration context.
Definition listen.h:33
void * thread_instance
thread / socket context
Definition listen.h:34
int fd
file descriptor for this socket - set by open
Definition listen.h:28
char const * server
Name of the virtual server client is associated with.
Definition client.h:133
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition client.h:83
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition client.h:84
char const * longname
Client identifier.
Definition client.h:87
CONF_SECTION * server_cs
Virtual server that the client is associated with.
Definition client.h:134
Describes a host allowed to send packets to the server.
Definition client.h:80
#define PERROR(_fmt,...)
Definition log.h:228
#define DEBUG3(_fmt,...)
Definition log.h:266
uint64_t total_responses
Definition stats.h:38
#define fr_time()
Definition event.c:60
main_config_t const * main_config
Main server configuration.
Definition main_config.c:58
unsigned short uint16_t
@ FR_TYPE_UINT32
32 Bit unsigned integer.
unsigned int uint32_t
long int ssize_t
unsigned char uint8_t
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
int fr_perm_getpwnam(TALLOC_CTX *ctx, struct passwd **out, char const *name)
Resolve a username to a passwd entry.
Definition perm.c:268
int fr_perm_gid_from_str(TALLOC_CTX *ctx, gid_t *out, char const *name)
Resolve a group name to a GID.
Definition perm.c:475
fr_client_t radclient
for faking out clients
char const * name
socket name
static void mod_network_get(int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, UNUSED void *instance)
static ssize_t mod_read(fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, size_t *leftover)
static const conf_parser_t peercred_config[]
char const * filename
filename of control socket
static int _close_cookies(proto_control_unix_thread_t *thread)
char const * gid_name
name of GID to require
bool recv_buff_is_set
Whether we were provided with a receive buffer value.
fr_cmd_info_t * info
for running commands
fr_io_data_read_t read
function to process data after reading
uint32_t recv_buff
How big the kernel's receive buffer should be.
fr_io_address_t * connection
for connected sockets.
fr_app_io_t proto_control_unix
static int mod_open(fr_listen_t *li)
Open a UNIX listener for control sockets.
static SINT write_stdout(void *instance, char const *buffer, INT buffer_size)
char const * peer_uid_name
name of UID to require
CONF_SECTION * cs
our configuration
char const * peer_gid_name
name of GID to require
static ssize_t mod_read_init(fr_listen_t *li, UNUSED void **packet_ctx, UNUSED fr_time_t *recv_time_p, uint8_t *buffer, size_t buffer_len, UNUSED size_t *leftover)
#define FR_WRITE
static ssize_t mod_write(fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
#define FR_READ
static SINT write_misc(void *instance, char const *buffer, INT buffer_size)
#define SINT
static int mod_connection_set(fr_listen_t *li, fr_io_address_t *connection)
static SINT write_stderr(void *instance, char const *buffer, INT buffer_size)
static int mod_fd_set(fr_listen_t *li, int fd)
Set the file descriptor for this socket.
fr_stats_t stats
statistics for this socket
static char const * mod_name(fr_listen_t *li)
uint32_t max_packet_size
for message ring buffer.
static int mod_instantiate(module_inst_ctx_t const *mctx)
static size_t mode_names_len
static ssize_t mod_read_command(fr_listen_t *li, UNUSED void **packet_ctx, UNUSED fr_time_t *recv_time_p, uint8_t *buffer, UNUSED size_t buffer_len, UNUSED size_t *leftover)
static fr_table_num_sorted_t mode_names[]
static const conf_parser_t unix_listen_config[]
char const * uid_name
name of UID to require
static fr_client_t * mod_client_find(fr_listen_t *li, UNUSED fr_ipaddr_t const *ipaddr, UNUSED int ipproto)
#define INT
#define fr_assert(_expr)
Definition rad_assert.h:37
static int ipproto
#define DEBUG2(fmt,...)
static bool done
Definition radclient.c:80
static rs_t * conf
Definition radsniff.c:52
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:351
void * data
Module's instance data.
Definition module.h:293
conf_parser_t const * config
How to convert a CONF_SECTION to a module instance.
Definition module.h:206
eap_aka_sim_process_conf_t * inst
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
Definition syserror.c:243
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
Definition table.h:653
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.
Definition talloc.c:545
#define talloc_get_type_abort_const
Definition talloc.h:110
"server local" time.
Definition time.h:69
int fd
File descriptor if this is a live socket.
Definition socket.h:78
char const * fr_strerror(void)
Get the last library error.
Definition strerror.c:553