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