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_start_time;
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);
190 typedef int (*rad_listen_print_t)(rad_listen_t *, char *, size_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;
205 rad_listen_print_t print;
211 typedef enum radlog_dest_t {
219 typedef struct main_config_t {
220 struct main_config *next;
221 time_t config_dead_time;
222 lrad_ipaddr_t myip; /* from the command-line only */
223 int port; /* from the command-line only */
225 int log_auth_badpass;
226 int log_auth_goodpass;
231 int allow_core_dumps;
234 int post_proxy_authorize;
235 int wake_all_if_all_dead;
236 int proxy_synchronous;
238 int proxy_retry_count;
239 int proxy_retry_delay;
241 const char *proxy_fail_type;
244 int max_request_time;
247 int kill_unresponsive_children;
250 char *do_nospace_user;
251 char *do_nospace_pass;
255 const char *pid_file;
256 const char *uid_name;
257 const char *gid_name;
258 rad_listen_t *listen;
261 radlog_dest_t radlog_dest;
262 CONF_SECTION *config;
265 const char *radiusd_conf;
268 #define DEBUG if(debug_flag)log_debug
269 #define DEBUG2 if (debug_flag > 1)log_debug
270 #define DEBUG3 if (debug_flag > 2)log_debug
272 #define SECONDS_PER_DAY 86400
273 #define MAX_REQUEST_TIME 30
274 #define CLEANUP_DELAY 5
275 #define MAX_REQUESTS 256
276 #define RETRY_DELAY 5
277 #define RETRY_COUNT 3
278 #define DEAD_TIME 120
292 * This definition of true as NOT false is definitive. :) Making
293 * it '1' can cause problems on stupid platforms. See articles
294 * on C portability for more information.
296 #define TRUE (!FALSE)
299 /* for paircompare_register */
300 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
302 typedef enum request_fail_t {
303 REQUEST_FAIL_UNKNOWN = 0,
304 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
305 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
306 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
307 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
308 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
309 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
310 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
311 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
312 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
313 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
319 * We really shouldn't have this many.
321 extern const char *progname;
322 extern int debug_flag;
323 extern const char *radacct_dir;
324 extern const char *radlog_dir;
325 extern const char *radlib_dir;
326 extern const char *radius_dir;
327 extern const char *radius_libdir;
328 extern uint32_t expiration_seconds;
329 extern int log_stripped_names;
330 extern int log_auth_detail;
331 extern const char *radiusd_version;
334 * Function prototypes.
338 int rad_accounting(REQUEST *);
341 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
342 const char *sessionid);
343 int session_zap(REQUEST *request, uint32_t nasaddr,
344 unsigned int port, const char *user,
345 const char *sessionid, uint32_t cliaddr,
346 char proto,int session_time);
350 void debug_pair(FILE *, VALUE_PAIR *);
352 int log_err (char *);
355 void (*reset_signal(int signo, void (*func)(int)))(int);
356 void request_free(REQUEST **request);
357 int rad_mkdir(char *directory, int mode);
358 int rad_checkfilename(const char *filename);
359 void *rad_malloc(size_t size); /* calls exit(1) on error! */
360 REQUEST *request_alloc(void);
361 REQUEST *request_alloc_fake(REQUEST *oldreq);
362 int request_data_add(REQUEST *request,
363 void *unique_ptr, int unique_int,
364 void *opaque, void (*free_opaque)(void *));
365 void *request_data_get(REQUEST *request,
366 void *unique_ptr, int unique_int);
367 int rad_copy_string(char *dst, const char *src);
368 int rad_copy_variable(char *dst, const char *from);
370 /* request_process.c */
371 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
372 void request_reject(REQUEST *request, request_fail_t reason);
373 void rfc_clean(RADIUS_PACKET *packet);
376 int read_clients_file(const char *file);
377 RADCLIENT *client_find(const lrad_ipaddr_t *ipaddr);
378 const char *client_name(const lrad_ipaddr_t *ipaddr);
379 void clients_free(RADCLIENT *cl);
382 REALM *realm_find(const char *, int);
383 REALM *realm_findbyaddr(uint32_t ipno, int port);
384 void realm_free(REALM *cl);
385 void realm_disable(uint32_t ipno, int port);
386 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
387 void pairlist_free(PAIR_LIST **);
388 int read_config_files(void);
389 int read_realms_file(const char *file);
392 int read_naslist_file(char *);
393 NAS *nas_find(uint32_t ipno);
399 int vradlog(int, const char *, va_list ap);
400 int radlog(int, const char *, ...)
402 __attribute__ ((format (printf, 2, 3)))
405 int log_debug(const char *, ...)
407 __attribute__ ((format (printf, 1, 2)))
410 void vp_listdebug(VALUE_PAIR *vp);
413 int proxy_receive(REQUEST *request);
414 int proxy_send(REQUEST *request);
417 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
418 int rad_authenticate (REQUEST *);
419 int rad_check_password(REQUEST *request);
420 int rad_postauth(REQUEST *);
423 int radius_exec_program(const char *, REQUEST *, int,
424 char *user_msg, int msg_len,
425 VALUE_PAIR *input_pairs,
426 VALUE_PAIR **output_pairs,
430 int timestr_match(char *, time_t);
433 int paircompare_register(int attr, int otherattr,
434 RAD_COMPARE_FUNC func,
436 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
437 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
439 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
440 void pair_builtincompare_init(void);
441 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
444 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
446 int radius_xlat(char * out, int outlen, const char *fmt,
447 REQUEST * request, RADIUS_ESCAPE_STRING func);
448 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
449 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
450 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
454 extern int thread_pool_init(int spawn_flag);
455 extern int thread_pool_clean(time_t now);
456 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
457 extern pid_t rad_fork(int exec_wait);
458 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
459 extern int total_active_threads(void);
461 #ifndef HAVE_PTHREAD_H
462 #define rad_fork(n) fork()
463 #define rad_waitpid waitpid
467 /* Define a global config structure */
468 extern struct main_config_t mainconfig;
470 int read_mainconfig(int reload);
471 int free_mainconfig(void);
472 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */
475 void listen_free(rad_listen_t **head);
476 int listen_init(const char *filename, rad_listen_t **head);
477 rad_listen_t *proxy_new_listener(void);