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/libradius.h>
15 #include <freeradius-devel/radpaths.h>
16 #include <freeradius-devel/conf.h>
17 #include <freeradius-devel/conffile.h>
18 #include <freeradius-devel/realms.h>
22 typedef pthread_t child_pid_t;
23 #define child_kill pthread_kill
25 typedef pid_t child_pid_t;
26 #define child_kill kill
29 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
32 #define REQUEST_MAGIC (0xdeadbeef)
38 typedef struct request_data_t request_data_t;
41 * For listening on multiple IP's and ports.
43 typedef struct rad_listen_t rad_listen_t;
45 #define REQUEST_DATA_REGEX (0xadbeef00)
46 #define REQUEST_MAX_REGEX (8)
48 typedef struct auth_req {
50 uint32_t magic; /* for debugging only */
52 RADIUS_PACKET *packet;
55 RADIUS_PACKET *proxy_reply;
56 VALUE_PAIR *config_items;
62 child_pid_t child_pid;
64 int number; /* internal server number */
66 rad_listen_t *listener;
67 rad_listen_t *proxy_listener;
71 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
73 int options; /* miscellanous options */
74 const char *module; /* for debugging unresponsive children */
75 const char *component; /* ditto */
77 struct timeval received;
78 struct timeval when; /* to wake up */
84 struct timeval next_when;
90 home_server *home_server;
92 struct timeval proxy_when;
94 int num_proxied_requests;
95 int num_proxied_responses;
99 #define RAD_REQUEST_OPTION_NONE (0)
101 #define REQUEST_ACTIVE (1)
102 #define REQUEST_STOP_PROCESSING (2)
104 #define REQUEST_QUEUED (1)
105 #define REQUEST_RUNNING (2)
106 #define REQUEST_PROXIED (3)
107 #define REQUEST_REJECT_DELAY (4)
108 #define REQUEST_CLEANUP_DELAY (5)
109 #define REQUEST_DONE (6)
112 * Function handler for requests.
114 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
116 typedef struct radclient {
117 lrad_ipaddr_t ipaddr;
125 int number; /* internal use only */
128 typedef struct radclient_list RADCLIENT_LIST;
130 typedef struct pair_list {
136 struct pair_list *next;
137 struct pair_list *lastdefault;
142 * Types of listeners.
144 * FIXME: Separate ports for proxy auth/acct?
146 typedef enum RAD_LISTEN_TYPE {
155 typedef int (*rad_listen_recv_t)(rad_listen_t *, RAD_REQUEST_FUNP *, REQUEST **);
156 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
157 typedef int (*rad_listen_print_t)(rad_listen_t *, char *, size_t);
158 typedef int (*rad_listen_encode_t)(rad_listen_t *, REQUEST *);
159 typedef int (*rad_listen_decode_t)(rad_listen_t *, REQUEST *);
161 struct rad_listen_t {
162 struct rad_listen_t *next; /* should be rbtree stuff */
165 * For normal sockets.
167 RAD_LISTEN_TYPE type;
169 const char *identity;
171 rad_listen_recv_t recv;
172 rad_listen_send_t send;
173 rad_listen_encode_t encode;
174 rad_listen_decode_t decode;
175 rad_listen_print_t print;
181 typedef enum radlog_dest_t {
190 typedef struct main_config_t {
191 struct main_config *next;
192 time_t config_dead_time;
193 lrad_ipaddr_t myip; /* from the command-line only */
194 int port; /* from the command-line only */
196 int log_auth_badpass;
197 int log_auth_goodpass;
201 int allow_core_dumps;
204 int wake_all_if_all_dead;
205 int proxy_synchronous;
207 int proxy_retry_count;
208 int proxy_retry_delay;
210 const char *proxy_fail_type;
213 int max_request_time;
216 #ifdef DELETE_BLOCKED_REQUESTS
217 int kill_unresponsive_children;
221 const char *pid_file;
222 const char *uid_name;
223 const char *gid_name;
224 rad_listen_t *listen;
227 radlog_dest_t radlog_dest;
228 CONF_SECTION *config;
229 RADCLIENT_LIST *clients;
230 const char *radiusd_conf;
233 #define DEBUG if(debug_flag)log_debug
234 #define DEBUG2 if (debug_flag > 1)log_debug
235 #define DEBUG3 if (debug_flag > 2)log_debug
237 #define SECONDS_PER_DAY 86400
238 #define MAX_REQUEST_TIME 30
239 #define CLEANUP_DELAY 5
240 #define MAX_REQUESTS 256
241 #define RETRY_DELAY 5
242 #define RETRY_COUNT 3
243 #define DEAD_TIME 120
258 * This definition of true as NOT false is definitive. :) Making
259 * it '1' can cause problems on stupid platforms. See articles
260 * on C portability for more information.
262 #define TRUE (!FALSE)
265 /* for paircompare_register */
266 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
268 typedef enum request_fail_t {
269 REQUEST_FAIL_UNKNOWN = 0,
270 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
271 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
272 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
273 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
274 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
275 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
276 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
277 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
278 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
279 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
285 * We really shouldn't have this many.
287 extern const char *progname;
288 extern int debug_flag;
289 extern const char *radacct_dir;
290 extern const char *radlog_dir;
291 extern const char *radlib_dir;
292 extern const char *radius_dir;
293 extern const char *radius_libdir;
294 extern uint32_t expiration_seconds;
295 extern int log_stripped_names;
296 extern int log_auth_detail;
297 extern const char *radiusd_version;
300 * Function prototypes.
304 int rad_accounting(REQUEST *);
307 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
308 const char *sessionid);
309 int session_zap(REQUEST *request, uint32_t nasaddr,
310 unsigned int port, const char *user,
311 const char *sessionid, uint32_t cliaddr,
312 char proto,int session_time);
316 void debug_pair(FILE *, VALUE_PAIR *);
318 int log_err (char *);
321 void (*reset_signal(int signo, void (*func)(int)))(int);
322 void request_free(REQUEST **request);
323 int rad_mkdir(char *directory, int mode);
324 int rad_checkfilename(const char *filename);
325 void *rad_malloc(size_t size); /* calls exit(1) on error! */
326 REQUEST *request_alloc(void);
327 REQUEST *request_alloc_fake(REQUEST *oldreq);
328 int request_data_add(REQUEST *request,
329 void *unique_ptr, int unique_int,
330 void *opaque, void (*free_opaque)(void *));
331 void *request_data_get(REQUEST *request,
332 void *unique_ptr, int unique_int);
333 void *request_data_reference(REQUEST *request,
334 void *unique_ptr, int unique_int);
335 int rad_copy_string(char *dst, const char *src);
336 int rad_copy_variable(char *dst, const char *from);
338 /* request_process.c */
339 int rad_respond(REQUEST *request, RAD_REQUEST_FUNP fun);
340 void request_reject(REQUEST *request, request_fail_t reason);
343 RADCLIENT_LIST *clients_init(void);
344 void clients_free(RADCLIENT_LIST *clients);
345 RADCLIENT_LIST *clients_parse_section(const char *filename,
346 CONF_SECTION *section);
347 void client_free(RADCLIENT *client);
348 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
349 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
350 const lrad_ipaddr_t *ipaddr);
351 const char *client_name(const RADCLIENT_LIST *clients,
352 const lrad_ipaddr_t *ipaddr);
353 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
355 RADCLIENT *client_find_old(const lrad_ipaddr_t *ipaddr);
356 const char *client_name_old(const lrad_ipaddr_t *ipaddr);
359 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
360 void pairlist_free(PAIR_LIST **);
361 int read_config_files(void);
367 int vradlog(int, const char *, va_list ap);
368 int radlog(int, const char *, ...)
370 __attribute__ ((format (printf, 2, 3)))
373 int log_debug(const char *, ...)
375 __attribute__ ((format (printf, 1, 2)))
378 void vp_listdebug(VALUE_PAIR *vp);
381 int proxy_receive(REQUEST *request);
382 int proxy_send(REQUEST *request);
385 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
386 int rad_authenticate (REQUEST *);
387 int rad_postauth(REQUEST *);
390 int radius_exec_program(const char *, REQUEST *, int,
391 char *user_msg, int msg_len,
392 VALUE_PAIR *input_pairs,
393 VALUE_PAIR **output_pairs,
397 int timestr_match(char *, time_t);
400 int paircompare_register(int attr, int otherattr,
401 RAD_COMPARE_FUNC func,
403 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
404 int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
406 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
407 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
410 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
412 int radius_xlat(char * out, int outlen, const char *fmt,
413 REQUEST * request, RADIUS_ESCAPE_STRING func);
414 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, size_t, RADIUS_ESCAPE_STRING func);
415 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
416 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
420 extern int thread_pool_init(int spawn_flag);
421 extern int thread_pool_clean(time_t now);
422 extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
423 extern pid_t rad_fork(void);
424 extern pid_t rad_waitpid(pid_t pid, int *status);
425 extern int total_active_threads(void);
427 #ifndef HAVE_PTHREAD_H
428 #define rad_fork(n) fork()
429 #define rad_waitpid(a,b) waitpid(a,b, 0)
433 /* Define a global config structure */
434 extern struct main_config_t mainconfig;
436 int read_mainconfig(int reload);
437 int free_mainconfig(void);
440 void listen_free(rad_listen_t **head);
441 int listen_init(const char *filename, rad_listen_t **head);
442 rad_listen_t *proxy_new_listener(void);
445 int radius_event_init(int spawn_flag);
446 void radius_event_free(void);
447 int radius_event_process(struct timeval **pptv);
448 void radius_handle_request(REQUEST *request, RAD_REQUEST_FUNP fun);
449 int received_request(rad_listen_t *listener,
450 RADIUS_PACKET *packet, REQUEST **prequest,
451 const RADCLIENT *client);
452 REQUEST *received_proxy_response(RADIUS_PACKET *packet);