removed warnings, add some typecasts
[libradsec.git] / radsecproxy.h
1 /*
2  * Copyright (C) 2006 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 RADLEN(x) ntohs(((uint16_t *)(x))[1])
10
11 #define SOCKADDR_SIZE(addr) ((addr).ss_family == AF_INET ? \
12                             sizeof(struct sockaddr_in) : \
13                             sizeof(struct sockaddr_in6))
14
15 #define CONFIG_MAIN "/etc/radsecproxy/radsecproxy.conf"
16 #define CONFIG_SERVERS "/etc/radsecproxy/servers.conf"
17 #define CONFIG_CLIENTS "/etc/radsecproxy/clients.conf"
18
19 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
20 #define MAX_REQUESTS 256
21 #define DEFAULT_TLS_SECRET "mysecret"
22 #define DEFAULT_UDP_PORT "1812"
23 #define DEFAULT_TLS_PORT "2083"
24 #define REQUEST_EXPIRY 20
25 #define REQUEST_RETRIES 3
26 #define MAX_CERT_DEPTH 5
27
28 #define RAD_Access_Request 1
29 #define RAD_Access_Accept 2
30 #define RAD_Access_Reject 3
31 #define RAD_Accounting_Request 4
32 #define RAD_Accounting_Response 5
33 #define RAD_Access_Challenge 11
34 #define RAD_Status_Server 12
35 #define RAD_Status_Client 13
36
37 #define RAD_Attr_User_Name 1
38 #define RAD_Attr_User_Password 2
39 #define RAD_Attr_Vendor_Specific 26
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 #define RAD_Attr_Type 0
47 #define RAD_Attr_Length 1
48 #define RAD_Attr_Value 2
49
50 struct options {
51     char *tlscacertificatefile;
52     char *tlscacertificatepath;
53     char *tlscertificatefile;
54     char *tlscertificatekeyfile;
55     char *udpserverport;
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     unsigned char *messageauthattrval;
66     uint8_t origid; /* used by servwr */
67     char origauth[16]; /* used by servwr */
68     struct sockaddr_storage fromsa; /* used by udpservwr */
69 };
70
71 /* replies that a server will send */
72 struct reply {
73     unsigned char *buf;
74     struct sockaddr_storage tosa; /* used by udpservwr */
75 };
76
77 struct replyq {
78     struct reply *replies;
79     int count;
80     int size;
81     pthread_mutex_t count_mutex;
82     pthread_cond_t count_cond;
83 };
84
85 struct peer {
86     char type; /* U for UDP, T for TLS */
87     char *host;
88     char *port;
89     char *secret;
90     SSL *ssl;
91     struct addrinfo *addrinfo;
92 };
93
94 struct client {
95     struct peer peer;
96     struct replyq *replyq;
97 };
98
99 struct server {
100     struct peer peer;
101     char *realmdata;
102     char **realms;
103     int sock;
104     pthread_mutex_t lock;
105     pthread_t clientth;
106     struct timeval lastconnecttry;
107     uint8_t connectionok;
108     int nextid;
109     struct request *requests;
110     uint8_t newrq;
111     pthread_mutex_t newrq_mutex;
112     pthread_cond_t newrq_cond;
113 };
114
115 void errx(char *format, ...);
116 void err(char *format, ...);
117 char *stringcopy(char *s, int len);
118 char *addr2string(struct sockaddr *addr, socklen_t len);
119 int bindport(int type, char *port);
120 int connectport(int type, char *host, char *port);