more generalised 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 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
28
29 #define RAD_UDP 0
30 #define RAD_TLS 1
31 #define RAD_TCP 2
32
33 #define RAD_Attr_User_Name 1
34 #define RAD_Attr_User_Password 2
35 #define RAD_Attr_Reply_Message 18
36 #define RAD_Attr_Vendor_Specific 26
37 #define RAD_Attr_Calling_Station_Id 31
38 #define RAD_Attr_Tunnel_Password 69
39 #define RAD_Attr_Message_Authenticator 80
40
41 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
42 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
43
44 struct options {
45     char **listenudp;
46     char **listentcp;
47     char **listentls;
48     char **listenaccudp;
49     char *sourceudp;
50     char *sourcetcp;
51     char *logdestination;
52     uint8_t loglevel;
53     uint8_t loopprevention;
54 };
55
56 /* requests that our client will send */
57 struct request {
58     unsigned char *buf;
59     uint8_t tries;
60     uint8_t received;
61     struct timeval expiry;
62     struct client *from;
63     char *origusername;
64     uint8_t origid; /* used by servwr */
65     char origauth[16]; /* used by servwr */
66     struct sockaddr_storage fromsa; /* used by udpservwr */
67     int fromudpsock; /* used by udpservwr */
68 };
69
70 /* replies that a server will send */
71 struct reply {
72     unsigned char *buf;
73     struct sockaddr_storage tosa; /* used by udpservwr */
74     int toudpsock; /* used by udpservwr */
75 };
76
77 struct replyq {
78     struct list *replies;
79     pthread_mutex_t mutex;
80     pthread_cond_t cond;
81 };
82
83 struct listenerarg {
84     int s;
85     uint8_t acconly;
86 };
87
88 struct clsrvconf {
89     char *name;
90     uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
91     const struct protodefs *pdef;
92     char *host;
93     char *port;
94     char *secret;
95     char *tls;
96     char *matchcertattr;
97     regex_t *certcnregex;
98     regex_t *certuriregex;
99     char *confrewrite;
100     char *rewriteattr;
101     regex_t *rewriteattrregex;
102     char *rewriteattrreplacement;
103     char *dynamiclookupcommand;
104     uint8_t statusserver;
105     uint8_t retryinterval;
106     uint8_t retrycount;
107     uint8_t certnamecheck;
108     SSL_CTX *ssl_ctx;
109     struct rewrite *rewrite;
110     struct addrinfo *addrinfo;
111     uint8_t prefixlen;
112     struct list *clients;
113     struct server *servers;
114 };
115
116 struct client {
117     struct clsrvconf *conf;
118     SSL *ssl;
119     struct replyq *replyq;
120 };
121
122 struct server {
123     struct clsrvconf *conf;
124     int sock;
125     SSL *ssl;
126     pthread_mutex_t lock;
127     pthread_t clientth;
128     uint8_t clientrdgone;
129     struct timeval lastconnecttry;
130     struct timeval lastreply;
131     uint8_t connectionok;
132     uint8_t lostrqs;
133     char *dynamiclookuparg;
134     int nextid;
135     struct request *requests;
136     uint8_t newrq;
137     pthread_mutex_t newrq_mutex;
138     pthread_cond_t newrq_cond;
139 };
140
141 struct realm {
142     char *name;
143     char *message;
144     uint8_t accresp;
145     regex_t regex;
146     pthread_mutex_t subrealms_mutex;
147     struct list *subrealms;
148     struct list *srvconfs;
149     struct list *accsrvconfs;
150 };
151
152 struct tls {
153     char *name;
154     SSL_CTX *ctx;
155 };
156
157 struct rewrite {
158     uint8_t *removeattrs;
159     uint32_t *removevendorattrs;
160 };
161
162 struct rewriteconf {
163     char *name;
164     struct rewrite *rewrite;
165 };
166
167 struct protodefs {
168     char *name;
169     char *secretdefault;
170     uint8_t socktype;
171     char *portdefault;
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))