radiusclient.h 13 KB

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