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