Update date in radsecproxy.conf.5.
[libradsec.git] / radsecproxy.h
1 /*
2  * Copyright (C) 2006-2009 Stig Venaas <venaas@uninett.no>
3  * Copyright (C) 2010,2011 NORDUnet A/S
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  */
9
10 #include <sys/time.h>
11 #include <stdint.h>
12 #include <pthread.h>
13 #include <regex.h>
14 #include "list.h"
15 #include "tlv11.h"
16 #include "radmsg.h"
17 #include "gconfig.h"
18
19 #define DEBUG_LEVEL 2
20
21 #define CONFIG_MAIN SYSCONFDIR"/radsecproxy.conf"
22
23 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
24 #define MAX_REQUESTS 256
25 #define REQUEST_RETRY_INTERVAL 5
26 #define REQUEST_RETRY_COUNT 2
27 #define DUPLICATE_INTERVAL REQUEST_RETRY_INTERVAL * REQUEST_RETRY_COUNT
28 #define MAX_CERT_DEPTH 5
29 #define STATUS_SERVER_PERIOD 25
30 #define IDLE_TIMEOUT 300
31
32 /* 27262 is vendor DANTE Ltd. */
33 #define DEFAULT_TTL_ATTR "27262:1"
34
35 #define RAD_UDP 0
36 #define RAD_TLS 1
37 #define RAD_TCP 2
38 #define RAD_DTLS 3
39 #define RAD_PROTOCOUNT 4
40
41 enum rsp_fticks_reporting_type {
42     RSP_FTICKS_REPORTING_NONE = 0, /* Default.  */
43     RSP_FTICKS_REPORTING_BASIC,
44     RSP_FTICKS_REPORTING_FULL
45 };
46
47 enum rsp_fticks_mac_type {
48     RSP_FTICKS_MAC_STATIC = 0,
49     RSP_FTICKS_MAC_ORIGINAL,
50     RSP_FTICKS_MAC_VENDOR_HASHED,
51     RSP_FTICKS_MAC_VENDOR_KEY_HASHED, /* Default.  */
52     RSP_FTICKS_MAC_FULLY_HASHED,
53     RSP_FTICKS_MAC_FULLY_KEY_HASHED
54 };
55
56 struct options {
57     char *pidfile;
58     char *logdestination;
59     char *ftickssyslogfacility;
60     char *ttlattr;
61     uint32_t ttlattrtype[2];
62     uint8_t addttl;
63     uint8_t loglevel;
64     uint8_t loopprevention;
65     enum rsp_fticks_reporting_type fticks_reporting;
66     enum rsp_fticks_mac_type fticks_mac;
67     uint8_t *fticks_key;
68 };
69
70 struct commonprotoopts {
71     char **listenargs;
72     char *sourcearg;
73 };
74
75 struct request {
76     struct timeval created;
77     uint32_t refcount;
78     uint8_t *buf, *replybuf;
79     struct radmsg *msg;
80     struct client *from;
81     struct server *to;
82     char *origusername;
83     uint8_t rqid;
84     uint8_t rqauth[16];
85     uint8_t newid;
86     int udpsock; /* only for UDP */
87     uint16_t udpport; /* only for UDP */
88 };
89
90 /* requests that our client will send */
91 struct rqout {
92     pthread_mutex_t *lock;
93     struct request *rq;
94     uint8_t tries;
95     struct timeval expiry;
96 };
97
98 struct gqueue {
99     struct list *entries;
100     pthread_mutex_t mutex;
101     pthread_cond_t cond;
102 };
103
104 struct clsrvconf {
105     char *name;
106     uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
107     const struct protodefs *pdef;
108     char **hostsrc;
109     char *portsrc;
110     struct list *hostports;
111     char *secret;
112     char *tls;
113     char *matchcertattr;
114     regex_t *certcnregex;
115     regex_t *certuriregex;
116     char *confrewritein;
117     char *confrewriteout;
118     char *confrewriteusername;
119     struct modattr *rewriteusername;
120     char *dynamiclookupcommand;
121     uint8_t statusserver;
122     uint8_t retryinterval;
123     uint8_t retrycount;
124     uint8_t dupinterval;
125     uint8_t certnamecheck;
126     uint8_t addttl;
127     uint8_t loopprevention;
128     struct rewrite *rewritein;
129     struct rewrite *rewriteout;
130     pthread_mutex_t *lock; /* only used for updating clients so far */
131     struct tls *tlsconf;
132     struct list *clients;
133     struct server *servers;
134     char *fticks_viscountry;
135     char *fticks_visinst;
136 };
137
138 #include "tlscommon.h"
139
140 struct client {
141     struct clsrvconf *conf;
142     int sock;
143     SSL *ssl;
144     struct request *rqs[MAX_REQUESTS];
145     struct gqueue *replyq;
146     struct gqueue *rbios; /* for dtls */
147     struct sockaddr *addr;
148     time_t expiry; /* for udp */
149 };
150
151 struct server {
152     struct clsrvconf *conf;
153     int sock;
154     SSL *ssl;
155     pthread_mutex_t lock;
156     pthread_t clientth;
157     uint8_t clientrdgone;
158     struct timeval lastconnecttry;
159     struct timeval lastreply;
160     uint8_t connectionok;
161     uint8_t lostrqs;
162     uint8_t dynstartup;
163     char *dynamiclookuparg;
164     int nextid;
165     struct timeval lastrcv;
166     struct rqout *requests;
167     uint8_t newrq;
168     pthread_mutex_t newrq_mutex;
169     pthread_cond_t newrq_cond;
170     struct gqueue *rbios; /* for dtls */
171 };
172
173 struct realm {
174     char *name;
175     char *message;
176     uint8_t accresp;
177     regex_t regex;
178     uint32_t refcount;
179     pthread_mutex_t mutex;
180     struct realm *parent;
181     struct list *subrealms;
182     struct list *srvconfs;
183     struct list *accsrvconfs;
184 };
185
186 struct modattr {
187     uint8_t t;
188     char *replacement;
189     regex_t *regex;
190 };
191
192 struct rewrite {
193     uint8_t *removeattrs;
194     uint32_t *removevendorattrs;
195     struct list *addattrs;
196     struct list *modattrs;
197 };
198
199 struct protodefs {
200     char *name;
201     char *secretdefault;
202     int socktype;
203     char *portdefault;
204     uint8_t retrycountdefault;
205     uint8_t retrycountmax;
206     uint8_t retryintervaldefault;
207     uint8_t retryintervalmax;
208     uint8_t duplicateintervaldefault;
209     void (*setprotoopts)(struct commonprotoopts *);
210     char **(*getlistenerargs)();
211     void *(*listener)(void*);
212     int (*connecter)(struct server *, struct timeval *, int, char *);
213     void *(*clientconnreader)(void*);
214     int (*clientradput)(struct server *, unsigned char *);
215     void (*addclient)(struct client *);
216     void (*addserverextra)(struct clsrvconf *);
217     void (*setsrcres)();
218     void (*initextra)();
219 };
220
221 #define RADLEN(x) ntohs(((uint16_t *)(x))[1])
222
223 #define ATTRTYPE(x) ((x)[0])
224 #define ATTRLEN(x) ((x)[1])
225 #define ATTRVAL(x) ((x) + 2)
226 #define ATTRVALLEN(x) ((x)[1] - 2)
227
228 struct clsrvconf *find_clconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
229 struct clsrvconf *find_srvconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
230 struct clsrvconf *find_clconf_type(uint8_t type, struct list_node **cur);
231 struct client *addclient(struct clsrvconf *conf, uint8_t lock);
232 void removelockedclient(struct client *client);
233 void removeclient(struct client *client);
234 struct gqueue *newqueue();
235 void freebios(struct gqueue *q);
236 struct request *newrequest();
237 void freerq(struct request *rq);
238 int radsrv(struct request *rq);
239 void replyh(struct server *server, unsigned char *buf);
240 struct addrinfo *resolve_hostport_addrinfo(uint8_t type, char *hostport);
241 uint8_t *radattr2ascii(struct tlv *attr);
242
243 /* Local Variables: */
244 /* c-file-style: "stroustrup" */
245 /* End: */