2 * Copyright (C) 2006-2008 Stig Venaas <venaas@uninett.no>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
11 #define CONFIG_MAIN "/etc/radsecproxy.conf"
13 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
14 #define MAX_REQUESTS 256
15 #define REQUEST_RETRY_INTERVAL 5
16 #define REQUEST_RETRY_COUNT 2
17 #define MAX_CERT_DEPTH 5
18 #define STATUS_SERVER_PERIOD 25
19 #define IDLE_TIMEOUT 300
20 #define RAD_Access_Request 1
21 #define RAD_Access_Accept 2
22 #define RAD_Access_Reject 3
23 #define RAD_Accounting_Request 4
24 #define RAD_Accounting_Response 5
25 #define RAD_Access_Challenge 11
26 #define RAD_Status_Server 12
27 #define RAD_Status_Client 13
34 #define RAD_Attr_User_Name 1
35 #define RAD_Attr_User_Password 2
36 #define RAD_Attr_Reply_Message 18
37 #define RAD_Attr_Vendor_Specific 26
38 #define RAD_Attr_Calling_Station_Id 31
39 #define RAD_Attr_Tunnel_Password 69
40 #define RAD_Attr_Message_Authenticator 80
42 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
43 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
57 uint8_t loopprevention;
60 /* requests that our client will send */
65 struct timeval expiry;
68 uint8_t origid; /* used by servwr */
69 char origauth[16]; /* used by servwr */
70 struct sockaddr_storage fromsa; /* used by udpservwr */
71 int fromudpsock; /* used by udpservwr */
74 /* replies that a server will send */
77 struct sockaddr_storage tosa; /* used by udpservwr */
78 int toudpsock; /* used by udpservwr */
83 pthread_mutex_t mutex;
89 uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
90 const struct protodefs *pdef;
97 regex_t *certuriregex;
100 char *rewriteusername;
101 regex_t *rewriteusernameregex;
102 char *rewriteusernamereplacement;
103 char *dynamiclookupcommand;
104 uint8_t statusserver;
105 uint8_t retryinterval;
107 uint8_t certnamecheck;
109 struct rewrite *rewritein;
110 struct rewrite *rewriteout;
111 struct addrinfo *addrinfo;
113 struct list *clients;
114 struct server *servers;
118 struct clsrvconf *conf;
119 int sock; /* for tcp/dtls */
121 struct queue *replyq;
122 struct queue *rbios; /* for dtls */
123 struct sockaddr_storage addr; /* for dtls */
127 struct clsrvconf *conf;
130 pthread_mutex_t lock;
132 uint8_t clientrdgone;
133 struct timeval lastconnecttry;
134 struct timeval lastreply;
135 uint8_t connectionok;
137 char *dynamiclookuparg;
139 struct timeval lastrcv;
140 struct request *requests;
142 pthread_mutex_t newrq_mutex;
143 pthread_cond_t newrq_cond;
144 struct queue *rbios; /* for dtls */
152 pthread_mutex_t subrealms_mutex;
153 struct list *subrealms;
154 struct list *srvconfs;
155 struct list *accsrvconfs;
171 uint8_t *removeattrs;
172 uint32_t *removevendorattrs;
180 uint8_t retrycountdefault;
181 uint8_t retrycountmax;
182 uint8_t retryintervaldefault;
183 uint8_t retryintervalmax;
184 void *(*listener)(void*);
186 int (*connecter)(struct server *, struct timeval *, int, char *);
187 void *(*clientconnreader)(void*);
188 int (*clientradput)(struct server *, unsigned char *);
189 void (*addclient)(struct client *);
190 void (*addserverextra)(struct clsrvconf *);
194 #define RADLEN(x) ntohs(((uint16_t *)(x))[1])
196 #define ATTRTYPE(x) ((x)[0])
197 #define ATTRLEN(x) ((x)[1])
198 #define ATTRVAL(x) ((x) + 2)
199 #define ATTRVALLEN(x) ((x)[1] - 2)
201 #define SOCKADDR_SIZE(addr) ((addr).ss_family == AF_INET ? \
202 sizeof(struct sockaddr_in) : \
203 sizeof(struct sockaddr_in6))
205 struct addrinfo *getsrcprotores(uint8_t type);
206 struct clsrvconf *find_clconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
207 struct clsrvconf *find_srvconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
208 struct clsrvconf *find_clconf_type(uint8_t type, struct list_node **cur);
209 struct client *addclient(struct clsrvconf *conf);
210 void removeclient(struct client *client);
211 void removeclientrqs(struct client *client);
212 struct queue *newqueue();
213 void removequeue(struct queue *q);
214 void freebios(struct queue *q);
215 int radsrv(struct request *rq);
216 X509 *verifytlscert(SSL *ssl);
217 int verifyconfcert(X509 *cert, struct clsrvconf *conf);
218 int replyh(struct server *server, unsigned char *buf);
219 int connecttcp(struct addrinfo *addrinfo, struct addrinfo *src);
220 int bindtoaddr(struct addrinfo *addrinfo, int family, int reuse, int v6only);