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