added configuration of tcp transport
[libradsec.git] / radsecproxy.h
1 /*
2  * Copyright (C) 2006-2008 Stig Venaas <venaas@uninett.no>
3  *
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.
7  */
8
9 #define DEBUG_LEVEL 3
10
11 #define CONFIG_MAIN "/etc/radsecproxy.conf"
12
13 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
14 #define MAX_REQUESTS 256
15 #define DEFAULT_UDP_PORT "1812"
16 #define DEFAULT_TLS_PORT "2083"
17 #define REQUEST_RETRY_INTERVAL 5
18 #define REQUEST_RETRY_COUNT 2
19 #define MAX_CERT_DEPTH 5
20 #define STATUS_SERVER_PERIOD 25
21 #define IDLE_TIMEOUT 300
22 #define RAD_Access_Request 1
23 #define RAD_Access_Accept 2
24 #define RAD_Access_Reject 3
25 #define RAD_Accounting_Request 4
26 #define RAD_Accounting_Response 5
27 #define RAD_Access_Challenge 11
28 #define RAD_Status_Server 12
29 #define RAD_Status_Client 13
30
31 #define RAD_UDP 0
32 #define RAD_TLS 1
33 #define RAD_TCP 2
34
35 #define RAD_Attr_User_Name 1
36 #define RAD_Attr_User_Password 2
37 #define RAD_Attr_Reply_Message 18
38 #define RAD_Attr_Vendor_Specific 26
39 #define RAD_Attr_Calling_Station_Id 31
40 #define RAD_Attr_Tunnel_Password 69
41 #define RAD_Attr_Message_Authenticator 80
42
43 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
44 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
45
46 struct options {
47     char **listenudp;
48     char **listentcp;
49     char **listentls;
50     char **listenaccudp;
51     char *sourceudp;
52     char *sourcetcp;
53     char *logdestination;
54     uint8_t loglevel;
55     uint8_t loopprevention;
56 };
57
58 /* requests that our client will send */
59 struct request {
60     unsigned char *buf;
61     uint8_t tries;
62     uint8_t received;
63     struct timeval expiry;
64     struct client *from;
65     char *origusername;
66     uint8_t origid; /* used by servwr */
67     char origauth[16]; /* used by servwr */
68     struct sockaddr_storage fromsa; /* used by udpservwr */
69     int fromudpsock; /* used by udpservwr */
70 };
71
72 /* replies that a server will send */
73 struct reply {
74     unsigned char *buf;
75     struct sockaddr_storage tosa; /* used by udpservwr */
76     int toudpsock; /* used by udpservwr */
77 };
78
79 struct replyq {
80     struct list *replies;
81     pthread_mutex_t mutex;
82     pthread_cond_t cond;
83 };
84
85 struct listenerarg {
86     int s;
87     uint8_t acconly;
88 };
89
90 struct clsrvconf {
91     char *name;
92     uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
93     const struct protodefs *pdef;
94     char *host;
95     char *port;
96     char *secret;
97     char *tls;
98     char *matchcertattr;
99     regex_t *certcnregex;
100     regex_t *certuriregex;
101     char *confrewrite;
102     char *rewriteattr;
103     regex_t *rewriteattrregex;
104     char *rewriteattrreplacement;
105     char *dynamiclookupcommand;
106     uint8_t statusserver;
107     uint8_t retryinterval;
108     uint8_t retrycount;
109     uint8_t certnamecheck;
110     SSL_CTX *ssl_ctx;
111     struct rewrite *rewrite;
112     struct addrinfo *addrinfo;
113     uint8_t prefixlen;
114     struct list *clients;
115     struct server *servers;
116 };
117
118 struct client {
119     struct clsrvconf *conf;
120     SSL *ssl;
121     struct replyq *replyq;
122 };
123
124 struct server {
125     struct clsrvconf *conf;
126     int sock;
127     SSL *ssl;
128     pthread_mutex_t lock;
129     pthread_t clientth;
130     uint8_t clientrdgone;
131     struct timeval lastconnecttry;
132     struct timeval lastreply;
133     uint8_t connectionok;
134     uint8_t lostrqs;
135     char *dynamiclookuparg;
136     int nextid;
137     struct request *requests;
138     uint8_t newrq;
139     pthread_mutex_t newrq_mutex;
140     pthread_cond_t newrq_cond;
141 };
142
143 struct realm {
144     char *name;
145     char *message;
146     uint8_t accresp;
147     regex_t regex;
148     pthread_mutex_t subrealms_mutex;
149     struct list *subrealms;
150     struct list *srvconfs;
151     struct list *accsrvconfs;
152 };
153
154 struct tls {
155     char *name;
156     SSL_CTX *ctx;
157 };
158
159 struct rewrite {
160     uint8_t *removeattrs;
161     uint32_t *removevendorattrs;
162 };
163
164 struct rewriteconf {
165     char *name;
166     struct rewrite *rewrite;
167 };
168
169 struct protodefs {
170     char *name;
171     char *secretdefault;
172     uint8_t retrycountdefault;
173     uint8_t retrycountmax;
174     uint8_t retryintervaldefault;
175     uint8_t retryintervalmax;
176 };
177
178 #define RADLEN(x) ntohs(((uint16_t *)(x))[1])
179
180 #define ATTRTYPE(x) ((x)[0])
181 #define ATTRLEN(x) ((x)[1])
182 #define ATTRVAL(x) ((x) + 2)
183 #define ATTRVALLEN(x) ((x)[1] - 2)
184
185 #define SOCKADDR_SIZE(addr) ((addr).ss_family == AF_INET ? \
186                             sizeof(struct sockaddr_in) : \
187                             sizeof(struct sockaddr_in6))