5 * libradius.h Structures and prototypes
6 * for the radius library.
14 #ifdef HAVE_SYS_TYPES_H
15 #include <sys/types.h>
22 #ifdef HAVE_INTTYPES_H
33 * Check for inclusion of <time.h>, versus <sys/time.h>
34 * Taken verbatim from the autoconf manual.
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
40 # ifdef HAVE_SYS_TIME_H
41 # include <sys/time.h>
50 #ifdef SIZEOF_UNSIGNED_INT
51 #if SIZEOF_UNSIGNED_INT != 4
52 #error FATAL: sizeof(unsigned int) != 4
57 * Include for modules.
64 #define AUTH_VECTOR_LEN 16
65 #define CHAP_VALUE_LENGTH 16
66 #define MAX_STRING_LEN 254 /* RFC2138: string 0-253 octets */
69 # define AUTH_HDR_LEN 20
70 # define VENDORPEC_USR 429
71 # define VENDOR(x) ((x >> 16) & 0xffff)
72 # define DEBUG if (librad_debug) printf
73 # define debug_pair(vp) do { if (librad_debug) { \
75 vp_print(stdout, vp); \
79 # define TAG_VALID(x) ((x) > 0 && (x) < 0x20)
80 # define TAG_VALID_ZERO(x) ((x) >= 0 && (x) < 0x20)
81 # define TAG_ANY -128 /* minimum signed char */
84 typedef struct attr_flags {
85 char addport; /* Add port to IP address */
86 char has_tag; /* attribute allows tags */
88 uint8_t encrypt; /* encryption method */
89 signed char len_disp; /* length displacement */
94 * Values of the encryption flags.
96 #define FLAG_ENCRYPT_NONE (0)
97 #define FLAG_ENCRYPT_USER_PASSWORD (1)
98 #define FLAG_ENCRYPT_TUNNEL_PASSWORD (2)
99 #define FLAG_ENCRYPT_ASCEND_SECRET (3)
101 typedef struct dict_attr {
107 struct dict_attr *next;
110 typedef struct dict_value {
115 struct dict_value *next;
118 typedef struct dict_vendor {
121 struct dict_vendor *next;
124 typedef struct value_pair {
128 int length; /* of strvalue */
131 uint8_t strvalue[MAX_STRING_LEN];
133 struct value_pair *next;
137 * vector: Request authenticator from access-request packet
138 * Put in there by rad_decode, and must be put in the
139 * response RADIUS_PACKET as well before calling rad_send
141 * verified: Filled in by rad_decode for accounting-request packets
143 * data,data_len: Used between rad_recv and rad_decode.
145 typedef struct radius_packet {
153 uint8_t vector[AUTH_VECTOR_LEN];
162 * Printing functions.
164 void librad_safeprint(char *in, int inlen, char *out, int outlen);
165 int vp_prints_value(char *out, int outlen, VALUE_PAIR *vp,int delimitst);
166 int vp_prints(char *out, int outlen, VALUE_PAIR *vp);
167 void vp_print(FILE *, VALUE_PAIR *);
168 void vp_printlist(FILE *, VALUE_PAIR *);
169 #define fprint_attr_val vp_print
172 * Dictionary functions.
174 int dict_addvendor(const char *name, int value);
175 int dict_addattr(const char *name, int vendor, int type, int value, ATTR_FLAGS flags);
176 int dict_addvalue(const char *namestr, char *attrstr, int value);
177 int dict_init(const char *dir, const char *fn);
178 DICT_ATTR *dict_attrbyvalue(int attr);
179 DICT_ATTR *dict_attrbyname(const char *attr);
180 DICT_VALUE *dict_valbyattr(int attr, int val);
181 DICT_VALUE *dict_valbyname(int attr, const char *val);
182 int dict_vendorname(const char *name);
187 #define dict_vendorcode
188 #define dict_vendorpec
191 #if 1 /* FIXME: compat */
192 #define dict_attrget dict_attrbyvalue
193 #define dict_attrfind dict_attrbyname
194 #define dict_valfind dict_valbyname
195 /*#define dict_valget dict_valbyattr almost but not quite*/
200 void librad_md5_calc(u_char *, u_char *, u_int);
204 void lrad_hmac_md5(const unsigned char *text, int text_len,
205 const unsigned char *key, int key_len,
206 unsigned char *digest);
209 int rad_send(RADIUS_PACKET *, const RADIUS_PACKET *, const char *secret);
210 RADIUS_PACKET *rad_recv(int fd);
211 int rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, const char *secret);
212 RADIUS_PACKET *rad_alloc(int newvector);
213 void rad_free(RADIUS_PACKET **);
214 int rad_pwencode(char *encpw, int *len, const char *secret, const char *vector);
215 int rad_pwdecode(char *encpw, int len, const char *secret, const char *vector);
216 int rad_tunnel_pwencode(char *encpw, int *len, const char *secret, const char *vector);
217 int rad_tunnel_pwdecode(char *encpw, int *len, const char *secret, const char *vector);
218 int rad_chap_encode(RADIUS_PACKET *packet, char *output, int id, VALUE_PAIR *password);
221 VALUE_PAIR *paircreate(int attr, int type);
222 void pairfree(VALUE_PAIR **);
223 VALUE_PAIR *pairfind(VALUE_PAIR *, int);
224 void pairdelete(VALUE_PAIR **, int);
225 void pairadd(VALUE_PAIR **, VALUE_PAIR *);
226 VALUE_PAIR *paircopy(VALUE_PAIR *vp);
227 VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr);
228 void pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
229 void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
230 VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value);
231 VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator);
232 VALUE_PAIR *pairread(char **ptr, LRAD_TOKEN *eol);
233 LRAD_TOKEN userparse(char *buffer, VALUE_PAIR **first_pair);
239 void librad_log(const char *, ...)
241 __attribute__ ((format (printf, 1, 2)))
245 void librad_perror(const char *, ...)
247 __attribute__ ((format (printf, 1, 2)))
250 extern char librad_errstr[];
251 extern int librad_dodns; /* 0 = no dns lookups */
252 extern int librad_debug; /* 0 = no debugging information */
253 extern int librad_max_attributes; /* per incoming packet */
256 * Several handy miscellaneous functions.
258 char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
259 uint32_t ip_getaddr (const char *);
260 char * ip_ntoa(char *, uint32_t);
261 uint32_t ip_addr(const char *);
262 char *ifid_ntoa(char *buffer, size_t size, uint8_t *ifid);
263 uint8_t *ifid_aton(const char *ifid_str, uint8_t *ifid);
264 char *strNcpy(char *dest, const char *src, int n);
265 void rad_lowercase(char *str);
266 void rad_rmspace(char *str);
267 int rad_lockfd(int fd, int lock_len);
268 int rad_lockfd_nonblock(int fd, int lock_len);
269 int rad_unlockfd(int fd, int lock_len);
273 int filterBinary(VALUE_PAIR *pair, const char *valstr);
274 void print_abinary(VALUE_PAIR *vp, u_char *buffer, int len);
275 #endif /*ASCEND_BINARY*/
277 #ifdef HAVE_LOCAL_SNPRINTF
279 int snprintf(char *str, size_t count, const char *fmt, ...);
280 int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
283 /* random numbers in isaac.c */
284 /* context of random number generator */
285 typedef struct lrad_randctx {
287 uint32_t randrsl[256];
288 uint32_t randmem[256];
294 void lrad_isaac(lrad_randctx *ctx);
295 void lrad_randinit(lrad_randctx *ctx, int flag);
296 uint32_t lrad_rand(void); /* like rand(), but better. */
298 void lrad_lmpwdhash(const unsigned char *password,unsigned char *lmhash);
299 void lrad_mschap(const unsigned char *win_password,
300 const unsigned char *challenge, unsigned char *response);
303 /* crypt wrapper from crypt.c */
304 int lrad_crypt_check(const char *key, const char *salt);
306 #endif /*LIBRADIUS_H*/