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