4 * radiusd.h Structures, prototypes and global variables
5 * for the FreeRADIUS server.
11 #include <freeradius-devel/ident.h>
12 RCSIDH(radiusd_h, "$Id$")
14 #include <freeradius-devel/missing.h>
15 #include <freeradius-devel/libradius.h>
16 #include <freeradius-devel/radpaths.h>
17 #include <freeradius-devel/conf.h>
18 #include <freeradius-devel/conffile.h>
27 typedef pthread_t child_pid_t;
28 #define child_kill pthread_kill
30 typedef pid_t child_pid_t;
31 #define child_kill kill
34 #ifdef HAVE_NETINET_IN_H
37 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
40 #define REQUEST_MAGIC (0xdeadbeef)
46 typedef struct request_data_t request_data_t;
49 * For listening on multiple IP's and ports.
51 typedef struct rad_listen_t rad_listen_t;
56 typedef struct request_list_t request_list_t;
58 #define REQUEST_DATA_REGEX (0xadbeef00)
59 #define REQUEST_MAX_REGEX (8)
61 typedef struct auth_req {
63 uint32_t magic; /* for debugging only */
65 RADIUS_PACKET *packet;
68 RADIUS_PACKET *proxy_reply;
69 VALUE_PAIR *config_items;
75 child_pid_t child_pid;
77 int number; /* internal server number */
79 rad_listen_t *listener;
80 rad_listen_t *proxy_listener;
83 * We could almost keep a const char here instead of a
84 * _copy_ of the secret... but what if the RADCLIENT
85 * structure is freed because it was taken out of the
86 * config file and SIGHUPed?
90 int proxy_outstanding;
91 time_t proxy_start_time;
95 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
98 int options; /* miscellanous options */
99 const char *module; /* for debugging unresponsive children */
100 const char *component; /* ditto */
104 #define RAD_REQUEST_OPTION_NONE (0)
105 #define RAD_REQUEST_OPTION_LOGGED_CHILD (1 << 0)
106 #define RAD_REQUEST_OPTION_DELAYED_REJECT (1 << 1)
107 #define RAD_REQUEST_OPTION_DONT_CACHE (1 << 2)
108 #define RAD_REQUEST_OPTION_FAKE_REQUEST (1 << 3)
109 #define RAD_REQUEST_OPTION_REJECTED (1 << 4)
110 #define RAD_REQUEST_OPTION_PROXIED (1 << 5)
111 #define RAD_REQUEST_OPTION_STOP_NOW (1 << 6)
112 #define RAD_REQUEST_OPTION_REPROCESS (1 << 7)
115 * Function handler for requests.
117 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
119 typedef struct radclient {
120 lrad_ipaddr_t ipaddr;
128 int number; /* internal use only */
131 typedef struct radclient_list RADCLIENT_LIST;
133 typedef struct _realm {
136 char acct_server[64];
137 lrad_ipaddr_t ipaddr; /* authentication */
138 lrad_ipaddr_t acct_ipaddr;
140 time_t last_reply; /* last time we saw a packet */
144 int trusted; /* old */
146 int active; /* is it dead? */
147 time_t wakeup; /* when we should try it again */
154 typedef struct pair_list {
160 struct pair_list *next;
161 struct pair_list *lastdefault;
166 * Types of listeners.
168 * FIXME: Separate ports for proxy auth/acct?
170 typedef enum RAD_LISTEN_TYPE {
179 typedef int (*rad_listen_recv_t)(rad_listen_t *, RAD_REQUEST_FUNP *, REQUEST **);
180 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
181 typedef int (*rad_listen_update_t)(rad_listen_t *, time_t);
182 typedef int (*rad_listen_print_t)(rad_listen_t *, char *, size_t);
184 struct rad_listen_t {
185 struct rad_listen_t *next; /* should be rbtree stuff */
188 * For normal sockets.
190 RAD_LISTEN_TYPE type;
192 const char *identity;
195 rad_listen_recv_t recv;
196 rad_listen_send_t send;
197 rad_listen_update_t update;
198 rad_listen_print_t print;
204 typedef enum radlog_dest_t {
213 typedef struct main_config_t {
214 struct main_config *next;
215 time_t config_dead_time;
216 lrad_ipaddr_t myip; /* from the command-line only */
217 int port; /* from the command-line only */
219 int log_auth_badpass;
220 int log_auth_goodpass;
224 int allow_core_dumps;
227 int wake_all_if_all_dead;
228 int proxy_synchronous;
230 int proxy_retry_count;
231 int proxy_retry_delay;
233 const char *proxy_fail_type;
236 int max_request_time;
239 int kill_unresponsive_children;
242 const char *pid_file;
243 const char *uid_name;
244 const char *gid_name;
245 rad_listen_t *listen;
248 radlog_dest_t radlog_dest;
249 CONF_SECTION *config;
250 RADCLIENT_LIST *clients;
252 const char *radiusd_conf;
255 #define DEBUG if(debug_flag)log_debug
256 #define DEBUG2 if (debug_flag > 1)log_debug
257 #define DEBUG3 if (debug_flag > 2)log_debug
259 #define SECONDS_PER_DAY 86400
260 #define MAX_REQUEST_TIME 30
261 #define CLEANUP_DELAY 5
262 #define MAX_REQUESTS 256
263 #define RETRY_DELAY 5
264 #define RETRY_COUNT 3
265 #define DEAD_TIME 120
279 * This definition of true as NOT false is definitive. :) Making
280 * it '1' can cause problems on stupid platforms. See articles
281 * on C portability for more information.
283 #define TRUE (!FALSE)
286 /* for paircompare_register */
287 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
289 typedef enum request_fail_t {
290 REQUEST_FAIL_UNKNOWN = 0,
291 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
292 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
293 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
294 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
295 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
296 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
297 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
298 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
299 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
300 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
306 * We really shouldn't have this many.
308 extern const char *progname;
309 extern int debug_flag;
310 extern const char *radacct_dir;
311 extern const char *radlog_dir;
312 extern const char *radlib_dir;
313 extern const char *radius_dir;
314 extern const char *radius_libdir;
315 extern uint32_t expiration_seconds;
316 extern int log_stripped_names;
317 extern int log_auth_detail;
318 extern const char *radiusd_version;
321 * Function prototypes.
325 int rad_accounting(REQUEST *);
328 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
329 const char *sessionid);
330 int session_zap(REQUEST *request, uint32_t nasaddr,
331 unsigned int port, const char *user,
332 const char *sessionid, uint32_t cliaddr,
333 char proto,int session_time);
337 void debug_pair(FILE *, VALUE_PAIR *);
339 int log_err (char *);
342 void (*reset_signal(int signo, void (*func)(int)))(int);
343 void request_free(REQUEST **request);
344 int rad_mkdir(char *directory, int mode);
345 int rad_checkfilename(const char *filename);
346 void *rad_malloc(size_t size); /* calls exit(1) on error! */
347 REQUEST *request_alloc(void);
348 REQUEST *request_alloc_fake(REQUEST *oldreq);
349 int request_data_add(REQUEST *request,
350 void *unique_ptr, int unique_int,
351 void *opaque, void (*free_opaque)(void *));
352 void *request_data_get(REQUEST *request,
353 void *unique_ptr, int unique_int);
354 void *request_data_reference(REQUEST *request,
355 void *unique_ptr, int unique_int);
356 int rad_copy_string(char *dst, const char *src);
357 int rad_copy_variable(char *dst, const char *from);
359 /* request_process.c */
360 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
361 void request_reject(REQUEST *request, request_fail_t reason);
364 RADCLIENT_LIST *clients_init(void);
365 void clients_free(RADCLIENT_LIST *clients);
366 RADCLIENT_LIST *clients_parse_section(const char *filename,
367 CONF_SECTION *section);
368 void client_free(RADCLIENT *client);
369 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
370 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
371 const lrad_ipaddr_t *ipaddr);
372 const char *client_name(const RADCLIENT_LIST *clients,
373 const lrad_ipaddr_t *ipaddr);
374 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
376 RADCLIENT *client_find_old(const lrad_ipaddr_t *ipaddr);
377 const char *client_name_old(const lrad_ipaddr_t *ipaddr);
380 REALM *realm_find(const char *, int);
381 REALM *realm_findbyaddr(uint32_t ipno, int port);
382 void realm_free(REALM *cl);
383 void realm_disable(REQUEST *);
384 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
385 void pairlist_free(PAIR_LIST **);
386 int read_config_files(void);
387 int read_realms_file(const char *file);
393 int vradlog(int, const char *, va_list ap);
394 int radlog(int, const char *, ...)
396 __attribute__ ((format (printf, 2, 3)))
399 int log_debug(const char *, ...)
401 __attribute__ ((format (printf, 1, 2)))
404 void vp_listdebug(VALUE_PAIR *vp);
407 int proxy_receive(REQUEST *request);
408 int proxy_send(REQUEST *request);
411 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
412 int rad_authenticate (REQUEST *);
413 int rad_postauth(REQUEST *);
416 int radius_exec_program(const char *, REQUEST *, int,
417 char *user_msg, int msg_len,
418 VALUE_PAIR *input_pairs,
419 VALUE_PAIR **output_pairs,
423 int timestr_match(char *, time_t);
426 int paircompare_register(int attr, int otherattr,
427 RAD_COMPARE_FUNC func,
429 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
430 int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
432 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
433 void pair_builtincompare_init(void);
434 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
437 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
439 int radius_xlat(char * out, int outlen, const char *fmt,
440 REQUEST * request, RADIUS_ESCAPE_STRING func);
441 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
442 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
443 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
447 extern int thread_pool_init(int spawn_flag);
448 extern int thread_pool_clean(time_t now);
449 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
450 extern pid_t rad_fork(int exec_wait);
451 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
452 extern int total_active_threads(void);
454 #ifndef HAVE_PTHREAD_H
455 #define rad_fork(n) fork()
456 #define rad_waitpid waitpid
460 /* Define a global config structure */
461 extern struct main_config_t mainconfig;
463 int read_mainconfig(int reload);
464 int free_mainconfig(void);
467 void listen_free(rad_listen_t **head);
468 int listen_init(const char *filename, rad_listen_t **head);
469 rad_listen_t *proxy_new_listener(void);