summaryrefslogtreecommitdiff
path: root/config.md
blob: 59bbed0be33160492b645a93b5035d51942faadd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
---
title: Configuring and Building HaxIRCd
---

HaxIRCd does not use an external configuration format. Instead, it is configured
via [`config.c`](#codeconfigccode), which is just another C source file.

Build options are also significant in determining the behavior of HaxIRCd. Refer
to the [`.makeopts`](#codemakeoptscode) section for details.

**Please note that there is no guarantee that the documentation here is
up-to-date. Refer to `config.h` to understand the definitions that `config.c`
should contain. Refer to the `Makefile` to understand the build options.**

# `config.c`
This is the main configuration file. When building HaxIRCd, it is built into an
object file and is linked into the main `HaxIRCd.so` shared object.

```c
#include <time.h>

#include "config.h"
#include "general_network.h"
#include "protocols.h"

#ifdef USE_SERVER
#include "server_network.h"
#endif

#ifdef USE_SERVER
struct server_config SERVER_CONFIG[] = {
	{
	 /*
	  * The name of the remote server. Must be in a valid DNS format,
	  * but doesn't have to resolve.
	  */
	 .name = STRING("peer.server.name"),

	 /*
	  * The server ID of the remote server. The format depends on the
	  * protocol, but most protocols expect a three-byte string,
	  * where the first byte is a number and the two subsequent
	  * bytes are alphanumeric. Letters should usually be in
	  * uppercase. Server IDs are not translted between protocols
	  * so a uniform format is generally required.
	  */
	 .sid = STRING("1UL"),

	 /*
	  * Passwords, should be self-explanatory.
	  */
	 .in_pass = STRING("password-to-expect-from-peer"),
	 .out_pass = STRING("password-to-send-to-peer"),

	 /*
	  * Which protocol to use. Currently, only InspIRCd protocols are
	  * supported. A custom HaxIRCd binary protocol is planned, and
	  * support for TS6, UnrealIRCd, and other protocols may be added.
	  *
	  * INSPIRCD4_PROTOCOL: the 1206 protocol native to InspIRCd v4
	  * INSPIRCD3_PROTOCOL: the 1205 protocol native to InspIRCd v3
	  * INSPIRCD2_PROTOCOL: the 1202 protocol native to InspIRCd v2
	  */
	 .protocol = INSPIRCD4_PROTOCOL,

	 .ignore_remote_unlinks = 0,
	 .ignore_remote_kills = 1,
	 .ignore_local_kills = 1,

	 /*
	  * Set autoconnect to 1 if you want to connect to this server.
	  * Set autoconnect to 0 if you want this server to connect to you.
	  */
	 .autoconnect = 1,

	 /*
	  * This option is ignored when autoconnect=0.
	  *
	  * TLS links are highly recommended if not connecting to localhost
	  * or otherwise over a secure channel such as WireGuard. Although
	  * GnuTLS is supported, the primary developers use OpenSSL, and
	  * OpenSSL is more common anyways.
	  * Buffering is also highly recommended as it measurably improves
	  * performance.
	  *
	  * NET_TYPE_PLAINTEXT: Plain TCP link
	  * NET_TYPE_GNUTLS: GnuTLS link
	  * NET_TYPE_OPENSSL: OpenSSL link
	  * NET_TYPE_PLAINTEXT_BUFFERED: Plain TCP link with buffering
	  * NET_TYPE_GNUTLS_BUFFERED: GnuTLS link with buffering
	  * NET_TYPE_OPENSSL_BUFFERED: OpenSSL link with buffering
	  */
	 .autoconnect_type = NET_TYPE_PLAINTEXT,

	 /*
	  * The address and the port to connect to. The address may be
	  * either an IP address or a resolvable domain.
	  */
	 .address = STRING("127.0.0.1"),
	 .port = STRING("7000"),
	},
};

size_t SERVER_CONFIG_LEN = sizeof(SERVER_CONFIG) / sizeof(*SERVER_CONFIG);
#endif

/*
 * Our own server ID. Most protocols expect a three-byte string,
 * where the first byte is a number and the two subsequent
 * bytes are alphanumeric. Letters should usually be in
 * uppercase. Server IDs are not translted between protocols
 * so a uniform format is generally required.
 */
struct string SID = STRING("5HX");

/*
 * Our server name. Well-formed DNS, doesn't have to resolve.
 */
struct string SERVER_NAME = STRING("haxircd.int");

/*
 * Our server description.
 */
struct string SERVER_FULLNAME = STRING("HaxIRCd");

/*
 * How many seconds of idleness should cause a PING to be sent.
 */
time_t PING_INTERVAL = 60;

/*
 * TLS certificates. If using Let's Encrypt or a similar provider,
 * supply the "fullchain" in *_CERT_PATH and the "privkey" in
 * *_KEY_PATH.
 *
 * NOTE: We do not check the validity of TLS certificates yet. CertFP
 * authentication will be added later.
 */
#if (defined(USE_GNUTLS_NETWORK) || defined(USE_GNUTLS_BUFFERED_NETWORK))
char GNUTLS_USE_SYSTEM_TRUST = 1;
char *GNUTLS_CERT_PATH = "/path/to/fullchain.pem";
char *GNUTLS_KEY_PATH = "/path/to/privkey.pem";
#endif
#if (defined(USE_OPENSSL_NETWORK) || defined(USE_OPENSSL_BUFFERED_NETWORK))
char OPENSSL_USE_SYSTEM_TRUST = 1;
char *OPENSSL_CERT_PATH = "/path/to/fullchain.pem";
char *OPENSSL_KEY_PATH = "/path/to/privkey.pem";
#endif

/*
 * The following section defines the port that each (network, protocol)
 * should listen on.
 */
#ifdef USE_SERVER
unsigned short SERVER_PORTS[NUM_NET_TYPES][NUM_PROTOCOLS] = {
#if (defined(USE_PLAINTEXT_NETWORK) || defined(USE_PLAINTEXT_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD2_PROTOCOL] = 7001,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD3_PROTOCOL] = 7002,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD4_PROTOCOL] = 7003,
#endif
#endif
#if (defined(USE_GNUTLS_NETWORK) || defined(USE_GNUTLS_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD2_PROTOCOL] = 7011,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD3_PROTOCOL] = 7012,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD4_PROTOCOL] = 7013,
#endif
#endif
#if (defined(USE_OPENSSL_NETWORK) || defined(USE_OPENSSL_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD2_PROTOCOL] = 7021,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD3_PROTOCOL] = 7022,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD4_PROTOCOL] = 7023,
#endif
#endif
};

/*
 * The following section defines the backlog of each protocol's
 * listening. This is passed into the backlog argument of listen(2).
 */
size_t SERVER_LISTEN[NUM_NET_TYPES][NUM_PROTOCOLS] = {
#if (defined(USE_PLAINTEXT_NETWORK) || defined(USE_PLAINTEXT_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD2_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD3_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD4_PROTOCOL] = 16,
#endif
#endif
#if (defined(USE_GNUTLS_NETWORK) || defined(USE_GNUTLS_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD2_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD3_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD4_PROTOCOL] = 16,
#endif
#endif
#if (defined(USE_OPENSSL_NETWORK) || defined(USE_OPENSSL_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD2_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD3_PROTOCOL] = 16,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD4_PROTOCOL] = 16,
#endif
#endif
};

/*
 * The following section defines whether HaxIRCd should listen for
 * incoming connections at all, for each (network, protocol) combination.
 */
char SERVER_INCOMING[NUM_NET_TYPES][NUM_PROTOCOLS] = {
#if (defined(USE_PLAINTEXT_NETWORK) || defined(USE_PLAINTEXT_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD2_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD3_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_PLAINTEXT][INSPIRCD4_PROTOCOL] = 1,
#endif
#endif
#if (defined(USE_GNUTLS_NETWORK) || defined(USE_GNUTLS_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD2_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD3_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_GNUTLS][INSPIRCD4_PROTOCOL] = 1,
#endif
#endif
#if (defined(USE_OPENSSL_NETWORK) || defined(USE_OPENSSL_BUFFERED_NETWORK))
#ifdef USE_INSPIRCD2_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD2_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD3_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD3_PROTOCOL] = 1,
#endif
#ifdef USE_INSPIRCD4_PROTOCOL
	[NET_TYPE_OPENSSL][INSPIRCD4_PROTOCOL] = 1,
#endif
#endif
};
#endif

/*
 * The following section includes configuration for the primary
 * pseudoclient, HaxServ.
 */
#ifdef USE_HAXSERV_PSEUDOCLIENT
struct string HAXSERV_UID = STRING("5HX000000");
struct string HAXSERV_NICK = STRING("HaxServ");
struct string HAXSERV_FULLNAME = STRING("HaxServ");
struct string HAXSERV_IDENT = STRING("HaxServ");
struct string HAXSERV_VHOST = STRING("services/HaxServ");
struct string HAXSERV_HOST = STRING("/dev/full");
struct string HAXSERV_ADDRESS = STRING("/dev/null");
struct string HAXSERV_PREJOIN_CHANNELS[] = {
	STRING("#chat"),
	STRING("#services"),
	STRING("#spam"),
};
size_t HAXSERV_NUM_PREJOIN_CHANNELS =
    sizeof(HAXSERV_PREJOIN_CHANNELS) / sizeof(*HAXSERV_PREJOIN_CHANNELS);
struct string HAXSERV_COMMAND_PREFIX = STRING("HaxServ: ");
struct string HAXSERV_REQUIRED_OPER_TYPE = STRING("NetAdmin");
struct string HAXSERV_LOG_CHANNEL = STRING("#services");
#endif

/*
 * You may specify the size of the ring buffers for each buffered
 * network backend here. They must be larger than any full message;
 * otherwise, undefined behavior occurs.
 */
#ifdef USE_PLAINTEXT_BUFFERED_NETWORK
size_t PLAINTEXT_BUFFERED_LEN = 1048576;
#endif
#ifdef USE_GNUTLS_BUFFERED_NETWORK
size_t GNUTLS_BUFFERED_LEN = 1048576;
#endif
#ifdef USE_OPENSSL_BUFFERED_NETWORK
size_t OPENSSL_BUFFERED_LEN = 1048576;
#endif

/*
 * The following section includes configuration for the IRC
 * services, such as NickServ.
 */
#ifdef USE_SERVICES_PSEUDOCLIENT
struct string NICKSERV_UID = STRING("5HX0000NS");
struct string NICKSERV_NICK = STRING("NickServ");
struct string NICKSERV_FULLNAME = STRING("Nickname Services");
struct string NICKSERV_IDENT = STRING("NickServ");
struct string NICKSERV_VHOST = STRING("services/NickServ");
struct string NICKSERV_HOST = STRING("localhost");
struct string NICKSERV_ADDRESS = STRING("/dev/null");
struct string SERVICES_CHANNEL = STRING("#services");
size_t SERVICES_DB_MAX_SIZE = 104857600;
struct string SERVICES_DB_PATH = STRING("services.mdb");
#endif
```

# `.makeopts`
Build options are significant in determining the functionality and behavior
of HaxIRCd. You may specify build options in a `.makeopts` file, such as
the following:

```makefile
# The following options control which network transports are built into
# HaxIRCd.
# PLAINTEXT: Use plain TCP sockets.
# GNUTLS:    Use TLS over TCP, as provided by GnuTLS.
# OPENSSL:   Use TLS over TCP, as provided by OpenSSL/LibreSSL.
# The BUFFERED variants causes sending to occur over a separate thread
# and uses a ring buffer to buffer messages, until full messages are
# ready to send. These usually perform better than their unbuffered
# counterparts. The size of the ring buffer is configurable in
# config.c.
LAST_PLAINTEXT_NETWORK = 1
LAST_GNUTLS_NETWORK =
LAST_OPENSSL_NETWORK = 1
LAST_PLAINTEXT_BUFFERED_NETWORK = 1
LAST_GNUTLS_BUFFERED_NETWORK =
LAST_OPENSSL_BUFFERED_NETWORK = 1

# CLIENT: Support connections from clients. (Not implemented yet.)
# SERVER: Support s2s connections.
LAST_CLIENT =
LAST_SERVER = 1

# The following control the server protocols compiled into HaxIRCd.
# You should enable at least one of them. Note that InspIRCd v(n+1) is
# compatible with INSPIRCD(n)_PROTOCOL.
LAST_INSPIRCD2_PROTOCOL = 1
LAST_INSPIRCD3_PROTOCOL = 1
LAST_INSPIRCD4_PROTOCOL = 1

# The following control pseudoclients compiled into HaxIRCd.
LAST_HAXSERV_PSEUDOCLIENT = 1
LAST_SERVICES_PSEUDOCLIENT = 1

# When SAFE_STACK is enabled, -fstack-check is added to CFLAGS.
LAST_SAFE_STACK = 1

# The following control how locks are handled in HaxIRCd.
# ATOMICS are recommended whenever supported. FUTEX is recommended on Linux.
# MISERABLE_SPINLOCKS may be used on systems that support neither POSIX
# semaphores or futexes. If neither FUTEX or MISERABLE_SPINLOCKS are
# defined, POSIX semaphores are used.
LAST_FUTEX = 1
LAST_MISERABLE_SPINLOCKS =
LAST_ATOMICS = 1

# You must enable at least one of the below. Enabling both is recommended,
# but if one of them is undesirable for whatever reason, you could turn it
# off here.
LAST_IPv4 = 1
LAST_IPv6 = 1

# General options.
LAST_CFLAGS =
LAST_LDFLAGS = -lpthread
LAST_CC = cc
```

You may also change individual parameters by passing arguments to Make. For
example, to enable IPv6 and InspIRCd v3 protocol support in the current build
and all future builds:

```sh
make IPv6=1 INSPIRCD3_PROTOCOL=1
```

# Building

```sh
make
```

# Running

```sh
./HaxIRCd
```