4 * radiusd.h Structures, prototypes and global variables
5 * for the FreeRADIUS server.
11 #include "libradius.h"
24 typedef pthread_t child_pid_t;
25 #define child_kill pthread_kill
27 typedef pid_t child_pid_t;
28 #define child_kill kill
31 #ifdef HAVE_NETINET_IN_H
32 #include <netinet/in.h>
35 #ifdef HAVE_ARPA_INET_H
36 #include <arpa/inet.h>
40 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
43 #define REQUEST_MAGIC (0xdeadbeef)
49 typedef struct request_data_t request_data_t;
52 * For listening on multiple IP's and ports.
54 typedef struct rad_listen_t rad_listen_t;
59 typedef struct request_list_t request_list_t;
61 #define REQUEST_DATA_REGEX (0xadbeef00)
62 #define REQUEST_MAX_REGEX (8)
64 typedef struct auth_req {
66 uint32_t magic; /* for debugging only */
68 RADIUS_PACKET *packet;
71 RADIUS_PACKET *proxy_reply;
72 VALUE_PAIR *config_items;
78 child_pid_t child_pid;
80 int number; /* internal server number */
82 rad_listen_t *listener;
83 rad_listen_t *proxy_listener;
86 * We could almost keep a const char here instead of a
87 * _copy_ of the secret... but what if the RADCLIENT
88 * structure is freed because it was taken out of the
89 * config file and SIGHUPed?
93 int proxy_outstanding;
94 time_t proxy_next_try;
98 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
101 int options; /* miscellanous options */
102 const char *module; /* for debugging unresponsive children */
103 const char *component; /* ditto */
107 #define RAD_REQUEST_OPTION_NONE (0)
108 #define RAD_REQUEST_OPTION_LOGGED_CHILD (1 << 0)
109 #define RAD_REQUEST_OPTION_DELAYED_REJECT (1 << 1)
110 #define RAD_REQUEST_OPTION_DONT_CACHE (1 << 2)
111 #define RAD_REQUEST_OPTION_FAKE_REQUEST (1 << 3)
112 #define RAD_REQUEST_OPTION_REJECTED (1 << 4)
113 #define RAD_REQUEST_OPTION_PROXIED (1 << 5)
114 #define RAD_REQUEST_OPTION_STOP_NOW (1 << 6)
115 #define RAD_REQUEST_OPTION_REPROCESS (1 << 7)
118 * Function handler for requests.
120 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
122 typedef struct radclient {
123 lrad_ipaddr_t ipaddr;
131 struct radclient *next;
142 typedef struct _realm {
145 char acct_server[64];
146 lrad_ipaddr_t ipaddr; /* authentication */
147 lrad_ipaddr_t acct_ipaddr;
149 time_t last_reply; /* last time we saw a packet */
153 int trusted; /* old */
155 int active; /* is it dead? */
156 time_t wakeup; /* when we should try it again */
163 typedef struct pair_list {
168 struct pair_list *next;
169 struct pair_list *lastdefault;
174 * Types of listeners.
176 * FIXME: Separate ports for proxy auth/acct?
178 typedef enum RAD_LISTEN_TYPE {
187 typedef int (*rad_listen_recv_t)(rad_listen_t *, RAD_REQUEST_FUNP *, REQUEST **);
188 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
189 typedef int (*rad_listen_update_t)(rad_listen_t *, time_t);
192 struct rad_listen_t {
193 struct rad_listen_t *next; /* should be rbtree stuff */
195 * For normal sockets.
197 RAD_LISTEN_TYPE type;
199 const char *identity;
202 rad_listen_recv_t recv;
203 rad_listen_send_t send;
204 rad_listen_update_t update;
207 * For normal sockets.
209 lrad_ipaddr_t ipaddr;
215 * FIXME: this stuff should either be in a union,
216 * or in a structure allocated per-type...
223 lrad_ipaddr_t client_ip;
229 typedef enum radlog_dest_t {
237 typedef struct main_config_t {
238 struct main_config *next;
239 time_t config_dead_time;
240 lrad_ipaddr_t myip; /* from the command-line only */
241 int port; /* from the command-line only */
243 int log_auth_badpass;
244 int log_auth_goodpass;
249 int allow_core_dumps;
252 int post_proxy_authorize;
253 int wake_all_if_all_dead;
254 int proxy_synchronous;
256 int proxy_retry_count;
257 int proxy_retry_delay;
259 const char *proxy_fail_type;
262 int max_request_time;
265 int kill_unresponsive_children;
268 char *do_nospace_user;
269 char *do_nospace_pass;
273 const char *pid_file;
274 const char *uid_name;
275 const char *gid_name;
276 rad_listen_t *listen;
279 radlog_dest_t radlog_dest;
280 CONF_SECTION *config;
283 const char *radiusd_conf;
286 #define DEBUG if(debug_flag)log_debug
287 #define DEBUG2 if (debug_flag > 1)log_debug
288 #define DEBUG3 if (debug_flag > 2)log_debug
290 #define SECONDS_PER_DAY 86400
291 #define MAX_REQUEST_TIME 30
292 #define CLEANUP_DELAY 5
293 #define MAX_REQUESTS 256
294 #define RETRY_DELAY 5
295 #define RETRY_COUNT 3
296 #define DEAD_TIME 120
310 * This definition of true as NOT false is definitive. :) Making
311 * it '1' can cause problems on stupid platforms. See articles
312 * on C portability for more information.
314 #define TRUE (!FALSE)
317 /* for paircompare_register */
318 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
320 typedef enum request_fail_t {
321 REQUEST_FAIL_UNKNOWN = 0,
322 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
323 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
324 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
325 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
326 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
327 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
328 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
329 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
330 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
331 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
337 * We really shouldn't have this many.
339 extern const char *progname;
340 extern int debug_flag;
341 extern const char *radacct_dir;
342 extern const char *radlog_dir;
343 extern const char *radlib_dir;
344 extern const char *radius_dir;
345 extern const char *radius_libdir;
346 extern uint32_t expiration_seconds;
347 extern int log_stripped_names;
348 extern int log_auth_detail;
349 extern const char *radiusd_version;
352 * Function prototypes.
356 int rad_accounting(REQUEST *);
359 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
360 const char *sessionid);
361 int session_zap(REQUEST *request, uint32_t nasaddr,
362 unsigned int port, const char *user,
363 const char *sessionid, uint32_t cliaddr,
364 char proto,int session_time);
368 void debug_pair(FILE *, VALUE_PAIR *);
370 int log_err (char *);
373 void (*reset_signal(int signo, void (*func)(int)))(int);
374 void request_free(REQUEST **request);
375 int rad_mkdir(char *directory, int mode);
376 int rad_checkfilename(const char *filename);
377 void *rad_malloc(size_t size); /* calls exit(1) on error! */
378 REQUEST *request_alloc(void);
379 REQUEST *request_alloc_fake(REQUEST *oldreq);
380 int request_data_add(REQUEST *request,
381 void *unique_ptr, int unique_int,
382 void *opaque, void (*free_opaque)(void *));
383 void *request_data_get(REQUEST *request,
384 void *unique_ptr, int unique_int);
385 int rad_copy_string(char *dst, const char *src);
386 int rad_copy_variable(char *dst, const char *from);
388 /* request_process.c */
389 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
390 void request_reject(REQUEST *request, request_fail_t reason);
391 void rfc_clean(RADIUS_PACKET *packet);
394 int read_clients_file(const char *file);
395 RADCLIENT *client_find(const lrad_ipaddr_t *ipaddr);
396 const char *client_name(const lrad_ipaddr_t *ipaddr);
397 void clients_free(RADCLIENT *cl);
400 REALM *realm_find(const char *, int);
401 REALM *realm_findbyaddr(uint32_t ipno, int port);
402 void realm_free(REALM *cl);
403 void realm_disable(uint32_t ipno, int port);
404 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
405 void pairlist_free(PAIR_LIST **);
406 int read_config_files(void);
407 int read_realms_file(const char *file);
410 int read_naslist_file(char *);
411 NAS *nas_find(uint32_t ipno);
417 int vradlog(int, const char *, va_list ap);
418 int radlog(int, const char *, ...)
420 __attribute__ ((format (printf, 2, 3)))
423 int log_debug(const char *, ...)
425 __attribute__ ((format (printf, 1, 2)))
428 void vp_listdebug(VALUE_PAIR *vp);
431 int proxy_receive(REQUEST *request);
432 int proxy_send(REQUEST *request);
435 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
436 int rad_authenticate (REQUEST *);
437 int rad_check_password(REQUEST *request);
438 int rad_postauth(REQUEST *);
441 int radius_exec_program(const char *, REQUEST *, int,
442 char *user_msg, int msg_len,
443 VALUE_PAIR *input_pairs,
444 VALUE_PAIR **output_pairs,
448 int timestr_match(char *, time_t);
451 int paircompare_register(int attr, int otherattr,
452 RAD_COMPARE_FUNC func,
454 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
455 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
457 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
458 void pair_builtincompare_init(void);
459 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
462 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
464 int radius_xlat(char * out, int outlen, const char *fmt,
465 REQUEST * request, RADIUS_ESCAPE_STRING func);
466 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
467 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
468 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
472 extern int thread_pool_init(int spawn_flag);
473 extern int thread_pool_clean(time_t now);
474 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
475 extern pid_t rad_fork(int exec_wait);
476 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
477 extern int total_active_threads(void);
479 #ifndef HAVE_PTHREAD_H
480 #define rad_fork(n) fork()
481 #define rad_waitpid waitpid
485 /* Define a global config structure */
486 extern struct main_config_t mainconfig;
488 int read_mainconfig(int reload);
489 int free_mainconfig(void);
490 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */
493 void listen_free(rad_listen_t **head);
494 int listen_init(const char *filename, rad_listen_t **head);
495 rad_listen_t *proxy_new_listener(void);