the macro NO_SUCH_CHILD_PID should be cast to child_pid_t, as
[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 #include "libradius.h"
10 #include "radpaths.h"
11 #include "conf.h"
12 #include "missing.h"
13
14 #if HAVE_PTHREAD_H
15 #include        <pthread.h>
16 typedef pthread_t child_pid_t;
17 #define child_kill pthread_kill
18 #else
19 typedef pid_t child_pid_t;
20 #define child_kill kill
21 #endif
22
23 #define NO_SUCH_CHILD_PID (child_pid_t) (0)
24
25 #ifndef NDEBUG
26 #define REQUEST_MAGIC (0xdeadbeef)
27 #endif
28
29 typedef struct auth_req {
30 #ifndef NDEBUG
31         uint32_t                magic; /* for debugging only */
32 #endif
33         RADIUS_PACKET           *packet;
34         RADIUS_PACKET           *proxy;
35         RADIUS_PACKET           *reply;
36         RADIUS_PACKET           *proxy_reply;
37         VALUE_PAIR              *config_items;
38         VALUE_PAIR              *username;
39         VALUE_PAIR              *password;
40         char                    secret[32];
41         child_pid_t             child_pid;
42         time_t                  timestamp;
43
44         /* Could almost keep a const char * here instead of a _copy_ of the
45          * secret... but what if the RADCLIENT structure is freed because it was
46          * taken out of the config file and SIGHUPed? */
47         char                    proxysecret[32];
48         int                     proxy_is_replicate;
49         int                     proxy_try_count;
50         time_t                  proxy_next_try;
51
52         int                     finished;
53         struct auth_req         *prev;
54         struct auth_req         *next;
55 } REQUEST;
56
57 /*
58  *  Function handler for requests.
59  */
60 typedef         int (*RAD_REQUEST_FUNP)(REQUEST *);
61
62 typedef struct radclient {
63         uint32_t                ipaddr;
64         char                    longname[256];
65         u_char                  secret[32];
66         char                    shortname[32];
67         struct radclient        *next;
68 } RADCLIENT;
69
70 typedef struct nas {
71         uint32_t                ipaddr;
72         char                    longname[256];
73         char                    shortname[32];
74         char                    nastype[32];
75         struct nas              *next;
76 } NAS;
77
78 typedef struct realm {
79         char                    realm[64];
80         char                    server[64];
81         uint32_t                ipaddr;
82         u_char                  secret[32];
83         int                     auth_port;
84         int                     acct_port;
85         int                     striprealm;
86         int                     trusted;
87         int                     notsuffix;
88         struct realm            *next;
89 } REALM;
90
91 typedef struct pair_list {
92         char                    *name;
93         VALUE_PAIR              *check;
94         VALUE_PAIR              *reply;
95         int                     lineno;
96         struct pair_list        *next;
97 } PAIR_LIST;
98
99 #define DEBUG   if(debug_flag)log_debug
100 #define DEBUG2  if (debug_flag > 1)log_debug
101
102 #define SECONDS_PER_DAY         86400
103 #define MAX_REQUEST_TIME        30
104 #define CLEANUP_DELAY           5
105 #define MAX_REQUESTS            256
106 /* FIXME: these two should be command-line options */
107 #define RETRY_DELAY             5
108 #define RETRY_COUNT             3
109
110 #define L_DBG                   1
111 #define L_AUTH                  2
112 #define L_INFO                  3
113 #define L_ERR                   4
114 #define L_PROXY                 5
115 #define L_CONS                  128
116
117 #ifndef FALSE
118 #define FALSE 0
119 #endif
120 #ifndef TRUE
121 /*
122  *      This definition of true as NOT false is definitive. :) Making
123  *      it '1' can cause problems on stupid platforms.  See articles
124  *      on C portability for more information.
125  */
126 #define TRUE (!FALSE)
127 #endif
128
129 /* for paircompare_register */
130 typedef int (*COMPARE)(VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
131
132 /*
133  *      Global variables.
134  */
135 extern const char       *progname;
136 extern int              debug_flag;
137 extern const char       *radacct_dir;
138 extern const char       *radlog_dir;
139 extern const char       *radlib_dir;
140 extern const char       *radius_dir;
141 extern const char       *radius_libdir;
142 extern uint32_t         expiration_seconds;
143 extern pid_t            radius_pid;
144 extern int              use_dbm;
145 extern int              log_stripped_names;
146 extern uint32_t         myip;
147 extern int              log_auth_detail;
148 extern int              log_auth;
149 extern int              log_auth_pass;
150 extern int              auth_port;
151 extern int              acct_port;
152 extern int              proxy_port;
153 extern int              proxyfd;
154
155 /*
156  *      Function prototypes.
157  */
158
159 /* acct.c */
160 int             rad_accounting(REQUEST *);
161
162 /* radutmp.c */
163 int             radutmp_add(REQUEST *);
164 int             radutmp_zap(uint32_t nas, int port, char *user, time_t t);
165 int             radutmp_checksimul(char *name, VALUE_PAIR *, int maxsimul);
166
167 /* radiusd.c */
168 void            debug_pair(FILE *, VALUE_PAIR *);
169 int             log_err (char *);
170 void            sig_cleanup(int);
171 int             rad_respond(REQUEST *, RAD_REQUEST_FUNP fun);
172
173 /* util.c */
174 void (*reset_signal(int signo, void (*func)(int)))(int);
175 void            request_free(REQUEST *request);
176 RADIUS_PACKET * build_reply(int code, REQUEST *request,
177                             VALUE_PAIR *vps, const char *user_msg);
178
179 /* files.c */
180 RADCLIENT       *client_find(uint32_t ipno);
181 char            *client_name(uint32_t ipno);
182 REALM           *realm_find(const char *);
183 PAIR_LIST       *pairlist_read(const char *file, int complain);
184 void            pairlist_free(PAIR_LIST **);
185 int             read_config_files(void);
186
187 /* nas.c */
188 int             read_naslist_file(char *);
189 NAS             *nas_find(uint32_t ipno);
190 char            *nas_name(uint32_t ipno);
191 char            *nas_name2(RADIUS_PACKET *r);
192 NAS             *nas_findbyname(char *nasname);
193
194 /* version.c */
195 void            version(void);
196
197 /* log.c */
198 int             log(int, const char *, ...);
199 int             log_debug(const char *, ...);
200
201 /* pam.c */
202 #ifdef WITH_PAM
203 int             pam_pass(char *name, char *passwd, const char *pamauth);
204 #define PAM_DEFAULT_TYPE    "radius"
205 #endif
206
207 /* proxy.c */
208 int proxy_receive(REQUEST *request);
209 int proxy_send(REQUEST *request);
210 struct timeval *proxy_setuptimeout(struct timeval *);
211 void proxy_retry(void);
212
213 /* auth.c */
214 char            *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
215 int             rad_authenticate (REQUEST *);
216
217 /* exec.c */
218 char            *radius_xlate(char *output, size_t outputlen,
219                               const char *fmt,
220                               VALUE_PAIR *req, VALUE_PAIR *reply);
221 int             radius_exec_program(const char *, VALUE_PAIR *, VALUE_PAIR **,
222                         int, const char **user_msg);
223
224 /* timestr.c */
225 int             timestr_match(char *, time_t);
226
227 /* valuepair.c */
228 int             paircompare_register(int attr, int otherattr, COMPARE func);
229 void            paircompare_unregister(int attr, COMPARE func);
230 int             paircmp(VALUE_PAIR *request, VALUE_PAIR *check,
231                         VALUE_PAIR **reply);
232 void            pair_builtincompare_init(void);
233
234 /* xlat.c */
235 int            radius_xlat2(char * out, int outlen, char *str,
236                             REQUEST * request, VALUE_PAIR *reply);
237
238 #ifdef WITH_THREAD_POOL
239 /* threads.c */
240 extern          int thread_pool_init(void);
241 extern          int thread_pool_clean(void);
242 #endif