]> jfr.im git - irc/freenode/solanum.git/blame - ircd/newconf.c
make more snotes L_NETWIDE
[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
1352static void
1353conf_set_connect_hub_mask(void *data)
1354{
1355 struct remote_conf *yy_hub;
1356
1357 if(EmptyString(yy_server->name))
1358 return;
1359
1360 yy_hub = make_remote_conf();
1361 yy_hub->flags = CONF_HUB;
1362
47a03750
VY
1363 yy_hub->host = rb_strdup(data);
1364 yy_hub->server = rb_strdup(yy_server->name);
330fc5c1 1365 rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list);
212380e3
WP
1366}
1367
1368static void
1369conf_set_connect_leaf_mask(void *data)
1370{
1371 struct remote_conf *yy_leaf;
1372
1373 if(EmptyString(yy_server->name))
1374 return;
1375
1376 yy_leaf = make_remote_conf();
1377 yy_leaf->flags = CONF_LEAF;
1378
47a03750
VY
1379 yy_leaf->host = rb_strdup(data);
1380 yy_leaf->server = rb_strdup(yy_server->name);
330fc5c1 1381 rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list);
212380e3
WP
1382}
1383
1384static void
1385conf_set_connect_class(void *data)
1386{
637c4932 1387 rb_free(yy_server->class_name);
47a03750 1388 yy_server->class_name = rb_strdup(data);
212380e3
WP
1389}
1390
1391static void
1392conf_set_exempt_ip(void *data)
1393{
1394 struct ConfItem *yy_tmp;
7d9e8e9d 1395 int masktype = parse_netmask_strict(data, NULL, NULL);
212380e3 1396
7d9e8e9d 1397 if(masktype != HM_IPV4 && masktype != HM_IPV6)
212380e3
WP
1398 {
1399 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1400 return;
1401 }
1402
1403 yy_tmp = make_conf();
47a03750
VY
1404 yy_tmp->passwd = rb_strdup("*");
1405 yy_tmp->host = rb_strdup(data);
212380e3 1406 yy_tmp->status = CONF_EXEMPTDLINE;
40c1fd47 1407 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
212380e3
WP
1408}
1409
1cf798be
EK
1410static void
1411conf_set_secure_ip(void *data)
1412{
1413 struct ConfItem *yy_tmp;
1414 int masktype = parse_netmask_strict(data, NULL, NULL);
1415
1416 if(masktype != HM_IPV4 && masktype != HM_IPV6)
1417 {
1418 conf_report_error("Ignoring secure -- invalid secure::ip.");
1419 return;
1420 }
1421
1422 yy_tmp = make_conf();
1423 yy_tmp->passwd = rb_strdup("*");
1424 yy_tmp->host = rb_strdup(data);
1425 yy_tmp->status = CONF_SECURE;
1426 add_conf_by_address(yy_tmp->host, CONF_SECURE, NULL, NULL, yy_tmp);
1427}
1428
212380e3
WP
1429static int
1430conf_cleanup_cluster(struct TopConf *tc)
1431{
637c4932 1432 rb_dlink_node *ptr, *next_ptr;
212380e3 1433
637c4932 1434 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
WP
1435 {
1436 free_remote_conf(ptr->data);
330fc5c1 1437 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
WP
1438 }
1439
1440 if(yy_shared != NULL)
1441 {
1442 free_remote_conf(yy_shared);
1443 yy_shared = NULL;
1444 }
1445
1446 return 0;
1447}
1448
1449static void
1450conf_set_cluster_name(void *data)
1451{
1452 if(yy_shared != NULL)
1453 free_remote_conf(yy_shared);
1454
1455 yy_shared = make_remote_conf();
47a03750 1456 yy_shared->server = rb_strdup(data);
330fc5c1 1457 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
212380e3
WP
1458
1459 yy_shared = NULL;
1460}
1461
1462static void
1463conf_set_cluster_flags(void *data)
1464{
1465 conf_parm_t *args = data;
1466 int flags = 0;
637c4932 1467 rb_dlink_node *ptr, *next_ptr;
212380e3
WP
1468
1469 if(yy_shared != NULL)
1470 free_remote_conf(yy_shared);
1471
1472 set_modes_from_table(&flags, "flag", cluster_table, args);
1473
637c4932 1474 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
212380e3
WP
1475 {
1476 yy_shared = ptr->data;
1477 yy_shared->flags = flags;
330fc5c1
WP
1478 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1479 rb_dlinkDestroy(ptr, &yy_cluster_list);
212380e3
WP
1480 }
1481
1482 yy_shared = NULL;
1483}
1484
1485static void
1486conf_set_general_havent_read_conf(void *data)
1487{
1488 if(*(unsigned int *) data)
1489 {
1490 conf_report_error("You haven't read your config file properly.");
1491 conf_report_error
1492 ("There is a line in the example conf that will kill your server if not removed.");
1493 conf_report_error
1494 ("Consider actually reading/editing the conf file, and removing this line.");
1495 if (!testing_conf)
1496 exit(0);
1497 }
1498}
1499
1500static void
1501conf_set_general_hide_error_messages(void *data)
1502{
1503 char *val = data;
1504
f956cb0f 1505 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1506 ConfigFileEntry.hide_error_messages = 2;
f956cb0f 1507 else if(rb_strcasecmp(val, "opers") == 0)
212380e3 1508 ConfigFileEntry.hide_error_messages = 1;
f956cb0f 1509 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1510 ConfigFileEntry.hide_error_messages = 0;
1511 else
1512 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1513}
1514
212380e3
WP
1515static void
1516conf_set_general_stats_k_oper_only(void *data)
1517{
1518 char *val = data;
1519
f956cb0f 1520 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1521 ConfigFileEntry.stats_k_oper_only = 2;
f956cb0f 1522 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1523 ConfigFileEntry.stats_k_oper_only = 1;
f956cb0f 1524 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1525 ConfigFileEntry.stats_k_oper_only = 0;
1526 else
1527 conf_report_error("Invalid setting '%s' for general::stats_k_oper_only.", val);
1528}
1529
1530static void
1531conf_set_general_stats_i_oper_only(void *data)
1532{
1533 char *val = data;
1534
f956cb0f 1535 if(rb_strcasecmp(val, "yes") == 0)
212380e3 1536 ConfigFileEntry.stats_i_oper_only = 2;
f956cb0f 1537 else if(rb_strcasecmp(val, "masked") == 0)
212380e3 1538 ConfigFileEntry.stats_i_oper_only = 1;
f956cb0f 1539 else if(rb_strcasecmp(val, "no") == 0)
212380e3
WP
1540 ConfigFileEntry.stats_i_oper_only = 0;
1541 else
1542 conf_report_error("Invalid setting '%s' for general::stats_i_oper_only.", val);
1543}
1544
1545static void
1546conf_set_general_compression_level(void *data)
1547{
1548#ifdef HAVE_LIBZ
1549 ConfigFileEntry.compression_level = *(unsigned int *) data;
1550
1551 if((ConfigFileEntry.compression_level < 1) || (ConfigFileEntry.compression_level > 9))
1552 {
1553 conf_report_error
1554 ("Invalid general::compression_level %d -- using default.",
1555 ConfigFileEntry.compression_level);
1556 ConfigFileEntry.compression_level = 0;
1557 }
1558#else
1559 conf_report_error("Ignoring general::compression_level -- zlib not available.");
1560#endif
1561}
1562
1563static void
1564conf_set_general_default_umodes(void *data)
1565{
1566 char *pm;
1567 int what = MODE_ADD, flag;
1568
1569 ConfigFileEntry.default_umodes = 0;
1570 for (pm = (char *) data; *pm; pm++)
1571 {
1572 switch (*pm)
1573 {
1574 case '+':
1575 what = MODE_ADD;
1576 break;
1577 case '-':
1578 what = MODE_DEL;
1579 break;
1580
1581 /* don't allow +o */
1582 case 'o':
1583 case 'S':
5fabe513 1584 case 'Z':
212380e3
WP
1585 case ' ':
1586 break;
1587
1588 default:
1589 if ((flag = user_modes[(unsigned char) *pm]))
1590 {
1591 /* Proper value has probably not yet been set
1592 * so don't check oper_only_umodes -- jilles */
1593 if (what == MODE_ADD)
1594 ConfigFileEntry.default_umodes |= flag;
1595 else
1596 ConfigFileEntry.default_umodes &= ~flag;
1597 }
1598 break;
1599 }
023c36ae 1600 }
212380e3
WP
1601}
1602
1603static void
1604conf_set_general_oper_umodes(void *data)
1605{
1606 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1607}
1608
13d8f0ed
WP
1609static void
1610conf_set_general_certfp_method(void *data)
1611{
1612 char *method = data;
1613
f018ed84 1614 if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA1))
cf430c1a 1615 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
f018ed84 1616 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA256))
cf430c1a 1617 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA256;
f018ed84 1618 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA512))
cf430c1a 1619 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA512;
f018ed84 1620 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA256))
cf430c1a 1621 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA256;
f018ed84 1622 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA512))
cf430c1a 1623 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA512;
13d8f0ed
WP
1624 else
1625 {
cf430c1a 1626 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
13d8f0ed
WP
1627 conf_report_error("Ignoring general::certfp_method -- bogus certfp method %s", method);
1628 }
1629}
1630
212380e3
WP
1631static void
1632conf_set_general_oper_only_umodes(void *data)
1633{
1634 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1635}
1636
1637static void
1638conf_set_general_oper_snomask(void *data)
1639{
1640 char *pm;
1641 int what = MODE_ADD, flag;
1642
1643 ConfigFileEntry.oper_snomask = 0;
1644 for (pm = (char *) data; *pm; pm++)
1645 {
1646 switch (*pm)
1647 {
1648 case '+':
1649 what = MODE_ADD;
1650 break;
1651 case '-':
1652 what = MODE_DEL;
1653 break;
1654
1655 default:
1656 if ((flag = snomask_modes[(unsigned char) *pm]))
1657 {
1658 if (what == MODE_ADD)
1659 ConfigFileEntry.oper_snomask |= flag;
1660 else
1661 ConfigFileEntry.oper_snomask &= ~flag;
1662 }
1663 break;
1664 }
1665 }
1666}
1667
6ac21a70
EK
1668static void
1669conf_set_general_hidden_caps(void *data)
1670{
1671 size_t n = 0;
1672
1673 for (conf_parm_t *arg = data; arg; arg = arg->next)
1674 n += 1;
1675
1676 if (ConfigFileEntry.hidden_caps != NULL)
1677 {
1678 for (n = 0; ConfigFileEntry.hidden_caps[n] != NULL; n++)
1679 rb_free(ConfigFileEntry.hidden_caps[n]);
1680 rb_free(ConfigFileEntry.hidden_caps);
1681 }
1682 ConfigFileEntry.hidden_caps = rb_malloc(sizeof *ConfigFileEntry.hidden_caps * (n + 1));
1683
1684 n = 0;
1685 for (conf_parm_t *arg = data; arg; arg = arg->next)
1686 {
1687 ConfigFileEntry.hidden_caps[n++] = rb_strdup(arg->v.string);
1688 }
1689 ConfigFileEntry.hidden_caps[n] = NULL;
1690}
1691
212380e3
WP
1692static void
1693conf_set_serverhide_links_delay(void *data)
1694{
1695 int val = *(unsigned int *) data;
1696
212380e3
WP
1697 ConfigServerHide.links_delay = val;
1698}
1699
212380e3
WP
1700static void
1701conf_set_service_name(void *data)
1702{
212380e3
WP
1703 const char *s;
1704 char *tmp;
1705 int dots = 0;
1706
1707 for(s = data; *s != '\0'; s++)
1708 {
1709 if(!IsServChar(*s))
1710 {
1711 conf_report_error("Ignoring service::name "
1712 "-- bogus servername.");
1713 return;
1714 }
1715 else if(*s == '.')
1716 dots++;
1717 }
1718
1719 if(!dots)
1720 {
1721 conf_report_error("Ignoring service::name -- must contain '.'");
1722 return;
1723 }
1724
47a03750 1725 tmp = rb_strdup(data);
330fc5c1 1726 rb_dlinkAddAlloc(tmp, &service_list);
212380e3
WP
1727}
1728
212380e3
WP
1729static int
1730conf_begin_alias(struct TopConf *tc)
1731{
eddc2ab6 1732 yy_alias = rb_malloc(sizeof(struct alias_entry));
212380e3
WP
1733
1734 if (conf_cur_block_name != NULL)
47a03750 1735 yy_alias->name = rb_strdup(conf_cur_block_name);
212380e3
WP
1736
1737 yy_alias->flags = 0;
212380e3
WP
1738
1739 return 0;
1740}
1741
1742static int
1743conf_end_alias(struct TopConf *tc)
1744{
212380e3
WP
1745 if (yy_alias == NULL)
1746 return -1;
1747
1748 if (yy_alias->name == NULL)
1749 {
1750 conf_report_error("Ignoring alias -- must have a name.");
1751
637c4932 1752 rb_free(yy_alias);
212380e3
WP
1753
1754 return -1;
1755 }
1756
1757 if (yy_alias->target == NULL)
1758 {
1759 conf_report_error("Ignoring alias -- must have a target.");
1760
637c4932 1761 rb_free(yy_alias);
212380e3
WP
1762
1763 return -1;
1764 }
1765
a4bf26dd 1766 rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
212380e3
WP
1767
1768 return 0;
1769}
1770
1771static void
1772conf_set_alias_name(void *data)
1773{
1774 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1775 return;
1776
47a03750 1777 yy_alias->name = rb_strdup(data);
212380e3
WP
1778}
1779
1780static void
1781conf_set_alias_target(void *data)
1782{
1783 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1784 return;
1785
47a03750 1786 yy_alias->target = rb_strdup(data);
212380e3
WP
1787}
1788
63eb8567
WP
1789static void
1790conf_set_channel_autochanmodes(void *data)
1791{
1792 char *pm;
1793 int what = MODE_ADD;
1794
1795 ConfigChannel.autochanmodes = 0;
1796 for (pm = (char *) data; *pm; pm++)
1797 {
1798 switch (*pm)
1799 {
1800 case '+':
1801 what = MODE_ADD;
1802 break;
1803 case '-':
1804 what = MODE_DEL;
1805 break;
1806
1807 default:
1808 if (chmode_table[(unsigned char) *pm].set_func == chm_simple)
1809 {
1810 if (what == MODE_ADD)
1811 ConfigChannel.autochanmodes |= chmode_table[(unsigned char) *pm].mode_type;
1812 else
1813 ConfigChannel.autochanmodes &= ~chmode_table[(unsigned char) *pm].mode_type;
1814 }
1815 else
1816 {
4952e40b 1817 conf_report_error("channel::autochanmodes -- Invalid channel mode %c", *pm);
63eb8567
WP
1818 continue;
1819 }
1820 break;
1821 }
1822 }
1823}
1824
3c93d380 1825/* XXX for below */
7f24f506 1826static void conf_set_dnsbl_entry_reason(void *data);
3c93d380 1827
d3f6b808
EM
1828#define IPTYPE_IPV4 1
1829#define IPTYPE_IPV6 2
1830
7f24f506
AC
1831static int
1832conf_warn_blacklist_deprecation(struct TopConf *tc)
1833{
1834 conf_report_error("blacklist{} blocks have been deprecated -- use dnsbl{} blocks instead.");
1835 return 0;
1836}
1837
212380e3 1838static void
7f24f506 1839conf_set_dnsbl_entry_host(void *data)
212380e3 1840{
7f24f506 1841 if (yy_dnsbl_entry_host)
3c93d380 1842 {
7f24f506
AC
1843 conf_report_error("dnsbl::host %s overlaps existing host %s",
1844 (char *)data, yy_dnsbl_entry_host);
3c93d380
EM
1845
1846 /* Cleanup */
7f24f506 1847 conf_set_dnsbl_entry_reason(NULL);
3c93d380
EM
1848 return;
1849 }
1850
7f24f506
AC
1851 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1852 yy_dnsbl_entry_host = rb_strdup(data);
212380e3
WP
1853}
1854
0a1e77c2 1855static void
7f24f506 1856conf_set_dnsbl_entry_type(void *data)
0a1e77c2
EM
1857{
1858 conf_parm_t *args = data;
1859
1860 /* Don't assume we have either if we got here */
7f24f506 1861 yy_dnsbl_entry_iptype = 0;
0a1e77c2
EM
1862
1863 for (; args; args = args->next)
1864 {
f956cb0f 1865 if (!rb_strcasecmp(args->v.string, "ipv4"))
7f24f506 1866 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
f956cb0f 1867 else if (!rb_strcasecmp(args->v.string, "ipv6"))
7f24f506 1868 yy_dnsbl_entry_iptype |= IPTYPE_IPV6;
0a1e77c2 1869 else
7f24f506 1870 conf_report_error("dnsbl::type has unknown address family %s",
0a1e77c2
EM
1871 args->v.string);
1872 }
1873
1874 /* If we have neither, just default to IPv4 */
7f24f506 1875 if (!yy_dnsbl_entry_iptype)
0a1e77c2 1876 {
7f24f506
AC
1877 conf_report_warning("dnsbl::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1878 yy_dnsbl_entry_iptype = IPTYPE_IPV4;
0a1e77c2
EM
1879 }
1880}
1881
3c93d380 1882static void
7f24f506 1883conf_set_dnsbl_entry_matches(void *data)
3c93d380
EM
1884{
1885 conf_parm_t *args = data;
d3f6b808 1886 enum filter_t { FILTER_NONE, FILTER_ALL, FILTER_LAST };
3c93d380
EM
1887
1888 for (; args; args = args->next)
1889 {
3c93d380
EM
1890 char *str = args->v.string;
1891 char *p;
d3f6b808 1892 enum filter_t type = FILTER_LAST;
3c93d380
EM
1893
1894 if (CF_TYPE(args->type) != CF_QSTRING)
1895 {
7f24f506 1896 conf_report_error("dnsbl::matches -- must be quoted string");
3c93d380
EM
1897 continue;
1898 }
1899
1900 if (str == NULL)
1901 {
7f24f506 1902 conf_report_error("dnsbl::matches -- invalid entry");
3c93d380
EM
1903 continue;
1904 }
1905
1906 if (strlen(str) > HOSTIPLEN)
1907 {
7f24f506 1908 conf_report_error("dnsbl::matches has an entry too long: %s",
3c93d380
EM
1909 str);
1910 continue;
1911 }
1912
1913 for (p = str; *p != '\0'; p++)
1914 {
1915 /* Check for validity */
1916 if (*p == '.')
d3f6b808
EM
1917 type = FILTER_ALL;
1918 else if (!isdigit((unsigned char)*p))
3c93d380 1919 {
7f24f506 1920 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380 1921 str);
d3f6b808 1922 type = FILTER_NONE;
3c93d380
EM
1923 break;
1924 }
1925 }
1926
d3f6b808 1927 if (type == FILTER_ALL)
3c93d380
EM
1928 {
1929 /* Basic IP sanity check */
1930 struct rb_sockaddr_storage tmp;
1931 if (rb_inet_pton(AF_INET, str, &tmp) <= 0)
1932 {
7f24f506 1933 conf_report_error("dnsbl::matches has invalid IP match entry %s",
3c93d380
EM
1934 str);
1935 continue;
1936 }
1937 }
d3f6b808 1938 else if (type == FILTER_LAST)
3c93d380
EM
1939 {
1940 /* Verify it's the correct length */
1941 if (strlen(str) > 3)
1942 {
7f24f506 1943 conf_report_error("dnsbl::matches has invalid octet match entry %s",
3c93d380
EM
1944 str);
1945 continue;
1946 }
1947 }
1948 else
1949 {
1950 continue; /* Invalid entry */
1951 }
1952
7f24f506 1953 rb_dlinkAddAlloc(rb_strdup(str), &yy_dnsbl_entry_filters);
3c93d380
EM
1954 }
1955}
1956
212380e3 1957static void
7f24f506 1958conf_set_dnsbl_entry_reason(void *data)
212380e3 1959{
3c93d380 1960 rb_dlink_node *ptr, *nptr;
212380e3 1961
7f24f506 1962 if (yy_dnsbl_entry_host && data)
212380e3 1963 {
7f24f506
AC
1964 yy_dnsbl_entry_reason = rb_strdup(data);
1965 if (yy_dnsbl_entry_iptype & IPTYPE_IPV6)
0a1e77c2 1966 {
a6a30cc7 1967 /* Make sure things fit (magic number 64 = alnum count + dots)
771dcfad
EM
1968 * 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
1969 */
7f24f506 1970 if ((64 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 1971 {
7f24f506
AC
1972 conf_report_error("dnsbl::host %s results in IPv6 queries that are too long",
1973 yy_dnsbl_entry_host);
0a1e77c2
EM
1974 goto cleanup_bl;
1975 }
1976 }
1977 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
7f24f506 1978 if ((yy_dnsbl_entry_iptype & IPTYPE_IPV4) && !(yy_dnsbl_entry_iptype & IPTYPE_IPV6))
0a1e77c2 1979 {
a6a30cc7
EM
1980 /* Make sure things fit for worst case (magic number 16 = number of nums + dots)
1981 * Example: 127.127.127.127.in-addr.arpa
771dcfad 1982 */
7f24f506 1983 if ((16 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
0a1e77c2 1984 {
7f24f506
AC
1985 conf_report_error("dnsbl::host %s results in IPv4 queries that are too long",
1986 yy_dnsbl_entry_host);
0a1e77c2
EM
1987 goto cleanup_bl;
1988 }
1989 }
1990
7f24f506 1991 add_dnsbl_entry(yy_dnsbl_entry_host, yy_dnsbl_entry_reason, yy_dnsbl_entry_iptype, &yy_dnsbl_entry_filters);
3c93d380 1992 }
0a1e77c2
EM
1993
1994cleanup_bl:
7f24f506 1995 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_dnsbl_entry_filters.head)
e232f35c 1996 {
d3f6b808 1997 rb_free(ptr->data);
7f24f506 1998 rb_dlinkDestroy(ptr, &yy_dnsbl_entry_filters);
212380e3 1999 }
3c93d380 2000
7f24f506 2001 yy_dnsbl_entry_filters = (rb_dlink_list){ NULL, NULL, 0 };
d3f6b808 2002
7f24f506
AC
2003 rb_free(yy_dnsbl_entry_host);
2004 rb_free(yy_dnsbl_entry_reason);
2005 yy_dnsbl_entry_host = NULL;
2006 yy_dnsbl_entry_reason = NULL;
2007 yy_dnsbl_entry_iptype = 0;
212380e3
WP
2008}
2009
51fa2ab8
EM
2010
2011struct opm_scanner
2012{
2013 const char *type;
2014 uint16_t port;
2015
2016 rb_dlink_node node;
2017};
2018
8275e270
EM
2019static int
2020conf_begin_opm(struct TopConf *tc)
2021{
2022 yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL;
9bba0f61 2023 yy_opm_port_ipv4 = yy_opm_port_ipv6 = yy_opm_timeout = 0;
5c5296c8 2024 delete_opm_proxy_scanner_all();
5e9a3f86 2025 delete_opm_listener_all();
8275e270
EM
2026 return 0;
2027}
2028
2029static int
2030conf_end_opm(struct TopConf *tc)
2031{
51fa2ab8
EM
2032 rb_dlink_node *ptr, *nptr;
2033 bool fail = false;
2034
ffa79a95 2035 if(rb_dlink_list_length(&yy_opm_scanner_list) == 0)
51fa2ab8 2036 {
c1f4db3f 2037 conf_report_error("No opm scanners configured -- disabling opm.");
51fa2ab8
EM
2038 fail = true;
2039 goto end;
2040 }
2041
8275e270
EM
2042 if(yy_opm_port_ipv4 > 0)
2043 {
2044 if(yy_opm_address_ipv4 != NULL)
5e9a3f86 2045 conf_create_opm_listener(yy_opm_address_ipv4, yy_opm_port_ipv4);
8275e270
EM
2046 else
2047 {
2048 char ip[HOSTIPLEN];
d4214e94 2049 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind4, ip, sizeof(ip)))
8275e270 2050 conf_report_error("No opm::listen_ipv4 nor serverinfo::vhost directive; cannot listen on IPv4");
8275e270 2051 else
5e9a3f86 2052 conf_create_opm_listener(ip, yy_opm_port_ipv4);
8275e270
EM
2053 }
2054 }
2055
2056 if(yy_opm_port_ipv6 > 0)
2057 {
2058 if(yy_opm_address_ipv6 != NULL)
5e9a3f86 2059 conf_create_opm_listener(yy_opm_address_ipv6, yy_opm_port_ipv6);
8275e270
EM
2060 else
2061 {
2062 char ip[HOSTIPLEN];
d4214e94 2063 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind6, ip, sizeof(ip)))
8275e270 2064 conf_report_error("No opm::listen_ipv6 nor serverinfo::vhost directive; cannot listen on IPv6");
8275e270 2065 else
5e9a3f86 2066 conf_create_opm_listener(ip, yy_opm_port_ipv6);
8275e270
EM
2067 }
2068 }
2069
51fa2ab8
EM
2070 /* If there's no listeners... */
2071 fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0);
c1f4db3f 2072 if(!fail && yy_opm_timeout > 0 && yy_opm_timeout < 60)
9bba0f61
EM
2073 /* Send timeout */
2074 set_authd_timeout("opm_timeout", yy_opm_timeout);
c1f4db3f
EM
2075 else if(fail)
2076 conf_report_error("No opm listeners -- disabling");
2077 else if(yy_opm_timeout <= 0 || yy_opm_timeout >= 60)
2078 conf_report_error("opm::timeout value is invalid -- ignoring");
9bba0f61 2079
51fa2ab8
EM
2080end:
2081 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_opm_scanner_list.head)
2082 {
2083 struct opm_scanner *scanner = ptr->data;
2084
2085 if(!fail)
2086 create_opm_proxy_scanner(scanner->type, scanner->port);
2087
2088 rb_dlinkDelete(&scanner->node, &yy_opm_scanner_list);
2089 rb_free(scanner);
2090 }
2091
34bc7cae
EM
2092 if(!fail)
2093 opm_check_enable(true);
2094
8275e270
EM
2095 rb_free(yy_opm_address_ipv4);
2096 rb_free(yy_opm_address_ipv6);
2097 return 0;
2098}
2099
9bba0f61
EM
2100static void
2101conf_set_opm_timeout(void *data)
2102{
2103 int timeout = *((int *)data);
2104
2105 if(timeout <= 0 || timeout > 60)
2106 {
2107 conf_report_error("opm::timeout value %d is bogus, ignoring", timeout);
2108 return;
2109 }
2110
2111 yy_opm_timeout = timeout;
2112}
51fa2ab8 2113
8275e270 2114static void
51fa2ab8 2115conf_set_opm_listen_address_both(void *data, bool ipv6)
8275e270
EM
2116{
2117 struct rb_sockaddr_storage addr;
51fa2ab8 2118 const char *confstr = (ipv6 ? "opm::listen_ipv6" : "opm::listen_ipv4");
8275e270
EM
2119 char *ip = data;
2120
17809d2d 2121 if(!rb_inet_pton_sock(ip, &addr))
8275e270 2122 {
51fa2ab8 2123 conf_report_error("%s is an invalid address: %s", confstr, ip);
8275e270
EM
2124 return;
2125 }
2126
51fa2ab8 2127 if(ipv6)
8275e270 2128 {
51fa2ab8
EM
2129 if(GET_SS_FAMILY(&addr) != AF_INET6)
2130 {
2131 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2132 return;
2133 }
2134
2135 if(yy_opm_address_ipv6 != NULL)
2136 {
2137 conf_report_error("%s overwrites previous address %s", confstr, ip);
2138 return;
2139 }
2140
2141 yy_opm_address_ipv6 = rb_strdup(ip);
51fa2ab8
EM
2142 }
2143 else
8275e270 2144 {
51fa2ab8
EM
2145 if(GET_SS_FAMILY(&addr) != AF_INET)
2146 {
2147 conf_report_error("%s is of the wrong address type: %s", confstr, ip);
2148 return;
2149 }
2150
2151 if(yy_opm_address_ipv4 != NULL)
2152 {
2153 conf_report_error("%s overwrites previous address %s", confstr, ip);
2154 return;
2155 }
2156
2157 yy_opm_address_ipv4 = rb_strdup(ip);
8275e270 2158 }
51fa2ab8 2159}
8275e270 2160
51fa2ab8
EM
2161static void
2162conf_set_opm_listen_address_ipv4(void *data)
2163{
2164 conf_set_opm_listen_address_both(data, false);
8275e270
EM
2165}
2166
2167static void
2168conf_set_opm_listen_address_ipv6(void *data)
2169{
51fa2ab8
EM
2170 conf_set_opm_listen_address_both(data, true);
2171}
8275e270 2172
51fa2ab8
EM
2173static void
2174conf_set_opm_listen_port_both(void *data, bool ipv6)
2175{
2176 int port = *((int *)data);
2177 const char *confstr = (ipv6 ? "opm::port_ipv6" : "opm::port_ipv4");
8275e270 2178
51fa2ab8 2179 if(port > 65535 || port <= 0)
8275e270 2180 {
51fa2ab8 2181 conf_report_error("%s is out of range: %d", confstr, port);
8275e270
EM
2182 return;
2183 }
2184
51fa2ab8 2185 if(ipv6)
8275e270 2186 {
51fa2ab8
EM
2187 if(yy_opm_port_ipv4)
2188 {
2189 conf_report_error("%s overwrites existing port %hu",
2190 confstr, yy_opm_port_ipv4);
2191 return;
2192 }
2193
2194 yy_opm_port_ipv4 = port;
8275e270 2195 }
51fa2ab8
EM
2196 else
2197 {
2198 if(yy_opm_port_ipv6)
2199 {
2200 conf_report_error("%s overwrites existing port %hu",
2201 confstr, yy_opm_port_ipv6);
2202 return;
2203 }
8275e270 2204
51fa2ab8
EM
2205 yy_opm_port_ipv6 = port;
2206 }
8275e270
EM
2207}
2208
2209static void
2210conf_set_opm_listen_port_ipv4(void *data)
2211{
51fa2ab8 2212 conf_set_opm_listen_port_both(data, false);
8275e270
EM
2213}
2214
2215static void
2216conf_set_opm_listen_port_ipv6(void *data)
2217{
51fa2ab8 2218 conf_set_opm_listen_port_both(data, true);
8275e270
EM
2219}
2220
2221static void
2222conf_set_opm_listen_port(void *data)
2223{
51fa2ab8
EM
2224 conf_set_opm_listen_port_both(data, true);
2225 conf_set_opm_listen_port_both(data, false);
2226}
8275e270 2227
51fa2ab8
EM
2228static void
2229conf_set_opm_scan_ports_all(void *data, const char *node, const char *type)
2230{
2231 conf_parm_t *args = data;
2232 for (; args; args = args->next)
8275e270 2233 {
51fa2ab8
EM
2234 rb_dlink_node *ptr;
2235 bool dup = false;
8275e270 2236
51fa2ab8
EM
2237 if(CF_TYPE(args->type) != CF_INT)
2238 {
2239 conf_report_error("%s argument is not an integer -- ignoring.", node);
2240 continue;
2241 }
5e9a3f86 2242
51fa2ab8
EM
2243 if(args->v.number > 65535 || args->v.number <= 0)
2244 {
2245 conf_report_error("%s argument is not an integer between 1 and 65535 -- ignoring.", node);
2246 continue;
2247 }
8275e270 2248
51fa2ab8
EM
2249 /* Check for duplicates */
2250 RB_DLINK_FOREACH(ptr, yy_opm_scanner_list.head)
2251 {
2252 struct opm_scanner *scanner = ptr->data;
2253
2254 if(scanner->port == args->v.number && strcmp(type, scanner->type) == 0)
2255 {
2256 conf_report_error("%s argument is duplicate", node);
2257 dup = true;
2258 break;
2259 }
2260 }
2261
2262 if(!dup)
2263 {
2264 struct opm_scanner *scanner = rb_malloc(sizeof(struct opm_scanner));
2265 scanner->port = args->v.number;
2266 scanner->type = type;
2267 rb_dlinkAdd(scanner, &scanner->node, &yy_opm_scanner_list);
2268 }
8275e270 2269 }
51fa2ab8 2270}
8275e270 2271
51fa2ab8
EM
2272static void
2273conf_set_opm_scan_ports_socks4(void *data)
2274{
2275 conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
2276}
8275e270 2277
51fa2ab8
EM
2278static void
2279conf_set_opm_scan_ports_socks5(void *data)
2280{
2281 conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
8275e270
EM
2282}
2283
fabe8b94
EM
2284static void
2285conf_set_opm_scan_ports_httpconnect(void *data)
2286{
2287 conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
2288}
2289
eb0814b3
EM
2290static void
2291conf_set_opm_scan_ports_httpsconnect(void *data)
2292{
2293 conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");
2294}
2295
212380e3
WP
2296/* public functions */
2297
2298
2299void
2300conf_report_error(const char *fmt, ...)
2301{
2302 va_list ap;
82236a2a 2303 char msg[BUFSIZE + 1] = { 0 };
212380e3
WP
2304
2305 va_start(ap, fmt);
82236a2a 2306 vsnprintf(msg, BUFSIZE, fmt, ap);
212380e3
WP
2307 va_end(ap);
2308
2309 if (testing_conf)
2310 {
2311 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2312 return;
2313 }
2314
2315 ierror("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2316 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "error: \"%s\", line %d: %s", current_file, lineno + 1, msg);
d84acbce
WP
2317}
2318
2319void
2320conf_report_warning(const char *fmt, ...)
2321{
2322 va_list ap;
82236a2a 2323 char msg[BUFSIZE + 1] = { 0 };
d84acbce
WP
2324
2325 va_start(ap, fmt);
82236a2a 2326 vsnprintf(msg, BUFSIZE, fmt, ap);
d84acbce
WP
2327 va_end(ap);
2328
2329 if (testing_conf)
2330 {
2331 fprintf(stderr, "\"%s\", line %d: %s\n", current_file, lineno + 1, msg);
2332 return;
2333 }
2334
2335 iwarn("\"%s\", line %d: %s", current_file, lineno + 1, msg);
a9227555 2336 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "warning: \"%s\", line %d: %s", current_file, lineno + 1, msg);
212380e3
WP
2337}
2338
2339int
2340conf_start_block(char *block, char *name)
2341{
2342 if((conf_cur_block = find_top_conf(block)) == NULL)
2343 {
2344 conf_report_error("Configuration block '%s' is not defined.", block);
2345 return -1;
2346 }
2347
2348 if(name)
47a03750 2349 conf_cur_block_name = rb_strdup(name);
212380e3
WP
2350 else
2351 conf_cur_block_name = NULL;
2352
2353 if(conf_cur_block->tc_sfunc)
2354 if(conf_cur_block->tc_sfunc(conf_cur_block) < 0)
2355 return -1;
2356
2357 return 0;
2358}
2359
2360int
2361conf_end_block(struct TopConf *tc)
2362{
e12981c0 2363 int ret = 0;
212380e3 2364 if(tc->tc_efunc)
e12981c0 2365 ret = tc->tc_efunc(tc);
212380e3 2366
637c4932 2367 rb_free(conf_cur_block_name);
e12981c0
KB
2368 conf_cur_block_name = NULL;
2369 return ret;
212380e3
WP
2370}
2371
2372static void
2373conf_set_generic_int(void *data, void *location)
2374{
2375 *((int *) location) = *((unsigned int *) data);
2376}
2377
2378static void
2379conf_set_generic_string(void *data, int len, void *location)
2380{
2381 char **loc = location;
2382 char *input = data;
2383
2e819b6b 2384 if(len && strlen(input) > (unsigned int)len)
212380e3
WP
2385 input[len] = '\0';
2386
637c4932 2387 rb_free(*loc);
47a03750 2388 *loc = rb_strdup(input);
212380e3
WP
2389}
2390
2391int
dceac3e4 2392conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value)
212380e3
WP
2393{
2394 struct ConfEntry *cf;
2395 conf_parm_t *cp;
2396
2397 if(!tc)
2398 return -1;
2399
2400 if((cf = find_conf_item(tc, item)) == NULL)
2401 {
2402 conf_report_error
ffa79a95 2403 ("Non-existent configuration setting %s::%s.", tc->tc_name, (char *) item);
212380e3
WP
2404 return -1;
2405 }
2406
2407 /* if it takes one thing, make sure they only passed one thing,
2408 and handle as needed. */
ed45dfe6 2409 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
212380e3
WP
2410 {
2411 conf_report_error
2412 ("Option %s::%s does not take a list of values.", tc->tc_name, item);
2413 return -1;
2414 }
2415
2416 cp = value->v.list;
2417
2418
2419 if(CF_TYPE(value->v.list->type) != CF_TYPE(cf->cf_type))
2420 {
023c36ae 2421 /* if it expects a string value, but we got a yesno,
212380e3
WP
2422 * convert it back
2423 */
2424 if((CF_TYPE(value->v.list->type) == CF_YESNO) &&
2425 (CF_TYPE(cf->cf_type) == CF_STRING))
2426 {
2427 value->v.list->type = CF_STRING;
2428
2429 if(cp->v.number == 1)
47a03750 2430 cp->v.string = rb_strdup("yes");
212380e3 2431 else
47a03750 2432 cp->v.string = rb_strdup("no");
212380e3
WP
2433 }
2434
2435 /* maybe it's a CF_TIME and they passed CF_INT --
2436 should still be valid */
2437 else if(!((CF_TYPE(value->v.list->type) == CF_INT) &&
2438 (CF_TYPE(cf->cf_type) == CF_TIME)))
2439 {
2440 conf_report_error
2441 ("Wrong type for %s::%s (expected %s, got %s)",
2442 tc->tc_name, (char *) item,
2443 conf_strtype(cf->cf_type), conf_strtype(value->v.list->type));
2444 return -1;
2445 }
2446 }
2447
2448 if(cf->cf_type & CF_FLIST)
2449 {
2450#if 0
2451 if(cf->cf_arg)
2452 conf_set_generic_list(value->v.list, cf->cf_arg);
2453 else
2454#endif
2455 /* just pass it the extended argument list */
2456 cf->cf_func(value->v.list);
2457 }
2458 else
2459 {
2460 /* it's old-style, needs only one arg */
2461 switch (cf->cf_type)
2462 {
2463 case CF_INT:
2464 case CF_TIME:
2465 case CF_YESNO:
2466 if(cf->cf_arg)
2467 conf_set_generic_int(&cp->v.number, cf->cf_arg);
2468 else
2469 cf->cf_func(&cp->v.number);
2470 break;
2471 case CF_STRING:
2472 case CF_QSTRING:
2473 if(EmptyString(cp->v.string))
2474 conf_report_error("Ignoring %s::%s -- empty field",
2475 tc->tc_name, item);
2476 else if(cf->cf_arg)
2477 conf_set_generic_string(cp->v.string, cf->cf_len, cf->cf_arg);
2478 else
2479 cf->cf_func(cp->v.string);
2480 break;
2481 }
2482 }
2483
2484
2485 return 0;
2486}
2487
2488int
2489add_conf_item(const char *topconf, const char *name, int type, void (*func) (void *))
2490{
2491 struct TopConf *tc;
2492 struct ConfEntry *cf;
2493
2494 if((tc = find_top_conf(topconf)) == NULL)
2495 return -1;
2496
12edf3e3 2497 if(find_conf_item(tc, name) != NULL)
212380e3
WP
2498 return -1;
2499
eddc2ab6 2500 cf = rb_malloc(sizeof(struct ConfEntry));
212380e3 2501
d7f753cd 2502 cf->cf_name = name;
212380e3
WP
2503 cf->cf_type = type;
2504 cf->cf_func = func;
2505 cf->cf_arg = NULL;
2506
330fc5c1 2507 rb_dlinkAddAlloc(cf, &tc->tc_items);
212380e3
WP
2508
2509 return 0;
2510}
2511
2512int
2513remove_conf_item(const char *topconf, const char *name)
2514{
2515 struct TopConf *tc;
2516 struct ConfEntry *cf;
330fc5c1 2517 rb_dlink_node *ptr;
212380e3
WP
2518
2519 if((tc = find_top_conf(topconf)) == NULL)
2520 return -1;
2521
2522 if((cf = find_conf_item(tc, name)) == NULL)
2523 return -1;
2524
330fc5c1 2525 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
212380e3
WP
2526 return -1;
2527
330fc5c1 2528 rb_dlinkDestroy(ptr, &tc->tc_items);
637c4932 2529 rb_free(cf);
212380e3
WP
2530
2531 return 0;
2532}
2533
2534/* *INDENT-OFF* */
2535static struct ConfEntry conf_serverinfo_table[] =
2536{
2537 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
212380e3
WP
2538
2539 { "network_name", CF_QSTRING, conf_set_serverinfo_network_name, 0, NULL },
2540 { "name", CF_QSTRING, conf_set_serverinfo_name, 0, NULL },
2541 { "sid", CF_QSTRING, conf_set_serverinfo_sid, 0, NULL },
2542 { "vhost", CF_QSTRING, conf_set_serverinfo_vhost, 0, NULL },
2543 { "vhost6", CF_QSTRING, conf_set_serverinfo_vhost6, 0, NULL },
2544
8bd5767b
JT
2545 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2546 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
023c36ae 2547 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
8bd5767b 2548 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
c1725bda 2549 { "ssl_cipher_list", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cipher_list },
c6d72037
VY
2550 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2551
101db4c4 2552 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
c2d96fcb 2553
b583faf9
WP
2554 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2555
212380e3
WP
2556 { "\0", 0, NULL, 0, NULL }
2557};
2558
2559static struct ConfEntry conf_admin_table[] =
2560{
2561 { "name", CF_QSTRING, NULL, 200, &AdminInfo.name },
2562 { "description",CF_QSTRING, NULL, 200, &AdminInfo.description },
2563 { "email", CF_QSTRING, NULL, 200, &AdminInfo.email },
2564 { "\0", 0, NULL, 0, NULL }
2565};
2566
2567static struct ConfEntry conf_log_table[] =
2568{
d74fa5b5
JT
2569 { "fname_userlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_userlog },
2570 { "fname_fuserlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_fuserlog },
2571 { "fname_operlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operlog },
2572 { "fname_foperlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_foperlog },
2573 { "fname_serverlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_serverlog },
2574 { "fname_killlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_killlog },
2575 { "fname_klinelog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_klinelog },
2576 { "fname_operspylog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_operspylog },
2577 { "fname_ioerrorlog", CF_QSTRING, NULL, PATH_MAX, &ConfigFileEntry.fname_ioerrorlog },
212380e3
WP
2578 { "\0", 0, NULL, 0, NULL }
2579};
2580
2581static struct ConfEntry conf_operator_table[] =
2582{
2583 { "rsa_public_key_file", CF_QSTRING, conf_set_oper_rsa_public_key_file, 0, NULL },
2584 { "flags", CF_STRING | CF_FLIST, conf_set_oper_flags, 0, NULL },
2585 { "umodes", CF_STRING | CF_FLIST, conf_set_oper_umodes, 0, NULL },
22c3b270 2586 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
212380e3
WP
2587 { "snomask", CF_QSTRING, conf_set_oper_snomask, 0, NULL },
2588 { "user", CF_QSTRING, conf_set_oper_user, 0, NULL },
2589 { "password", CF_QSTRING, conf_set_oper_password, 0, NULL },
ff31db84 2590 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
212380e3
WP
2591 { "\0", 0, NULL, 0, NULL }
2592};
2593
f8606875
WP
2594static struct ConfEntry conf_privset_table[] =
2595{
2596 { "extends", CF_QSTRING, conf_set_privset_extends, 0, NULL },
2597 { "privs", CF_STRING | CF_FLIST, conf_set_privset_privs, 0, NULL },
2598 { "\0", 0, NULL, 0, NULL }
2599};
2600
212380e3
WP
2601static struct ConfEntry conf_class_table[] =
2602{
2603 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
e33e589c 2604 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
e33e589c 2605 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
212380e3
WP
2606 { "number_per_cidr", CF_INT, conf_set_class_number_per_cidr, 0, NULL },
2607 { "number_per_ip", CF_INT, conf_set_class_number_per_ip, 0, NULL },
2608 { "number_per_ip_global", CF_INT,conf_set_class_number_per_ip_global, 0, NULL },
2609 { "number_per_ident", CF_INT, conf_set_class_number_per_ident, 0, NULL },
2610 { "connectfreq", CF_TIME, conf_set_class_connectfreq, 0, NULL },
2611 { "max_number", CF_INT, conf_set_class_max_number, 0, NULL },
7c7065b0 2612 { "max_autoconn", CF_INT, conf_set_class_max_autoconn, 0, NULL },
212380e3
WP
2613 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2614 { "\0", 0, NULL, 0, NULL }
2615};
2616
2617static struct ConfEntry conf_auth_table[] =
2618{
2619 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
40c1fd47 2620 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
212380e3
WP
2621 { "password", CF_QSTRING, conf_set_auth_passwd, 0, NULL },
2622 { "class", CF_QSTRING, conf_set_auth_class, 0, NULL },
2623 { "spoof", CF_QSTRING, conf_set_auth_spoof, 0, NULL },
2624 { "redirserv", CF_QSTRING, conf_set_auth_redir_serv, 0, NULL },
2625 { "redirport", CF_INT, conf_set_auth_redir_port, 0, NULL },
2626 { "flags", CF_STRING | CF_FLIST, conf_set_auth_flags, 0, NULL },
2627 { "\0", 0, NULL, 0, NULL }
2628};
2629
2630static struct ConfEntry conf_connect_table[] =
2631{
2632 { "send_password", CF_QSTRING, conf_set_connect_send_password, 0, NULL },
2633 { "accept_password", CF_QSTRING, conf_set_connect_accept_password, 0, NULL },
ff0cc1e6 2634 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
212380e3
WP
2635 { "flags", CF_STRING | CF_FLIST, conf_set_connect_flags, 0, NULL },
2636 { "host", CF_QSTRING, conf_set_connect_host, 0, NULL },
2637 { "vhost", CF_QSTRING, conf_set_connect_vhost, 0, NULL },
2638 { "port", CF_INT, conf_set_connect_port, 0, NULL },
2639 { "aftype", CF_STRING, conf_set_connect_aftype, 0, NULL },
2640 { "hub_mask", CF_QSTRING, conf_set_connect_hub_mask, 0, NULL },
2641 { "leaf_mask", CF_QSTRING, conf_set_connect_leaf_mask, 0, NULL },
2642 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2643 { "\0", 0, NULL, 0, NULL }
2644};
2645
2646static struct ConfEntry conf_general_table[] =
2647{
2648 { "oper_only_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_only_umodes, 0, NULL },
2649 { "oper_umodes", CF_STRING | CF_FLIST, conf_set_general_oper_umodes, 0, NULL },
2650 { "oper_snomask", CF_QSTRING, conf_set_general_oper_snomask, 0, NULL },
2651 { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL },
2652 { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL },
2653 { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL },
212380e3
WP
2654 { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL },
2655 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
2656 { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL },
2657
2658 { "default_operstring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_operstring },
2659 { "default_adminstring",CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.default_adminstring },
2660 { "servicestring", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.servicestring },
212380e3
WP
2661 { "kline_reason", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.kline_reason },
2662 { "identify_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifyservice },
2663 { "identify_command", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.identifycommand },
7d33cce8 2664 { "sasl_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.sasl_service },
212380e3
WP
2665
2666 { "anti_spam_exit_message_time", CF_TIME, NULL, 0, &ConfigFileEntry.anti_spam_exit_message_time },
2667 { "disable_fake_channels", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_fake_channels },
2668 { "min_nonwildcard_simple", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard_simple },
2669 { "non_redundant_klines", CF_YESNO, NULL, 0, &ConfigFileEntry.non_redundant_klines },
2670 { "tkline_expire_notices", CF_YESNO, NULL, 0, &ConfigFileEntry.tkline_expire_notices },
2671
6ac21a70
EK
2672 { "hidden_caps", CF_QSTRING | CF_FLIST, conf_set_general_hidden_caps, 0, NULL },
2673
212380e3
WP
2674 { "anti_nick_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.anti_nick_flood },
2675 { "burst_away", CF_YESNO, NULL, 0, &ConfigFileEntry.burst_away },
2676 { "caller_id_wait", CF_TIME, NULL, 0, &ConfigFileEntry.caller_id_wait },
2677 { "client_exit", CF_YESNO, NULL, 0, &ConfigFileEntry.client_exit },
212380e3 2678 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
330692a1 2679 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
b3a00991 2680 { "post_registration_delay", CF_TIME, NULL, 0, &ConfigFileEntry.post_registration_delay },
212380e3
WP
2681 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2682 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
944b0584 2683 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
212380e3 2684 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
212380e3
WP
2685 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2686 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
212380e3 2687 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
212380e3
WP
2688 { "hide_spoof_ips", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_spoof_ips },
2689 { "dline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.dline_with_reason },
2690 { "kline_with_reason", CF_YESNO, NULL, 0, &ConfigFileEntry.kline_with_reason },
9914c013 2691 { "hide_tkdline_duration", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_tkdline_duration },
212380e3
WP
2692 { "map_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.map_oper_only },
2693 { "max_accept", CF_INT, NULL, 0, &ConfigFileEntry.max_accept },
2694 { "max_monitor", CF_INT, NULL, 0, &ConfigFileEntry.max_monitor },
2695 { "max_nick_time", CF_TIME, NULL, 0, &ConfigFileEntry.max_nick_time },
2696 { "max_nick_changes", CF_INT, NULL, 0, &ConfigFileEntry.max_nick_changes },
2697 { "max_targets", CF_INT, NULL, 0, &ConfigFileEntry.max_targets },
2698 { "min_nonwildcard", CF_INT, NULL, 0, &ConfigFileEntry.min_nonwildcard },
2699 { "nick_delay", CF_TIME, NULL, 0, &ConfigFileEntry.nick_delay },
2700 { "no_oper_flood", CF_YESNO, NULL, 0, &ConfigFileEntry.no_oper_flood },
2701 { "operspy_admin_only", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_admin_only },
2702 { "operspy_dont_care_user_info", CF_YESNO, NULL, 0, &ConfigFileEntry.operspy_dont_care_user_info },
2703 { "pace_wait", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait },
2704 { "pace_wait_simple", CF_TIME, NULL, 0, &ConfigFileEntry.pace_wait_simple },
2705 { "ping_cookie", CF_YESNO, NULL, 0, &ConfigFileEntry.ping_cookie },
2706 { "reject_after_count", CF_INT, NULL, 0, &ConfigFileEntry.reject_after_count },
2707 { "reject_ban_time", CF_TIME, NULL, 0, &ConfigFileEntry.reject_ban_time },
2708 { "reject_duration", CF_TIME, NULL, 0, &ConfigFileEntry.reject_duration },
43946961
JT
2709 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2710 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
212380e3
WP
2711 { "short_motd", CF_YESNO, NULL, 0, &ConfigFileEntry.short_motd },
2712 { "stats_c_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_c_oper_only },
2713 { "stats_e_disabled", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_e_disabled },
2714 { "stats_h_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_h_oper_only },
2715 { "stats_o_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_o_oper_only },
2716 { "stats_P_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_P_oper_only },
2717 { "stats_y_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.stats_y_oper_only },
2718 { "target_change", CF_YESNO, NULL, 0, &ConfigFileEntry.target_change },
2719 { "ts_max_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_max_delta },
212380e3
WP
2720 { "ts_warn_delta", CF_TIME, NULL, 0, &ConfigFileEntry.ts_warn_delta },
2721 { "use_whois_actually", CF_YESNO, NULL, 0, &ConfigFileEntry.use_whois_actually },
2722 { "warn_no_nline", CF_YESNO, NULL, 0, &ConfigFileEntry.warn_no_nline },
1702b694 2723 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
e6e54763
SB
2724 { "client_flood_max_lines", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_max_lines },
2725 { "client_flood_burst_rate", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_rate },
2726 { "client_flood_burst_max", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_burst_max },
2727 { "client_flood_message_num", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_num },
2728 { "client_flood_message_time", CF_INT, NULL, 0, &ConfigFileEntry.client_flood_message_time },
e88a1f1b 2729 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
d42e6915 2730 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
71c95533 2731 { "hide_opers_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers_in_whois },
1123eefc 2732 { "hide_opers", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers },
13d8f0ed 2733 { "certfp_method", CF_STRING, conf_set_general_certfp_method, 0, NULL },
b674a619 2734 { "drain_reason", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.drain_reason },
fff4f763 2735 { "tls_ciphers_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.tls_ciphers_oper_only },
212380e3
WP
2736 { "\0", 0, NULL, 0, NULL }
2737};
2738
2739static struct ConfEntry conf_channel_table[] =
2740{
2741 { "default_split_user_count", CF_INT, NULL, 0, &ConfigChannel.default_split_user_count },
2742 { "default_split_server_count", CF_INT, NULL, 0, &ConfigChannel.default_split_server_count },
2743 { "burst_topicwho", CF_YESNO, NULL, 0, &ConfigChannel.burst_topicwho },
212380e3
WP
2744 { "kick_on_split_riding", CF_YESNO, NULL, 0, &ConfigChannel.kick_on_split_riding },
2745 { "knock_delay", CF_TIME, NULL, 0, &ConfigChannel.knock_delay },
2746 { "knock_delay_channel",CF_TIME, NULL, 0, &ConfigChannel.knock_delay_channel },
2747 { "max_bans", CF_INT, NULL, 0, &ConfigChannel.max_bans },
2748 { "max_bans_large", CF_INT, NULL, 0, &ConfigChannel.max_bans_large },
2749 { "max_chans_per_user", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user },
a4721f5e 2750 { "max_chans_per_user_large", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user_large },
212380e3
WP
2751 { "no_create_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_create_on_split },
2752 { "no_join_on_split", CF_YESNO, NULL, 0, &ConfigChannel.no_join_on_split },
6865c0b0 2753 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
212380e3
WP
2754 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2755 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2da6f6eb 2756 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
212380e3 2757 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
c2c25552 2758 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
717238d2 2759 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
341f971e 2760 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
63eb8567 2761 { "autochanmodes", CF_QSTRING, conf_set_channel_autochanmodes, 0, NULL },
d513218a 2762 { "displayed_usercount", CF_INT, NULL, 0, &ConfigChannel.displayed_usercount },
14482679 2763 { "strip_topic_colors", CF_YESNO, NULL, 0, &ConfigChannel.strip_topic_colors },
04e5ed6c 2764 { "opmod_send_statusmsg", CF_YESNO, NULL, 0, &ConfigChannel.opmod_send_statusmsg },
212380e3
WP
2765 { "\0", 0, NULL, 0, NULL }
2766};
2767
2768static struct ConfEntry conf_serverhide_table[] =
2769{
2770 { "disable_hidden", CF_YESNO, NULL, 0, &ConfigServerHide.disable_hidden },
2771 { "flatten_links", CF_YESNO, NULL, 0, &ConfigServerHide.flatten_links },
2772 { "hidden", CF_YESNO, NULL, 0, &ConfigServerHide.hidden },
2773 { "links_delay", CF_TIME, conf_set_serverhide_links_delay, 0, NULL },
2774 { "\0", 0, NULL, 0, NULL }
2775};
2776/* *INDENT-ON* */
2777
2778void
2779newconf_init()
2780{
2781 add_top_conf("modules", NULL, NULL, NULL);
2782 add_conf_item("modules", "path", CF_QSTRING, conf_set_modules_path);
2783 add_conf_item("modules", "module", CF_QSTRING, conf_set_modules_module);
2784
2785 add_top_conf("serverinfo", NULL, NULL, conf_serverinfo_table);
2786 add_top_conf("admin", NULL, NULL, conf_admin_table);
2787 add_top_conf("log", NULL, NULL, conf_log_table);
2788 add_top_conf("operator", conf_begin_oper, conf_end_oper, conf_operator_table);
2789 add_top_conf("class", conf_begin_class, conf_end_class, conf_class_table);
f8606875 2790 add_top_conf("privset", NULL, NULL, conf_privset_table);
212380e3
WP
2791
2792 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
02270e96 2793 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
c53ca1e0 2794 add_conf_item("listen", "wsock", CF_YESNO, conf_set_listen_wsock);
212380e3 2795 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
c6d72037 2796 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
c6ad9b0c
SA
2797 add_conf_item("listen", "sctp_port", CF_INT | CF_FLIST, conf_set_listen_sctp_port);
2798 add_conf_item("listen", "sctp_sslport", CF_INT | CF_FLIST, conf_set_listen_sctp_sslport);
212380e3
WP
2799 add_conf_item("listen", "ip", CF_QSTRING, conf_set_listen_address);
2800 add_conf_item("listen", "host", CF_QSTRING, conf_set_listen_address);
2801
2802 add_top_conf("auth", conf_begin_auth, conf_end_auth, conf_auth_table);
2803
212380e3
WP
2804 add_top_conf("connect", conf_begin_connect, conf_end_connect, conf_connect_table);
2805
2806 add_top_conf("exempt", NULL, NULL, NULL);
2807 add_conf_item("exempt", "ip", CF_QSTRING, conf_set_exempt_ip);
2808
1cf798be
EK
2809 add_top_conf("secure", NULL, NULL, NULL);
2810 add_conf_item("secure", "ip", CF_QSTRING, conf_set_secure_ip);
2811
212380e3
WP
2812 add_top_conf("cluster", conf_cleanup_cluster, conf_cleanup_cluster, NULL);
2813 add_conf_item("cluster", "name", CF_QSTRING, conf_set_cluster_name);
2814 add_conf_item("cluster", "flags", CF_STRING | CF_FLIST, conf_set_cluster_flags);
2815
2816 add_top_conf("general", NULL, NULL, conf_general_table);
2817 add_top_conf("channel", NULL, NULL, conf_channel_table);
2818 add_top_conf("serverhide", NULL, NULL, conf_serverhide_table);
2819
c46a4ecd 2820 add_top_conf("service", NULL, NULL, NULL);
212380e3
WP
2821 add_conf_item("service", "name", CF_QSTRING, conf_set_service_name);
2822
2823 add_top_conf("alias", conf_begin_alias, conf_end_alias, NULL);
2824 add_conf_item("alias", "name", CF_QSTRING, conf_set_alias_name);
2825 add_conf_item("alias", "target", CF_QSTRING, conf_set_alias_target);
2826
7f24f506
AC
2827 add_top_conf("dnsbl", NULL, NULL, NULL);
2828 add_conf_item("dnsbl", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2829 add_conf_item("dnsbl", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2830 add_conf_item("dnsbl", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2831 add_conf_item("dnsbl", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
2832
2833 add_top_conf("blacklist", conf_warn_blacklist_deprecation, NULL, NULL);
2834 add_conf_item("blacklist", "host", CF_QSTRING, conf_set_dnsbl_entry_host);
2835 add_conf_item("blacklist", "type", CF_STRING | CF_FLIST, conf_set_dnsbl_entry_type);
2836 add_conf_item("blacklist", "matches", CF_QSTRING | CF_FLIST, conf_set_dnsbl_entry_matches);
2837 add_conf_item("blacklist", "reject_reason", CF_QSTRING, conf_set_dnsbl_entry_reason);
8275e270
EM
2838
2839 add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
9bba0f61 2840 add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
8275e270 2841 add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
8275e270 2842 add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
51fa2ab8 2843 add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);
8275e270
EM
2844 add_conf_item("opm", "port_v6", CF_INT, conf_set_opm_listen_port_ipv6);
2845 add_conf_item("opm", "listen_port", CF_INT, conf_set_opm_listen_port);
51fa2ab8
EM
2846 add_conf_item("opm", "socks4_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks4);
2847 add_conf_item("opm", "socks5_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_socks5);
fabe8b94 2848 add_conf_item("opm", "httpconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpconnect);
eb0814b3 2849 add_conf_item("opm", "httpsconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpsconnect);
212380e3 2850}