aee2585c2a0f137c2a2d558d448bfee0aedbba30
[freeradius.git] / src / include / radiusd.h
1 #ifndef RADIUSD_H
2 #define RADIUSD_H
3 /*
4  * radiusd.h    Structures, prototypes and global variables
5  *              for the Cistron Radius server.
6  *
7  * Version:     $Id$
8  *
9  */
10 #include "libradius.h"
11 #include "radpaths.h"
12 #include "conf.h"
13 #include "missing.h"
14
15 #if HAVE_UNISTD_H
16 #include <unistd.h>
17 #endif
18
19 #if HAVE_PTHREAD_H
20 #include        <pthread.h>
21 typedef pthread_t child_pid_t;
22 #define child_kill pthread_kill
23 #else
24 typedef pid_t child_pid_t;
25 #define child_kill kill
26 #endif
27
28 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
29
30 #ifndef NDEBUG
31 #define REQUEST_MAGIC (0xdeadbeef)
32 #endif
33
34 typedef struct auth_req {
35 #ifndef NDEBUG
36         uint32_t                magic; /* for debugging only */
37 #endif
38         RADIUS_PACKET           *packet;
39         RADIUS_PACKET           *proxy;
40         RADIUS_PACKET           *reply;
41         RADIUS_PACKET           *proxy_reply;
42         VALUE_PAIR              *config_items;
43         VALUE_PAIR              *username;
44         VALUE_PAIR              *password;
45         char                    secret[32];
46         child_pid_t             child_pid;
47         time_t                  timestamp;
48         int                     number; /* internal server number */
49
50         /* Could almost keep a const char * here instead of a _copy_ of the
51          * secret... but what if the RADCLIENT structure is freed because it was
52          * taken out of the config file and SIGHUPed? */
53         char                    proxysecret[32];
54         int                     proxy_is_replicate;
55         int                     proxy_try_count;
56         time_t                  proxy_next_try;
57
58         int                     simul_max;
59         int                     simul_count;
60         int                     simul_mpp; /* WEIRD: 1 is false, 2 is true */
61
62         int                     finished;
63         void                    **container;
64 } REQUEST;
65
66 /*
67  *  Function handler for requests.
68  */
69 typedef         int (*RAD_REQUEST_FUNP)(REQUEST *);
70
71 typedef struct radclient {
72         uint32_t                ipaddr;
73         uint32_t                netmask;
74         char                    longname[256];
75         u_char                  secret[32];
76         char                    shortname[32];
77         struct radclient        *next;
78 } RADCLIENT;
79
80 typedef struct nas {
81         uint32_t                ipaddr;
82         char                    longname[256];
83         char                    shortname[32];
84         char                    nastype[32];
85         struct nas              *next;
86 } NAS;
87
88 typedef struct realm {
89         char                    realm[64];
90         char                    server[64];
91         uint32_t                ipaddr;
92         u_char                  secret[32];
93         int                     auth_port;
94         int                     acct_port;
95         int                     striprealm;
96         int                     trusted;
97         int                     notrealm;
98         struct realm            *next;
99 } REALM;
100
101 typedef struct pair_list {
102         char                    *name;
103         VALUE_PAIR              *check;
104         VALUE_PAIR              *reply;
105         int                     lineno;
106         struct pair_list        *next;
107         struct pair_list        *lastdefault;
108 } PAIR_LIST;
109
110 typedef struct main_config_t {
111         int             log_auth;
112         int             log_auth_badpass;
113         int             log_auth_goodpass;
114         int             do_usercollide;
115         char    *do_lower_user;
116         char    *do_lower_pass;
117         char    *do_nospace_user;
118         char    *do_nospace_pass;
119         char            *nospace_time;
120 } MAIN_CONFIG_T;
121
122 #define DEBUG   if(debug_flag)log_debug
123 #define DEBUG2  if (debug_flag > 1)log_debug
124
125 #define SECONDS_PER_DAY         86400
126 #define MAX_REQUEST_TIME        30
127 #define CLEANUP_DELAY           5
128 #define MAX_REQUESTS            256
129 #define RETRY_DELAY             5
130 #define RETRY_COUNT             3
131
132 #define L_DBG                   1
133 #define L_AUTH                  2
134 #define L_INFO                  3
135 #define L_ERR                   4
136 #define L_PROXY                 5
137 #define L_CONS                  128
138
139 #ifndef FALSE
140 #define FALSE 0
141 #endif
142 #ifndef TRUE
143 /*
144  *      This definition of true as NOT false is definitive. :) Making
145  *      it '1' can cause problems on stupid platforms.  See articles
146  *      on C portability for more information.
147  */
148 #define TRUE (!FALSE)
149 #endif
150
151 /* for paircompare_register */
152 typedef int (*RAD_COMPARE_FUNC)(void *instance, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
153
154 /*
155  *      Global variables.
156  */
157 extern const char       *progname;
158 extern int              debug_flag;
159 extern const char       *radacct_dir;
160 extern const char       *radlog_dir;
161 extern const char       *radlib_dir;
162 extern const char       *radius_dir;
163 extern const char       *radius_libdir;
164 extern uint32_t         expiration_seconds;
165 extern int              use_dbm;
166 extern int              log_stripped_names;
167 extern uint32_t         myip;
168 extern int              log_auth_detail;
169 extern int              auth_port;
170 extern int              acct_port;
171 extern int              acctfd;
172 extern int              proxy_port;
173 extern int              proxyfd;
174 extern int              proxy_retry_count;
175 extern int              proxy_retry_delay;
176 extern int              spawn_flag;
177
178 /* Define a global config structure */
179 extern struct main_config_t mainconfig;
180
181 /*
182  *      Function prototypes.
183  */
184
185 /* acct.c */
186 int             rad_accounting(REQUEST *);
187
188 /* session.c */
189 int             rad_check_ts(uint32_t nasaddr, int port, const char *user,
190                              const char *sessionid);
191 int             session_zap(uint32_t nasaddr, int port, const char *user,
192                             const char *sessionid, uint32_t cliaddr,
193                             char proto, time_t t);
194
195 /* radiusd.c */
196 void            debug_pair(FILE *, VALUE_PAIR *);
197 int             log_err (char *);
198 void            sig_cleanup(int);
199 int             rad_process(REQUEST *, int);
200 int             rad_respond(REQUEST *, RAD_REQUEST_FUNP fun);
201
202 /* util.c */
203 void (*reset_signal(int signo, void (*func)(int)))(int);
204 void            request_free(REQUEST **request);
205 int             rad_mkdir(char *directory, int mode);
206 int             rad_checkfilename(const char *filename);
207 void            *rad_malloc(size_t size); /* calls exit(1) on error! */
208 void            xfree(const char *ptr);
209
210 /* client.c */
211 int             read_clients_file(const char *file);
212 RADCLIENT       *client_find(uint32_t ipno);
213 const char      *client_name(uint32_t ipno);
214 void            client_walk(void);
215
216 /* files.c */
217 REALM           *realm_find(const char *);
218 REALM           *realm_findbyaddr(uint32_t ipno);
219 int             pairlist_read(const char *file, PAIR_LIST **list, int complain);
220 void            pairlist_free(PAIR_LIST **);
221 int             read_config_files(void);
222
223 /* nas.c */
224 int             read_naslist_file(char *);
225 NAS             *nas_find(uint32_t ipno);
226 const char      *nas_name(uint32_t ipno);
227 const char      *nas_name2(RADIUS_PACKET *r);
228 NAS             *nas_findbyname(char *nasname);
229
230 /* version.c */
231 void            version(void);
232
233 /* log.c */
234 int             radlog(int, const char *, ...)
235 #ifdef __GNUC__
236                 __attribute__ ((format (printf, 2, 3)))
237 #endif
238 ;
239 int             log_debug(const char *, ...)
240 #ifdef __GNUC__
241                 __attribute__ ((format (printf, 1, 2)))
242 #endif
243 ;
244
245 /* proxy.c */
246 int proxy_receive(REQUEST *request);
247 int proxy_send(REQUEST *request);
248
249 /* auth.c */
250 char    *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
251 int             rad_authenticate (REQUEST *);
252 VALUE_PAIR      *rad_getpass(REQUEST *request);
253
254 /* exec.c */
255 int             radius_exec_program(const char *,  REQUEST *,
256                                     int, const char **user_msg);
257
258 /* timestr.c */
259 int             timestr_match(char *, time_t);
260
261 /* valuepair.c */
262 int             paircompare_register(int attr, int otherattr,
263                                      RAD_COMPARE_FUNC func,
264                                      void *instance);
265 void            paircompare_unregister(int attr, RAD_COMPARE_FUNC func);
266 int             paircmp(VALUE_PAIR *request, VALUE_PAIR *check,
267                         VALUE_PAIR **reply);
268 int             simplepaircmp(VALUE_PAIR *, VALUE_PAIR *);
269 void            pair_builtincompare_init(void);
270
271 /* xlat.c */
272 int            radius_xlat2(char * out, int outlen, const char *fmt,
273                             REQUEST * request);
274
275 #ifdef WITH_THREAD_POOL
276 /* threads.c */
277 extern          int thread_pool_init(void);
278 extern          int thread_pool_clean(time_t now);
279 #endif
280 #endif /*RADIUSD_H*/