Initial revision
[freeradius.git] / src / include / libradius.h
1 /*
2  * libradius.h  Structures and prototypes
3  *              for the radius library.
4  *
5  * Version:     @(#)libradius.h  1.00  19-Jul-1999  miquels@cistron.nl
6  *
7  */
8
9 #include "radius.h"
10 #include "token.h"
11
12 #define AUTH_VECTOR_LEN         16
13 #define MAX_STRING_LEN          254     /* RFC2138: string 0-253 octets */
14
15 #ifdef _LIBRADIUS
16 #  define AUTH_HDR_LEN          20
17 #  define VENDORPEC_USR         429
18 #  define VENDOR(x)             (x >> 16)
19 #  define DEBUG                 if (librad_debug) printf
20 #  define debug_pair(vp)        do { if (librad_debug) { \
21                                         putchar('\t'); \
22                                         vp_print(stdout, vp); \
23                                         putchar('\n'); \
24                                      } \
25                                 } while(0)
26 #endif
27
28 typedef unsigned int UINT4;
29
30 typedef struct dict_attr {
31         char                    name[32];
32         int                     attr;
33         int                     type;
34         int                     vendor;
35         struct dict_attr        *next;
36 } DICT_ATTR;
37
38 typedef struct dict_value {
39         char                    name[32];
40         char                    attrname[32];
41         int                     attr;
42         int                     value;
43         struct dict_value       *next;
44 } DICT_VALUE;
45
46 typedef struct dict_vendor {
47         char                    vendorname[32];
48         int                     vendorpec;
49         int                     vendorcode;
50         struct dict_vendor      *next;
51 } DICT_VENDOR;
52
53 typedef struct value_pair {
54         char                    name[32];
55         int                     attribute;
56         int                     type;
57         int                     length; /* of strvalue */
58         UINT4                   lvalue;
59         int                     operator;
60         int                     addport;
61         char                    strvalue[MAX_STRING_LEN];
62         struct value_pair       *next;
63 } VALUE_PAIR;
64
65 /*
66  *      vector:         Request authenticator from access-request packet
67  *                      Put in there by rad_decode, and must be put in the
68  *                      response RADIUS_PACKET as well before calling rad_send
69  *
70  *      verified:       Filled in by rad_decode for accounting-request packets
71  *
72  *      data,data_len:  Used between rad_recv and rad_decode.
73  */
74 typedef struct radius_packet {
75         UINT4                   src_ipaddr;
76         UINT4                   dst_ipaddr;
77         u_short                 src_port;
78         u_short                 dst_port;
79         int                     id;
80         int                     code;
81         char                    vector[16];
82         time_t                  timestamp;
83         int                     verified;
84         char                    *data;
85         int                     data_len;
86         VALUE_PAIR              *vps;
87 } RADIUS_PACKET;
88
89 /*
90  *      Printing functions.
91  */
92 void            vp_prints(char *out, int outlen, VALUE_PAIR *vp);
93 void            vp_print(FILE *, VALUE_PAIR *);
94 void            vp_printlist(FILE *, VALUE_PAIR *);
95 #define         fprint_attr_val vp_print
96
97 /*
98  *      Dictionary functions.
99  */
100 int             dict_init(char *dir, char *fn);
101 DICT_ATTR       *dict_attrbyvalue(int attr);
102 DICT_ATTR       *dict_attrbyname(char *attr);
103 DICT_VALUE      *dict_valbyattr(int attr, int val);
104 DICT_VALUE      *dict_valbyname(char *val);
105 int             dict_vendorcode(int);
106 int             dict_vendorpec(int);
107
108 #if 1 /* FIXME: compat */
109 #define dict_attrget    dict_attrbyvalue
110 #define dict_attrfind   dict_attrbyname
111 #define dict_valfind    dict_valbyname
112 /*#define dict_valget   dict_valbyattr almost but not quite*/
113 #endif
114
115 /* md5.c */
116
117 void            librad_md5_calc(u_char *, u_char *, u_int);
118
119 /* radius.c */
120 int             rad_send(RADIUS_PACKET *, int fd, char *secret);
121 RADIUS_PACKET   *rad_recv(int fd);
122 int             rad_decode(RADIUS_PACKET *packet, char *secret);
123 RADIUS_PACKET   *rad_alloc(int newvector);
124 void            rad_free(RADIUS_PACKET *);
125 int             rad_pwencode(char *encpw, int *len, char *secret, char *vector);
126 int             rad_pwdecode(char *encpw, int len, char *secret, char *vector);
127 int             calc_digest (RADIUS_PACKET *packet, char *secret);
128 int             calc_acctdigest(RADIUS_PACKET *packet, char *secret,
129                         char *data, int len);
130
131 /* valuepair.c */
132 VALUE_PAIR      *paircreate(int attr, int type);
133 void            pairfree(VALUE_PAIR *);
134 VALUE_PAIR      *pairfind(VALUE_PAIR *, int);
135 void            pairdelete(VALUE_PAIR **, int);
136 void            pairadd(VALUE_PAIR **, VALUE_PAIR *);
137 VALUE_PAIR      *paircopy(VALUE_PAIR *vp);
138 VALUE_PAIR      *paircopy2(VALUE_PAIR *vp, int attr);
139 void            pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
140 void            pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
141 VALUE_PAIR      *pairread(char **ptr, int *eol);
142 int             userparse(char *buffer, VALUE_PAIR **first_pair);
143
144 /*
145  *      Error functions.
146  */
147 #ifdef _LIBRADIUS
148 void            librad_log(char *, ...);
149 #endif
150 void            librad_perror(char *, ...);
151 extern char     *librad_errstr;
152 extern int      librad_dodns;
153 extern int      librad_debug;
154
155 /*
156  *      Several handy miscellaneous functions.
157  */
158 char *          ip_hostname (UINT4);
159 UINT4           ip_getaddr (char *);
160 char *          ip_ntoa(char *, UINT4);
161 UINT4           ip_addr(char *);
162