4 * radiusd.h Structures, prototypes and global variables
5 * for the FreeRADIUS server.
10 #include "libradius.h"
23 typedef pthread_t child_pid_t;
24 #define child_kill pthread_kill
26 typedef pid_t child_pid_t;
27 #define child_kill kill
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
34 #ifdef HAVE_ARPA_INET_H
35 #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)
103 * Function handler for requests.
105 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
107 typedef struct radclient {
116 struct radclient *next;
127 typedef struct _realm {
130 char acct_server[64];
131 uint32_t ipaddr; /* authentication */
132 uint32_t acct_ipaddr;
134 time_t last_reply; /* last time we saw a packet */
138 int trusted; /* old */
140 int active; /* is it dead? */
141 time_t wakeup; /* when we should try it again */
148 typedef struct pair_list {
153 struct pair_list *next;
154 struct pair_list *lastdefault;
159 * Types of listeners.
161 typedef enum RAD_LISTEN_TYPE {
170 * For listening on multiple IP's and ports.
172 typedef struct rad_listen_t {
173 struct rad_listen_t *next; /* could be rbtree stuff */
175 RAD_LISTEN_TYPE type;
181 typedef enum radlog_dest_t {
189 typedef struct main_config_t {
190 struct main_config *next;
191 time_t config_dead_time;
194 int log_auth_badpass;
195 int log_auth_goodpass;
200 int allow_core_dumps;
203 int post_proxy_authorize;
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 int kill_unresponsive_children;
219 char *do_nospace_user;
220 char *do_nospace_pass;
224 const char *pid_file;
225 const char *uid_name;
226 const char *gid_name;
227 rad_listen_t *listen;
229 radlog_dest_t radlog_dest;
230 CONF_SECTION *config;
235 #define DEBUG if(debug_flag)log_debug
236 #define DEBUG2 if (debug_flag > 1)log_debug
237 #define DEBUG3 if (debug_flag > 2)log_debug
239 #define SECONDS_PER_DAY 86400
240 #define MAX_REQUEST_TIME 30
241 #define CLEANUP_DELAY 5
242 #define MAX_REQUESTS 256
243 #define RETRY_DELAY 5
244 #define RETRY_COUNT 3
245 #define DEAD_TIME 120
259 * This definition of true as NOT false is definitive. :) Making
260 * it '1' can cause problems on stupid platforms. See articles
261 * on C portability for more information.
263 #define TRUE (!FALSE)
266 /* for paircompare_register */
267 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
269 typedef enum request_fail_t {
270 REQUEST_FAIL_UNKNOWN = 0,
271 REQUEST_FAIL_NO_THREADS, /* no threads to handle it */
272 REQUEST_FAIL_DECODE, /* rad_decode didn't like it */
273 REQUEST_FAIL_PROXY, /* call to proxy modules failed */
274 REQUEST_FAIL_PROXY_SEND, /* proxy_send didn't like it */
275 REQUEST_FAIL_NO_RESPONSE, /* we weren't told to respond, so we reject */
276 REQUEST_FAIL_HOME_SERVER, /* the home server didn't respond */
277 REQUEST_FAIL_HOME_SERVER2, /* another case of the above */
278 REQUEST_FAIL_HOME_SERVER3, /* another case of the above */
279 REQUEST_FAIL_NORMAL_REJECT, /* authentication failure */
280 REQUEST_FAIL_SERVER_TIMEOUT /* the server took too long to process the request */
286 * We really shouldn't have this many.
288 extern const char *progname;
289 extern int debug_flag;
290 extern const char *radacct_dir;
291 extern const char *radlog_dir;
292 extern const char *radlib_dir;
293 extern const char *radius_dir;
294 extern const char *radius_libdir;
295 extern uint32_t expiration_seconds;
296 extern int log_stripped_names;
297 extern int log_auth_detail;
298 extern const char *radiusd_version;
301 * Function prototypes.
305 int rad_accounting(REQUEST *);
308 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
309 const char *sessionid);
310 int session_zap(REQUEST *request, uint32_t nasaddr,
311 unsigned int port, const char *user,
312 const char *sessionid, uint32_t cliaddr,
317 void debug_pair(FILE *, VALUE_PAIR *);
319 int log_err (char *);
322 void (*reset_signal(int signo, void (*func)(int)))(int);
323 void request_free(REQUEST **request);
324 int rad_mkdir(char *directory, int mode);
325 int rad_checkfilename(const char *filename);
326 void *rad_malloc(size_t size); /* calls exit(1) on error! */
327 REQUEST *request_alloc(void);
328 REQUEST *request_alloc_fake(REQUEST *oldreq);
329 int request_data_add(REQUEST *request,
330 void *unique_ptr, int unique_int,
331 void *opaque, void (*free_opaque)(void *));
332 void *request_data_get(REQUEST *request,
333 void *unique_ptr, int unique_int);
334 void request_reject(REQUEST *request, request_fail_t reason);
335 void rfc_clean(RADIUS_PACKET *packet);
338 int read_clients_file(const char *file);
339 RADCLIENT *client_find(uint32_t ipno);
340 const char *client_name(uint32_t ipno);
341 void client_walk(void);
342 void clients_free(RADCLIENT *cl);
345 REALM *realm_find(const char *, int);
346 REALM *realm_findbyaddr(uint32_t ipno, int port);
347 void realm_free(REALM *cl);
348 void realm_disable(uint32_t ipno, int port);
349 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
350 void pairlist_free(PAIR_LIST **);
351 int read_config_files(void);
352 int read_realms_file(const char *file);
355 int read_naslist_file(char *);
356 NAS *nas_find(uint32_t ipno);
357 const char *nas_name(uint32_t ipno);
358 const char *nas_name2(RADIUS_PACKET *r);
359 char * nas_name3(char *buf, size_t buflen, uint32_t ipno);
360 NAS *nas_findbyname(char *nasname);
366 int vradlog(int, const char *, va_list ap);
367 int radlog(int, const char *, ...)
369 __attribute__ ((format (printf, 2, 3)))
372 int log_debug(const char *, ...)
374 __attribute__ ((format (printf, 1, 2)))
377 void vp_listdebug(VALUE_PAIR *vp);
380 int proxy_receive(REQUEST *request);
381 int proxy_send(REQUEST *request);
384 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
385 int rad_authenticate (REQUEST *);
386 int rad_check_password(REQUEST *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);
396 int timestr_match(char *, time_t);
399 int paircompare_register(int attr, int otherattr,
400 RAD_COMPARE_FUNC func,
402 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
403 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
405 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
406 void pair_builtincompare_init(void);
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(int exec_wait);
424 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
425 extern int rad_savepid(pid_t pid, int status);
426 extern int total_active_threads(void);
428 #ifndef HAVE_PTHREAD_H
429 #define rad_fork(n) fork()
430 #define rad_waitpid waitpid
434 /* Define a global config structure */
435 extern struct main_config_t mainconfig;
437 int read_mainconfig(int reload);
438 int free_mainconfig(void);
439 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */