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 #ifdef DELETE_BLOCKED_REQUESTS
240 int kill_unresponsive_children;
244 const char *pid_file;
245 const char *uid_name;
246 const char *gid_name;
247 rad_listen_t *listen;
250 radlog_dest_t radlog_dest;
251 CONF_SECTION *config;
252 RADCLIENT_LIST *clients;
254 const char *radiusd_conf;
257 #define DEBUG if(debug_flag)log_debug
258 #define DEBUG2 if (debug_flag > 1)log_debug
259 #define DEBUG3 if (debug_flag > 2)log_debug
261 #define SECONDS_PER_DAY 86400
262 #define MAX_REQUEST_TIME 30
263 #define CLEANUP_DELAY 5
264 #define MAX_REQUESTS 256
265 #define RETRY_DELAY 5
266 #define RETRY_COUNT 3
267 #define DEAD_TIME 120
282 * This definition of true as NOT false is definitive. :) Making
283 * it '1' can cause problems on stupid platforms. See articles
284 * on C portability for more information.
286 #define TRUE (!FALSE)
289 /* for paircompare_register */
290 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
292 typedef enum request_fail_t {
293 REQUEST_FAIL_UNKNOWN = 0,
294 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
295 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
296 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
297 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
298 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
299 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
300 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
301 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
302 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
303 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
309 * We really shouldn't have this many.
311 extern const char *progname;
312 extern int debug_flag;
313 extern const char *radacct_dir;
314 extern const char *radlog_dir;
315 extern const char *radlib_dir;
316 extern const char *radius_dir;
317 extern const char *radius_libdir;
318 extern uint32_t expiration_seconds;
319 extern int log_stripped_names;
320 extern int log_auth_detail;
321 extern const char *radiusd_version;
324 * Function prototypes.
328 int rad_accounting(REQUEST *);
331 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
332 const char *sessionid);
333 int session_zap(REQUEST *request, uint32_t nasaddr,
334 unsigned int port, const char *user,
335 const char *sessionid, uint32_t cliaddr,
336 char proto,int session_time);
340 void debug_pair(FILE *, VALUE_PAIR *);
342 int log_err (char *);
345 void (*reset_signal(int signo, void (*func)(int)))(int);
346 void request_free(REQUEST **request);
347 int rad_mkdir(char *directory, int mode);
348 int rad_checkfilename(const char *filename);
349 void *rad_malloc(size_t size); /* calls exit(1) on error! */
350 REQUEST *request_alloc(void);
351 REQUEST *request_alloc_fake(REQUEST *oldreq);
352 int request_data_add(REQUEST *request,
353 void *unique_ptr, int unique_int,
354 void *opaque, void (*free_opaque)(void *));
355 void *request_data_get(REQUEST *request,
356 void *unique_ptr, int unique_int);
357 void *request_data_reference(REQUEST *request,
358 void *unique_ptr, int unique_int);
359 int rad_copy_string(char *dst, const char *src);
360 int rad_copy_variable(char *dst, const char *from);
362 /* request_process.c */
363 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
364 void request_reject(REQUEST *request, request_fail_t reason);
367 RADCLIENT_LIST *clients_init(void);
368 void clients_free(RADCLIENT_LIST *clients);
369 RADCLIENT_LIST *clients_parse_section(const char *filename,
370 CONF_SECTION *section);
371 void client_free(RADCLIENT *client);
372 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
373 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
374 const lrad_ipaddr_t *ipaddr);
375 const char *client_name(const RADCLIENT_LIST *clients,
376 const lrad_ipaddr_t *ipaddr);
377 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
379 RADCLIENT *client_find_old(const lrad_ipaddr_t *ipaddr);
380 const char *client_name_old(const lrad_ipaddr_t *ipaddr);
383 REALM *realm_find(const char *, int);
384 REALM *realm_findbyaddr(uint32_t ipno, int port);
385 void realm_free(REALM *cl);
386 void realm_disable(REQUEST *);
387 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
388 void pairlist_free(PAIR_LIST **);
389 int read_config_files(void);
390 int read_realms_file(const char *file);
396 int vradlog(int, const char *, va_list ap);
397 int radlog(int, const char *, ...)
399 __attribute__ ((format (printf, 2, 3)))
402 int log_debug(const char *, ...)
404 __attribute__ ((format (printf, 1, 2)))
407 void vp_listdebug(VALUE_PAIR *vp);
410 int proxy_receive(REQUEST *request);
411 int proxy_send(REQUEST *request);
414 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
415 int rad_authenticate (REQUEST *);
416 int rad_postauth(REQUEST *);
419 int radius_exec_program(const char *, REQUEST *, int,
420 char *user_msg, int msg_len,
421 VALUE_PAIR *input_pairs,
422 VALUE_PAIR **output_pairs,
426 int timestr_match(char *, time_t);
429 int paircompare_register(int attr, int otherattr,
430 RAD_COMPARE_FUNC func,
432 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
433 int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
435 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
436 void pair_builtincompare_init(void);
437 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
440 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
442 int radius_xlat(char * out, int outlen, const char *fmt,
443 REQUEST * request, RADIUS_ESCAPE_STRING func);
444 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
445 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
446 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
450 extern int thread_pool_init(int spawn_flag);
451 extern int thread_pool_clean(time_t now);
452 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
453 extern pid_t rad_fork(void);
454 extern pid_t rad_waitpid(pid_t pid, int *status);
455 extern int total_active_threads(void);
457 #ifndef HAVE_PTHREAD_H
458 #define rad_fork(n) fork()
459 #define rad_waitpid(a,b) waitpid(a,b, 0)
463 /* Define a global config structure */
464 extern struct main_config_t mainconfig;
466 int read_mainconfig(int reload);
467 int free_mainconfig(void);
470 void listen_free(rad_listen_t **head);
471 int listen_init(const char *filename, rad_listen_t **head);
472 rad_listen_t *proxy_new_listener(void);