4 * radiusd.h Structures, prototypes and global variables
5 * for the FreeRADIUS server.
10 #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 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
34 #define REQUEST_MAGIC (0xdeadbeef)
37 typedef struct auth_req {
39 uint32_t magic; /* for debugging only */
41 RADIUS_PACKET *packet;
44 RADIUS_PACKET *proxy_reply;
45 VALUE_PAIR *config_items;
49 child_pid_t child_pid;
51 int number; /* internal server number */
53 /* Could almost keep a const char * here instead of a _copy_ of the
54 * secret... but what if the RADCLIENT structure is freed because it was
55 * taken out of the config file and SIGHUPed? */
57 int proxy_is_replicate;
59 time_t proxy_next_try;
63 int simul_mpp; /* WEIRD: 1 is false, 2 is true */
66 int options; /* miscellanous options */
70 #define RAD_REQUEST_OPTION_NONE (0)
71 #define RAD_REQUEST_OPTION_LOGGED_CHILD (1 << 0)
72 #define RAD_REQUEST_OPTION_DELAYED_REJECT (1 << 1)
73 #define RAD_REQUEST_OPTION_DONT_CACHE (1 << 2)
76 * Function handler for requests.
78 typedef int (*RAD_REQUEST_FUNP)(REQUEST *);
80 typedef struct radclient {
89 struct radclient *next;
100 typedef struct _realm {
103 char acct_server[64];
104 uint32_t ipaddr; /* authentication */
105 uint32_t acct_ipaddr;
107 time_t last_reply; /* last time we saw a packet */
111 int trusted; /* old */
113 int active; /* is it dead? */
114 time_t wakeup; /* when we should try it again */
121 typedef struct pair_list {
126 struct pair_list *next;
127 struct pair_list *lastdefault;
130 typedef struct main_config_t {
131 struct main_config *next;
132 time_t config_dead_time;
135 int log_auth_badpass;
136 int log_auth_goodpass;
141 int allow_core_dumps;
144 int post_proxy_authorize;
145 int wake_all_if_all_dead;
146 int proxy_synchronous;
148 int proxy_retry_count;
149 int proxy_retry_delay;
153 int max_request_time;
156 int kill_unresponsive_children;
159 char *do_nospace_user;
160 char *do_nospace_pass;
164 const char *pid_file;
165 const char *uid_name;
166 const char *gid_name;
167 CONF_SECTION *config;
172 #define DEBUG if(debug_flag)log_debug
173 #define DEBUG2 if (debug_flag > 1)log_debug
175 #define SECONDS_PER_DAY 86400
176 #define MAX_REQUEST_TIME 30
177 #define CLEANUP_DELAY 5
178 #define MAX_REQUESTS 256
179 #define RETRY_DELAY 5
180 #define RETRY_COUNT 3
181 #define DEAD_TIME 120
195 * This definition of true as NOT false is definitive. :) Making
196 * it '1' can cause problems on stupid platforms. See articles
197 * on C portability for more information.
199 #define TRUE (!FALSE)
202 /* for paircompare_register */
203 typedef int (*RAD_COMPARE_FUNC)(void *instance, REQUEST *,VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
205 typedef enum radlog_dest_t {
216 extern const char *progname;
217 extern int debug_flag;
218 extern int syslog_facility;
219 extern const char *radacct_dir;
220 extern const char *radlog_dir;
221 extern const char *radlib_dir;
222 extern const char *radius_dir;
223 extern const char *radius_libdir;
224 extern radlog_dest_t radlog_dest;
225 extern uint32_t expiration_seconds;
226 extern int log_stripped_names;
227 extern int log_auth_detail;
228 extern int auth_port;
229 extern int acct_port;
230 extern int proxy_port;
232 extern const char *radiusd_version;
235 * Function prototypes.
239 int rad_accounting(REQUEST *);
242 int rad_check_ts(uint32_t nasaddr, unsigned int port, const char *user,
243 const char *sessionid);
244 int session_zap(int fd, uint32_t nasaddr, unsigned int port, const char *user,
245 const char *sessionid, uint32_t cliaddr,
246 char proto, time_t t);
249 void debug_pair(FILE *, VALUE_PAIR *);
250 int log_err (char *);
251 int rad_process(REQUEST *, int);
252 int rad_respond(REQUEST *, RAD_REQUEST_FUNP fun);
255 void (*reset_signal(int signo, void (*func)(int)))(int);
256 void request_free(REQUEST **request);
257 int rad_mkdir(char *directory, int mode);
258 int rad_checkfilename(const char *filename);
259 void *rad_malloc(size_t size); /* calls exit(1) on error! */
260 void xfree(const char *ptr);
261 void rad_assert_fail (const char *file, unsigned int line);
264 int read_clients_file(const char *file);
265 RADCLIENT *client_find(uint32_t ipno);
266 const char *client_name(uint32_t ipno);
267 void client_walk(void);
268 void clients_free(RADCLIENT *cl);
271 REALM *realm_find(const char *, int);
272 REALM *realm_findbyaddr(uint32_t ipno, int port);
273 void realm_free(REALM *cl);
274 void realm_disable(uint32_t ipno, int port);
275 int pairlist_read(const char *file, PAIR_LIST **list, int complain);
276 void pairlist_free(PAIR_LIST **);
277 int read_config_files(void);
278 int read_realms_file(const char *file);
281 int read_naslist_file(char *);
282 NAS *nas_find(uint32_t ipno);
283 const char *nas_name(uint32_t ipno);
284 const char *nas_name2(RADIUS_PACKET *r);
285 char * nas_name3(char *buf, size_t buflen, uint32_t ipno);
286 NAS *nas_findbyname(char *nasname);
292 int vradlog(int, const char *, va_list ap);
293 int radlog(int, const char *, ...)
295 __attribute__ ((format (printf, 2, 3)))
298 int log_debug(const char *, ...)
300 __attribute__ ((format (printf, 1, 2)))
303 void vp_listdebug(VALUE_PAIR *vp);
306 int proxy_receive(REQUEST *request);
307 int proxy_send(REQUEST *request);
310 char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
311 int rad_authenticate (REQUEST *);
312 int rad_check_password(REQUEST *request);
315 int radius_exec_program(const char *, REQUEST *, int,
316 char *user_msg, int msg_len,
317 VALUE_PAIR *input_pairs,
318 VALUE_PAIR **output_pairs);
321 int timestr_match(char *, time_t);
324 int paircompare_register(int attr, int otherattr,
325 RAD_COMPARE_FUNC func,
327 void paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
328 int paircmp(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
330 int simplepaircmp(REQUEST *, VALUE_PAIR *, VALUE_PAIR *);
331 void pair_builtincompare_init(void);
332 void pairxlatmove(REQUEST *, VALUE_PAIR **to, VALUE_PAIR **from);
335 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
337 int radius_xlat(char * out, int outlen, const char *fmt,
338 REQUEST * request, RADIUS_ESCAPE_STRING func);
339 typedef int (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char *, char *, int, RADIUS_ESCAPE_STRING func);
340 int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance);
341 void xlat_unregister(const char *module, RAD_XLAT_FUNC func);
345 extern int thread_pool_init(void);
346 extern int thread_pool_clean(time_t now);
347 extern void rad_exec_init(void);
348 extern pid_t rad_fork(int exec_wait);
349 extern pid_t rad_waitpid(pid_t pid, int *status, int options);
350 extern int rad_savepid(pid_t pid, int status);
351 extern int total_active_threads(void);
353 #ifndef HAVE_PTHREAD_H
354 #define rad_fork(n) fork()
355 #define rad_waitpid waitpid
359 /* Define a global config structure */
360 extern struct main_config_t mainconfig;
362 int read_mainconfig(int reload);
363 int free_mainconfig(void);
364 CONF_SECTION *read_radius_conf_file(void); /* for radwho and friends. */