5 * libradius.h Structures and prototypes
6 * for the radius library.
15 #include <sys/types.h>
29 * Check for inclusion of <time.h>, versus <sys/time.h>
30 * Taken verbatim from the autoconf manual.
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
37 # include <sys/time.h>
46 #ifdef SIZEOF_UNSIGNED_INT
47 #if SIZEOF_UNSIGNED_INT != 4
48 #error FATAL: sizeof(unsigned int) != 4
52 #define AUTH_VECTOR_LEN 16
53 #define CHAP_VALUE_LENGTH 16
54 #define MAX_STRING_LEN 254 /* RFC2138: string 0-253 octets */
56 #define PW_AUTH_UDP_PORT 1645
57 #define PW_ACCT_UDP_PORT 1646
60 # define AUTH_HDR_LEN 20
61 # define VENDORPEC_USR 429
62 # define VENDOR(x) (x >> 16)
63 # define DEBUG if (librad_debug) printf
64 # define debug_pair(vp) do { if (librad_debug) { \
66 vp_print(stdout, vp); \
72 typedef struct dict_attr {
77 struct dict_attr *next;
80 typedef struct dict_value {
85 struct dict_value *next;
88 typedef struct dict_vendor {
92 struct dict_vendor *next;
95 typedef struct value_pair {
99 int length; /* of strvalue */
103 uint8_t strvalue[MAX_STRING_LEN];
104 struct value_pair *next;
108 * vector: Request authenticator from access-request packet
109 * Put in there by rad_decode, and must be put in the
110 * response RADIUS_PACKET as well before calling rad_send
112 * verified: Filled in by rad_decode for accounting-request packets
114 * data,data_len: Used between rad_recv and rad_decode.
116 typedef struct radius_packet {
124 uint8_t vector[AUTH_VECTOR_LEN];
133 * Printing functions.
135 void librad_safeprint(char *in, int inlen, char *out, int outlen);
136 int vp_prints_value(char *out, int outlen, VALUE_PAIR *vp,int delimitst);
137 int vp_prints(char *out, int outlen, VALUE_PAIR *vp);
138 void vp_print(FILE *, VALUE_PAIR *);
139 void vp_printlist(FILE *, VALUE_PAIR *);
140 #define fprint_attr_val vp_print
143 * Dictionary functions.
145 int dict_addvendor(const char *name, int value);
146 int dict_addattr(const char *name, int vendor, int type, int value);
147 int dict_addvalue(const char *namestr, char *attrstr, int value);
148 int dict_init(const char *dir, const char *fn);
149 DICT_ATTR *dict_attrbyvalue(int attr);
150 DICT_ATTR *dict_attrbyname(const char *attr);
151 DICT_VALUE *dict_valbyattr(int attr, int val);
152 DICT_VALUE *dict_valbyname(const char *val);
153 int dict_vendorcode(int);
154 int dict_vendorpec(int);
155 int dict_vendorname(const char *name);
157 #if 1 /* FIXME: compat */
158 #define dict_attrget dict_attrbyvalue
159 #define dict_attrfind dict_attrbyname
160 #define dict_valfind dict_valbyname
161 /*#define dict_valget dict_valbyattr almost but not quite*/
166 void librad_md5_calc(u_char *, u_char *, u_int);
169 int rad_send(RADIUS_PACKET *, const char *secret);
170 RADIUS_PACKET *rad_recv(int fd);
171 int rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, const char *secret);
172 RADIUS_PACKET *rad_alloc(int newvector);
173 void rad_free(RADIUS_PACKET **);
174 int rad_pwencode(char *encpw, int *len, const char *secret, const char *vector);
175 int rad_pwdecode(char *encpw, int len, const char *secret, const char *vector);
176 int rad_chap_encode(RADIUS_PACKET *packet, char *output, int id, VALUE_PAIR *password);
177 int calc_acctdigest(RADIUS_PACKET *packet, const char *secret,
178 char *data, int len);
181 VALUE_PAIR *paircreate(int attr, int type);
182 void pairfree(VALUE_PAIR **);
183 VALUE_PAIR *pairfind(VALUE_PAIR *, int);
184 void pairdelete(VALUE_PAIR **, int);
185 void pairadd(VALUE_PAIR **, VALUE_PAIR *);
186 VALUE_PAIR *paircopy(VALUE_PAIR *vp);
187 VALUE_PAIR *paircopy2(VALUE_PAIR *vp, int attr);
188 void pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
189 void pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
190 VALUE_PAIR *pairmake(const char *attribute, const char *value, int operator);
191 VALUE_PAIR *pairread(char **ptr, int *eol);
192 int userparse(char *buffer, VALUE_PAIR **first_pair);
198 void librad_log(const char *, ...)
200 __attribute__ ((format (printf, 1, 2)))
204 void librad_perror(const char *, ...)
206 __attribute__ ((format (printf, 1, 2)))
209 extern char librad_errstr[];
210 extern int librad_dodns;
211 extern int librad_debug;
214 * Several handy miscellaneous functions.
216 char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr);
217 uint32_t ip_getaddr (const char *);
218 char * ip_ntoa(char *, uint32_t);
219 uint32_t ip_addr(const char *);
220 char *strNcpy(char *dest, const char *src, int n);
221 void rad_lowercase(char *str);
222 void rad_rmspace(char *str);
226 int filterBinary(VALUE_PAIR *pair, const char *valstr);
227 void print_abinary(VALUE_PAIR *vp, u_char *buffer, int len);
228 #endif /*ASCEND_BINARY*/
230 #endif /*LIBRADIUS_H*/