1 /*
2  *	aprsc
3  *
4  *	(c) Heikki Hannikainen, OH7LZB <hessu@hes.iki.fi>
5  *
6  *     This program is licensed under the BSD license, which can be found
7  *     in the file LICENSE.
8  *
9  */
10 
11 #ifndef CONFIG_H
12 #define CONFIG_H
13 
14 #define PROGNAME "aprsc"
15 #define CRLF "\r\n"
16 
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <inttypes.h>
23 #include <netdb.h>
24 
25 #include "ac-hdrs.h"
26 #include "acl.h"
27 #include "ssl.h"
28 
29 #ifndef AI_PASSIVE
30 #include "netdb6.h"
31 #endif
32 
33 /* do we use posix capabilities? */
34 #ifdef HAVE_PRCTL_H
35 #ifdef HAVE_CAPABILITY_H
36 #define USE_POSIX_CAP
37 #endif
38 #endif
39 
40 /* do we use eventfd? No. */
41 #undef HAVE_EVENTFD_H
42 #ifdef HAVE_EVENTFD_H
43 #include <sys/eventfd.h>
44 #ifdef EFD_NONBLOCK
45 #ifdef EFD_CLOEXEC
46 #define USE_EVENTFD
47 #endif
48 #endif
49 #endif
50 
51 /* do we use clock_gettime to get monotonic time? */
52 #include <time.h>
53 #ifdef HAVE_CLOCK_GETTIME
54 #ifdef CLOCK_MONOTONIC
55 #define USE_CLOCK_GETTIME
56 #endif
57 #endif
58 
59 /* SCTP? */
60 #ifdef HAVE_NETINET_SCTP_H
61 #if defined(SOCK_SEQPACKET) && defined(IPPROTO_SCTP)
62 #define USE_SCTP
63 #endif
64 #endif
65 
66 extern int fork_a_daemon;	/* fork a daemon */
67 
68 extern int dump_requests;	/* print requests */
69 extern int dump_splay;		/* print splay tree information */
70 
71 extern int workers_configured;	/* number of workers to run */
72 
73 extern int stats_interval;
74 extern int expiry_interval;
75 
76 extern int pbuf_global_expiration;
77 extern int pbuf_global_dupe_expiration;
78 
79 
80 extern int obuf_size;
81 extern int ibuf_size;
82 
83 extern int new_fileno_limit;
84 extern int maxclients;
85 
86 extern int lastposition_storetime;
87 extern int dupefilter_storetime;
88 extern int heard_list_storetime;
89 extern int courtesy_list_storetime;
90 extern int upstream_timeout;
91 extern int client_timeout;
92 extern int client_login_timeout;
93 
94 extern int disallow_unverified;		/* don't allow unverified clients to transmit packets */
95 extern int quirks_mode;
96 
97 extern int verbose;
98 
99 extern char *serverid;
100 extern int serverid_len;
101 extern char *passcode;
102 extern char *myemail;
103 extern char *myadmin;
104 extern char *http_status_options;
105 extern char *fake_version;
106 
107 extern char **disallow_srccall_glob;
108 extern char **disallow_login_glob;
109 
110 extern char def_cfgfile[];
111 extern char *cfgfile;
112 extern char *pidfile;
113 extern char *rundir;
114 extern char *webdir;
115 extern char def_logname[];
116 extern char *logname;
117 extern char *chrootdir;
118 extern char *setuid_s;
119 
120 extern int disallow_other_protocol_id;
121 extern char q_protocol_id;
122 
123 #define LISTEN_MAX_FILTERS 10
124 
125 struct listen_config_t {
126 	struct listen_config_t *next;
127 	struct listen_config_t **prevp; /* pointer to the *next pointer in the previous node */
128 
129 	int   id;			/* id of listener config */
130 
131 	const char *proto;		/* protocol: tcp / udp / sctp */
132 	const char *name;		/* name of socket */
133 	const char *host;		/* hostname or dotted-quad IP to bind the UDP socket to, default INADDR_ANY */
134 	int   portnum;
135 	int   clients_max;
136 	int   corepeer;			/* special listener for corepeer packets */
137 	int   hidden;
138 
139 	const char *keyfile;		/* SSL server key file */
140 	const char *certfile;		/* SSL server certificate file */
141 	const char *cafile;		/* SSL ca certificate for validating client certs */
142 	const char *crlfile;		/* SSL certificate revocation file */
143 
144 	struct addrinfo *ai;
145 	struct acl_t *acl;
146 
147 	const char *filters[LISTEN_MAX_FILTERS];		/* up to 10 filters, NULL when not defined */
148 
149 	int client_flags;	/* cflags set for clients of this socket */
150 
151 	/* reconfiguration support flags */
152 	int   changed;		/* configuration has changed */
153 };
154 
155 struct peerip_config_t {
156 	struct peerip_config_t *next;
157 	struct peerip_config_t **prevp; /* pointer to the *next pointer in the previous node */
158 
159 	const char *name;			/* name of socket */
160 	const char *host;			/* hostname or dotted-quad IP to bind the UDP socket to, default INADDR_ANY */
161 	const char *serverid;			/* expected/configured serverid of remote */
162 	struct addrinfo *ai;
163 
164 	int   af;
165 	int remote_port;
166 	int local_port;
167 
168 
169 	int client_flags;
170 };
171 
172 struct uplink_config_t {
173 	struct uplink_config_t *next;
174 	struct uplink_config_t **prevp; /* pointer to the *next pointer in the previous node */
175 
176 	const char *name;			/* name of socket */
177 	const char *proto;
178 	const char *host;			/* hostname or dotted-quad IP to bind the UDP socket to, default INADDR_ANY */
179 	const char *port;
180 
181 	const char *keyfile;			/* SSL client key file */
182 	const char *certfile;			/* SSL client certificate file */
183 	const char *cafile;			/* SSL ca certificate for validating server certs */
184 	const char *crlfile;			/* SSL certificate revocation file */
185 
186 #ifdef USE_SSL
187 	struct ssl_t *ssl;			/* SSL state */
188 #endif
189 
190 	int client_flags;
191 	int state;				/* the state of the uplink */
192 	void *client_ptr;			/* pointer to the client structure for state matching */
193 };
194 
195 #define UPLINK_ST_UNKNOWN	-1
196 #define UPLINK_ST_NOT_LINKED	0
197 #define UPLINK_ST_CONNECTING	1
198 #define UPLINK_ST_CONNECTED	2
199 #define UPLINK_ST_LINKED	3
200 
201 extern struct listen_config_t *listen_config;
202 extern struct peerip_config_t *peerip_config;
203 extern struct uplink_config_t *uplink_config_install;
204 extern int uplink_config_updated;
205 extern int listen_low_ports;
206 
207 extern struct sockaddr_in uplink_bind_v4;		/* address to bind when connecting out */
208 extern socklen_t uplink_bind_v4_len;
209 extern struct sockaddr_in6 uplink_bind_v6;		/* and the same for IPv6 */
210 extern socklen_t uplink_bind_v6_len;
211 
212 #define MAX_COREPEERS		16
213 
214 /* http server config */
215 
216 struct http_config_t {
217 	struct http_config_t *next;
218 	struct http_config_t **prevp;
219 
220 	char *host;			/* name of socket */
221 	int port;
222 
223 	int upload_port;
224 
225 	struct acl_t *acl;
226 };
227 
228 extern struct http_config_t *http_config;
229 
230 extern char *http_bind;
231 extern int http_port;
232 extern char *http_bind_upload;
233 extern int http_port_upload;
234 
235 extern int parse_args_noshell(char *argv[],char *cmd);
236 extern void sanitize_ascii_string(char *s);
237 
238 extern void free_uplink_config(struct uplink_config_t **lc);
239 extern struct listen_config_t *find_listen_config_id(struct listen_config_t *l, int id);
240 
241 extern int read_config(void);
242 extern void free_config(void);
243 
244 #endif
245 
246