Detach as default, options for foreground and debug level
[radsecproxy.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 DEBUG_LEVEL 2
16
17 #define CONFIG_MAIN "/etc/radsecproxy/radsecproxy.conf"
18 #define CONFIG_SERVERS "/etc/radsecproxy/servers.conf"
19 #define CONFIG_CLIENTS "/etc/radsecproxy/clients.conf"
20
21 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
22 #define MAX_REQUESTS 256
23 #define DEFAULT_TLS_SECRET "mysecret"
24 #define DEFAULT_UDP_PORT "1812"
25 #define DEFAULT_TLS_PORT "2083"
26 #define REQUEST_EXPIRY 20
27 #define REQUEST_RETRIES 3
28 #define MAX_CERT_DEPTH 5
29 #define STATUS_SERVER_PERIOD 25
30 #define RAD_Access_Request 1
31 #define RAD_Access_Accept 2
32 #define RAD_Access_Reject 3
33 #define RAD_Accounting_Request 4
34 #define RAD_Accounting_Response 5
35 #define RAD_Access_Challenge 11
36 #define RAD_Status_Server 12
37 #define RAD_Status_Client 13
38
39 #define RAD_Attr_User_Name 1
40 #define RAD_Attr_User_Password 2
41 #define RAD_Attr_Vendor_Specific 26
42 #define RAD_Attr_Tunnel_Password 69
43 #define RAD_Attr_Message_Authenticator 80
44
45 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
46 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
47
48 #define RAD_Attr_Type 0
49 #define RAD_Attr_Length 1
50 #define RAD_Attr_Value 2
51
52 struct options {
53     char *tlscacertificatefile;
54     char *tlscacertificatepath;
55     char *tlscertificatefile;
56     char *tlscertificatekeyfile;
57     char *tlscertificatekeypassword;
58     char *listenudp;
59     char *listentcp;
60     char *logdestination;
61     uint8_t loglevel;
62     uint8_t statusserver;
63 };
64
65 /* requests that our client will send */
66 struct request {
67     unsigned char *buf;
68     uint8_t tries;
69     uint8_t received;
70     struct timeval expiry;
71     struct client *from;
72     unsigned char *messageauthattrval;
73     uint8_t origid; /* used by servwr */
74     char origauth[16]; /* used by servwr */
75     struct sockaddr_storage fromsa; /* used by udpservwr */
76 };
77
78 /* replies that a server will send */
79 struct reply {
80     unsigned char *buf;
81     struct sockaddr_storage tosa; /* used by udpservwr */
82 };
83
84 struct replyq {
85     struct reply *replies;
86     int count;
87     int size;
88     pthread_mutex_t count_mutex;
89     pthread_cond_t count_cond;
90 };
91
92 struct peer {
93     char type; /* U for UDP, T for TLS */
94     char *host;
95     char *port;
96     char *secret;
97     SSL *ssl;
98     struct addrinfo *addrinfo;
99 };
100
101 struct client {
102     struct peer peer;
103     struct replyq *replyq;
104 };
105
106 struct server {
107     struct peer peer;
108     char *realmdata;
109     char **realms;
110     int sock;
111     pthread_mutex_t lock;
112     pthread_t clientth;
113     struct timeval lastconnecttry;
114     uint8_t connectionok;
115     int nextid;
116     struct request *requests;
117     uint8_t newrq;
118     pthread_mutex_t newrq_mutex;
119     pthread_cond_t newrq_cond;
120 };
121
122 void errx(char *format, ...);
123 void err(char *format, ...);
124 char *stringcopy(char *s, int len);
125 char *addr2string(struct sockaddr *addr, socklen_t len);
126 int bindport(int type, char *port);
127 int connectport(int type, char *host, char *port);