]> jfr.im git - irc/freenode/solanum.git/blame - ircd/newconf.c
add ConfigFileEntry.oper_secure_only, to require TLS to oper up (#76)
[irc/freenode/solanum.git] / ircd / newconf.c
CommitLineData
212380e3 1/* This code is in the public domain.
212380e3
WP
2 */
3
4#include "stdinc.h"
5
6#ifdef HAVE_LIBCRYPTO
7#include <openssl/pem.h>
8#include <openssl/rsa.h>
9#endif
10
212380e3 11#include "newconf.h"
212380e3 12#include "ircd_defs.h"
4016731b 13#include "logger.h"
212380e3
WP
14#include "s_conf.h"
15#include "s_user.h"
16#include "s_newconf.h"
17#include "send.h"
18#include "setup.h"
19#include "modules.h"
20#include "listener.h"
21#include "hostmask.h"
22#include "s_serv.h"
212380e3
WP
23#include "hash.h"
24#include "cache.h"
25#include "ircd.h"
26#include "snomask.h"
c6d72037 27#include "sslproc.h"
c53ca1e0 28#include "wsproc.h"
f8606875 29#include "privilege.h"
63eb8567 30#include "chmode.h"
f018ed84 31#include "certfp.h"
212380e3
WP
32
33#define CF_TYPE(x) ((x) & CF_MTYPE)
34
02270e96 35static int yy_defer_accept = 1;
c53ca1e0 36static int yy_wsock = 0;
02270e96 37
212380e3 38struct TopConf *conf_cur_block;
e12981c0 39static char *conf_cur_block_name = NULL;
212380e3 40
330fc5c1 41static rb_dlink_list conf_items;
212380e3
WP
42
43static struct ConfItem *yy_aconf = NULL;
44
45static struct Class *yy_class = NULL;
46
47static struct remote_conf *yy_shared = NULL;
48static struct server_conf *yy_server = NULL;
49
330fc5c1
WP
50static rb_dlink_list yy_aconf_list;
51static rb_dlink_list yy_oper_list;
330fc5c1 52static rb_dlink_list yy_cluster_list;
212380e3
WP
53static struct oper_conf *yy_oper = NULL;
54
55static struct alias_entry *yy_alias = NULL;
56
7f24f506
AC
57static char *yy_dnsbl_entry_host = NULL;
58static char *yy_dnsbl_entry_reason = NULL;
59static uint8_t yy_dnsbl_entry_iptype = 0;
60static rb_dlink_list yy_dnsbl_entry_filters = { NULL, NULL, 0 };
0a1e77c2 61
8275e270
EM
62static char *yy_opm_address_ipv4 = NULL;
63static char *yy_opm_address_ipv6 = NULL;
64static uint16_t yy_opm_port_ipv4 = 0;
65static uint16_t yy_opm_port_ipv6 = 0;
9bba0f61 66static int yy_opm_timeout = 0;
51fa2ab8 67static rb_dlink_list yy_opm_scanner_list;
8275e270 68
f8606875 69static char *yy_privset_extends = NULL;
212380e3
WP
70
71static const char *
72conf_strtype(int type)
73{
dceac3e4 74 switch (CF_TYPE(type))
212380e3
WP
75 {
76 case CF_INT:
77 return "integer value";
78 case CF_STRING:
79 return "unquoted string";
80 case CF_YESNO:
81 return "yes/no value";
82 case CF_QSTRING:
83 return "quoted string";
84 case CF_TIME:
85 return "time/size value";
86 default:
87 return "unknown type";
88 }
89}
90
91int
023c36ae 92add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
212380e3
WP
93 int (*efunc) (struct TopConf *), struct ConfEntry *items)
94{
95 struct TopConf *tc;
96
eddc2ab6 97 tc = rb_malloc(sizeof(struct TopConf));
212380e3 98
d7f753cd 99 tc->tc_name = name;
212380e3
WP
100 tc->tc_sfunc = sfunc;
101 tc->tc_efunc = efunc;
102 tc->tc_entries = items;
103
330fc5c1 104 rb_dlinkAddAlloc(tc, &conf_items);
212380e3
WP
105 return 0;
106}
107
108struct TopConf *
109find_top_conf(const char *name)
110{
330fc5c1 111 rb_dlink_node *d;
212380e3
WP
112 struct TopConf *tc;
113
5cefa1d6 114 RB_DLINK_FOREACH(d, conf_items.head)
212380e3
WP
115 {
116 tc = d->data;
f956cb0f 117 if(rb_strcasecmp(tc->tc_name, name) == 0)
212380e3
WP
118 return tc;
119 }
120
121 return NULL;
122}
123
124
125struct ConfEntry *
126find_conf_item(const struct TopConf *top, const char *name)
127{
128 struct ConfEntry *cf;
330fc5c1 129 rb_dlink_node *d;
212380e3
WP
130
131 if(top->tc_entries)
132 {
133 int i;
134
135 for(i = 0; top->tc_entries[i].cf_type; i++)
136 {
137 cf = &top->tc_entries[i];
138
f956cb0f 139 if(!rb_strcasecmp(cf->cf_name, name))
212380e3
WP
140 return cf;
141 }
142 }
143
5cefa1d6 144 RB_DLINK_FOREACH(d, top->tc_items.head)
212380e3
WP
145 {
146 cf = d->data;
f956cb0f 147 if(rb_strcasecmp(cf->cf_name, name) == 0)
212380e3
WP
148 return cf;
149 }
150
151 return NULL;
152}
153
154int
155remove_top_conf(char *name)
156{
157 struct TopConf *tc;
330fc5c1 158 rb_dlink_node *ptr;
212380e3
WP
159
160 if((tc = find_top_conf(name)) == NULL)
161 return -1;
162
330fc5c1 163 if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL)
212380e3
WP
164 return -1;
165
330fc5c1 166 rb_dlinkDestroy(ptr, &conf_items);
637c4932 167 rb_free(tc);
212380e3
WP
168
169 return 0;
170}
171
172static void
173conf_set_serverinfo_name(void *data)
174{
175 if(ServerInfo.name == NULL)
176 {
177 const char *s;
178 int dots = 0;
179
180 for(s = data; *s != '\0'; s++)
181 {
182 if(!IsServChar(*s))
183 {
184 conf_report_error("Ignoring serverinfo::name "
185 "-- bogus servername.");
186 return;
187 }
188 else if(*s == '.')
189 ++dots;
190 }
191
192 if(!dots)
193 {
194 conf_report_error("Ignoring serverinfo::name -- must contain '.'");
195 return;
196 }
197
198 s = data;
199
200 if(IsDigit(*s))
201 {
202 conf_report_error("Ignoring serverinfo::name -- cannot begin with digit.");
203 return;
204 }
205
206 /* the ircd will exit() in main() if we dont set one */
207 if(strlen(s) <= HOSTLEN)
47a03750 208 ServerInfo.name = rb_strdup((char *) data);
212380e3
WP
209 }
210}
211
212static void
213conf_set_serverinfo_sid(void *data)
214{
215 char *sid = data;
216
217 if(ServerInfo.sid[0] == '\0')
218 {
219 if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) ||
220 !IsIdChar(sid[2]) || sid[3] != '\0')
221 {
222 conf_report_error("Ignoring serverinfo::sid "
223 "-- bogus sid.");
224 return;
225 }
226
0982871a 227 rb_strlcpy(ServerInfo.sid, sid, sizeof(ServerInfo.sid));
212380e3
WP
228 }
229}
230
231static void
232conf_set_serverinfo_network_name(void *data)
233{
234 char *p;
235
236 if((p = strchr((char *) data, ' ')))
237 *p = '\0';
238
637c4932 239 rb_free(ServerInfo.network_name);
47a03750 240 ServerInfo.network_name = rb_strdup((char *) data);
212380e3
WP
241}
242
243static void
244conf_set_serverinfo_vhost(void *data)
245{
d4214e94
SA
246 struct rb_sockaddr_storage addr;
247
17809d2d 248 if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET)
212380e3 249 {
532f83a7 250 conf_report_error("Invalid IPv4 address for server vhost (%s)", (char *) data);
212380e3
WP
251 return;
252 }
d4214e94
SA
253
254 ServerInfo.bind4 = addr;
212380e3
WP
255}
256
257static void
258conf_set_serverinfo_vhost6(void *data)
259{
d4214e94 260
d4214e94
SA
261 struct rb_sockaddr_storage addr;
262
17809d2d 263 if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET6)
212380e3 264 {
532f83a7 265 conf_report_error("Invalid IPv6 address for server vhost (%s)", (char *) data);
212380e3
WP
266 return;
267 }
268
d4214e94 269 ServerInfo.bind6 = addr;
212380e3
WP
270}
271
b583faf9
WP
272static void
273conf_set_serverinfo_nicklen(void *data)
274{
7b42eab6 275 ConfigFileEntry.nicklen = (*(unsigned int *) data) + 1;
b583faf9
WP
276
277 if (ConfigFileEntry.nicklen > NICKLEN)
278 {
279 conf_report_error("Warning -- ignoring serverinfo::nicklen -- provided nicklen (%u) is greater than allowed nicklen (%u)",
ca8ff483 280 ConfigFileEntry.nicklen - 1, NICKLEN - 1);
b583faf9
WP
281 ConfigFileEntry.nicklen = NICKLEN;
282 }
ca8ff483
JT
283 else if (ConfigFileEntry.nicklen < 9 + 1)
284 {
285 conf_report_error("Warning -- serverinfo::nicklen is too low (%u) -- forcing 9",
4f0d2b58 286 ConfigFileEntry.nicklen - 1);
ca8ff483
JT
287 ConfigFileEntry.nicklen = 9 + 1;
288 }
b583faf9
WP
289}
290
212380e3
WP
291static void
292conf_set_modules_module(void *data)
293{
212380e3
WP
294 char *m_bn;
295
b7a689d1 296 m_bn = rb_basename((char *) data);
212380e3 297
e55a9d6a 298 if(findmodule_byname(m_bn) == NULL)
aa483e55 299 load_one_module((char *) data, MAPI_ORIGIN_EXTENSION, false);
212380e3 300
637c4932 301 rb_free(m_bn);
212380e3
WP
302}
303
304static void
305conf_set_modules_path(void *data)
306{
212380e3 307 mod_add_path((char *) data);
212380e3
WP
308}
309
310struct mode_table
311{
312 const char *name;
313 int mode;
314};
315
316/* *INDENT-OFF* */
317static struct mode_table umode_table[] = {
212380e3
WP
318 {"deaf", UMODE_DEAF },
319 {"invisible", UMODE_INVISIBLE },
320 {"locops", UMODE_LOCOPS },
321 {"noforward", UMODE_NOFORWARD },
212380e3
WP
322 {"servnotice", UMODE_SERVNOTICE},
323 {"wallop", UMODE_WALLOP },
324 {"operwall", UMODE_OPERWALL },
325 {NULL, 0}
326};
327
19c13ce5 328static struct mode_table oper_table[] = {
212380e3 329 {"encrypted", OPER_ENCRYPTED },
b1594414 330 {"need_ssl", OPER_NEEDSSL },
212380e3
WP
331 {NULL, 0}
332};
333
334static struct mode_table auth_table[] = {
fbe8d087
EM
335 {"encrypted", CONF_FLAGS_ENCRYPTED },
336 {"spoof_notice", CONF_FLAGS_SPOOF_NOTICE },
337 {"exceed_limit", CONF_FLAGS_NOLIMIT },
338 {"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL },
339 {"proxy_exempt", CONF_FLAGS_EXEMPTPROXY },
340 {"kline_exempt", CONF_FLAGS_EXEMPTKLINE },
341 {"flood_exempt", CONF_FLAGS_EXEMPTFLOOD },
342 {"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT },
343 {"shide_exempt", CONF_FLAGS_EXEMPTSHIDE },
344 {"jupe_exempt", CONF_FLAGS_EXEMPTJUPE },
345 {"resv_exempt", CONF_FLAGS_EXEMPTRESV },
346 {"no_tilde", CONF_FLAGS_NO_TILDE },
347 {"need_ident", CONF_FLAGS_NEED_IDENTD },
348 {"have_ident", CONF_FLAGS_NEED_IDENTD },
349 {"need_ssl", CONF_FLAGS_NEED_SSL },
350 {"need_sasl", CONF_FLAGS_NEED_SASL },
351 {"extend_chans", CONF_FLAGS_EXTEND_CHANS },
c6ad9b0c 352 {"allow_sctp", CONF_FLAGS_ALLOW_SCTP },
67e05d5b 353 {"kline_spoof_ip", CONF_FLAGS_KLINE_SPOOF },
212380e3
WP
354 {NULL, 0}
355};
356
357static struct mode_table connect_table[] = {
358 { "autoconn", SERVER_AUTOCONN },
359 { "compressed", SERVER_COMPRESSED },
360 { "encrypted", SERVER_ENCRYPTED },
361 { "topicburst", SERVER_TB },
6003ce76 362 { "sctp", SERVER_SCTP },
c6d72037 363 { "ssl", SERVER_SSL },
087555a0 364 { "no-export", SERVER_NO_EXPORT },
212380e3
WP
365 { NULL, 0 },
366};
367
368static struct mode_table cluster_table[] = {
369 { "kline", SHARED_PKLINE },
370 { "tkline", SHARED_TKLINE },
371 { "unkline", SHARED_UNKLINE },
372 { "locops", SHARED_LOCOPS },
373 { "xline", SHARED_PXLINE },
374 { "txline", SHARED_TXLINE },
375 { "unxline", SHARED_UNXLINE },
376 { "resv", SHARED_PRESV },
377 { "tresv", SHARED_TRESV },
378 { "unresv", SHARED_UNRESV },
379 { "all", CLUSTER_ALL },
380 {NULL, 0}
381};
212380e3
WP
382/* *INDENT-ON* */
383
384static int
385find_umode(struct mode_table *tab, const char *name)
386{
387 int i;
388
389 for (i = 0; tab[i].name; i++)
390 {
391 if(strcmp(tab[i].name, name) == 0)
392 return tab[i].mode;
393 }
394
395 return -1;
396}
397
398static void
399set_modes_from_table(int *modes, const char *whatis, struct mode_table *tab, conf_parm_t * args)
400{
401 for (; args; args = args->next)
402 {
403 const char *umode;
404 int dir = 1;
405 int mode;
406
dceac3e4 407 if(CF_TYPE(args->type) != CF_STRING)
212380e3
WP
408 {
409 conf_report_error("Warning -- %s is not a string; ignoring.", whatis);
410 continue;
411 }
412
413 umode = args->v.string;
414
415 if(*umode == '~')
416 {
417 dir = 0;
418 umode++;
419 }
420
421 mode = find_umode(tab, umode);
422
423 if(mode == -1)
424 {
425 conf_report_error("Warning -- unknown %s %s.", whatis, args->v.string);
426 continue;
427 }
428
429 if(mode)
430 {
431 if(dir)
432 *modes |= mode;
433 else
434 *modes &= ~mode;
435 }
436 else
437 *modes = 0;
438 }
439}
440
f8606875
WP
441static void
442conf_set_privset_extends(void *data)
443{
444 yy_privset_extends = rb_strdup((char *) data);
445}
446
447static void
448conf_set_privset_privs(void *data)
449{
450 char *privs = NULL;
451 conf_parm_t *args = data;
452
453 for (; args; args = args->next)
454 {
455 if (privs == NULL)
456 privs = rb_strdup(args->v.string);
457 else
458 {
459 char *privs_old = privs;
460
461 privs = rb_malloc(strlen(privs_old) + 1 + strlen(args->v.string) + 1);
065f67db 462 strcpy(privs, privs_old);
f8606875
WP
463 strcat(privs, " ");
464 strcat(privs, args->v.string);
465
466 rb_free(privs_old);
467 }
468 }
469
470 if (privs)
471 {
472 if (yy_privset_extends)
473 {
474 struct PrivilegeSet *set = privilegeset_get(yy_privset_extends);
475
476 if (!set)
477 {
49b0375d 478 conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name);
f8606875 479
49b0375d 480 set = privilegeset_get("default");
f8606875
WP
481 }
482
483 privilegeset_extend(set, conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
484
485 rb_free(yy_privset_extends);
486 yy_privset_extends = NULL;
487 }
488 else
489 privilegeset_set_new(conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
490
491 rb_free(privs);
492 }
493}
494
212380e3
WP
495static int
496conf_begin_oper(struct TopConf *tc)
497{
330fc5c1 498 rb_dlink_node *ptr;
637c4932 499 rb_dlink_node *next_ptr;
212380e3
WP
500
501 if(yy_oper != NULL)
502 {
503 free_oper_conf(yy_oper);
504 yy_oper = NULL;
505 }
506
637c4932 507 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
212380e3
WP
508 {
509 free_oper_conf(ptr->data);
330fc5c1 510 rb_dlinkDestroy(ptr, &yy_oper_list);
212380e3
WP
511 }
512
513 yy_oper = make_oper_conf();
10847f65 514 yy_oper->flags |= OPER_ENCRYPTED;
212380e3
WP
515
516 return 0;
517}
518
519static int
520conf_end_oper(struct TopConf *tc)
521{
522 struct oper_conf *yy_tmpoper;
330fc5c1 523 rb_dlink_node *ptr;
637c4932 524 rb_dlink_node *next_ptr;
212380e3
WP
525
526 if(conf_cur_block_name != NULL)
527 {
528 if(strlen(conf_cur_block_name) > OPERNICKLEN)
529 conf_cur_block_name[OPERNICKLEN] = '\0';
530
47a03750 531 yy_oper->name = rb_strdup(conf_cur_block_name);
212380e3
WP
532 }
533
534 if(EmptyString(yy_oper->name))
535 {
536 conf_report_error("Ignoring operator block -- missing name.");
537 return 0;
538 }
539
540#ifdef HAVE_LIBCRYPTO
541 if(EmptyString(yy_oper->passwd) && EmptyString(yy_oper->rsa_pubkey_file))
542#else
543 if(EmptyString(yy_oper->passwd))
544#endif
545 {
546 conf_report_error("Ignoring operator block for %s -- missing password",
547 yy_oper->name);
548 return 0;
549 }
550
7d5acab7
JT
551
552 if (!yy_oper->privset)
553 yy_oper->privset = privilegeset_get("default");
554
212380e3
WP
555 /* now, yy_oper_list contains a stack of oper_conf's with just user
556 * and host in, yy_oper contains the rest of the information which
557 * we need to copy into each element in yy_oper_list
558 */
637c4932 559 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
212380e3
WP
560 {
561 yy_tmpoper = ptr->data;
562
47a03750 563 yy_tmpoper->name = rb_strdup(yy_oper->name);
212380e3
WP
564
565 /* could be an rsa key instead.. */
566 if(!EmptyString(yy_oper->passwd))
47a03750 567 yy_tmpoper->passwd = rb_strdup(yy_oper->passwd);
212380e3
WP
568
569 yy_tmpoper->flags = yy_oper->flags;
570 yy_tmpoper->umodes = yy_oper->umodes;
571 yy_tmpoper->snomask = yy_oper->snomask;
22c3b270 572 yy_tmpoper->privset = yy_oper->privset;
212380e3
WP
573
574#ifdef HAVE_LIBCRYPTO
575 if(yy_oper->rsa_pubkey_file)
576 {
577 BIO *file;
578
579 if((file = BIO_new_file(yy_oper->rsa_pubkey_file, "r")) == NULL)
580 {
581 conf_report_error("Ignoring operator block for %s -- "
582 "rsa_public_key_file cant be opened",
583 yy_tmpoper->name);
584 return 0;
585 }
023c36ae 586
212380e3
WP
587 yy_tmpoper->rsa_pubkey =
588 (RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL);
589
c422d2a0 590 (void)BIO_set_close(file, BIO_CLOSE);
212380e3
WP
591 BIO_free(file);
592
593 if(yy_tmpoper->rsa_pubkey == NULL)
594 {
595 conf_report_error("Ignoring operator block for %s -- "
596 "rsa_public_key_file key invalid; check syntax",
597 yy_tmpoper->name);
598 return 0;
599 }
600 }
63c7a68e
EM
601
602 if(!EmptyString(yy_oper->certfp))
462ae9d7 603 yy_tmpoper->certfp = rb_strdup(yy_oper->certfp);
212380e3
WP
604#endif
605
606 /* all is ok, put it on oper_conf_list */
330fc5c1 607 rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list);
212380e3
WP
608 }
609
610 free_oper_conf(yy_oper);
611 yy_oper = NULL;
612
613 return 0;
614}
615
616static void
617conf_set_oper_flags(void *data)
618{
619 conf_parm_t *args = data;
620
19c13ce5 621 set_modes_from_table(&yy_oper->flags, "flag", oper_table, args);
212380e3
WP
622}
623
ff31db84
WP
624static void
625conf_set_oper_fingerprint(void *data)
626{
462ae9d7
JT
627 if (yy_oper->certfp)
628 rb_free(yy_oper->certfp);
ff31db84
WP
629 yy_oper->certfp = rb_strdup((char *) data);
630}
631
22c3b270
WP
632static void
633conf_set_oper_privset(void *data)
634{
635 yy_oper->privset = privilegeset_get((char *) data);
636}
637
212380e3
WP
638static void
639conf_set_oper_user(void *data)
640{
641 struct oper_conf *yy_tmpoper;
642 char *p;
643 char *host = (char *) data;
644
645 yy_tmpoper = make_oper_conf();
646
647 if((p = strchr(host, '@')))
648 {
649 *p++ = '\0';
650
47a03750
VY
651 yy_tmpoper->username = rb_strdup(host);
652 yy_tmpoper->host = rb_strdup(p);
212380e3
WP
653 }
654 else
655 {
656
47a03750
VY
657 yy_tmpoper->username = rb_strdup("*");
658 yy_tmpoper->host = rb_strdup(host);
212380e3
WP
659 }
660
661 if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host))
662 {
663 conf_report_error("Ignoring user -- missing username/host");
664 free_oper_conf(yy_tmpoper);
665 return;
666 }
667
330fc5c1 668 rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list);
212380e3
WP
669}
670
671static void
672conf_set_oper_password(void *data)
673{
674 if(yy_oper->passwd)
675 {
676 memset(yy_oper->passwd, 0, strlen(yy_oper->passwd));
637c4932 677 rb_free(yy_oper->passwd);
212380e3
WP
678 }
679
47a03750 680 yy_oper->passwd = rb_strdup((char *) data);
212380e3
WP
681}
682
683static void
684conf_set_oper_rsa_public_key_file(void *data)
685{
686#ifdef HAVE_LIBCRYPTO
637c4932 687 rb_free(yy_oper->rsa_pubkey_file);
47a03750 688 yy_oper->rsa_pubkey_file = rb_strdup((char *) data);
212380e3
WP
689#else
690 conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available");
691#endif
692}
693
694static void
695conf_set_oper_umodes(void *data)
696{
697 set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data);
698}
699
700static void
701conf_set_oper_snomask(void *data)
702{
703 yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data);
704}
705
706static int
707conf_begin_class(struct TopConf *tc)
708{
709 if(yy_class)
710 free_class(yy_class);
711
712 yy_class = make_class();
713 return 0;
714}
715
716static int
717conf_end_class(struct TopConf *tc)
718{
719 if(conf_cur_block_name != NULL)
47a03750 720 yy_class->class_name = rb_strdup(conf_cur_block_name);
212380e3
WP
721
722 if(EmptyString(yy_class->class_name))
723 {
724 conf_report_error("Ignoring connect block -- missing name.");
725 return 0;
726 }
727
728 add_class(yy_class);
729 yy_class = NULL;
730 return 0;
731}
732
733static void
734conf_set_class_ping_time(void *data)
735{
736 yy_class->ping_freq = *(unsigned int *) data;
737}
738
739static void
e33e589c 740conf_set_class_cidr_ipv4_bitlen(void *data)
212380e3 741{
e33e589c
JT
742 unsigned int maxsize = 32;
743 if(*(unsigned int *) data > maxsize)
744 conf_report_error
745 ("class::cidr_ipv4_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
746 *(unsigned int *) data, maxsize);
747 else
748 yy_class->cidr_ipv4_bitlen = *(unsigned int *) data;
749
750}
751
e33e589c
JT
752static void
753conf_set_class_cidr_ipv6_bitlen(void *data)
754{
212380e3 755 unsigned int maxsize = 128;
212380e3
WP
756 if(*(unsigned int *) data > maxsize)
757 conf_report_error
e33e589c 758 ("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
212380e3
WP
759 *(unsigned int *) data, maxsize);
760 else
e33e589c 761 yy_class->cidr_ipv6_bitlen = *(unsigned int *) data;
212380e3
WP
762
763}
e33e589c 764
212380e3
WP
765static void
766conf_set_class_number_per_cidr(void *data)
767{
768 yy_class->cidr_amount = *(unsigned int *) data;
769}
770
771static void
772conf_set_class_number_per_ip(void *data)
773{
774 yy_class->max_local = *(unsigned int *) data;
775}
776
777
778static void
779conf_set_class_number_per_ip_global(void *data)
780{
781 yy_class->max_global = *(unsigned int *) data;
782}
783
784static void
785conf_set_class_number_per_ident(void *data)
786{
787 yy_class->max_ident = *(unsigned int *) data;
788}
789
790static void
791conf_set_class_connectfreq(void *data)
792{
793 yy_class->con_freq = *(unsigned int *) data;
794}
795
796static void
797conf_set_class_max_number(void *data)
798{
799 yy_class->max_total = *(unsigned int *) data;
800}
801
7c7065b0
EK
802static void
803conf_set_class_max_autoconn(void *data)
804{
805 yy_class->max_autoconn = *(unsigned int *) data;
806}
807
212380e3
WP
808static void
809conf_set_class_sendq(void *data)
810{
811 yy_class->max_sendq = *(unsigned int *) data;
812}
813
c6ad9b0c 814static char *listener_address[2];
212380e3
WP
815
816static int
817conf_begin_listen(struct TopConf *tc)
818{
c6ad9b0c
SA
819 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
820 rb_free(listener_address[i]);
821 listener_address[i] = NULL;
822 }
dcf45070
WP
823 yy_wsock = 0;
824 yy_defer_accept = 0;
212380e3
WP
825 return 0;
826}
827
828static int
829conf_end_listen(struct TopConf *tc)
830{
c6ad9b0c
SA
831 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
832 rb_free(listener_address[i]);
833 listener_address[i] = NULL;
834 }
dcf45070
WP
835 yy_wsock = 0;
836 yy_defer_accept = 0;
212380e3
WP
837 return 0;
838}
839
02270e96
WP
840static void
841conf_set_listen_defer_accept(void *data)
842{
843 yy_defer_accept = *(unsigned int *) data;
844}
c6d72037 845
c53ca1e0
WP
846static void
847conf_set_listen_wsock(void *data)
848{
849 yy_wsock = *(unsigned int *) data;
850}
851
212380e3 852static void
c6ad9b0c 853conf_set_listen_port_both(void *data, int ssl, int sctp)
212380e3
WP
854{
855 conf_parm_t *args = data;
856 for (; args; args = args->next)
857 {
dceac3e4 858 if(CF_TYPE(args->type) != CF_INT)
212380e3 859 {
c6ad9b0c 860 conf_report_error("listener::port argument is not an integer -- ignoring.");
212380e3
WP
861 continue;
862 }
c6ad9b0c 863 if(listener_address[0] == NULL)
212380e3 864 {
c6ad9b0c
SA
865 if (sctp) {
866 conf_report_error("listener::sctp_port has no addresses -- ignoring.");
867 } else {
868 add_tcp_listener(args->v.number, NULL, AF_INET, ssl, ssl || yy_defer_accept, yy_wsock);
869 add_tcp_listener(args->v.number, NULL, AF_INET6, ssl, ssl || yy_defer_accept, yy_wsock);
870 }
212380e3
WP
871 }
872 else
873 {
874 int family;
c6ad9b0c 875 if(strchr(listener_address[0], ':') != NULL)
212380e3 876 family = AF_INET6;
023c36ae 877 else
212380e3 878 family = AF_INET;
023c36ae 879
c6ad9b0c
SA
880 if (sctp) {
881#ifdef HAVE_LIBSCTP
882 add_sctp_listener(args->v.number, listener_address[0], listener_address[1], ssl, yy_wsock);
883#else
884 conf_report_error("Warning -- ignoring listener::sctp_port -- SCTP support not available.");
885#endif
886 } else {
887 add_tcp_listener(args->v.number, listener_address[0], family, ssl, ssl || yy_defer_accept, yy_wsock);
888 }
212380e3 889 }
212380e3
WP
890 }
891}
892
8bd5767b
JT
893static void
894conf_set_listen_port(void *data)
895{
c6ad9b0c 896 conf_set_listen_port_both(data, 0, 0);
8bd5767b
JT
897}
898
899static void
900conf_set_listen_sslport(void *data)
901{
c6ad9b0c
SA
902 conf_set_listen_port_both(data, 1, 0 );
903}
904
905static void
906conf_set_listen_sctp_port(void *data)
907{
908 conf_set_listen_port_both(data, 0, 1);
909}
910
911static void
912conf_set_listen_sctp_sslport(void *data)
913{
914 conf_set_listen_port_both(data, 1, 1);
c6d72037
VY
915}
916
212380e3
WP
917static void
918conf_set_listen_address(void *data)
919{
c6ad9b0c
SA
920 rb_free(listener_address[1]);
921 listener_address[1] = listener_address[0];
922 listener_address[0] = rb_strdup(data);
212380e3
WP
923}
924
925static int
926conf_begin_auth(struct TopConf *tc)
927{
330fc5c1 928 rb_dlink_node *ptr;
637c4932 929 rb_dlink_node *next_ptr;
212380e3
WP
930
931 if(yy_aconf)
932 free_conf(yy_aconf);
933
637c4932 934 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
212380e3
WP
935 {
936 free_conf(ptr->data);
330fc5c1 937 rb_dlinkDestroy(ptr, &yy_aconf_list);
212380e3
WP
938 }
939
940 yy_aconf = make_conf();
941 yy_aconf->status = CONF_CLIENT;
942
943 return 0;
944}
945
946static int
947conf_end_auth(struct TopConf *tc)
948{
3d1f32c0 949 struct ConfItem *yy_tmp, *found_conf;
330fc5c1 950 rb_dlink_node *ptr;
637c4932 951 rb_dlink_node *next_ptr;
212380e3 952
27f616dd
JT
953 if(EmptyString(yy_aconf->info.name))
954 yy_aconf->info.name = rb_strdup("NOMATCH");
212380e3
WP
955
956 /* didnt even get one ->host? */
957 if(EmptyString(yy_aconf->host))
958 {
959 conf_report_error("Ignoring auth block -- missing user@host");
960 return 0;
961 }
962
963 /* so the stacking works in order.. */
964 collapse(yy_aconf->user);
965 collapse(yy_aconf->host);
966 conf_add_class_to_conf(yy_aconf);
3d1f32c0 967 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
6e5e2b00 968 conf_report_error("Ignoring redundant auth block (after *@*)");
3d1f32c0 969 else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) &&
5f2df251 970 (!found_conf->spasswd || (yy_aconf->spasswd &&
3d1f32c0 971 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd))))
6e5e2b00
JT
972 conf_report_error("Ignoring duplicate auth block for %s@%s",
973 yy_aconf->user, yy_aconf->host);
974 else
975 add_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user, yy_aconf->spasswd, yy_aconf);
212380e3 976
637c4932 977 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
212380e3
WP
978 {
979 yy_tmp = ptr->data;
980
981 if(yy_aconf->passwd)
47a03750 982 yy_tmp->passwd = rb_strdup(yy_aconf->passwd);
212380e3 983
40c1fd47
VY
984 if(yy_aconf->spasswd)
985 yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
023c36ae 986
212380e3 987 /* this will always exist.. */
27f616dd 988 yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
212380e3
WP
989
990 if(yy_aconf->className)
47a03750 991 yy_tmp->className = rb_strdup(yy_aconf->className);
212380e3
WP
992
993 yy_tmp->flags = yy_aconf->flags;
994 yy_tmp->port = yy_aconf->port;
995
996 collapse(yy_tmp->user);
997 collapse(yy_tmp->host);
998
999 conf_add_class_to_conf(yy_tmp);
1000
0c2ea0c3 1001 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
6e5e2b00 1002 conf_report_error("Ignoring redundant auth block (after *@*)");
0c2ea0c3
JT
1003 else if ((found_conf = find_exact_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user)) &&
1004 (!found_conf->spasswd || (yy_tmp->spasswd &&
1005 0 == irccmp(found_conf->spasswd, yy_tmp->spasswd))))
6e5e2b00
JT
1006 conf_report_error("Ignoring duplicate auth block for %s@%s",
1007 yy_tmp->user, yy_tmp->host);
1008 else
1009 add_conf_by_address(yy_tmp->host, CONF_CLIENT, yy_tmp->user, yy_tmp->spasswd, yy_tmp);
330fc5c1 1010 rb_dlinkDestroy(ptr, &yy_aconf_list);
212380e3
WP
1011 }
1012
1013 yy_aconf = NULL;
1014 return 0;
1015}
1016
1017static void
1018conf_set_auth_user(void *data)
1019{
1020 struct ConfItem *yy_tmp;
1021 char *p;
1022
1023 /* The first user= line doesn't allocate a new conf */
1024 if(!EmptyString(yy_aconf->host))
1025 {
1026 yy_tmp = make_conf();
1027 yy_tmp->status = CONF_CLIENT;
1028 }
1029 else
1030 yy_tmp = yy_aconf;
1031
1032 if((p = strchr(data, '@')))
1033 {
1034 *p++ = '\0';
1035
47a03750
VY
1036 yy_tmp->user = rb_strdup(data);
1037 yy_tmp->host = rb_strdup(p);
212380e3
WP
1038 }
1039 else
1040 {
47a03750
VY
1041 yy_tmp->user = rb_strdup("*");
1042 yy_tmp->host = rb_strdup(data);
212380e3
WP
1043 }
1044
1045 if(yy_aconf != yy_tmp)
330fc5c1 1046 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
212380e3
WP
1047}
1048
40c1fd47
VY
1049static void
1050conf_set_auth_auth_user(void *data)
1051{
1052 if(yy_aconf->spasswd)
1053 memset(yy_aconf->spasswd, 0, strlen(yy_aconf->spasswd));
1054 rb_free(yy_aconf->spasswd);
1055 yy_aconf->spasswd = rb_strdup(data);
1056}
1057
212380e3
WP
1058static void
1059conf_set_auth_passwd(void *data)
1060{
1061 if(yy_aconf->passwd)
1062 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
637c4932 1063 rb_free(yy_aconf->passwd);
47a03750 1064 yy_aconf->passwd = rb_strdup(data);
212380e3
WP
1065}
1066
1067static void
1068conf_set_auth_spoof(void *data)
1069{
1070 char *p;
1071 char *user = NULL;
1072 char *host = NULL;
1073
1074 host = data;
1075
1076 /* user@host spoof */
1077 if((p = strchr(host, '@')) != NULL)
1078 {
1079 *p = '\0';
1080 user = data;
1081 host = p+1;
1082
1083 if(EmptyString(user))
1084 {
1085 conf_report_error("Warning -- spoof ident empty.");
1086 return;
1087 }
1088
1089 if(strlen(user) > USERLEN)
1090 {
1091 conf_report_error("Warning -- spoof ident length invalid.");
1092 return;
1093 }
1094
1095 if(!valid_username(user))
1096 {
1097 conf_report_error("Warning -- invalid spoof (ident).");
1098 return;
1099 }
1100
1101 /* this must be restored! */
1102 *p = '@';
1103 }
1104
1105 if(EmptyString(host))
1106 {
1107 conf_report_error("Warning -- spoof host empty.");
1108 return;
1109 }
1110
1111 if(strlen(host) > HOSTLEN)
1112 {
1113 conf_report_error("Warning -- spoof host length invalid.");
1114 return;
1115 }
1116
1117 if(!valid_hostname(host))
1118 {
1119 conf_report_error("Warning -- invalid spoof (host).");
1120 return;
1121 }
1122
27f616dd
JT
1123 rb_free(yy_aconf->info.name);
1124 yy_aconf->info.name = rb_strdup(data);
212380e3
WP
1125 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1126}
1127
1128static void
1129conf_set_auth_flags(void *data)
1130{
1131 conf_parm_t *args = data;
1132
1133 set_modes_from_table((int *) &yy_aconf->flags, "flag", auth_table, args);
1134}
1135
1136static void
1137conf_set_auth_redir_serv(void *data)
1138{
1139 yy_aconf->flags |= CONF_FLAGS_REDIR;
27f616dd
JT
1140 rb_free(yy_aconf->info.name);
1141 yy_aconf->info.name = rb_strdup(data);
212380e3
WP
1142}
1143
1144static void
1145conf_set_auth_redir_port(void *data)
1146{
1147 int port = *(unsigned int *) data;
1148
1149 yy_aconf->flags |= CONF_FLAGS_REDIR;
1150 yy_aconf->port = port;
1151}
1152
1153static void
1154conf_set_auth_class(void *data)
1155{
637c4932 1156 rb_free(yy_aconf->className);
47a03750 1157 yy_aconf->className = rb_strdup(data);
212380e3
WP
1158}
1159
212380e3
WP
1160static int
1161conf_begin_connect(struct TopConf *tc)
1162{
1163 if(yy_server)
1164 free_server_conf(yy_server);
1165
1166 yy_server = make_server_conf();
1167 yy_server->port = PORTNUM;
5aa453a4 1168 yy_server->flags |= SERVER_TB;
212380e3
WP
1169
1170 if(conf_cur_block_name != NULL)
47a03750 1171 yy_server->name = rb_strdup(conf_cur_block_name);
212380e3
WP
1172
1173 return 0;
1174}
1175
1176static int
1177conf_end_connect(struct TopConf *tc)
1178{
1179 if(EmptyString(yy_server->name))
1180 {
1181 conf_report_error("Ignoring connect block -- missing name.");
1182 return 0;
1183 }
1184
1185 if(ServerInfo.name != NULL && !irccmp(ServerInfo.name, yy_server->name))
1186 {
1187 conf_report_error("Ignoring connect block for %s -- name is equal to my own name.",
1188 yy_server->name);
1189 return 0;
1190 }
1191
ff0cc1e6 1192 if((EmptyString(yy_server->passwd) || EmptyString(yy_server->spasswd)) && EmptyString(yy_server->certfp))
212380e3 1193 {
c8f26906 1194 conf_report_error("Ignoring connect block for %s -- no fingerprint or password credentials provided.",
212380e3
WP
1195 yy_server->name);
1196 return 0;
1197 }
1198
f61d0961
SA
1199 if((yy_server->flags & SERVER_SSL) && EmptyString(yy_server->certfp))
1200 {
1201 conf_report_error("Ignoring connect block for %s -- no fingerprint provided for SSL connection.",
1202 yy_server->name);
1203 return 0;
1204 }
1205
d4214e94
SA
1206 if(EmptyString(yy_server->connect_host)
1207 && GET_SS_FAMILY(&yy_server->connect4) != AF_INET
d4214e94 1208 && GET_SS_FAMILY(&yy_server->connect6) != AF_INET6
d4214e94 1209 )
212380e3
WP
1210 {
1211 conf_report_error("Ignoring connect block for %s -- missing host.",
1212 yy_server->name);
1213 return 0;
1214 }
1215
1216#ifndef HAVE_LIBZ
1217 if(ServerConfCompressed(yy_server))
1218 {
1219 conf_report_error("Ignoring connect::flags::compressed -- zlib not available.");
1220 yy_server->flags &= ~SERVER_COMPRESSED;
1221 }
1222#endif
1223
1224 add_server_conf(yy_server);
330fc5c1 1225 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
212380e3
WP
1226
1227 yy_server = NULL;
1228 return 0;
1229}
1230
1231static void
1232conf_set_connect_host(void *data)
1233{
d4214e94
SA
1234 struct rb_sockaddr_storage addr;
1235
17809d2d 1236 if(rb_inet_pton_sock(data, &addr) <= 0)
d4214e94
SA
1237 {
1238 rb_free(yy_server->connect_host);
1239 yy_server->connect_host = rb_strdup(data);
1240 }
1241 else if(GET_SS_FAMILY(&addr) == AF_INET)
1242 {
1243 yy_server->connect4 = addr;
1244 }
d4214e94
SA
1245 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1246 {
1247 yy_server->connect6 = addr;
1248 }
d4214e94
SA
1249 else
1250 {
1251 conf_report_error("Unsupported IP address for server connect host (%s)",
1252 (char *)data);
1253 return;
1254 }
212380e3
WP
1255}
1256
1257static void
1258conf_set_connect_vhost(void *data)
1259{
d4214e94
SA
1260 struct rb_sockaddr_storage addr;
1261
17809d2d 1262 if(rb_inet_pton_sock(data, &addr) <= 0)
d4214e94
SA
1263 {
1264 rb_free(yy_server->bind_host);
1265 yy_server->bind_host = rb_strdup(data);
1266 }
1267 else if(GET_SS_FAMILY(&addr) == AF_INET)
212380e3 1268 {
d4214e94
SA
1269 yy_server->bind4 = addr;
1270 }
d4214e94
SA
1271 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1272 {
1273 yy_server->bind6 = addr;
1274 }
d4214e94
SA
1275 else
1276 {
1277 conf_report_error("Unsupported IP address for server connect vhost (%s)",
1278 (char *)data);
212380e3
WP
1279 return;
1280 }
212380e3
WP
1281}
1282
1283static void
1284conf_set_connect_send_password(void *data)
1285{
1286 if(yy_server->spasswd)
1287 {
1288 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
637c4932 1289 rb_free(yy_server->spasswd);
212380e3
WP
1290 }
1291
47a03750 1292 yy_server->spasswd = rb_strdup(data);
212380e3
WP
1293}
1294
1295static void
1296conf_set_connect_accept_password(void *data)
1297{
1298 if(yy_server->passwd)
1299 {
1300 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
637c4932 1301 rb_free(yy_server->passwd);
212380e3 1302 }
47a03750 1303 yy_server->passwd = rb_strdup(data);
212380e3
WP
1304}
1305
ff0cc1e6
WP
1306static void
1307conf_set_connect_fingerprint(void *data)
1308{
462ae9d7
JT
1309 if (yy_server->certfp)
1310 rb_free(yy_server->certfp);
ff0cc1e6
WP
1311 yy_server->certfp = rb_strdup((char *) data);
1312
1313 /* force SSL to be enabled if fingerprint is enabled. */
1314 yy_server->flags |= SERVER_SSL;
1315}
1316
212380e3
WP
1317static void
1318conf_set_connect_port(void *data)
1319{
1320 int port = *(unsigned int *) data;
1321
1322 if(port < 1)
1323 port = PORTNUM;
1324
1325 yy_server->port = port;
1326}
1327
1328static void
1329conf_set_connect_aftype(void *data)
1330{
1331 char *aft = data;
1332
f956cb0f 1333 if(rb_strcasecmp(aft, "ipv4") == 0)
212380e3 1334 yy_server->aftype = AF_INET;
f956cb0f 1335 else if(rb_strcasecmp(aft, "ipv6") == 0)
212380e3 1336 yy_server->aftype = AF_INET6;
212380e3
WP
1337 else
1338 conf_report_error("connect::aftype '%s' is unknown.", aft);
1339}
1340
1341static void
1342conf_set_connect_flags(void *data)
1343{
1344 conf_parm_t *args = data;
1345
1346 /* note, we allow them to set compressed, then remove it later if
1347 * they do and LIBZ isnt available
1348 */
1349 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1350}
1351
212380e3
WP
1352static void
1353conf_set_connect_class(void *data)
1354{
637c4932 1355 rb_free(yy_server->class_name);
47a03750 1356 yy_server->class_name = rb_strdup(data);
212380e3
WP
1357}
1358
1359static void
1360conf_set_exempt_ip(void *data)
1361{
1362 struct ConfItem *yy_tmp;
7d9e8e9d 1363 int masktype = parse_netmask_strict(data, NULL, NULL);
212380e3 1364
7d9e8e9d 1365 if(masktype != HM_IPV4 && masktype != HM_IPV6)
212380e3
WP
1366 {
1367 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1368 return;
1369 }
1370
1371 yy_tmp = make_conf();
47a03750
VY
1372 yy_tmp->passwd = rb_strdup("*");
1373 yy_tmp->host = rb_strdup(data);
212380e3 1374 yy_tmp->status = CONF_EXEMPTDLINE;
40c1fd47 1375 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
212380e3
WP
1376}
1377
1cf798be
EK
1378static void
1379conf_set_secure_ip(void *data)
1380{
1381 struct ConfItem *yy_tmp;
1382 int masktype = parse_netmask_strict(data, NULL, NULL);
1383
1384 if(masktype != HM_IPV4 && masktype != HM_IPV6)
1385 {
1386 conf_report_error("Ignoring secure -- invalid secure::ip.");
1387 return;
1388 }
1389
1390 yy_tmp = make_conf();
1391 yy_tmp->passwd = rb_strdup("*");
1392 yy_tmp->host = rb_strdup(data);
1393 yy_tmp->status = CONF_SECURE;
1394 add_conf_by_address(yy_tmp->host, CONF_SECURE, NULL, NULL, yy_tmp);
1395}
1396
212380e3
WP
1397static int
1398conf_cleanup_cluster(struct TopConf *tc)
1399{
637c4932 1400 rb_dlink_node *ptr, *next_ptr;
212380e3 1401
637c4932 1402 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
WP
1403 {
1404 free_remote_conf(ptr->data);
330fc5c1 1405 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
WP
1406 }
1407
1408 if(yy_shared != NULL)
1409 {
1410 free_remote_conf(yy_shared);
1411 yy_shared = NULL;
1412 }
1413
1414 return 0;
1415}
1416
1417static void
1418conf_set_cluster_name(void *data)
1419{
1420 if(yy_shared != NULL)
1421 free_remote_conf(yy_shared);
1422
1423 yy_shared = make_remote_conf();
47a03750 1424 yy_shared->server = rb_strdup(data);
330fc5c1 1425 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
212380e3
WP
1426
1427 yy_shared = NULL;
1428}
1429
1430static void
1431conf_set_cluster_flags(void *data)
1432{
1433 conf_parm_t *args = data;
1434 int flags = 0;
637c4932 1435 rb_dlink_node *ptr, *next_ptr;
212380e3
WP
1436
1437 if(yy_shared != NULL)
1438 free_remote_conf(yy_shared);
1439
1440 set_modes_from_table(&flags, "flag", cluster_table, args);
1441
637c4932 1442 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
WP
1443 {
1444 yy_shared = ptr->data;
1445 yy_shared->flags = flags;
330fc5c1
WP
1446 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1447 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
WP
1448 }
1449
1450 yy_shared = NULL;
1451}
1452
1453static void
1454conf_set_general_havent_read_conf(void *data)
1455{
1456 if(*(unsigned int *) data)
1457 {
1458 conf_report_error("You haven't read your config file properly.");
1459 conf_report_error
1460 ("There is a line in the example conf that will kill your server if not removed.");
1461 conf_report_error
1462 ("Consider actually reading/editing the conf file, and removing this line.");
1463 if (!testing_conf)
1464 exit(0);
1465 }
1466}
1467
1468static void
1469conf_set_general_hide_error_messages(void *data)
1470{
1471 char *val = data;
1472
f956cb0f 1473 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1474 ConfigFileEntry.hide_error_messages = 2;
f956cb0f 1475 else if(rb_strcasecmp(val, "opers") == 0)
212380e3 1476 ConfigFileEntry.hide_error_messages = 1;
f956cb0f 1477 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1478 ConfigFileEntry.hide_error_messages = 0;
1479 else
1480 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1481}
1482
212380e3
WP
1483static void
1484conf_set_general_stats_k_oper_only(void *data)
1485{
1486 char *val = data;
1487
f956cb0f 1488 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1489 ConfigFileEntry.stats_k_oper_only = 2;
f956cb0f 1490 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1491 ConfigFileEntry.stats_k_oper_only = 1;
f956cb0f 1492 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1493 ConfigFileEntry.stats_k_oper_only = 0;
1494 else
1495 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1496}
1497
1498static void
1499conf_set_general_stats_i_oper_only(void *data)
1500{
1501 char *val = data;
1502
f956cb0f 1503 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1504 ConfigFileEntry.stats_i_oper_only = 2;
f956cb0f 1505 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1506 ConfigFileEntry.stats_i_oper_only = 1;
f956cb0f 1507 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1508 ConfigFileEntry.stats_i_oper_only = 0;
1509 else
1510 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1511}
1512
63ab1dd6
EK
1513static void
1514conf_set_general_stats_l_oper_only(void *data)
1515{
1516 char *val = data;
1517
1518 if(rb_strcasecmp(val, "yes") == 0)
1519 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_YES;
1520 else if(rb_strcasecmp(val, "self") == 0)
1521 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_SELF;
1522 else if(rb_strcasecmp(val, "no") == 0)
1523 ConfigFileEntry.stats_l_oper_only = STATS_L_OPER_ONLY_NO;
1524 else
1525 conf_report_error("Invalid setting '%s' for general::stats_l_oper_only.", val);
1526}
1527
212380e3
WP
1528static void
1529conf_set_general_compression_level(void *data)
1530{
1531#ifdef HAVE_LIBZ
1532 ConfigFileEntry.compression_level = *(unsigned int *) data;
1533
1534 if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9))
1535 {
1536 conf_report_error
1537 ("Invalid general::compression_level %d -- using default.",
1538 ConfigFileEntry.compression_level);
1539 ConfigFileEntry.compression_level = 0;
1540 }
1541#else
1542 conf_report_error("Ignoring general::compression_level -- zlib not available.");
1543#endif
1544}
1545
1546static void
1547conf_set_general_default_umodes(void *data)
1548{
1549 char *pm;
1550 int what = MODE_ADD, flag;
1551
1552 ConfigFileEntry.default_umodes = 0;
1553 for (pm = (char *) data; *pm; pm++)
1554 {
1555 switch (*pm)
1556 {
1557 case '+':
1558 what = MODE_ADD;
1559 break;
1560 case '-':
1561 what = MODE_DEL;
1562 break;
1563
1564 /* don't allow +o */
1565 case 'o':
1566 case 'S':
5fabe513 1567 case 'Z':
212380e3
WP
1568 case ' ':
1569 break;
1570
1571 default:
1572 if ((flag = user_modes[(unsigned char) *pm]))
1573 {
1574 /* Proper value has probably not yet been set
1575 * so don't check oper_only_umodes -- jilles */
1576 if (what == MODE_ADD)
1577 ConfigFileEntry.default_umodes |= flag;
1578 else
1579 ConfigFileEntry.default_umodes &= ~flag;
1580 }
1581 break;
1582 }
023c36ae 1583 }
212380e3
WP
1584}
1585
1586static void
1587conf_set_general_oper_umodes(void *data)
1588{
1589 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1590}
1591
13d8f0ed
WP
1592static void
1593conf_set_general_certfp_method(void *data)
1594{
1595 char *method = data;
1596
f018ed84 1597 if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA1))
cf430c1a 1598 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
f018ed84 1599 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA256))
cf430c1a 1600 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA256;
f018ed84 1601 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA512))
cf430c1a 1602 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA512;
f018ed84 1603 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA256))
cf430c1a 1604 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA256;
f018ed84 1605 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA512))
cf430c1a 1606 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA512;
13d8f0ed
WP
1607 else
1608 {
cf430c1a 1609 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
13d8f0ed
WP
1610 conf_report_error("Ignoring general::certfp_method -- bogus certfp method %s", method);
1611 }
1612}
1613
212380e3
WP
1614static void
1615conf_set_general_oper_only_umodes(void *data)
1616{
1617 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1618}
1619
1620static void
1621conf_set_general_oper_snomask(void *data)
1622{
1623 char *pm;
1624 int what = MODE_ADD, flag;
1625
1626 ConfigFileEntry.oper_snomask = 0;
1627 for (pm = (char *) data; *pm; pm++)
1628 {
1629 switch (*pm)
1630 {
1631 case '+':
1632 what = MODE_ADD;
1633 break;
1634 case '-':
1635 what = MODE_DEL;
1636 break;
1637
1638 default:
1639 if ((flag = snomask_modes[(unsigned char) *pm]))
1640 {
1641 if (what == MODE_ADD)
1642 ConfigFileEntry.oper_snomask |= flag;
1643 else
1644 ConfigFileEntry.oper_snomask &= ~flag;
1645 }
1646 break;
1647 }
1648 }
1649}
1650
6ac21a70
EK
1651static void
1652conf_set_general_hidden_caps(void *data)
1653{
1654 size_t n = 0;
1655
1656 for (conf_parm_t *arg = data; arg; arg = arg->next)
1657 n += 1;
1658
1659 if (ConfigFileEntry.hidden_caps != NULL)
1660 {
1661 for (n = 0; ConfigFileEntry.hidden_caps[n] != NULL; n++)
1662 rb_free(ConfigFileEntry.hidden_caps[n]);
1663 rb_free(ConfigFileEntry.hidden_caps);
1664 }
1665 ConfigFileEntry.hidden_caps = rb_malloc(sizeof *ConfigFileEntry.hidden_caps * (n + 1));
1666
1667 n = 0;
1668 for (conf_parm_t *arg = data; arg; arg = arg->next)
1669 {
1670 ConfigFileEntry.hidden_caps[n++] = rb_strdup(arg->v.string);
1671 }
1672 ConfigFileEntry.hidden_caps[n] = NULL;
1673}
1674
212380e3
WP
1675static void
1676conf_set_serverhide_links_delay(void *data)
1677{
1678 int val = *(unsigned int *) data;
1679
212380e3
WP
1680 ConfigServerHide.links_delay = val;
1681}
1682
212380e3
WP
1683static void
1684conf_set_service_name(void *data)
1685{
212380e3
WP
1686 const char *s;
1687 char *tmp;
1688 int dots = 0;
1689
1690 for(s = data; *s != '\0'; s++)
1691 {
1692 if(!IsServChar(*s))
1693 {
1694 conf_report_error("Ignoring service::name "
1695 "-- bogus servername.");
1696 return;
1697 }
1698 else if(*s == '.')
1699 dots++;
1700 }
1701
1702 if(!dots)
1703 {
1704 conf_report_error("Ignoring service::name -- must contain '.'");
1705 return;
1706 }
1707
47a03750 1708 tmp = rb_strdup(data);
330fc5c1 1709 rb_dlinkAddAlloc(tmp, &service_list);
212380e3
WP
1710}
1711
212380e3
WP
1712static int
1713conf_begin_alias(struct TopConf *tc)
1714{
eddc2ab6 1715 yy_alias = rb_malloc(sizeof(struct alias_entry));
212380e3
WP
1716
1717 if (conf_cur_block_name != NULL)
47a03750 1718 yy_alias->name = rb_strdup(conf_cur_block_name);
212380e3
WP
1719
1720 yy_alias->flags = 0;
212380e3
WP
1721
1722 return 0;
1723}
1724
1725static int
1726conf_end_alias(struct TopConf *tc)
1727{
212380e3
WP
1728 if (yy_alias == NULL)
1729 return -1;
1730
1731 if (yy_alias->name == NULL)
1732 {
1733 conf_report_error("Ignoring alias -- must have a name.");
1734
637c4932 1735 rb_free(yy_alias);
212380e3
WP
1736
1737 return -1;
1738 }
1739
1740 if (yy_alias->target == NULL)
1741 {
1742 conf_report_error("Ignoring alias -- must have a target.");
1743
637c4932 1744 rb_free(yy_alias);
212380e3
WP
1745
1746 return -1;
1747 }
1748
a4bf26dd 1749 rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
212380e3
WP
1750
1751 return 0;
1752}
1753
1754static void
1755conf_set_alias_name(void *data)
1756{
1757 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1758 return;
1759
47a03750 1760 yy_alias->name = rb_strdup(data);
212380e3
WP
1761}
1762
1763static void
1764conf_set_alias_target(void *data)
1765{
1766 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1767 return;
1768
47a03750 1769 yy_alias->target = rb_strdup(data);
212380e3
WP
1770}
1771
63eb8567
WP
1772static void
1773conf_set_channel_autochanmodes(void *data)
1774{
1775 char *pm;
1776 int what = MODE_ADD;
1777
1778 ConfigChannel.autochanmodes = 0;
1779 for (pm = (char *) data; *pm; pm++)
1780 {
1781 switch (*pm)
1782 {
1783 case '+':
1784 what = MODE_ADD;
1785 break;
1786 case '-':
1787 what = MODE_DEL;
1788 break;
1789
1790 default:
1791 if (chmode_table[(unsigned char) *pm].set_func == chm_simple)
1792 {
1793 if (what == MODE_ADD)
1794 ConfigChannel.autochanmodes |= chmode_table[(unsigned char) *pm].mode_type;
1795 else
1796 ConfigChannel.autochanmodes &= ~chmode_table[(unsigned char) *pm].mode_type;
1797 }
1798 else
1799 {
4952e40b 1800 conf_report_error("channel::autochanmodes -- Invalid channel mode %c", *pm);
63eb8567
WP
1801 continue;
1802 }
1803 break;
1804 }
1805 }
1806}
1807
3c93d380 1808/* XXX for below */
7f24f506 1809static void conf_set_dnsbl_entry_reason(void *data);
3c93d380 1810
d3f6b808
EM
1811#define IPTYPE_IPV4 1
1812#define IPTYPE_IPV6 2
1813
7f24f506
AC
1814static int
1815conf_warn_blacklist_deprecation(struct TopConf *tc)
1816{
1817 conf_report_error("blacklist{} blocks have been deprecated -- use dnsbl{} blocks instead.");
1818 return 0;
1819}
1820
212380e3 1821static void
7f24f506 1822conf_set_dnsbl_entry_host(void *data)
212380e3 1823{
7f24f506 1824 if (yy_dnsbl_entry_host)
3c93d380 1825 {
7f24f506
AC
1826 conf_report_error("dnsbl::host %s overlaps existing host %s",
1827 (char *)data, yy_dnsbl_entry_host);
3c93d380
EM
1828
1829 /* Cleanup */
7f24f506 1830 conf_set_dnsbl_entry_reason(NULL);
3c93d380
EM
1831 return;
1832 }
1833
7f24f506
AC
1834 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1835 yy_dnsbl_entry_host = rb_strdup(data);
212380e3
WP
1836}
1837
0a1e77c2 1838static void
7f24f506 1839conf_set_dnsbl_entry_type(void *data)
0a1e77c2
EM
1840{
1841 conf_parm_t *args = data;
1842
1843 /* Don't assume we have either if we got here */
7f24f506 1844 yy_dnsbl_entry_iptype = 0;
0a1e77c2
EM
1845
1846 for (; args; args = args->next)
1847 {
f956cb0f 1848 if (!rb_strcasecmp(args->v.string, "ipv4"))
7f24f506 1849 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
f956cb0f 1850 else if (!rb_strcasecmp(args->v.string, "ipv6"))
7f24f506 1851 yy_dnsbl_entry_iptype |= IPTYPE_IPV6;
0a1e77c2 1852 else
7f24f506 1853 conf_report_error("dnsbl::type has unknown address family %s",
0a1e77c2
EM
1854 args->v.string);
1855 }
1856
1857 /* If we have neither, just default to IPv4 */
7f24f506 1858 if (!yy_dnsbl_entry_iptype)
0a1e77c2 1859 {
7f24f506
AC
1860 conf_report_warning("dnsbl::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1861 yy_dnsbl_entry_iptype = IPTYPE_IPV4;
0a1e77c2
EM
1862 }
1863}
1864
3c93d380 1865static void
7f24f506 1866conf_set_dnsbl_entry_matches(void *data)
3c93d380
EM
1867{
1868 conf_parm_t *args = data;
d3f6b808 1869 enum filter_t { FILTER_NONE, FILTER_ALL, FILTER_LAST };
3c93d380
EM
1870
1871 for (; args; args = args->next)
1872 {
3c93d380
EM
1873 char *str = args->v.string;
1874 char *p;
d3f6b808 1875 enum filter_t type = FILTER_LAST;
3c93d380
EM
1876
1877 if (CF_TYPE(args->type) != CF_QSTRING)
1878 {
7f24f506 1879 conf_report_error("dnsbl::matches -- must be quoted string");
3c93d380
EM
1880 continue;
1881 }
1882
1883 if (str == NULL)
1884 {
7f24f506 1885 conf_report_error("dnsbl::matches -- invalid entry");
3c93d380
EM
1886 continue;
1887 }
1888
1889 if (strlen(str) > HOSTIPLEN)
1890 {
7f24f506 1891 conf_report_error("dnsbl::matches has an entry too long: %s",
3c93d380
EM
1892 str);
1893 continue;
1894 }
1895
1896 for (p = str; *p != '\0'; p++)
1897 {
1898 /* Check for validity */
1899 if (*p == '.')
d3f6b808
EM
1900 type = FILTER_ALL;
1901 else if (!isdigit((unsigned char)*p))
3c93d380 1902 {
7f24f506 1903 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380 1904 str);
d3f6b808 1905 type = FILTER_NONE;
3c93d380
EM
1906 break;
1907 }
1908 }
1909
d3f6b808 1910 if (type == FILTER_ALL)
3c93d380
EM
1911 {
1912 /* Basic IP sanity check */
1913 struct rb_sockaddr_storage tmp;
1914 if (rb_inet_pton(AF_INET, str, &tmp) <= 0)
1915 {
7f24f506 1916 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380
EM
1917 str);
1918 continue;
1919 }
1920 }
d3f6b808 1921 else if (type == FILTER_LAST)
3c93d380
EM
1922 {
1923 /* Verify it's the correct length */
1924 if (strlen(str) > 3)
1925 {
7f24f506 1926 conf_report_error("dnsbl::matches has invalid octet match entry %s",
3c93d380
EM
1927 str);
1928 continue;
1929 }
1930 }
1931 else
1932 {
1933 continue; /* Invalid entry */
1934 }
1935
7f24f506 1936 rb_dlinkAddAlloc(rb_strdup(str), &yy_dnsbl_entry_filters);
3c93d380
EM
1937 }
1938}
1939
212380e3 1940static void
7f24f506 1941conf_set_dnsbl_entry_reason(void *data)
212380e3 1942{
3c93d380 1943 rb_dlink_node *ptr, *nptr;
212380e3 1944
7f24f506 1945 if (yy_dnsbl_entry_host && data)
212380e3 1946 {
7f24f506
AC
1947 yy_dnsbl_entry_reason = rb_strdup(data);
1948 if (yy_dnsbl_entry_iptype & IPTYPE_IPV6)
0a1e77c2 1949 {
a6a30cc7 1950 /* Make sure things fit (magic number 64 = alnum count + dots)
771dcfad
EM
1951 * Example: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
1952 */
7f24f506 1953 if ((64 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 1954 {
7f24f506
AC
1955 conf_report_error("dnsbl::host %s results in IPv6 queries that are too long",
1956 yy_dnsbl_entry_host);
0a1e77c2
EM
1957 goto cleanup_bl;
1958 }
1959 }
1960 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
7f24f506 1961 if ((yy_dnsbl_entry_iptype & IPTYPE_IPV4) && !(yy_dnsbl_entry_iptype & IPTYPE_IPV6))
0a1e77c2 1962 {
a6a30cc7
EM
1963 /* Make sure things fit for worst case (magic number 16 = number of nums + dots)
1964 * Example: 127.127.127.127.in-addr.arpa
771dcfad 1965 */
7f24f506 1966 if ((16 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 1967 {
7f24f506
AC
1968 conf_report_error("dnsbl::host %s results in IPv4 queries that are too long",
1969 yy_dnsbl_entry_host);
0a1e77c2
EM
1970 goto cleanup_bl;
1971 }
1972 }
1973
7f24f506 1974 add_dnsbl_entry(yy_dnsbl_entry_host, yy_dnsbl_entry_reason, yy_dnsbl_entry_iptype, &yy_dnsbl_entry_filters);
3c93d380 1975 }
0a1e77c2
EM
1976
1977cleanup_bl:
7f24f506 1978 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_dnsbl_entry_filters.head)
e232f35c 1979 {
d3f6b808 1980 rb_free(ptr->data);
7f24f506 1981 rb_dlinkDestroy(ptr, &yy_dnsbl_entry_filters);
212380e3 1982 }
3c93d380 1983
7f24f506 1984 yy_dnsbl_entry_filters = (rb_dlink_list){ NULL, NULL, 0 };
d3f6b808 1985
7f24f506
AC
1986 rb_free(yy_dnsbl_entry_host);
1987 rb_free(yy_dnsbl_entry_reason);
1988 yy_dnsbl_entry_host = NULL;
1989 yy_dnsbl_entry_reason = NULL;
1990 yy_dnsbl_entry_iptype = 0;
212380e3
WP
1991}
1992
51fa2ab8
EM
1993
1994struct opm_scanner
1995{
1996 const char *type;
1997 uint16_t port;
1998
1999 rb_dlink_node node;
2000};
2001
8275e270
EM
2002static int
2003conf_begin_opm(struct TopConf *tc)
2004{
2005 yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL;
9bba0f61 2006 yy_opm_port_ipv4 = yy_opm_port_ipv6 = yy_opm_timeout = 0;
5c5296c8 2007 delete_opm_proxy_scanner_all();
5e9a3f86 2008 delete_opm_listener_all();
8275e270
EM
2009 return 0;
2010}
2011
2012static int
2013conf_end_opm(struct TopConf *tc)
2014{
51fa2ab8
EM
2015 rb_dlink_node *ptr, *nptr;
2016 bool fail = false;
2017
ffa79a95 2018 if(rb_dlink_list_length(&yy_opm_scanner_list) == 0)
51fa2ab8 2019 {
c1f4db3f 2020 conf_report_error("No opm scanners configured -- disabling opm.");
51fa2ab8
EM
2021 fail = true;
2022 goto end;
2023 }
2024
8275e270
EM
2025 if(yy_opm_port_ipv4 > 0)
2026 {
2027 if(yy_opm_address_ipv4 != NULL)
5e9a3f86 2028 conf_create_opm_listener(yy_opm_address_ipv4, yy_opm_port_ipv4);
8275e270
EM
2029 else
2030 {
2031 char ip[HOSTIPLEN];
d4214e94 2032 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind4, ip, sizeof(ip)))
8275e270 2033 conf_report_error("No opm::listen_ipv4 nor serverinfo::vhost directive; cannot listen on IPv4");
8275e270 2034 else
5e9a3f86 2035 conf_create_opm_listener(ip, yy_opm_port_ipv4);
8275e270
EM
2036 }
2037 }
2038
2039 if(yy_opm_port_ipv6 > 0)
2040 {
2041 if(yy_opm_address_ipv6 != NULL)
5e9a3f86 2042 conf_create_opm_listener(yy_opm_address_ipv6, yy_opm_port_ipv6);
8275e270
EM
2043 else
2044 {
2045 char ip[HOSTIPLEN];
d4214e94 2046 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind6, ip, sizeof(ip)))
8275e270 2047 conf_report_error("No opm::listen_ipv6 nor serverinfo::vhost directive; cannot listen on IPv6");
8275e270 2048 else
5e9a3f86 2049 conf_create_opm_listener(ip, yy_opm_port_ipv6);
8275e270
EM
2050 }
2051 }
2052
51fa2ab8
EM
2053 /* If there's no listeners... */
2054 fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0);
c1f4db3f 2055 if(!fail && yy_opm_timeout > 0 && yy_opm_timeout < 60)
9bba0f61
EM
2056 /* Send timeout */
2057 set_authd_timeout("opm_timeout", yy_opm_timeout);
c1f4db3f
EM
2058 else if(fail)
2059 conf_report_error("No opm listeners -- disabling");
2060 else if(yy_opm_timeout <= 0 || yy_opm_timeout >= 60)
2061 conf_report_error("opm::timeout value is invalid -- ignoring");
9bba0f61 2062
51fa2ab8
EM
2063end:
2064 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head)
2065 {
2066 struct opm_scanner *scanner = ptr->data;
2067
2068 if(!fail)
2069 create_opm_proxy_scanner(scanner->type, scanner->port);
2070
2071 rb_dlinkDelete(&scanner->node, &yy_opm_scanner_list);
2072 rb_free(scanner);
2073 }
2074
34bc7cae
EM
2075 if(!fail)
2076 opm_check_enable(true);
2077
8275e270
EM
2078 rb_free(yy_opm_address_ipv4);
2079 rb_free(yy_opm_address_ipv6);
2080 return 0;
2081}
2082
9bba0f61
EM
2083static void
2084conf_set_opm_timeout(void *data)
2085{
2086 int timeout = *((int *)data);
2087
2088 if(timeout <= 0 || timeout > 60)
2089 {
2090 conf_report_error("opm::timeout value %d is bogus, ignoring", timeout);
2091 return;
2092 }
2093
2094 yy_opm_timeout = timeout;
2095}
51fa2ab8 2096
8275e270 2097static void
51fa2ab8 2098conf_set_opm_listen_address_both(void *data, bool ipv6)
8275e270
EM
2099{
2100 struct rb_sockaddr_storage addr;
51fa2ab8 2101 const char *confstr = (ipv6 ? "opm::listen_ipv6" : "opm::listen_ipv4");
8275e270
EM
2102 char *ip = data;
2103
17809d2d 2104 if(!rb_inet_pton_sock(ip, &addr))
8275e270 2105 {
51fa2ab8 2106 conf_report_error("%s is an invalid address: %s", confstr, ip);
8275e270
EM
2107 return;
2108 }
2109
51fa2ab8 2110 if(ipv6)
8275e270 2111 {
51fa2ab8
EM
2112 if(GET_SS_FAMILY(&addr) != AF_INET6)
2113 {
2114 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2115 return;
2116 }
2117
2118 if(yy_opm_address_ipv6 != NULL)
2119 {
2120 conf_report_error("%s overwrites previous address %s", confstr, ip);
2121 return;
2122 }
2123
2124 yy_opm_address_ipv6 = rb_strdup(ip);
51fa2ab8
EM
2125 }
2126 else
8275e270 2127 {
51fa2ab8
EM
2128 if(GET_SS_FAMILY(&addr) != AF_INET)
2129 {
2130 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2131 return;
2132 }
2133
2134 if(yy_opm_address_ipv4 != NULL)
2135 {
2136 conf_report_error("%s overwrites previous address %s", confstr, ip);
2137 return;
2138 }
2139
2140 yy_opm_address_ipv4 = rb_strdup(ip);
8275e270 2141 }
51fa2ab8 2142}
8275e270 2143
51fa2ab8
EM
2144static void
2145conf_set_opm_listen_address_ipv4(void *data)
2146{
2147 conf_set_opm_listen_address_both(data, false);
8275e270
EM
2148}
2149
2150static void
2151conf_set_opm_listen_address_ipv6(void *data)
2152{
51fa2ab8
EM
2153 conf_set_opm_listen_address_both(data, true);
2154}
8275e270 2155
51fa2ab8
EM
2156static void
2157conf_set_opm_listen_port_both(void *data, bool ipv6)
2158{
2159 int port = *((int *)data);
2160 const char *confstr = (ipv6 ? "opm::port_ipv6" : "opm::port_ipv4");
8275e270 2161
51fa2ab8 2162 if(port > 65535 || port <= 0)
8275e270 2163 {
51fa2ab8 2164 conf_report_error("%s is out of range: %d", confstr, port);
8275e270
EM
2165 return;
2166 }
2167
51fa2ab8 2168 if(ipv6)
8275e270 2169 {
51fa2ab8
EM
2170 if(yy_opm_port_ipv4)
2171 {
2172 conf_report_error("%s overwrites existing port %hu",
2173 confstr, yy_opm_port_ipv4);
2174 return;
2175 }
2176
2177 yy_opm_port_ipv4 = port;
8275e270 2178 }
51fa2ab8
EM
2179 else
2180 {
2181 if(yy_opm_port_ipv6)
2182 {
2183 conf_report_error("%s overwrites existing port %hu",
2184 confstr, yy_opm_port_ipv6);
2185 return;
2186 }
8275e270 2187
51fa2ab8
EM
2188 yy_opm_port_ipv6 = port;
2189 }
8275e270
EM
2190}
2191
2192static void
2193conf_set_opm_listen_port_ipv4(void *data)
2194{
51fa2ab8 2195 conf_set_opm_listen_port_both(data, false);
8275e270
EM
2196}
2197
2198static void
2199conf_set_opm_listen_port_ipv6(void *data)
2200{
51fa2ab8 2201 conf_set_opm_listen_port_both(data, true);
8275e270
EM
2202}
2203
2204static void
2205conf_set_opm_listen_port(void *data)
2206{
51fa2ab8
EM
2207 conf_set_opm_listen_port_both(data, true);
2208 conf_set_opm_listen_port_both(data, false);
2209}
8275e270 2210
51fa2ab8
EM
2211static void
2212conf_set_opm_scan_ports_all(void *data, const char *node, const char *type)
2213{
2214 conf_parm_t *args = data;
2215 for (; args; args = args->next)
8275e270 2216 {
51fa2ab8
EM
2217 rb_dlink_node *ptr;
2218 bool dup = false;
8275e270 2219
51fa2ab8
EM
2220 if(CF_TYPE(args->type) != CF_INT)
2221 {
2222 conf_report_error("%s argument is not an integer -- ignoring.", node);
2223 continue;
2224 }
5e9a3f86 2225
51fa2ab8
EM
2226 if(args->v.number > 65535 || args->v.number <= 0)
2227 {
2228 conf_report_error("%s argument is not an integer between 1 and 65535 -- ignoring.", node);
2229 continue;
2230 }
8275e270 2231
51fa2ab8
EM
2232 /* Check for duplicates */
2233 RB_DLINK_FOREACH(ptr, yy_opm_scanner_list.head)
2234 {
2235 struct opm_scanner *scanner = ptr->data;
2236
2237 if(scanner->port == args->v.number && strcmp(type, scanner->type) == 0)
2238 {
2239 conf_report_error("%s argument is duplicate", node);
2240 dup = true;
2241 break;
2242 }
2243 }
2244
2245 if(!dup)
2246 {
2247 struct opm_scanner *scanner = rb_malloc(sizeof(struct opm_scanner));
2248 scanner->port = args->v.number;
2249 scanner->type = type;
2250 rb_dlinkAdd(scanner, &scanner->node, &yy_opm_scanner_list);
2251 }
8275e270 2252 }
51fa2ab8 2253}
8275e270 2254
51fa2ab8
EM
2255static void
2256conf_set_opm_scan_ports_socks4(void *data)
2257{
2258 conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
2259}
8275e270 2260
51fa2ab8
EM
2261static void
2262conf_set_opm_scan_ports_socks5(void *data)
2263{
2264 conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
8275e270
EM
2265}
2266
fabe8b94
EM
2267static void
2268conf_set_opm_scan_ports_httpconnect(void *data)
2269{
2270 conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
2271}
2272
eb0814b3
EM
2273static void
2274conf_set_opm_scan_ports_httpsconnect(void *data)
2275{
2276 conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");
2277}
2278
212380e3
WP
2279/* public functions */
2280
2281
2282void
2283conf_report_error(const char *fmt, ...)
2284{
2285 va_list ap;
82236a2a 2286 char msg[BUFSIZE + 1] = { 0 };
212380e3
WP
2287
2288 va_start(ap, fmt);
82236a2a 2289 vsnprintf(msg, BUFSIZE, fmt, ap);
212380e3
WP
2290 va_end(ap);
2291
2292 if (testing_conf)
2293 {
2294 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2295 return;
2296 }
2297
2298 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2299 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "error: \"%s\", line %d: %s", current_file, lineno + 1, msg);
d84acbce
WP
2300}
2301
2302void
2303conf_report_warning(const char *fmt, ...)
2304{
2305 va_list ap;
82236a2a 2306 char msg[BUFSIZE + 1] = { 0 };
d84acbce
WP
2307
2308 va_start(ap, fmt);
82236a2a 2309 vsnprintf(msg, BUFSIZE, fmt, ap);
d84acbce
WP
2310 va_end(ap);
2311
2312 if (testing_conf)
2313 {
2314 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2315 return;
2316 }
2317
2318 iwarn("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2319 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "warning: \"%s\", line %d: %s", current_file, lineno + 1, msg);
212380e3
WP
2320}
2321
2322int
2323conf_start_block(char *block, char *name)
2324{
2325 if((conf_cur_block = find_top_conf(block)) == NULL)
2326 {
2327 conf_report_error("Configuration block '%s' is not defined.", block);
2328 return -1;
2329 }
2330
2331 if(name)
47a03750 2332 conf_cur_block_name = rb_strdup(name);
212380e3
WP
2333 else
2334 conf_cur_block_name = NULL;
2335
2336 if(conf_cur_block->tc_sfunc)
2337 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
2338 return -1;
2339
2340 return 0;
2341}
2342
2343int
2344conf_end_block(struct TopConf *tc)
2345{
e12981c0 2346 int ret = 0;
212380e3 2347 if(tc->tc_efunc)
e12981c0 2348 ret = tc->tc_efunc(tc);
212380e3 2349
637c4932 2350 rb_free(conf_cur_block_name);
e12981c0
KB
2351 conf_cur_block_name = NULL;
2352 return ret;
212380e3
WP
2353}
2354
2355static void
2356conf_set_generic_int(void *data, void *location)
2357{
2358 *((int *) location) = *((unsigned int *) data);
2359}
2360
2361static void
2362conf_set_generic_string(void *data, int len, void *location)
2363{
2364 char **loc = location;
2365 char *input = data;
2366
2e819b6b 2367 if(len && strlen(input) > (unsigned int)len)
212380e3
WP
2368 input[len] = '\0';
2369
637c4932 2370 rb_free(*loc);
47a03750 2371 *loc = rb_strdup(input);
212380e3
WP
2372}
2373
2374int
dceac3e4 2375conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value)
212380e3
WP
2376{
2377 struct ConfEntry *cf;
2378 conf_parm_t *cp;
2379
2380 if(!tc)
2381 return -1;
2382
2383 if((cf = find_conf_item(tc, item)) == NULL)
2384 {
2385 conf_report_error
ffa79a95 2386 ("Non-existent configuration setting %s::%s.", tc->tc_name, (char *) item);
212380e3
WP
2387 return -1;
2388 }
2389
2390 /* if it takes one thing, make sure they only passed one thing,
2391 and handle as needed. */
ed45dfe6 2392 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
212380e3
WP
2393 {
2394 conf_report_error
2395 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
2396 return -1;
2397 }
2398
2399 cp = value->v.list;
2400
2401
2402 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
2403 {
023c36ae 2404 /* if it expects a string value, but we got a yesno,
212380e3
WP
2405 * convert it back
2406 */
2407 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
2408 (CF_TYPE(cf->cf_type) == CF_STRING))
2409 {
2410 value->v.list->type = CF_STRING;
2411
2412 if(cp->v.number == 1)
47a03750 2413 cp->v.string = rb_strdup("yes");
212380e3 2414 else
47a03750 2415 cp->v.string = rb_strdup("no");
212380e3
WP
2416 }
2417
2418 /* maybe it's a CF_TIME and they passed CF_INT --
2419 should still be valid */
2420 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
2421 (CF_TYPE(cf->cf_type) == CF_TIME)))
2422 {
2423 conf_report_error
2424 ("Wrong type for %s::%s (expected %s, got %s)",
2425 tc->tc_name, (char *) item,
2426 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
2427 return -1;
2428 }
2429 }
2430
2431 if(cf->cf_type & CF_FLIST)
2432 {
2433#if 0
2434 if(cf->cf_arg)
2435 conf_set_generic_list(value->v.list, cf->cf_arg);
2436 else
2437#endif
2438 /* just pass it the extended argument list */
2439 cf->cf_func(value->v.list);
2440 }
2441 else
2442 {
2443 /* it's old-style, needs only one arg */
2444 switch (cf->cf_type)
2445 {
2446 case CF_INT:
2447 case CF_TIME:
2448 case CF_YESNO:
2449 if(cf->cf_arg)
2450 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2451 else
2452 cf->cf_func(&cp->v.number);
2453 break;
2454 case CF_STRING:
2455 case CF_QSTRING:
2456 if(EmptyString(cp->v.string))
2457 conf_report_error("Ignoring %s::%s -- empty field",
2458 tc->tc_name, item);
2459 else if(cf->cf_arg)
2460 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2461 else
2462 cf->cf_func(cp->v.string);
2463 break;
2464 }
2465 }
2466
2467
2468 return 0;
2469}
2470
2471int
2472add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2473{
2474 struct TopConf *tc;
2475 struct ConfEntry *cf;
2476
2477 if((tc = find_top_conf(topconf)) == NULL)
2478 return -1;
2479
12edf3e3 2480 if(find_conf_item(tc, name) != NULL)
212380e3
WP
2481 return -1;
2482
eddc2ab6 2483 cf = rb_malloc(sizeof(struct ConfEntry));
212380e3 2484
d7f753cd 2485 cf->cf_name = name;
212380e3
WP
2486 cf->cf_type = type;
2487 cf->cf_func = func;
2488 cf->cf_arg = NULL;
2489
330fc5c1 2490 rb_dlinkAddAlloc(cf, &tc->tc_items);
212380e3
WP
2491
2492 return 0;
2493}
2494
2495int
2496remove_conf_item(const char *topconf, const char *name)
2497{
2498 struct TopConf *tc;
2499 struct ConfEntry *cf;
330fc5c1 2500 rb_dlink_node *ptr;
212380e3
WP
2501
2502 if((tc = find_top_conf(topconf)) == NULL)
2503 return -1;
2504
2505 if((cf = find_conf_item(tc, name)) == NULL)
2506 return -1;
2507
330fc5c1 2508 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
212380e3
WP
2509 return -1;
2510
330fc5c1 2511 rb_dlinkDestroy(ptr, &tc->tc_items);
637c4932 2512 rb_free(cf);
212380e3
WP
2513
2514 return 0;
2515}
2516
2517/* *INDENT-OFF* */
2518static struct ConfEntry conf_serverinfo_table[] =
2519{
2520 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
212380e3
WP
2521
2522 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2523 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2524 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2525 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2526 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2527
8bd5767b
JT
2528 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2529 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
023c36ae 2530 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
8bd5767b 2531 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
c1725bda 2532 { "ssl_cipher_list", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cipher_list },
c6d72037
VY
2533 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2534
101db4c4 2535 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
c2d96fcb 2536
b583faf9
WP
2537 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2538
212380e3
WP
2539 { "\0", 0, NULL, 0, NULL }
2540};
2541
2542static struct ConfEntry conf_admin_table[] =
2543{
2544 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2545 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2546 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2547 { "\0", 0, NULL, 0, NULL }
2548};
2549
2550static struct ConfEntry conf_log_table[] =
2551{
d74fa5b5
JT
2552 { "fname_userlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_userlog },
2553 { "fname_fuserlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_fuserlog },
2554 { "fname_operlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operlog },
2555 { "fname_foperlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_foperlog },
2556 { "fname_serverlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_serverlog },
2557 { "fname_killlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_killlog },
2558 { "fname_klinelog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_klinelog },
2559 { "fname_operspylog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operspylog },
2560 { "fname_ioerrorlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_ioerrorlog },
212380e3
WP
2561 { "\0", 0, NULL, 0, NULL }
2562};
2563
2564static struct ConfEntry conf_operator_table[] =
2565{
2566 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2567 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2568 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
22c3b270 2569 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
212380e3
WP
2570 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2571 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2572 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
ff31db84 2573 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
212380e3
WP
2574 { "\0", 0, NULL, 0, NULL }
2575};
2576
f8606875
WP
2577static struct ConfEntry conf_privset_table[] =
2578{
2579 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2580 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2581 { "\0", 0, NULL, 0, NULL }
2582};
2583
212380e3
WP
2584static struct ConfEntry conf_class_table[] =
2585{
2586 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
e33e589c 2587 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
e33e589c 2588 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
212380e3
WP
2589 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2590 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2591 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2592 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2593 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2594 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
7c7065b0 2595 { "max_autoconn", CF_INT, conf_set_class_max_autoconn, 0, NULL },
212380e3
WP
2596 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2597 { "\0", 0, NULL, 0, NULL }
2598};
2599
2600static struct ConfEntry conf_auth_table[] =
2601{
2602 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
40c1fd47 2603 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
212380e3
WP
2604 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2605 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2606 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2607 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2608 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2609 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
2610 { "\0", 0, NULL, 0, NULL }
2611};
2612
2613static struct ConfEntry conf_connect_table[] =
2614{
2615 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2616 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
ff0cc1e6 2617 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
212380e3
WP
2618 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2619 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2620 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2621 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2622 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
212380e3
WP
2623 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2624 { "\0", 0, NULL, 0, NULL }
2625};
2626
2627static struct ConfEntry conf_general_table[] =
2628{
2629 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2630 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2631 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
2632 { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL },
2633 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2634 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
212380e3 2635 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
63ab1dd6
EK
2636 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2637 { "stats_l_oper_only", CF_STRING, conf_set_general_stats_l_oper_only, 0, NULL },
212380e3
WP
2638 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2639
2640 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2641 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2642 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
212380e3
WP
2643 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2644 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2645 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
7d33cce8 2646 { "sasl_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.sasl_service },
212380e3
WP
2647
2648 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2649 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2650 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2651 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2652 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2653
6ac21a70
EK
2654 { "hidden_caps", CF_QSTRING | CF_FLIST, conf_set_general_hidden_caps, 0, NULL },
2655
212380e3
WP
2656 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2657 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2658 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2659 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
212380e3 2660 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
330692a1 2661 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
b3a00991 2662 { "post_registration_delay", CF_TIME, NULL, 0, &ConfigFileEntry.post_registration_delay },
212380e3
WP
2663 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2664 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
944b0584 2665 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
212380e3 2666 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
212380e3
WP
2667 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2668 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
212380e3 2669 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
212380e3
WP
2670 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2671 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2672 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
9914c013 2673 { "hide_tkdline_duration", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_tkdline_duration },
212380e3
WP
2674 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2675 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2676 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2677 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2678 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2679 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2680 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2681 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2682 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2683 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2684 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2685 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2686 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2687 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2688 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2689 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2690 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
43946961
JT
2691 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2692 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
212380e3
WP
2693 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2694 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2695 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
212380e3
WP
2696 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2697 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2698 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2699 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2700 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
212380e3
WP
2701 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2702 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2703 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
1702b694 2704 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
e6e54763
SB
2705 { "client_flood_max_lines", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_max_lines },
2706 { "client_flood_burst_rate", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_rate },
2707 { "client_flood_burst_max", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_max },
2708 { "client_flood_message_num", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_num },
2709 { "client_flood_message_time", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_time },
e88a1f1b 2710 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
d42e6915 2711 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
71c95533 2712 { "hide_opers_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers_in_whois },
1123eefc 2713 { "hide_opers", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers },
13d8f0ed 2714 { "certfp_method", CF_STRING, conf_set_general_certfp_method, 0, NULL },
b674a619 2715 { "drain_reason", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.drain_reason },
fff4f763 2716 { "tls_ciphers_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.tls_ciphers_oper_only },
40ecb85a 2717 { "oper_secure_only", CF_YESNO, NULL, 0, &ConfigFileEntry.oper_secure_only },
212380e3
WP
2718 { "\0", 0, NULL, 0, NULL }
2719};
2720
2721static struct ConfEntry conf_channel_table[] =
2722{
2723 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2724 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2725 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
212380e3
WP
2726 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2727 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2728 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2729 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2730 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2731 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
a4721f5e 2732 { "max_chans_per_user_large", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user_large },
212380e3
WP
2733 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2734 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
6865c0b0 2735 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
212380e3
WP
2736 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2737 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2da6f6eb 2738 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
212380e3 2739 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
c2c25552 2740 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
717238d2 2741 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
341f971e 2742 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
63eb8567 2743 { "autochanmodes", CF_QSTRING, conf_set_channel_autochanmodes, 0, NULL },
d513218a 2744 { "displayed_usercount", CF_INT, NULL, 0, &ConfigChannel.displayed_usercount },
14482679 2745 { "strip_topic_colors", CF_YESNO, NULL, 0, &ConfigChannel.strip_topic_colors },
04e5ed6c 2746 { "opmod_send_statusmsg", CF_YESNO, NULL, 0, &ConfigChannel.opmod_send_statusmsg },
212380e3
WP
2747 { "\0", 0, NULL, 0, NULL }
2748};
2749
2750static struct ConfEntry conf_serverhide_table[] =
2751{
2752 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2753 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2754 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2755 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2756 { "\0", 0, NULL, 0, NULL }
2757};
2758/* *INDENT-ON* */
2759
2760void
2761newconf_init()
2762{
2763 add_top_conf("modules", NULL, NULL, NULL);
2764 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2765 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2766
2767 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2768 add_top_conf("admin", NULL, NULL, conf_admin_table);
2769 add_top_conf("log", NULL, NULL, conf_log_table);
2770 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2771 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
f8606875 2772 add_top_conf("privset", NULL, NULL, conf_privset_table);
212380e3
WP
2773
2774 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
02270e96 2775 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
c53ca1e0 2776 add_conf_item("listen", "wsock", CF_YESNO, conf_set_listen_wsock);
212380e3 2777 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
c6d72037 2778 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
c6ad9b0c
SA
2779 add_conf_item("listen", "sctp_port", CF_INT | CF_FLIST, conf_set_listen_sctp_port);
2780 add_conf_item("listen", "sctp_sslport", CF_INT | CF_FLIST, conf_set_listen_sctp_sslport);
212380e3
WP
2781 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2782 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2783
2784 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2785
212380e3
WP
2786 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2787
2788 add_top_conf("exempt", NULL, NULL, NULL);
2789 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2790
1cf798be
EK
2791 add_top_conf("secure", NULL, NULL, NULL);
2792 add_conf_item("secure", "ip", CF_QSTRING, conf_set_secure_ip);
2793
212380e3
WP
2794 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2795 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2796 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2797
2798 add_top_conf("general", NULL, NULL, conf_general_table);
2799 add_top_conf("channel", NULL, NULL, conf_channel_table);
2800 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2801
c46a4ecd 2802 add_top_conf("service", NULL, NULL, NULL);
212380e3
WP
2803 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2804
2805 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2806 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2807 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2808
7f24f506
AC
2809 add_top_conf("dnsbl", NULL, NULL, NULL);
2810 add_conf_item("dnsbl", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2811 add_conf_item("dnsbl", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2812 add_conf_item("dnsbl", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2813 add_conf_item("dnsbl", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
2814
2815 add_top_conf("blacklist", conf_warn_blacklist_deprecation, NULL, NULL);
2816 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2817 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2818 add_conf_item("blacklist", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2819 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
8275e270
EM
2820
2821 add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
9bba0f61 2822 add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
8275e270 2823 add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
8275e270 2824 add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
51fa2ab8 2825 add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);
8275e270
EM
2826 add_conf_item("opm", "port_v6", CF_INT, conf_set_opm_listen_port_ipv6);
2827 add_conf_item("opm", "listen_port", CF_INT, conf_set_opm_listen_port);
51fa2ab8
EM
2828 add_conf_item("opm", "socks4_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks4);
2829 add_conf_item("opm", "socks5_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks5);
fabe8b94 2830 add_conf_item("opm", "httpconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpconnect);
eb0814b3 2831 add_conf_item("opm", "httpsconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpsconnect);
212380e3 2832}