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