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;
51 #define REQUEST_DATA_REGEX (0xadbeef00)
52 #define REQUEST_MAX_REGEX (8)
54 typedef struct auth_req {
56 uint32_t magic; /* for debugging only */
58 RADIUS_PACKET *packet;
61 RADIUS_PACKET *proxy_reply;
62 VALUE_PAIR *config_items;
67 child_pid_t child_pid;
69 int number; /* internal server number */
72 * We could almost keep a const char here instead of a
73 * _copy_ of the secret... but what if the RADCLIENT
74 * structure is freed because it was taken out of the
75 * config file and SIGHUPed?
79 int proxy_outstanding;
80 time_t proxy_next_try;
84 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
87 int options; /* miscellanous options */
88 const char *module; /* for debugging unresponsive children */
89 const char *component; /* ditto */
93 #define RAD_REQUEST_OPTION_NONE (0)
94 #define RAD_REQUEST_OPTION_LOGGED_CHILD (1 << 0)
95 #define RAD_REQUEST_OPTION_DELAYED_REJECT (1 << 1)
96 #define RAD_REQUEST_OPTION_DONT_CACHE (1 << 2)
97 #define RAD_REQUEST_OPTION_FAKE_REQUEST (1 << 3)
98 #define RAD_REQUEST_OPTION_REJECTED (1 << 4)
99 #define RAD_REQUEST_OPTION_PROXIED (1 << 5)
100 #define RAD_REQUEST_OPTION_STOP_NOW (1 << 6)
101 #define RAD_REQUEST_OPTION_REPROCESS (1 << 7)
104 * Function handler for requests.
106 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
108 typedef struct radclient {
109 lrad_ipaddr_t ipaddr;
117 struct radclient *next;
128 typedef struct _realm {
131 char acct_server[64];
132 lrad_ipaddr_t ipaddr; /* authentication */
133 lrad_ipaddr_t acct_ipaddr;
135 time_t last_reply; /* last time we saw a packet */
139 int trusted; /* old */
141 int active; /* is it dead? */
142 time_t wakeup; /* when we should try it again */
149 typedef struct pair_list {
154 struct pair_list *next;
155 struct pair_list *lastdefault;
160 * Types of listeners.
162 typedef enum RAD_LISTEN_TYPE {
171 * For listening on multiple IP's and ports.
173 typedef struct rad_listen_t rad_listen_t;
175 struct rad_listen_t {
176 struct rad_listen_t *next; /* should be rbtree stuff */
177 lrad_ipaddr_t ipaddr;
178 RAD_LISTEN_TYPE type;
181 int (*recv)(rad_listen_t *,
182 RAD_REQUEST_FUNP *, REQUEST **);
186 typedef enum radlog_dest_t {
194 typedef struct main_config_t {
195 struct main_config *next;
196 time_t config_dead_time;
197 lrad_ipaddr_t myip; /* from the command-line only */
198 int port; /* from the command-line only */
200 int log_auth_badpass;
201 int log_auth_goodpass;
206 int allow_core_dumps;
209 int post_proxy_authorize;
210 int wake_all_if_all_dead;
211 int proxy_synchronous;
213 int proxy_retry_count;
214 int proxy_retry_delay;
216 const char *proxy_fail_type;
219 int max_request_time;
222 int kill_unresponsive_children;
225 char *do_nospace_user;
226 char *do_nospace_pass;
230 const char *pid_file;
231 const char *uid_name;
232 const char *gid_name;
233 rad_listen_t *listen;
236 radlog_dest_t radlog_dest;
237 CONF_SECTION *config;
242 #define DEBUG if(debug_flag)log_debug
243 #define DEBUG2 if (debug_flag > 1)log_debug
244 #define DEBUG3 if (debug_flag > 2)log_debug
246 #define SECONDS_PER_DAY 86400
247 #define MAX_REQUEST_TIME 30
248 #define CLEANUP_DELAY 5
249 #define MAX_REQUESTS 256
250 #define RETRY_DELAY 5
251 #define RETRY_COUNT 3
252 #define DEAD_TIME 120
266 * This definition of true as NOT false is definitive. :) Making
267 * it '1' can cause problems on stupid platforms. See articles
268 * on C portability for more information.
270 #define TRUE (!FALSE)
273 /* for paircompare_register */
274 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
276 typedef enum request_fail_t {
277 REQUEST_FAIL_UNKNOWN = 0,
278 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
279 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
280 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
281 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
282 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
283 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
284 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
285 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
286 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
287 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
293 * We really shouldn't have this many.
295 extern const char *progname;
296 extern int debug_flag;
297 extern const char *radacct_dir;
298 extern const char *radlog_dir;
299 extern const char *radlib_dir;
300 extern const char *radius_dir;
301 extern const char *radius_libdir;
302 extern uint32_t expiration_seconds;
303 extern int log_stripped_names;
304 extern int log_auth_detail;
305 extern const char *radiusd_version;
308 * Function prototypes.
312 int rad_accounting(REQUEST *);
315 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
316 const char *sessionid);
317 int session_zap(REQUEST *request, uint32_t nasaddr,
318 unsigned int port, const char *user,
319 const char *sessionid, uint32_t cliaddr,
320 char proto,int session_time);
324 void debug_pair(FILE *, VALUE_PAIR *);
326 int log_err (char *);
329 void (*reset_signal(int signo, void (*func)(int)))(int);
330 void request_free(REQUEST **request);
331 int rad_mkdir(char *directory, int mode);
332 int rad_checkfilename(const char *filename);
333 void *rad_malloc(size_t size); /* calls exit(1) on error! */
334 REQUEST *request_alloc(void);
335 REQUEST *request_alloc_fake(REQUEST *oldreq);
336 int request_data_add(REQUEST *request,
337 void *unique_ptr, int unique_int,
338 void *opaque, void (*free_opaque)(void *));
339 void *request_data_get(REQUEST *request,
340 void *unique_ptr, int unique_int);
341 int rad_copy_string(char *dst, const char *src);
342 int rad_copy_variable(char *dst, const char *from);
344 /* request_process.c */
345 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
346 void request_reject(REQUEST *request, request_fail_t reason);
347 void rfc_clean(RADIUS_PACKET *packet);
350 int read_clients_file(const char *file);
351 RADCLIENT *client_find(const lrad_ipaddr_t *ipaddr);
352 const char *client_name(const lrad_ipaddr_t *ipaddr);
353 void clients_free(RADCLIENT *cl);
356 REALM *realm_find(const char *, int);
357 REALM *realm_findbyaddr(uint32_t ipno, int port);
358 void realm_free(REALM *cl);
359 void realm_disable(uint32_t ipno, int port);
360 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
361 void pairlist_free(PAIR_LIST **);
362 int read_config_files(void);
363 int read_realms_file(const char *file);
366 int read_naslist_file(char *);
367 NAS *nas_find(uint32_t ipno);
373 int vradlog(int, const char *, va_list ap);
374 int radlog(int, const char *, ...)
376 __attribute__ ((format (printf, 2, 3)))
379 int log_debug(const char *, ...)
381 __attribute__ ((format (printf, 1, 2)))
384 void vp_listdebug(VALUE_PAIR *vp);
387 int proxy_receive(REQUEST *request);
388 int proxy_send(REQUEST *request);
391 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
392 int rad_authenticate (REQUEST *);
393 int rad_check_password(REQUEST *request);
394 int rad_postauth(REQUEST *);
397 int radius_exec_program(const char *, REQUEST *, int,
398 char *user_msg, int msg_len,
399 VALUE_PAIR *input_pairs,
400 VALUE_PAIR **output_pairs,
404 int timestr_match(char *, time_t);
407 int paircompare_register(int attr, int otherattr,
408 RAD_COMPARE_FUNC func,
410 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
411 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
413 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
414 void pair_builtincompare_init(void);
415 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
418 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
420 int radius_xlat(char * out, int outlen, const char *fmt,
421 REQUEST * request, RADIUS_ESCAPE_STRING func);
422 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
423 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
424 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
428 extern int thread_pool_init(int spawn_flag);
429 extern int thread_pool_clean(time_t now);
430 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
431 extern pid_t rad_fork(int exec_wait);
432 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
433 extern int total_active_threads(void);
435 #ifndef HAVE_PTHREAD_H
436 #define rad_fork(n) fork()
437 #define rad_waitpid waitpid
441 /* Define a global config structure */
442 extern struct main_config_t mainconfig;
444 int read_mainconfig(int reload);
445 int free_mainconfig(void);
446 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */
449 void listen_free(rad_listen_t **head);
450 int listen_init(const char *filename, rad_listen_t **head);
451 int proxy_new_listener(void);