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;
56 #define REQUEST_DATA_REGEX (0xadbeef00)
57 #define REQUEST_MAX_REGEX (8)
59 typedef struct auth_req {
61 uint32_t magic; /* for debugging only */
63 RADIUS_PACKET *packet;
66 RADIUS_PACKET *proxy_reply;
67 VALUE_PAIR *config_items;
73 child_pid_t child_pid;
75 int number; /* internal server number */
77 rad_listen_t *listener;
78 rad_listen_t *proxy_listener;
81 * We could almost keep a const char here instead of a
82 * _copy_ of the secret... but what if the RADCLIENT
83 * structure is freed because it was taken out of the
84 * config file and SIGHUPed?
88 int proxy_outstanding;
89 time_t proxy_next_try;
93 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
96 int options; /* miscellanous options */
97 const char *module; /* for debugging unresponsive children */
98 const char *component; /* ditto */
102 #define RAD_REQUEST_OPTION_NONE (0)
103 #define RAD_REQUEST_OPTION_LOGGED_CHILD (1 << 0)
104 #define RAD_REQUEST_OPTION_DELAYED_REJECT (1 << 1)
105 #define RAD_REQUEST_OPTION_DONT_CACHE (1 << 2)
106 #define RAD_REQUEST_OPTION_FAKE_REQUEST (1 << 3)
107 #define RAD_REQUEST_OPTION_REJECTED (1 << 4)
108 #define RAD_REQUEST_OPTION_PROXIED (1 << 5)
109 #define RAD_REQUEST_OPTION_STOP_NOW (1 << 6)
110 #define RAD_REQUEST_OPTION_REPROCESS (1 << 7)
113 * Function handler for requests.
115 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
117 typedef struct radclient {
118 lrad_ipaddr_t ipaddr;
126 struct radclient *next;
137 typedef struct _realm {
140 char acct_server[64];
141 lrad_ipaddr_t ipaddr; /* authentication */
142 lrad_ipaddr_t acct_ipaddr;
144 time_t last_reply; /* last time we saw a packet */
148 int trusted; /* old */
150 int active; /* is it dead? */
151 time_t wakeup; /* when we should try it again */
158 typedef struct pair_list {
163 struct pair_list *next;
164 struct pair_list *lastdefault;
169 * Types of listeners.
171 * FIXME: Separate ports for proxy auth/acct?
173 typedef enum RAD_LISTEN_TYPE {
182 struct rad_listen_t {
183 struct rad_listen_t *next; /* should be rbtree stuff */
185 * For normal sockets.
187 RAD_LISTEN_TYPE type;
190 int (*recv)(rad_listen_t *,
191 RAD_REQUEST_FUNP *, REQUEST **);
192 int (*send)(rad_listen_t *, REQUEST *);
195 * For normal sockets.
197 lrad_ipaddr_t ipaddr;
203 * FIXME: this stuff should either be in a union,
204 * or in a structure allocated per-type...
215 typedef enum radlog_dest_t {
223 typedef struct main_config_t {
224 struct main_config *next;
225 time_t config_dead_time;
226 lrad_ipaddr_t myip; /* from the command-line only */
227 int port; /* from the command-line only */
229 int log_auth_badpass;
230 int log_auth_goodpass;
235 int allow_core_dumps;
238 int post_proxy_authorize;
239 int wake_all_if_all_dead;
240 int proxy_synchronous;
242 int proxy_retry_count;
243 int proxy_retry_delay;
245 const char *proxy_fail_type;
248 int max_request_time;
251 int kill_unresponsive_children;
254 char *do_nospace_user;
255 char *do_nospace_pass;
259 const char *pid_file;
260 const char *uid_name;
261 const char *gid_name;
262 rad_listen_t *listen;
265 radlog_dest_t radlog_dest;
266 CONF_SECTION *config;
271 #define DEBUG if(debug_flag)log_debug
272 #define DEBUG2 if (debug_flag > 1)log_debug
273 #define DEBUG3 if (debug_flag > 2)log_debug
275 #define SECONDS_PER_DAY 86400
276 #define MAX_REQUEST_TIME 30
277 #define CLEANUP_DELAY 5
278 #define MAX_REQUESTS 256
279 #define RETRY_DELAY 5
280 #define RETRY_COUNT 3
281 #define DEAD_TIME 120
295 * This definition of true as NOT false is definitive. :) Making
296 * it '1' can cause problems on stupid platforms. See articles
297 * on C portability for more information.
299 #define TRUE (!FALSE)
302 /* for paircompare_register */
303 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
305 typedef enum request_fail_t {
306 REQUEST_FAIL_UNKNOWN = 0,
307 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
308 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
309 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
310 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
311 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
312 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
313 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
314 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
315 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
316 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
322 * We really shouldn't have this many.
324 extern const char *progname;
325 extern int debug_flag;
326 extern const char *radacct_dir;
327 extern const char *radlog_dir;
328 extern const char *radlib_dir;
329 extern const char *radius_dir;
330 extern const char *radius_libdir;
331 extern uint32_t expiration_seconds;
332 extern int log_stripped_names;
333 extern int log_auth_detail;
334 extern const char *radiusd_version;
337 * Function prototypes.
341 int rad_accounting(REQUEST *);
344 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
345 const char *sessionid);
346 int session_zap(REQUEST *request, uint32_t nasaddr,
347 unsigned int port, const char *user,
348 const char *sessionid, uint32_t cliaddr,
349 char proto,int session_time);
353 void debug_pair(FILE *, VALUE_PAIR *);
355 int log_err (char *);
358 void (*reset_signal(int signo, void (*func)(int)))(int);
359 void request_free(REQUEST **request);
360 int rad_mkdir(char *directory, int mode);
361 int rad_checkfilename(const char *filename);
362 void *rad_malloc(size_t size); /* calls exit(1) on error! */
363 REQUEST *request_alloc(void);
364 REQUEST *request_alloc_fake(REQUEST *oldreq);
365 int request_data_add(REQUEST *request,
366 void *unique_ptr, int unique_int,
367 void *opaque, void (*free_opaque)(void *));
368 void *request_data_get(REQUEST *request,
369 void *unique_ptr, int unique_int);
370 int rad_copy_string(char *dst, const char *src);
371 int rad_copy_variable(char *dst, const char *from);
373 /* request_process.c */
374 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
375 void request_reject(REQUEST *request, request_fail_t reason);
376 void rfc_clean(RADIUS_PACKET *packet);
379 int read_clients_file(const char *file);
380 RADCLIENT *client_find(const lrad_ipaddr_t *ipaddr);
381 const char *client_name(const lrad_ipaddr_t *ipaddr);
382 void clients_free(RADCLIENT *cl);
385 REALM *realm_find(const char *, int);
386 REALM *realm_findbyaddr(uint32_t ipno, int port);
387 void realm_free(REALM *cl);
388 void realm_disable(uint32_t ipno, int port);
389 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
390 void pairlist_free(PAIR_LIST **);
391 int read_config_files(void);
392 int read_realms_file(const char *file);
395 int read_naslist_file(char *);
396 NAS *nas_find(uint32_t ipno);
402 int vradlog(int, const char *, va_list ap);
403 int radlog(int, const char *, ...)
405 __attribute__ ((format (printf, 2, 3)))
408 int log_debug(const char *, ...)
410 __attribute__ ((format (printf, 1, 2)))
413 void vp_listdebug(VALUE_PAIR *vp);
416 int proxy_receive(REQUEST *request);
417 int proxy_send(REQUEST *request);
420 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
421 int rad_authenticate (REQUEST *);
422 int rad_check_password(REQUEST *request);
423 int rad_postauth(REQUEST *);
426 int radius_exec_program(const char *, REQUEST *, int,
427 char *user_msg, int msg_len,
428 VALUE_PAIR *input_pairs,
429 VALUE_PAIR **output_pairs,
433 int timestr_match(char *, time_t);
436 int paircompare_register(int attr, int otherattr,
437 RAD_COMPARE_FUNC func,
439 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
440 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
442 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
443 void pair_builtincompare_init(void);
444 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
447 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
449 int radius_xlat(char * out, int outlen, const char *fmt,
450 REQUEST * request, RADIUS_ESCAPE_STRING func);
451 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
452 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
453 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
457 extern int thread_pool_init(int spawn_flag);
458 extern int thread_pool_clean(time_t now);
459 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
460 extern pid_t rad_fork(int exec_wait);
461 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
462 extern int total_active_threads(void);
464 #ifndef HAVE_PTHREAD_H
465 #define rad_fork(n) fork()
466 #define rad_waitpid waitpid
470 /* Define a global config structure */
471 extern struct main_config_t mainconfig;
473 int read_mainconfig(int reload);
474 int free_mainconfig(void);
475 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */
478 void listen_free(rad_listen_t **head);
479 int listen_init(const char *filename, rad_listen_t **head);
480 rad_listen_t *proxy_new_listener(void);