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
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 */
68 #define PW_AUTH_UDP_PORT 1812
69 #define PW_ACCT_UDP_PORT 1813
72 # define AUTH_HDR_LEN 20
73 # define VENDORPEC_USR 429
74 # define VENDOR(x) (x >> 16)
75 # define DEBUG if (librad_debug) printf
76 # define debug_pair(vp) do { if (librad_debug) { \
78 vp_print(stdout, vp); \
82 # define TAG_VALID(x) ((x) > 0 && (x) < 0x20)
83 # define TAG_VALID_ZERO(x) ((x) >= 0 && (x) < 0x20)
84 # define TAG_ANY -128 /* minimum signed char */
87 typedef struct attr_flags {
88 char addport; /* Add port to IP address */
89 char has_tag; /* attribute allows tags */
91 char encrypt; /* encryption method */
92 signed char len_disp; /* length displacement */
95 typedef struct dict_attr {
101 struct dict_attr *next;
104 typedef struct dict_value {
109 struct dict_value *next;
112 typedef struct dict_vendor {
115 struct dict_vendor *next;
118 typedef struct value_pair {
122 int length; /* of strvalue */
125 uint8_t strvalue[MAX_STRING_LEN];
127 struct value_pair *next;
131 * vector: Request authenticator from access-request packet
132 * Put in there by rad_decode, and must be put in the
133 * response RADIUS_PACKET as well before calling rad_send
135 * verified: Filled in by rad_decode for accounting-request packets
137 * data,data_len: Used between rad_recv and rad_decode.
139 typedef struct radius_packet {
147 uint8_t vector[AUTH_VECTOR_LEN];
156 * Printing functions.
158 void librad_safeprint(char *in, int inlen, char *out, int outlen);
159 int vp_prints_value(char *out, int outlen, VALUE_PAIR *vp,int delimitst);
160 int vp_prints(char *out, int outlen, VALUE_PAIR *vp);
161 void vp_print(FILE *, VALUE_PAIR *);
162 void vp_printlist(FILE *, VALUE_PAIR *);
163 #define fprint_attr_val vp_print
166 * Dictionary functions.
168 int dict_addvendor(const char *name, int value);
169 int dict_addattr(const char *name, int vendor, int type, int value, ATTR_FLAGS flags);
170 int dict_addvalue(const char *namestr, char *attrstr, int value);
171 int dict_init(const char *dir, const char *fn);
172 DICT_ATTR *dict_attrbyvalue(int attr);
173 DICT_ATTR *dict_attrbyname(const char *attr);
174 DICT_VALUE *dict_valbyattr(int attr, int val);
175 DICT_VALUE *dict_valbyname(int attr, const char *val);
176 int dict_vendorname(const char *name);
181 #define dict_vendorcode
182 #define dict_vendorpec
185 #if 1 /* FIXME: compat */
186 #define dict_attrget dict_attrbyvalue
187 #define dict_attrfind dict_attrbyname
188 #define dict_valfind dict_valbyname
189 /*#define dict_valget dict_valbyattr almost but not quite*/
194 void librad_md5_calc(u_char *, u_char *, u_int);
198 void lrad_hmac_md5(const unsigned char *text, int text_len,
199 const unsigned char *key, int key_len,
200 unsigned char *digest);
203 int rad_send(RADIUS_PACKET *, const RADIUS_PACKET *, const char *secret);
204 RADIUS_PACKET *rad_recv(int fd);
205 int rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, const char *secret);
206 RADIUS_PACKET *rad_alloc(int newvector);
207 void rad_free(RADIUS_PACKET **);
208 int rad_pwencode(char *encpw, int *len, const char *secret, const char *vector);
209 int rad_pwdecode(char *encpw, int len, const char *secret, const char *vector);
210 int rad_tunnel_pwencode(char *encpw, int *len, const char *secret, const char *vector);
211 int rad_tunnel_pwdecode(char *encpw, int *len, const char *secret, const char *vector);
212 int rad_chap_encode(RADIUS_PACKET *packet, char *output, int id, VALUE_PAIR *password);
215 VALUE_PAIR *paircreate(int attr, int type);
216 void pairfree(VALUE_PAIR **);
217 VALUE_PAIR *pairfind(VALUE_PAIR *, int);
218 void pairdelete(VALUE_PAIR **, int);
219 void pairadd(VALUE_PAIR **, VALUE_PAIR *);
220 VALUE_PAIR *paircopy(VALUE_PAIR *vp);
221 VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr);
222 void pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
223 void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
224 VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator);
225 VALUE_PAIR *pairread(char **ptr, LRAD_TOKEN *eol);
226 LRAD_TOKEN userparse(char *buffer, VALUE_PAIR **first_pair);
232 void librad_log(const char *, ...)
234 __attribute__ ((format (printf, 1, 2)))
238 void librad_perror(const char *, ...)
240 __attribute__ ((format (printf, 1, 2)))
243 extern char librad_errstr[];
244 extern int librad_dodns; /* 0 = no dns lookups */
245 extern int librad_debug; /* 0 = no debugging information */
246 extern int librad_max_attributes; /* per incoming packet */
249 * Several handy miscellaneous functions.
251 char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
252 uint32_t ip_getaddr (const char *);
253 char * ip_ntoa(char *, uint32_t);
254 uint32_t ip_addr(const char *);
255 char *strNcpy(char *dest, const char *src, int n);
256 void rad_lowercase(char *str);
257 void rad_rmspace(char *str);
258 int rad_lockfd(int fd, int lock_len);
259 int rad_unlockfd(int fd, int lock_len);
263 int filterBinary(VALUE_PAIR *pair, const char *valstr);
264 void print_abinary(VALUE_PAIR *vp, u_char *buffer, int len);
265 #endif /*ASCEND_BINARY*/
267 #ifdef HAVE_LOCAL_SNPRINTF
269 int snprintf(char *str, size_t count, const char *fmt, ...);
270 int vsnprintf(char *str, size_t count, const char *fmt, va_list arg);
273 #endif /*LIBRADIUS_H*/