Use the proper verify_request function instead of talloc_get_type_abort
[freeradius.git] / src / include / radiusd.h
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 #ifndef RADIUSD_H
17 #define RADIUSD_H
18 /*
19  * $Id$
20  *
21  * @file radiusd.h
22  * @brief Structures, prototypes and global variables for the FreeRADIUS server.
23  *
24  * @copyright 1999-2000,2002-2008  The FreeRADIUS server project
25  */
26
27 RCSIDH(radiusd_h, "$Id$")
28
29 #include <freeradius-devel/libradius.h>
30 #include <freeradius-devel/radpaths.h>
31 #include <freeradius-devel/conf.h>
32 #include <freeradius-devel/conffile.h>
33 #include <freeradius-devel/event.h>
34 #include <freeradius-devel/connection.h>
35 #include <freeradius-devel/map.h>
36
37 typedef struct rad_request REQUEST;
38
39 #include <freeradius-devel/log.h>
40
41 #ifdef HAVE_PTHREAD_H
42 #  include <pthread.h>
43 #else
44 #  include <sys/wait.h>
45 #endif
46
47 #ifndef NDEBUG
48 #  define REQUEST_MAGIC (0xdeadbeef)
49 #endif
50
51 /*
52  *      WITH_VMPS is handled by src/include/features.h
53  */
54 #ifdef WITHOUT_VMPS
55 #  undef WITH_VMPS
56 #endif
57
58 #ifdef WITH_TLS
59 #  include <freeradius-devel/tls.h>
60 #endif
61
62 #include <freeradius-devel/stats.h>
63 #include <freeradius-devel/realms.h>
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 /*
70  *      See util.c
71  */
72 typedef struct request_data_t request_data_t;
73
74 typedef struct radclient {
75         fr_ipaddr_t             ipaddr;
76         fr_ipaddr_t             src_ipaddr;
77         char const              *longname;
78         char const              *secret;
79         char const              *shortname;
80         bool                    message_authenticator;
81         char const              *nas_type;
82         char const              *login;
83         char const              *password;
84         char const              *server;
85         int                     number; /* internal use only */
86         CONF_SECTION const      *cs;
87 #ifdef WITH_STATS
88         fr_stats_t              auth;
89 #ifdef WITH_ACCOUNTING
90         fr_stats_t              acct;
91 #endif
92 #ifdef WITH_COA
93         fr_stats_t              coa;
94         fr_stats_t              dsc;
95 #endif
96 #endif
97
98         struct timeval          response_window;
99
100         int                     proto;
101 #ifdef WITH_TCP
102         fr_socket_limit_t       limit;
103 #endif
104 #ifdef WITH_TLS
105         bool                    tls_required;
106 #endif
107
108 #ifdef WITH_DYNAMIC_CLIENTS
109         uint32_t                lifetime;
110         uint32_t                dynamic; /* was dynamically defined */
111         time_t                  created;
112         time_t                  last_new_client;
113         char const              *client_server;
114         bool                    rate_limit;
115 #endif
116
117 #ifdef WITH_COA
118         char const              *coa_name;
119         home_server_t           *coa_server;
120         home_pool_t             *coa_pool;
121 #endif
122 } RADCLIENT;
123
124 /*
125  *      Types of listeners.
126  *
127  *      Ordered by priority!
128  */
129 typedef enum RAD_LISTEN_TYPE {
130         RAD_LISTEN_NONE = 0,
131 #ifdef WITH_PROXY
132         RAD_LISTEN_PROXY,
133 #endif
134         RAD_LISTEN_AUTH,
135 #ifdef WITH_ACCOUNTING
136         RAD_LISTEN_ACCT,
137 #endif
138 #ifdef WITH_DETAIL
139         RAD_LISTEN_DETAIL,
140 #endif
141 #ifdef WITH_VMPS
142         RAD_LISTEN_VQP,
143 #endif
144 #ifdef WITH_DHCP
145         RAD_LISTEN_DHCP,
146 #endif
147 #ifdef WITH_COMMAND_SOCKET
148         RAD_LISTEN_COMMAND,
149 #endif
150 #ifdef WITH_COA
151         RAD_LISTEN_COA,
152 #endif
153         RAD_LISTEN_MAX
154 } RAD_LISTEN_TYPE;
155
156 /** Return codes indicating the result of the module call
157  *
158  * All module functions must return one of the codes listed below (apart from
159  * RLM_MODULE_NUMCODES, which is used to check for validity).
160  */
161 typedef enum rlm_rcodes {
162         RLM_MODULE_REJECT = 0,  //!< Immediately reject the request.
163         RLM_MODULE_FAIL,        //!< Module failed, don't reply.
164         RLM_MODULE_OK,          //!< The module is OK, continue.
165         RLM_MODULE_HANDLED,     //!< The module handled the request, so stop.
166         RLM_MODULE_INVALID,     //!< The module considers the request invalid.
167         RLM_MODULE_USERLOCK,    //!< Reject the request (user is locked out).
168         RLM_MODULE_NOTFOUND,    //!< User not found.
169         RLM_MODULE_NOOP,        //!< Module succeeded without doing anything.
170         RLM_MODULE_UPDATED,     //!< OK (pairs modified).
171         RLM_MODULE_NUMCODES,    //!< How many valid return codes there are.
172         RLM_MODULE_UNKNOWN      //!< Error resolving rcode (should not be
173                                 //!< returned by modules).
174 } rlm_rcode_t;
175 extern const FR_NAME_NUMBER modreturn_table[];
176
177 /*
178  *      For listening on multiple IP's and ports.
179  */
180 typedef struct rad_listen_t rad_listen_t;
181
182 typedef         void (*fr_request_process_t)(REQUEST *, int);
183 /*
184  *  Function handler for requests.
185  */
186 typedef         int (*RAD_REQUEST_FUNP)(REQUEST *);
187
188 #define REQUEST_DATA_REGEX (0xadbeef00)
189 #define REQUEST_MAX_REGEX (8)
190
191 #if defined(WITH_VERIFY_PTR)
192 #  define VERIFY_REQUEST(_x) verify_request(_x)
193 #else
194 /*
195  *  Even if were building without WITH_VERIFY_PTR
196  *  the pointer must not be NULL when these various macros are used
197  *  so we can add some sneaky asserts.
198  */
199 #  define VERIFY_REQUEST(_x) rad_assert(_x)
200 #endif
201
202 typedef enum {
203         REQUEST_ACTIVE = 1,
204         REQUEST_STOP_PROCESSING,
205         REQUEST_COUNTED
206 } rad_master_state_t;
207 #define REQUEST_MASTER_NUM_STATES (REQUEST_COUNTED + 1)
208
209 typedef enum {
210         REQUEST_QUEUED = 1,
211         REQUEST_RUNNING,
212         REQUEST_PROXIED,
213         REQUEST_RESPONSE_DELAY,
214         REQUEST_CLEANUP_DELAY,
215         REQUEST_DONE
216 } rad_child_state_t;
217 #define REQUEST_CHILD_NUM_STATES (REQUEST_DONE + 1)
218
219 struct rad_request {
220 #ifndef NDEBUG
221         uint32_t                magic;          //!< Magic number used to detect memory corruption,
222                                                 //!< or request structs that have not been properly initialised.
223 #endif
224         RADIUS_PACKET           *packet;        //!< Incoming request.
225 #ifdef WITH_PROXY
226         RADIUS_PACKET           *proxy;         //!< Outgoing request.
227 #endif
228         RADIUS_PACKET           *reply;         //!< Outgoing response.
229 #ifdef WITH_PROXY
230         RADIUS_PACKET           *proxy_reply;   //!< Incoming response.
231 #endif
232         VALUE_PAIR              *config_items;  //!< VALUE_PAIRs used to set per request parameters
233                                                 //!< for modules and the server core at runtime.
234         VALUE_PAIR              *username;      //!< Cached username VALUE_PAIR.
235         VALUE_PAIR              *password;      //!< Cached password VALUE_PAIR.
236
237         fr_request_process_t    process;        //!< The function to call to move the request through the state machine.
238
239         RAD_REQUEST_FUNP        handle;         //!< The function to call to move the request through the
240                                                 //!< various server configuration sections.
241
242         struct main_config_t    *root;          //!< Pointer to the main config hack to try and deal with hup.
243
244         request_data_t          *data;          //!< Request metadata.
245
246         RADCLIENT               *client;        //!< The client that originally sent us the request.
247
248 #ifdef HAVE_PTHREAD_H
249         pthread_t               child_pid;      //!< Current thread handling the request.
250 #endif
251         time_t                  timestamp;      //!< When the request was received.
252         unsigned int            number;         //!< Monotonically increasing request number. Reset on server restart.
253
254         rad_listen_t            *listener;      //!< The listener that received the request.
255 #ifdef WITH_PROXY
256         rad_listen_t            *proxy_listener;//!< Listener for outgoing requests.
257 #endif
258
259         rlm_rcode_t             rcode;          //!< Last rcode returned by a module
260
261         int                     simul_max;      //!< Maximum number of concurrent sessions for this user.
262 #ifdef WITH_SESSION_MGMT
263         int                     simul_count;    //!< The current number of sessions for this user.
264         int                     simul_mpp;      //!< WEIRD: 1 is false, 2 is true.
265 #endif
266
267         char const              *module;        //!< Module the request is currently being processed by.
268         char const              *component;     //!< Section the request is in.
269
270         int                     delay;
271
272         rad_master_state_t      master_state;
273         rad_child_state_t       child_state;
274         RAD_LISTEN_TYPE         priority;
275
276         int                     response_delay;
277         int                     timer_action;
278         fr_event_t              *ev;
279
280         bool                    in_request_hash;
281 #ifdef WITH_PROXY
282         bool                    in_proxy_hash;
283
284         home_server_t           *home_server;
285         home_pool_t             *home_pool;     //!< For dynamic failover
286
287         struct timeval          proxy_retransmit;
288
289         uint32_t                num_proxied_requests;
290         uint32_t                num_proxied_responses;
291 #endif
292
293         char const              *server;
294         REQUEST                 *parent;
295
296         struct {
297                 radlog_func_t   func;           //!< Function to call to output log messages about this
298                                                 //!< request.
299
300                 log_debug_t     lvl;            //!< Request options, currently just holds the debug level or
301                                                 //!< the request.
302
303                 uint8_t         indent;         //!< By how much to indent log messages. uin8_t so it's obvious
304                                                 //!< when a request has been exdented too much.
305         } log;
306
307 #ifdef WITH_COA
308         REQUEST                 *coa;           //!< CoA request originated by this request.
309         uint32_t                num_coa_requests;//!< Counter for number of requests sent including
310                                                 //!< retransmits.
311 #endif
312 };                              /* REQUEST typedef */
313
314 #define RAD_REQUEST_OPTION_NONE         (0)
315 #define RAD_REQUEST_OPTION_DEBUG        (1)
316 #define RAD_REQUEST_OPTION_DEBUG2       (2)
317 #define RAD_REQUEST_OPTION_DEBUG3       (3)
318 #define RAD_REQUEST_OPTION_DEBUG4       (4)
319
320 typedef struct radclient_list RADCLIENT_LIST;
321
322 typedef int (*rad_listen_recv_t)(rad_listen_t *);
323 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
324 typedef int (*rad_listen_print_t)(rad_listen_t const *, char *, size_t);
325 typedef int (*rad_listen_encode_t)(rad_listen_t *, REQUEST *);
326 typedef int (*rad_listen_decode_t)(rad_listen_t *, REQUEST *);
327
328 struct rad_listen_t {
329         struct rad_listen_t *next; /* should be rbtree stuff */
330
331         /*
332          *      For normal sockets.
333          */
334         RAD_LISTEN_TYPE type;
335         int             fd;
336         char const      *server;
337         int             status;
338 #ifdef WITH_TCP
339         int             count;
340         bool            dual;
341 #endif
342         bool            nodup;
343         bool            synchronous;
344         uint32_t        workers;
345
346 #ifdef WITH_TLS
347         fr_tls_server_conf_t *tls;
348 #endif
349
350         rad_listen_recv_t recv;
351         rad_listen_send_t send;
352         rad_listen_encode_t encode;
353         rad_listen_decode_t decode;
354         rad_listen_print_t print;
355
356         CONF_SECTION const *cs;
357         void            *data;
358
359 #ifdef WITH_STATS
360         fr_stats_t      stats;
361 #endif
362 };
363
364 /*
365  *      This shouldn't really be exposed...
366  */
367 typedef struct listen_socket_t {
368         /*
369          *      For normal sockets.
370          */
371         fr_ipaddr_t     my_ipaddr;
372         uint16_t        my_port;
373
374         char const      *interface;
375 #ifdef SO_BROADCAST
376         int             broadcast;
377 #endif
378         time_t          rate_time;
379         uint32_t        rate_pps_old;
380         uint32_t        rate_pps_now;
381         uint32_t        max_rate;
382
383         /* for outgoing sockets */
384         home_server_t   *home;
385         fr_ipaddr_t     other_ipaddr;
386         uint16_t        other_port;
387
388         int             proto;
389
390 #ifdef WITH_TCP
391         /* for a proxy connecting to home servers */
392         time_t          last_packet;
393         time_t          opened;
394         fr_event_t      *ev;
395
396         fr_socket_limit_t limit;
397
398         struct listen_socket_t *parent;
399         RADCLIENT       *client;
400
401         RADIUS_PACKET   *packet; /* for reading partial packets */
402 #endif
403
404 #ifdef WITH_TLS
405         tls_session_t   *ssn;
406         REQUEST         *request; /* horrible hacks */
407         VALUE_PAIR      *certs;
408         pthread_mutex_t mutex;
409         uint8_t         *data;
410         size_t          partial;
411 #endif
412
413         RADCLIENT_LIST  *clients;
414 } listen_socket_t;
415
416 #define RAD_LISTEN_STATUS_INIT       (0)
417 #define RAD_LISTEN_STATUS_KNOWN      (1)
418 #define RAD_LISTEN_STATUS_EOL        (2)
419 #define RAD_LISTEN_STATUS_REMOVE_NOW (3)
420
421 typedef struct main_config_t {
422         struct main_config *next;
423         fr_ipaddr_t     myip;   /* from the command-line only */
424         uint16_t        port;   /* from the command-line only */
425         bool            log_auth;
426         bool            log_auth_badpass;
427         bool            log_auth_goodpass;
428         bool            allow_core_dumps;
429         uint32_t        debug_level;
430         bool            daemonize;
431 #ifdef WITH_PROXY
432         bool            proxy_requests;
433 #endif
434         uint32_t        reject_delay;
435         bool            status_server;
436         char const      *allow_vulnerable_openssl;
437
438         uint32_t        max_request_time;
439         uint32_t        cleanup_delay;
440         uint32_t        max_requests;
441         char const      *log_file;
442         char const      *dictionary_dir;
443         char const      *checkrad;
444         char const      *pid_file;
445         rad_listen_t    *listen;
446         int             syslog_facility;
447         CONF_SECTION    *config;
448         char const      *name;
449         char const      *auth_badpass_msg;
450         char const      *auth_goodpass_msg;
451         bool            debug_memory;
452         bool            memory_report;
453         char const      *panic_action;
454         char const      *denied_msg;
455         struct timeval  init_delay; /* initial request processing delay */
456 } MAIN_CONFIG_T;
457
458 #define SECONDS_PER_DAY         86400
459 #define MAX_REQUEST_TIME        30
460 #define CLEANUP_DELAY           5
461 #define MAX_REQUESTS            256
462 #define RETRY_DELAY             5
463 #define RETRY_COUNT             3
464 #define DEAD_TIME               120
465 #define EXEC_TIMEOUT            10
466
467 /* for paircompare_register */
468 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
469
470 typedef enum request_fail {
471         REQUEST_FAIL_UNKNOWN = 0,
472         REQUEST_FAIL_NO_THREADS,        //!< No threads to handle it.
473         REQUEST_FAIL_DECODE,            //!< Rad_decode didn't like it.
474         REQUEST_FAIL_PROXY,             //!< Call to proxy modules failed.
475         REQUEST_FAIL_PROXY_SEND,        //!< Proxy_send didn't like it.
476         REQUEST_FAIL_NO_RESPONSE,       //!< We weren't told to respond, so we reject.
477         REQUEST_FAIL_HOME_SERVER,       //!< The home server didn't respond.
478         REQUEST_FAIL_HOME_SERVER2,      //!< Another case of the above.
479         REQUEST_FAIL_HOME_SERVER3,      //!< Another case of the above.
480         REQUEST_FAIL_NORMAL_REJECT,     //!< Authentication failure.
481         REQUEST_FAIL_SERVER_TIMEOUT     //!< The server took too long to process the request.
482 } request_fail_t;
483
484 /*
485  *      Global variables.
486  *
487  *      We really shouldn't have this many.
488  */
489 extern char const       *progname;
490 extern log_debug_t      debug_flag;
491 extern char const       *radacct_dir;
492 extern char const       *radlog_dir;
493 extern char const       *radlib_dir;
494 extern char const       *radius_libdir;
495 extern uint32_t         expiration_seconds;
496 extern bool             log_stripped_names;
497 extern bool             log_auth_detail;
498 extern char const       *radiusd_version;
499 void                    radius_signal_self(int flag);
500
501 typedef enum {
502         RADIUS_SIGNAL_SELF_NONE         = (0),
503         RADIUS_SIGNAL_SELF_HUP          = (1 << 0),
504         RADIUS_SIGNAL_SELF_TERM         = (1 << 1),
505         RADIUS_SIGNAL_SELF_EXIT         = (1 << 2),
506         RADIUS_SIGNAL_SELF_DETAIL       = (1 << 3),
507         RADIUS_SIGNAL_SELF_NEW_FD       = (1 << 4),
508         RADIUS_SIGNAL_SELF_MAX          = (1 << 5)
509 } radius_signal_t;
510 /*
511  *      Function prototypes.
512  */
513
514 /* acct.c */
515 int             rad_accounting(REQUEST *);
516
517 /* session.c */
518 int             rad_check_ts(uint32_t nasaddr, uint32_t nas_port, char const *user, char const *sessionid);
519 int             session_zap(REQUEST *request, uint32_t nasaddr,
520                             uint32_t nas_port, char const *user,
521                             char const *sessionid, uint32_t cliaddr,
522                             char proto, int session_time);
523
524 /* radiusd.c */
525 #undef debug_pair
526 void            debug_pair(VALUE_PAIR *);
527 void            debug_pair_list(VALUE_PAIR *);
528 void            rdebug_pair_list(int, REQUEST *, VALUE_PAIR *);
529 int             log_err (char *);
530
531 /* util.c */
532 #define MEM(x) if (!(x)) { ERROR("Out of memory"); exit(1); }
533 void (*reset_signal(int signo, void (*func)(int)))(int);
534 int             request_opaque_free(REQUEST *request);
535 int             rad_mkdir(char *directory, mode_t mode);
536 void            *rad_malloc(size_t size); /* calls exit(1) on error! */
537 void            rad_const_free(void const *ptr);
538 REQUEST         *request_alloc(TALLOC_CTX *ctx);
539 REQUEST         *request_alloc_fake(REQUEST *oldreq);
540 REQUEST         *request_alloc_coa(REQUEST *request);
541 int             request_data_add(REQUEST *request,
542                                  void *unique_ptr, int unique_int,
543                                  void *opaque, bool free_opaque);
544 void            *request_data_get(REQUEST *request,
545                                   void *unique_ptr, int unique_int);
546 void            *request_data_reference(REQUEST *request,
547                                   void *unique_ptr, int unique_int);
548 int             rad_copy_string(char *dst, char const *src);
549 int             rad_copy_string_bare(char *dst, char const *src);
550 int             rad_copy_variable(char *dst, char const *from);
551 uint32_t        rad_pps(uint32_t *past, uint32_t *present, time_t *then, struct timeval *now);
552 int             rad_expand_xlat(REQUEST *request, char const *cmd,
553                                 int max_argc, char *argv[], bool can_fail,
554                                 size_t argv_buflen, char *argv_buf);
555 void            rad_regcapture(REQUEST *request, int compare, char const *value,
556                                regmatch_t rxmatch[]);
557 void            verify_request(REQUEST *request);                       /* only for special debug builds */
558
559 /* client.c */
560 RADCLIENT_LIST  *clients_init(CONF_SECTION *cs);
561 void            clients_free(RADCLIENT_LIST *clients);
562 RADCLIENT_LIST  *clients_parse_section(CONF_SECTION *section, bool tls_required);
563 void            client_free(RADCLIENT *client);
564 int             client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
565 #ifdef WITH_DYNAMIC_CLIENTS
566 void            client_delete(RADCLIENT_LIST *clients, RADCLIENT *client);
567 RADCLIENT       *client_from_request(RADCLIENT_LIST *clients, REQUEST *request);
568 #endif
569 RADCLIENT       *client_from_query(TALLOC_CTX *ctx, char const *identifier, char const *secret, char const *shortname,
570                                    char const *type, char const *server, bool require_ma) CC_HINT(nonnull(2, 3));
571
572 RADCLIENT       *client_find(RADCLIENT_LIST const *clients,
573                              fr_ipaddr_t const *ipaddr, int proto);
574
575 RADCLIENT       *client_findbynumber(RADCLIENT_LIST const *clients,
576                                      int number);
577 RADCLIENT       *client_find_old(fr_ipaddr_t const *ipaddr);
578 bool            client_validate(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c);
579 RADCLIENT       *client_read(char const *filename, int in_server, int flag);
580
581
582 /* files.c */
583 int             pairlist_read(TALLOC_CTX *ctx, char const *file, PAIR_LIST **list, int complain);
584 void            pairlist_free(PAIR_LIST **);
585
586 /* version.c */
587 int             rad_check_lib_magic(uint64_t magic);
588 int             ssl_check_consistency(void);
589 char const      *ssl_version_by_num(uint64_t version);
590 char const      *ssl_version_range(uint64_t low, uint64_t high);
591 char const      *ssl_version(void);
592 void            version(void);
593
594 /* auth.c */
595 char    *auth_name(char *buf, size_t buflen, REQUEST *request, bool do_cli);
596 int             rad_authenticate (REQUEST *);
597 int             rad_postauth(REQUEST *);
598 int             rad_virtual_server(REQUEST *);
599
600 /* exec.c */
601 pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
602                            int *input_fd, int *output_fd,
603                            VALUE_PAIR *input_pairs, bool shell_escape);
604 int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
605                             char *answer, int left);
606 int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool shell_escape,
607                         char *user_msg, size_t msg_len, int timeout,
608                         VALUE_PAIR *input_pairs, VALUE_PAIR **output_pairs);
609 void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quench)
610      CC_HINT(nonnull (3));
611
612 /* valuepair.c */
613 int paircompare_register(DICT_ATTR const *attribute, DICT_ATTR const *from,
614           bool first_only, RAD_COMPARE_FUNC func, void *instance);
615 void            paircompare_unregister(DICT_ATTR const *attr, RAD_COMPARE_FUNC func);
616 void            paircompare_unregister_instance(void *instance);
617 int             paircompare(REQUEST *request, VALUE_PAIR *req_list,
618                             VALUE_PAIR *check, VALUE_PAIR **rep_list);
619 value_pair_tmpl_t *radius_xlat2tmpl(TALLOC_CTX *ctx, xlat_exp_t *xlat);
620 int             radius_xlat_do(REQUEST *request, VALUE_PAIR *vp);
621 int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp);
622 int radius_callback_compare(REQUEST *request, VALUE_PAIR *req,
623                             VALUE_PAIR *check, VALUE_PAIR *check_pairs,
624                             VALUE_PAIR **reply_pairs);
625 int radius_find_compare(DICT_ATTR const *attribute);
626 VALUE_PAIR      *radius_paircreate(TALLOC_CTX *ctx, VALUE_PAIR **vps, unsigned int attribute, unsigned int vendor);
627
628 void module_failure_msg(REQUEST *request, char const *fmt, ...) CC_HINT(format (printf, 2, 3));
629 void vmodule_failure_msg(REQUEST *request, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0));
630
631 /*
632  *      Less code == fewer bugs
633  *
634  * @param _a attribute
635  * @param _b value
636  * @param _c op
637  */
638 #define pairmake_packet(_a, _b, _c) pairmake(request->packet, &request->packet->vps, _a, _b, _c)
639 #define pairmake_reply(_a, _b, _c) pairmake(request->reply, &request->reply->vps, _a, _b, _c)
640 #define pairmake_config(_a, _b, _c) pairmake(request, &request->config_items, _a, _b, _c)
641
642
643 /* xlat.c */
644 typedef size_t (*RADIUS_ESCAPE_STRING)(REQUEST *, char *out, size_t outlen, char const *in, void *arg);
645
646 ssize_t radius_xlat(char *out, size_t outlen, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape,
647                     void *escape_ctx)
648         CC_HINT(nonnull (1 ,3 ,4));
649
650 ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape, void *escape_ctx)
651         CC_HINT(nonnull (1, 2, 3));
652
653 ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, RADIUS_ESCAPE_STRING escape,
654                             void *ctx)
655         CC_HINT(nonnull (1, 2, 3));
656
657 typedef ssize_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char const *, char *, size_t);
658 int             xlat_register(char const *module, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape,
659                               void *instance);
660 void            xlat_unregister(char const *module, RAD_XLAT_FUNC func, void *instance);
661 ssize_t         xlat_fmt_to_ref(uint8_t const **out, REQUEST *request, char const *fmt);
662 void            xlat_free(void);
663
664 /* threads.c */
665 extern int thread_pool_init(CONF_SECTION *cs, bool *spawn_flag);
666 extern void thread_pool_stop(void);
667 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
668 extern pid_t rad_fork(void);
669 extern pid_t rad_waitpid(pid_t pid, int *status);
670 extern int total_active_threads(void);
671 extern void thread_pool_lock(void);
672 extern void thread_pool_unlock(void);
673 extern void thread_pool_queue_stats(int array[RAD_LISTEN_MAX], int pps[2]);
674
675 #ifndef HAVE_PTHREAD_H
676 #define rad_fork(n) fork()
677 #define rad_waitpid(a,b) waitpid(a,b, 0)
678 #endif
679
680 /* main_config.c */
681 /* Define a global config structure */
682 extern struct main_config_t main_config;
683
684 void set_radius_dir(TALLOC_CTX *ctx, char const *path);
685 char const *get_radius_dir(void);
686 int main_config_init(void);
687 int main_config_free(void);
688 void main_config_hup(void);
689 void hup_logfile(void);
690 void fr_suid_down(void);
691 void fr_suid_up(void);
692 void fr_suid_down_permanent(void);
693
694 /* listen.c */
695 void listen_free(rad_listen_t **head);
696 int listen_init(CONF_SECTION *cs, rad_listen_t **head, bool spawn_flag);
697 rad_listen_t *proxy_new_listener(home_server_t *home, uint16_t src_port);
698 RADCLIENT *client_listener_find(rad_listen_t *listener, fr_ipaddr_t const *ipaddr, uint16_t src_port);
699
700 #ifdef WITH_STATS
701 RADCLIENT_LIST *listener_find_client_list(fr_ipaddr_t const *ipaddr, uint16_t port);
702 #endif
703 rad_listen_t *listener_find_byipaddr(fr_ipaddr_t const *ipaddr, uint16_t port, int proto);
704 int rad_status_server(REQUEST *request);
705
706 /* event.c */
707 typedef enum event_corral_t {
708         EVENT_CORRAL_MAIN = 0,  //!< Always main thread event list
709         EVENT_CORRAL_AUX        //!< Maybe main thread or one shared by modules
710 } event_corral_t;
711
712 fr_event_list_t *radius_event_list_corral(event_corral_t hint);
713 int radius_event_init(TALLOC_CTX *ctx);
714 int radius_event_start(CONF_SECTION *cs, bool spawn_flag);
715 void radius_event_free(void);
716 int radius_event_process(void);
717 void radius_update_listener(rad_listen_t *listener);
718 void revive_home_server(void *ctx);
719 void mark_home_server_dead(home_server_t *home, struct timeval *when);
720
721 /* evaluate.c */
722 typedef struct fr_cond_t fr_cond_t;
723 typedef int (*radius_tmpl_getvalue_t)(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *map, void *ctx);
724
725 int radius_evaluate_tmpl(REQUEST *request, int modreturn, int depth,
726                          value_pair_tmpl_t const *vpt);
727 int radius_evaluate_map(REQUEST *request, int modreturn, int depth,
728                         fr_cond_t const *c);
729 int radius_evaluate_cond(REQUEST *request, int modreturn, int depth,
730                          fr_cond_t const *c);
731 void radius_pairmove(REQUEST *request, VALUE_PAIR **to, VALUE_PAIR *from, bool do_xlat) CC_HINT(nonnull);
732
733 VALUE_PAIR **radius_list(REQUEST *request, pair_lists_t list);
734 TALLOC_CTX *radius_list_ctx(REQUEST *request, pair_lists_t list_name);
735 pair_lists_t radius_list_name(char const **name, pair_lists_t unknown);
736 int radius_request(REQUEST **request, request_refs_t name);
737 request_refs_t radius_request_name(char const **name, request_refs_t unknown);
738
739 int radius_mapexec(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *map);
740 int radius_map2vp(VALUE_PAIR **out, REQUEST *request, value_pair_map_t const *map, void *ctx) CC_HINT(nonnull (1,2,3));
741 void radius_map_debug(REQUEST *request, value_pair_map_t const *map, VALUE_PAIR const *vp) CC_HINT(nonnull(1, 2));
742 int radius_map2request(REQUEST *request, value_pair_map_t const *map, radius_tmpl_getvalue_t func, void *ctx);
743
744 int radius_strpair2map(value_pair_map_t **out, REQUEST *request, char const *raw,
745                        request_refs_t dst_request_def, pair_lists_t dst_list_def,
746                        request_refs_t src_request_def, pair_lists_t src_list_def);
747 bool radius_map_dst_valid(REQUEST *request, value_pair_map_t const *map);
748 int radius_tmpl_get_vp(VALUE_PAIR **out, REQUEST *request, value_pair_tmpl_t const *vpt);
749 int radius_get_vp(VALUE_PAIR **out, REQUEST *request, char const *name);
750 int radius_tmpl_copy_vp(VALUE_PAIR **out, REQUEST *request, value_pair_tmpl_t const *vpt);
751 int radius_copy_vp(VALUE_PAIR **out, REQUEST *request, char const *name);
752
753 #ifdef WITH_TLS
754 /*
755  *      For run-time patching of which function handles which socket.
756  */
757 int dual_tls_recv(rad_listen_t *listener);
758 int dual_tls_send(rad_listen_t *listener, REQUEST *request);
759 int proxy_tls_recv(rad_listen_t *listener);
760 int proxy_tls_send(rad_listen_t *listener, REQUEST *request);
761 #endif
762
763 /*
764  *      For radmin over TCP.
765  */
766 #define PW_RADMIN_PORT 18120
767
768 #ifdef __cplusplus
769 }
770 #endif
771
772 #endif /*RADIUSD_H*/