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