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