5 * libradius.h Structures and prototypes
6 * for the radius library.
15 #include <sys/types.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>
41 # include <sys/time.h>
50 #ifdef SIZEOF_UNSIGNED_INT
51 #if SIZEOF_UNSIGNED_INT != 4
52 #error FATAL: sizeof(unsigned int) != 4
58 #define AUTH_VECTOR_LEN 16
59 #define CHAP_VALUE_LENGTH 16
60 #define MAX_STRING_LEN 254 /* RFC2138: string 0-253 octets */
62 #define PW_AUTH_UDP_PORT 1645
63 #define PW_ACCT_UDP_PORT 1646
66 # define AUTH_HDR_LEN 20
67 # define VENDORPEC_USR 429
68 # define VENDOR(x) (x >> 16)
69 # define DEBUG if (librad_debug) printf
70 # define debug_pair(vp) do { if (librad_debug) { \
72 vp_print(stdout, vp); \
76 # define TAG_VALID(x) ((x) > 0 && (x) < 0x20)
77 # define TAG_VALID_ZERO(x) ((x) >= 0 && (x) < 0x20)
78 # define TAG_ANY -128 /* minimum signed char */
81 typedef struct attr_flags {
82 char addport; /* Add port to IP address */
83 char has_tag; /* attribute allows tags */
85 char encrypt; /* encryption method */
86 signed char len_disp; /* length displacement */
89 typedef struct dict_attr {
95 struct dict_attr *next;
98 typedef struct dict_value {
103 struct dict_value *next;
106 typedef struct dict_vendor {
109 struct dict_vendor *next;
112 typedef struct value_pair {
116 int length; /* of strvalue */
119 uint8_t strvalue[MAX_STRING_LEN];
121 struct value_pair *next;
125 * vector: Request authenticator from access-request packet
126 * Put in there by rad_decode, and must be put in the
127 * response RADIUS_PACKET as well before calling rad_send
129 * verified: Filled in by rad_decode for accounting-request packets
131 * data,data_len: Used between rad_recv and rad_decode.
133 typedef struct radius_packet {
141 uint8_t vector[AUTH_VECTOR_LEN];
150 * Printing functions.
152 void librad_safeprint(char *in, int inlen, char *out, int outlen);
153 int vp_prints_value(char *out, int outlen, VALUE_PAIR *vp,int delimitst);
154 int vp_prints(char *out, int outlen, VALUE_PAIR *vp);
155 void vp_print(FILE *, VALUE_PAIR *);
156 void vp_printlist(FILE *, VALUE_PAIR *);
157 #define fprint_attr_val vp_print
160 * Dictionary functions.
162 int dict_addvendor(const char *name, int value);
163 int dict_addattr(const char *name, int vendor, int type, int value, ATTR_FLAGS flags);
164 int dict_addvalue(const char *namestr, char *attrstr, int value);
165 int dict_init(const char *dir, const char *fn);
166 DICT_ATTR *dict_attrbyvalue(int attr);
167 DICT_ATTR *dict_attrbyname(const char *attr);
168 DICT_VALUE *dict_valbyattr(int attr, int val);
169 DICT_VALUE *dict_valbyname(int attr, const char *val);
170 int dict_vendorname(const char *name);
175 #define dict_vendorcode
176 #define dict_vendorpec
179 #if 1 /* FIXME: compat */
180 #define dict_attrget dict_attrbyvalue
181 #define dict_attrfind dict_attrbyname
182 #define dict_valfind dict_valbyname
183 /*#define dict_valget dict_valbyattr almost but not quite*/
188 void librad_md5_calc(u_char *, u_char *, u_int);
192 void lrad_hmac_md5(const unsigned char *text, int text_len,
193 const unsigned char *key, int key_len,
194 unsigned char *digest);
197 int rad_send(RADIUS_PACKET *, const RADIUS_PACKET *, const char *secret);
198 RADIUS_PACKET *rad_recv(int fd);
199 int rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, const char *secret);
200 RADIUS_PACKET *rad_alloc(int newvector);
201 void rad_free(RADIUS_PACKET **);
202 int rad_pwencode(char *encpw, int *len, const char *secret, const char *vector);
203 int rad_pwdecode(char *encpw, int len, const char *secret, const char *vector);
204 int rad_tunnel_pwencode(char *encpw, int *len, const char *secret, const char *vector);
205 int rad_tunnel_pwdecode(char *encpw, int *len, const char *secret, const char *vector);
206 int rad_chap_encode(RADIUS_PACKET *packet, char *output, int id, VALUE_PAIR *password);
209 VALUE_PAIR *paircreate(int attr, int type);
210 void pairfree(VALUE_PAIR **);
211 VALUE_PAIR *pairfind(VALUE_PAIR *, int);
212 void pairdelete(VALUE_PAIR **, int);
213 void pairadd(VALUE_PAIR **, VALUE_PAIR *);
214 VALUE_PAIR *paircopy(VALUE_PAIR *vp);
215 VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr);
216 void pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
217 void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
218 VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator);
219 VALUE_PAIR *pairread(char **ptr, LRAD_TOKEN *eol);
220 LRAD_TOKEN userparse(char *buffer, VALUE_PAIR **first_pair);
226 void librad_log(const char *, ...)
228 __attribute__ ((format (printf, 1, 2)))
232 void librad_perror(const char *, ...)
234 __attribute__ ((format (printf, 1, 2)))
237 extern char librad_errstr[];
238 extern int librad_dodns; /* 0 = no dns lookups */
239 extern int librad_debug; /* 0 = no debugging information */
240 extern int librad_max_attributes; /* per incoming packet */
243 * Several handy miscellaneous functions.
245 char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
246 uint32_t ip_getaddr (const char *);
247 char * ip_ntoa(char *, uint32_t);
248 uint32_t ip_addr(const char *);
249 char *strNcpy(char *dest, const char *src, int n);
250 void rad_lowercase(char *str);
251 void rad_rmspace(char *str);
252 int rad_lockfd(int fd, int lock_len);
253 int rad_unlockfd(int fd, int lock_len);
257 int filterBinary(VALUE_PAIR *pair, const char *valstr);
258 void print_abinary(VALUE_PAIR *vp, u_char *buffer, int len);
259 #endif /*ASCEND_BINARY*/
261 #ifdef HAVE_LOCAL_SNPRINTF
263 int snprintf(char *str, size_t count, const char *fmt, ...);
264 int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
267 #endif /*LIBRADIUS_H*/