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