This is the bigger part of the modular session framework. It is not ready to
[freeradius.git] / src / include / radiusd.h
1 /*
2  * radiusd.h    Structures, prototypes and global variables
3  *              for the Cistron Radius server.
4  *
5  * Version:     $Id$
6  *
7  */
8
9 #ifndef RADIUSD_H
10 #define RADIUSD_H
11 #include "libradius.h"
12 #include "radpaths.h"
13 #include "conf.h"
14 #include "missing.h"
15
16 #if HAVE_UNISTD_H
17 #include <unistd.h>
18 #endif
19
20 #if HAVE_PTHREAD_H
21 #include        <pthread.h>
22 typedef pthread_t child_pid_t;
23 #define child_kill pthread_kill
24 #else
25 typedef pid_t child_pid_t;
26 #define child_kill kill
27 #endif
28
29 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
30
31 #ifndef NDEBUG
32 #define REQUEST_MAGIC (0xdeadbeef)
33 #endif
34
35 typedef struct auth_req {
36 #ifndef NDEBUG
37         uint32_t                magic; /* for debugging only */
38 #endif
39         RADIUS_PACKET           *packet;
40         RADIUS_PACKET           *proxy;
41         RADIUS_PACKET           *reply;
42         RADIUS_PACKET           *proxy_reply;
43         VALUE_PAIR              *config_items;
44         VALUE_PAIR              *username;
45         VALUE_PAIR              *password;
46         char                    secret[32];
47         child_pid_t             child_pid;
48         time_t                  timestamp;
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         struct auth_req         *prev;
64         struct auth_req         *next;
65 } REQUEST;
66
67 /*
68  *  Function handler for requests.
69  */
70 typedef         int (*RAD_REQUEST_FUNP)(REQUEST *);
71
72 typedef struct radclient {
73         uint32_t                ipaddr;
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                     notsuffix;
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 } PAIR_LIST;
108
109 #define DEBUG   if(debug_flag)log_debug
110 #define DEBUG2  if (debug_flag > 1)log_debug
111
112 #define SECONDS_PER_DAY         86400
113 #define MAX_REQUEST_TIME        30
114 #define CLEANUP_DELAY           5
115 #define MAX_REQUESTS            256
116 /* FIXME: these two should be command-line options */
117 #define RETRY_DELAY             5
118 #define RETRY_COUNT             3
119
120 #define L_DBG                   1
121 #define L_AUTH                  2
122 #define L_INFO                  3
123 #define L_ERR                   4
124 #define L_PROXY                 5
125 #define L_CONS                  128
126
127 #ifndef FALSE
128 #define FALSE 0
129 #endif
130 #ifndef TRUE
131 /*
132  *      This definition of true as NOT false is definitive. :) Making
133  *      it '1' can cause problems on stupid platforms.  See articles
134  *      on C portability for more information.
135  */
136 #define TRUE (!FALSE)
137 #endif
138
139 /* for paircompare_register */
140 typedef int (*COMPARE)(VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
141
142 /*
143  *      Global variables.
144  */
145 extern const char       *progname;
146 extern int              debug_flag;
147 extern char             *radacct_dir;
148 extern char             *radlog_dir;
149 extern const char       *radlib_dir;
150 extern char             *radius_dir;
151 extern const char       *radius_libdir;
152 extern uint32_t         expiration_seconds;
153 extern int              use_dbm;
154 extern int              log_stripped_names;
155 extern uint32_t         myip;
156 extern int              log_auth_detail;
157 extern int              log_auth;
158 extern int              log_auth_pass;
159 extern int              auth_port;
160 extern int              acct_port;
161 extern int              proxy_port;
162 extern int              proxyfd;
163 extern int              proxy_retry_count;
164 extern int              proxy_retry_delay;
165
166 /*
167  *      Function prototypes.
168  */
169
170 /* acct.c */
171 int             rad_accounting(REQUEST *);
172
173 /* radutmp.c */
174 int             radutmp_add(REQUEST *);
175 int             radutmp_zap(uint32_t nas, int port, char *user, time_t t);
176 int             radutmp_checksimul(char *name, VALUE_PAIR *, int maxsimul);
177
178 /* session.c */
179 int             rad_check_ts(uint32_t nasaddr, int port, const char *user,
180                              const char *sessionid);
181 int             session_zap(uint32_t nasaddr, int port, const char *user,
182                             const char *sessionid, uint32_t cliaddr,
183                             char proto, time_t t);
184
185 /* radiusd.c */
186 void            debug_pair(FILE *, VALUE_PAIR *);
187 int             log_err (char *);
188 void            sig_cleanup(int);
189 int             rad_respond(REQUEST *, RAD_REQUEST_FUNP fun);
190
191 /* util.c */
192 void (*reset_signal(int signo, void (*func)(int)))(int);
193 void            request_free(REQUEST *request);
194 RADIUS_PACKET * build_reply(int code, REQUEST *request,
195                             VALUE_PAIR *vps, const char *user_msg);
196
197 /* files.c */
198 RADCLIENT       *client_find(uint32_t ipno);
199 char            *client_name(uint32_t ipno);
200 REALM           *realm_find(const char *);
201 REALM           *realm_findbyaddr(uint32_t ipno);
202 int             pairlist_read(const char *file, PAIR_LIST **list, int complain);
203 void            pairlist_free(PAIR_LIST **);
204 int             read_config_files(void);
205
206 /* nas.c */
207 int             read_naslist_file(char *);
208 NAS             *nas_find(uint32_t ipno);
209 char            *nas_name(uint32_t ipno);
210 char            *nas_name2(RADIUS_PACKET *r);
211 NAS             *nas_findbyname(char *nasname);
212
213 /* version.c */
214 void            version(void);
215
216 /* log.c */
217 int             radlog(int, const char *, ...)
218 #ifdef __GNUC__
219                 __attribute__ ((format (printf, 2, 3)))
220 #endif
221 ;
222 int             log_debug(const char *, ...)
223 #ifdef __GNUC__
224                 __attribute__ ((format (printf, 1, 2)))
225 #endif
226 ;
227
228 /* pam.c */
229 #ifdef WITH_PAM
230 int             pam_pass(char *name, char *passwd, const char *pamauth);
231 #define PAM_DEFAULT_TYPE    "radius"
232 #endif
233
234 /* proxy.c */
235 int proxy_receive(REQUEST *request);
236 int proxy_send(REQUEST *request);
237
238 /* auth.c */
239 char            *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
240 int             rad_authenticate (REQUEST *);
241
242 /* exec.c */
243 char            *radius_xlate(char *output, size_t outputlen,
244                               const char *fmt,
245                               VALUE_PAIR *req, VALUE_PAIR *reply);
246 int             radius_exec_program(const char *, VALUE_PAIR *, VALUE_PAIR **,
247                         int, const char **user_msg);
248
249 /* timestr.c */
250 int             timestr_match(char *, time_t);
251
252 /* valuepair.c */
253 int             paircompare_register(int attr, int otherattr, COMPARE func);
254 void            paircompare_unregister(int attr, COMPARE func);
255 int             paircmp(VALUE_PAIR *request, VALUE_PAIR *check,
256                         VALUE_PAIR **reply);
257 void            pair_builtincompare_init(void);
258
259 /* xlat.c */
260 int            radius_xlat2(char * out, int outlen, char *str,
261                             REQUEST * request, VALUE_PAIR *reply);
262
263 #ifdef WITH_THREAD_POOL
264 /* threads.c */
265 extern          int thread_pool_init(void);
266 extern          int thread_pool_clean(void);
267 #endif
268 #endif /*RADIUSD_H*/