]> git.ozlabs.org Git - ppp.git/blob - pppd/plugins/radius/radiusclient.h
config: Include some extra files in the tarball
[ppp.git] / pppd / plugins / radius / radiusclient.h
1 /*
2  * Copyright (C) 1995,1996,1997,1998 Lars Fenneberg
3  *
4  * Copyright 1992 Livingston Enterprises, Inc.
5  *
6  * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan
7  * and Merit Network, Inc. All Rights Reserved
8  *
9  * See the file COPYRIGHT for the respective terms and conditions.
10  * If the file is missing contact me at lf@elemental.net
11  * and I'll send you a copy.
12  *
13  */
14
15 #ifndef RADIUSCLIENT_H
16 #define RADIUSCLIENT_H
17
18 #include <sys/types.h>
19 #include <stdio.h>
20 #include <time.h>
21 #include <stdbool.h>
22
23 #include <pppd/pppd.h>
24 #include <pppd/options.h>
25
26 #ifndef _UINT4_T
27 /* This works for all machines that Linux runs on... */
28 typedef unsigned int UINT4;
29 typedef int          INT4;
30 #endif
31
32 #define AUTH_VECTOR_LEN         16
33 #define AUTH_PASS_LEN           (3 * 16) /* multiple of 16 */
34 #define AUTH_ID_LEN             64
35 #define AUTH_STRING_LEN         253      /* maximum of 253 */
36
37 #define BUFFER_LEN              8192
38
39 #define NAME_LENGTH             32
40 #define GETSTR_LENGTH           128     /* must be bigger than AUTH_PASS_LEN */
41
42 /* codes for radius_buildreq, radius_getport, etc. */
43 #define AUTH                    0
44 #define ACCT                    1
45
46 /* defines for config.c */
47
48 #define SERVER_MAX 8
49
50 #define AUTH_LOCAL_FST  (1<<0)
51 #define AUTH_RADIUS_FST (1<<1)
52 #define AUTH_LOCAL_SND  (1<<2)
53 #define AUTH_RADIUS_SND (1<<3)
54
55 typedef struct server {
56         int max;
57         char *name[SERVER_MAX];
58         unsigned short port[SERVER_MAX];
59 } SERVER;
60
61 typedef struct pw_auth_hdr
62 {
63         u_char          code;
64         u_char          id;
65         u_short         length;
66         u_char          vector[AUTH_VECTOR_LEN];
67         u_char          data[2];
68 } AUTH_HDR;
69
70 #define AUTH_HDR_LEN                    20
71 #define MAX_SECRET_LENGTH               (3 * 16) /* MUST be multiple of 16 */
72 #define CHAP_VALUE_LENGTH               16
73
74 #define PW_AUTH_UDP_PORT                1812
75 #define PW_ACCT_UDP_PORT                1813
76
77 #define PW_TYPE_STRING                  0
78 #define PW_TYPE_INTEGER                 1
79 #define PW_TYPE_IPADDR                  2
80 #define PW_TYPE_DATE                    3
81 #define PW_TYPE_ABINARY                 4
82 #define PW_TYPE_OCTETS                  5
83 #define PW_TYPE_IFID                    6
84 #define PW_TYPE_IPV6ADDR                7
85 #define PW_TYPE_IPV6PREFIX              8
86 #define PW_TYPE_BYTE                    9
87 #define PW_TYPE_SHORT                   10
88 #define PW_TYPE_ETHERNET                11
89 #define PW_TYPE_SIGNED                  12
90 #define PW_TYPE_COMBO_IP                13
91 #define PW_TYPE_TLV                     14
92
93 /* standard RADIUS codes */
94
95 #define PW_ACCESS_REQUEST               1
96 #define PW_ACCESS_ACCEPT                2
97 #define PW_ACCESS_REJECT                3
98 #define PW_ACCOUNTING_REQUEST           4
99 #define PW_ACCOUNTING_RESPONSE          5
100 #define PW_ACCOUNTING_STATUS            6
101 #define PW_PASSWORD_REQUEST             7
102 #define PW_PASSWORD_ACK                 8
103 #define PW_PASSWORD_REJECT              9
104 #define PW_ACCOUNTING_MESSAGE           10
105 #define PW_ACCESS_CHALLENGE             11
106 #define PW_STATUS_SERVER                12
107 #define PW_STATUS_CLIENT                13
108
109
110 /* standard RADIUS attribute-value pairs */
111
112 #define PW_USER_NAME                    1       /* string */
113 #define PW_USER_PASSWORD                2       /* string */
114 #define PW_CHAP_PASSWORD                3       /* string */
115 #define PW_NAS_IP_ADDRESS               4       /* ipaddr */
116 #define PW_NAS_PORT                     5       /* integer */
117 #define PW_SERVICE_TYPE                 6       /* integer */
118 #define PW_FRAMED_PROTOCOL              7       /* integer */
119 #define PW_FRAMED_IP_ADDRESS            8       /* ipaddr */
120 #define PW_FRAMED_IP_NETMASK            9       /* ipaddr */
121 #define PW_FRAMED_ROUTING               10      /* integer */
122 #define PW_FILTER_ID                    11      /* string */
123 #define PW_FRAMED_MTU                   12      /* integer */
124 #define PW_FRAMED_COMPRESSION           13      /* integer */
125 #define PW_LOGIN_IP_HOST                14      /* ipaddr */
126 #define PW_LOGIN_SERVICE                15      /* integer */
127 #define PW_LOGIN_PORT                   16      /* integer */
128 #define PW_OLD_PASSWORD                 17      /* string */ /* deprecated */
129 #define PW_REPLY_MESSAGE                18      /* string */
130 #define PW_LOGIN_CALLBACK_NUMBER        19      /* string */
131 #define PW_FRAMED_CALLBACK_ID           20      /* string */
132 #define PW_EXPIRATION                   21      /* date */ /* deprecated */
133 #define PW_FRAMED_ROUTE                 22      /* string */
134 #define PW_FRAMED_IPX_NETWORK           23      /* integer */
135 #define PW_STATE                        24      /* string */
136 #define PW_CLASS                        25      /* string */
137 #define PW_VENDOR_SPECIFIC              26      /* string */
138 #define PW_SESSION_TIMEOUT              27      /* integer */
139 #define PW_IDLE_TIMEOUT                 28      /* integer */
140 #define PW_TERMINATION_ACTION           29      /* integer */
141 #define PW_CALLED_STATION_ID            30      /* string */
142 #define PW_CALLING_STATION_ID           31      /* string */
143 #define PW_NAS_IDENTIFIER               32      /* string */
144 #define PW_PROXY_STATE                  33      /* string */
145 #define PW_LOGIN_LAT_SERVICE            34      /* string */
146 #define PW_LOGIN_LAT_NODE               35      /* string */
147 #define PW_LOGIN_LAT_GROUP              36      /* string */
148 #define PW_FRAMED_APPLETALK_LINK        37      /* integer */
149 #define PW_FRAMED_APPLETALK_NETWORK     38      /* integer */
150 #define PW_FRAMED_APPLETALK_ZONE        39      /* string */
151 #define PW_CHAP_CHALLENGE               60      /* string */
152 #define PW_NAS_PORT_TYPE                61      /* integer */
153 #define PW_PORT_LIMIT                   62      /* integer */
154 #define PW_LOGIN_LAT_PORT               63      /* string */
155
156 /* Vendor RADIUS attribute-value pairs */
157 #define PW_MS_CHAP_CHALLENGE            11      /* string */
158 #define PW_MS_CHAP_RESPONSE             1       /* string */
159 #define PW_MS_CHAP2_RESPONSE            25      /* string */
160 #define PW_MS_CHAP2_SUCCESS             26      /* string */
161 #define PW_MS_MPPE_ENCRYPTION_POLICY    7       /* string */
162 #define PW_MS_MPPE_ENCRYPTION_TYPE      8       /* string */
163 #define PW_MS_MPPE_ENCRYPTION_TYPES PW_MS_MPPE_ENCRYPTION_TYPE
164 #define PW_MS_CHAP_MPPE_KEYS            12      /* string */
165 #define PW_MS_MPPE_SEND_KEY             16      /* string */
166 #define PW_MS_MPPE_RECV_KEY             17      /* string */
167 #define PW_MS_PRIMARY_DNS_SERVER        28      /* ipaddr */
168 #define PW_MS_SECONDARY_DNS_SERVER      29      /* ipaddr */
169 #define PW_MS_PRIMARY_NBNS_SERVER       30      /* ipaddr */
170 #define PW_MS_SECONDARY_NBNS_SERVER     31      /* ipaddr */
171
172 /*      Accounting */
173
174 #define PW_ACCT_STATUS_TYPE             40      /* integer */
175 #define PW_ACCT_DELAY_TIME              41      /* integer */
176 #define PW_ACCT_INPUT_OCTETS            42      /* integer */
177 #define PW_ACCT_OUTPUT_OCTETS           43      /* integer */
178 #define PW_ACCT_SESSION_ID              44      /* string */
179 #define PW_ACCT_AUTHENTIC               45      /* integer */
180 #define PW_ACCT_SESSION_TIME            46      /* integer */
181 #define PW_ACCT_INPUT_PACKETS           47      /* integer */
182 #define PW_ACCT_OUTPUT_PACKETS          48      /* integer */
183 #define PW_ACCT_TERMINATE_CAUSE         49      /* integer */
184 #define PW_ACCT_MULTI_SESSION_ID        50      /* string */
185 #define PW_ACCT_LINK_COUNT              51      /* integer */
186
187 /* From RFC 2869 */
188 #define PW_ACCT_INPUT_GIGAWORDS         52      /* integer */
189 #define PW_ACCT_OUTPUT_GIGAWORDS        53      /* integer */
190 #define PW_ACCT_INTERIM_INTERVAL        85      /* integer */
191
192 /*      Merit Experimental Extensions */
193
194 #define PW_USER_ID                      222     /* string */
195 #define PW_USER_REALM                   223     /* string */
196
197
198 /*      Session limits */
199 #define PW_SESSION_OCTETS_LIMIT         227    /* integer */
200 #define PW_OCTETS_DIRECTION             228    /* integer */
201
202 /*      Integer Translations */
203
204 /*      SERVICE TYPES   */
205
206 #define PW_LOGIN                        1
207 #define PW_FRAMED                       2
208 #define PW_CALLBACK_LOGIN               3
209 #define PW_CALLBACK_FRAMED              4
210 #define PW_OUTBOUND                     5
211 #define PW_ADMINISTRATIVE               6
212 #define PW_NAS_PROMPT                   7
213 #define PW_AUTHENTICATE_ONLY            8
214 #define PW_CALLBACK_NAS_PROMPT          9
215
216 /*      FRAMED PROTOCOLS        */
217
218 #define PW_PPP                          1
219 #define PW_SLIP                         2
220 #define PW_ARA                          3
221 #define PW_GANDALF                      4
222 #define PW_XYLOGICS                     5
223
224 /*      FRAMED ROUTING VALUES   */
225
226 #define PW_NONE                         0
227 #define PW_BROADCAST                    1
228 #define PW_LISTEN                       2
229 #define PW_BROADCAST_LISTEN             3
230
231 /*      FRAMED COMPRESSION TYPES        */
232
233 #define PW_VAN_JACOBSON_TCP_IP          1
234 #define PW_IPX_HEADER_COMPRESSION       2
235
236 /*      LOGIN SERVICES  */
237
238 #define PW_TELNET                       0
239 #define PW_RLOGIN                       1
240 #define PW_TCP_CLEAR                    2
241 #define PW_PORTMASTER                   3
242 #define PW_LAT                          4
243 #define PW_X25_PAD                      5
244 #define PW_X25_T3POS                    6
245
246 /*      TERMINATION ACTIONS     */
247
248 #define PW_DEFAULT                      0
249 #define PW_RADIUS_REQUEST               1
250
251 /*      PROHIBIT PROTOCOL  */
252
253 #define PW_DUMB         0       /* 1 and 2 are defined in FRAMED PROTOCOLS */
254 #define PW_AUTH_ONLY    3
255 #define PW_ALL          255
256
257 /*      ACCOUNTING STATUS TYPES    */
258
259 #define PW_STATUS_START         1
260 #define PW_STATUS_STOP          2
261 #define PW_STATUS_ALIVE         3
262 #define PW_STATUS_MODEM_START   4
263 #define PW_STATUS_MODEM_STOP    5
264 #define PW_STATUS_CANCEL        6
265 #define PW_ACCOUNTING_ON        7
266 #define PW_ACCOUNTING_OFF       8
267
268 /*      ACCOUNTING TERMINATION CAUSES   */
269
270 #define PW_USER_REQUEST         1
271 #define PW_LOST_CARRIER         2
272 #define PW_LOST_SERVICE         3
273 #define PW_ACCT_IDLE_TIMEOUT    4
274 #define PW_ACCT_SESSION_TIMEOUT 5
275 #define PW_ADMIN_RESET          6
276 #define PW_ADMIN_REBOOT         7
277 #define PW_PORT_ERROR           8
278 #define PW_NAS_ERROR            9
279 #define PW_NAS_REQUEST          10
280 #define PW_NAS_REBOOT           11
281 #define PW_PORT_UNNEEDED        12
282 #define PW_PORT_PREEMPTED       13
283 #define PW_PORT_SUSPENDED       14
284 #define PW_SERVICE_UNAVAILABLE  15
285 #define PW_CALLBACK             16
286 #define PW_USER_ERROR           17
287 #define PW_HOST_REQUEST         18
288
289 /*     NAS PORT TYPES    */
290
291 #define PW_ASYNC                0
292 #define PW_SYNC                 1
293 #define PW_ISDN_SYNC            2
294 #define PW_ISDN_SYNC_V120       3
295 #define PW_ISDN_SYNC_V110       4
296 #define PW_VIRTUAL              5
297
298 /*         AUTHENTIC TYPES */
299 #define PW_RADIUS       1
300 #define PW_LOCAL        2
301 #define PW_REMOTE       3
302
303 /*    Session-Octets-Limit    */
304 #define PW_OCTETS_DIRECTION_SUM 0
305 #define PW_OCTETS_DIRECTION_IN  1
306 #define PW_OCTETS_DIRECTION_OUT 2
307 #define PW_OCTETS_DIRECTION_MAX 3
308
309
310 /* Vendor codes */
311 #define VENDOR_NONE     (-1)
312 #define VENDOR_MICROSOFT        311
313
314 /* Server data structures */
315
316 typedef struct dict_attr
317 {
318         char              name[NAME_LENGTH + 1];        /* attribute name */
319         int               value;                        /* attribute index */
320         int               type;                         /* string, int, etc. */
321         int               vendorcode;                   /* vendor code */
322         struct dict_attr *next;
323 } DICT_ATTR;
324
325 typedef struct dict_value
326 {
327         char               attrname[NAME_LENGTH +1];
328         char               name[NAME_LENGTH + 1];
329         int                value;
330         struct dict_value *next;
331 } DICT_VALUE;
332
333 typedef struct vendor_dict
334 {
335     char vendorname[NAME_LENGTH + 1];
336     int vendorcode;
337     DICT_ATTR *attributes;
338     struct vendor_dict *next;
339 } VENDOR_DICT;
340
341 typedef struct value_pair
342 {
343         char               name[NAME_LENGTH + 1];
344         int                attribute;
345         int                vendorcode;
346         int                type;
347         UINT4              lvalue;
348         u_char             strvalue[AUTH_STRING_LEN + 1];
349         struct value_pair *next;
350 } VALUE_PAIR;
351
352 /* don't change this, as it has to be the same as in the Merit radiusd code */
353 #define MGMT_POLL_SECRET        "Hardlyasecret"
354
355 /*      Define return codes from "SendServer" utility */
356
357 #define BADRESP_RC      -2
358 #define ERROR_RC        -1
359 #define OK_RC           0
360 #define TIMEOUT_RC      1
361
362 typedef struct send_data /* Used to pass information to sendserver() function */
363 {
364         u_char          code;           /* RADIUS packet code */
365         u_char          seq_nbr;        /* Packet sequence number */
366         char           *server;         /* Name/addrress of RADIUS server */
367         int             svc_port;       /* RADIUS protocol destination port */
368         int             timeout;        /* Session timeout in seconds */
369         int             retries;
370         VALUE_PAIR     *send_pairs;     /* More a/v pairs to send */
371         VALUE_PAIR     *receive_pairs;  /* Where to place received a/v pairs */
372 } SEND_DATA;
373
374 typedef struct request_info
375 {
376         char            secret[MAX_SECRET_LENGTH + 1];
377         u_char          request_vector[AUTH_VECTOR_LEN];
378 } REQUEST_INFO;
379
380 #ifndef MIN
381 #define MIN(a, b)     ((a) < (b) ? (a) : (b))
382 #endif
383 #ifndef MAX
384 #define MAX(a, b)     ((a) > (b) ? (a) : (b))
385 #endif
386
387 #ifndef PATH_MAX
388 #define PATH_MAX        1024
389 #endif
390
391 typedef struct env
392 {
393         int maxsize, size;
394         char **env;
395 } ENV;
396
397 #define ENV_SIZE        128
398
399 /*      Function prototypes     */
400
401 /*      avpair.c                */
402
403 VALUE_PAIR *rc_avpair_add(VALUE_PAIR **, int, const void *, int, int);
404 int rc_avpair_assign(VALUE_PAIR *, const void *, int);
405 VALUE_PAIR *rc_avpair_new(int, const void *, int, int);
406 VALUE_PAIR *rc_avpair_gen(AUTH_HDR *);
407 VALUE_PAIR *rc_avpair_get(VALUE_PAIR *, UINT4);
408 VALUE_PAIR *rc_avpair_copy(VALUE_PAIR *);
409 void rc_avpair_insert(VALUE_PAIR **, VALUE_PAIR *, VALUE_PAIR *);
410 void rc_avpair_free(VALUE_PAIR *);
411 int rc_avpair_parse(char *, VALUE_PAIR **);
412 int rc_avpair_tostr(VALUE_PAIR *, char *, int, char *, int);
413 VALUE_PAIR *rc_avpair_readin(FILE *);
414
415 /*      buildreq.c              */
416
417 void rc_buildreq(SEND_DATA *, int, char *, unsigned short, int, int);
418 unsigned char rc_get_seqnbr(void);
419 int rc_auth(UINT4, VALUE_PAIR *, VALUE_PAIR **, char *, REQUEST_INFO *);
420 int rc_auth_using_server(SERVER *, UINT4, VALUE_PAIR *, VALUE_PAIR **,
421                          char *, REQUEST_INFO *);
422 int rc_auth_proxy(VALUE_PAIR *, VALUE_PAIR **, char *);
423 int rc_acct(UINT4, VALUE_PAIR *);
424 int rc_acct_using_server(SERVER *, UINT4, VALUE_PAIR *);
425 int rc_acct_proxy(VALUE_PAIR *);
426 int rc_check(char *, unsigned short, char *);
427
428 /*      clientid.c              */
429
430 int rc_read_mapfile(char *);
431 UINT4 rc_map2id(const char *);
432
433 /*      config.c                */
434
435 int rc_read_config(char *);
436 char *rc_conf_str(char *);
437 int rc_conf_int(char *);
438 SERVER *rc_conf_srv(char *);
439 int rc_find_server(char *, UINT4 *, char *);
440
441 /*      dict.c                  */
442
443 int rc_read_dictionary(char *);
444 DICT_ATTR *rc_dict_getattr(int, int);
445 DICT_ATTR *rc_dict_findattr(char *);
446 DICT_VALUE *rc_dict_findval(char *);
447 DICT_VALUE * rc_dict_getval(UINT4, char *);
448 VENDOR_DICT * rc_dict_findvendor(char *);
449 VENDOR_DICT * rc_dict_getvendor(int);
450
451 /*      ip_util.c               */
452
453 UINT4 rc_get_ipaddr(const char *);
454 int rc_good_ipaddr(const char *);
455 const char *rc_ip_hostname(UINT4);
456 UINT4 rc_own_ipaddress(void);
457 UINT4 rc_own_bind_ipaddress(void);
458
459
460 /*      sendserver.c            */
461
462 int rc_send_server(SEND_DATA *, char *, REQUEST_INFO *);
463
464 /*      util.c                  */
465
466 void rc_str2tm(char *, struct tm *);
467 char *rc_mksid(void);
468 void rc_mdelay(int);
469
470 /* md5.c                        */
471
472 int rc_md5_calc(unsigned char *out, const unsigned char *in, unsigned int inl);
473
474 #endif /* RADIUSCLIENT_H */