]> jfr.im git - solanum.git/blob - ircd/newconf.c
ircd/authproc.c: avoid crash on lack of any configured DNSBLs
[solanum.git] / ircd / newconf.c
1 /* This code is in the public domain.
2 */
3
4 #include "stdinc.h"
5
6 #ifdef HAVE_LIBCRYPTO
7 #include <openssl/evp.h>
8 #include <openssl/pem.h>
9 #include <openssl/rsa.h>
10 #if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
11 #include <openssl/decoder.h>
12 #include <openssl/core.h>
13 #endif
14 #endif
15
16 #include "newconf.h"
17 #include "ircd_defs.h"
18 #include "logger.h"
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"
28 #include "hash.h"
29 #include "cache.h"
30 #include "ircd.h"
31 #include "snomask.h"
32 #include "sslproc.h"
33 #include "wsproc.h"
34 #include "privilege.h"
35 #include "chmode.h"
36 #include "certfp.h"
37
38 #define CF_TYPE(x) ((x) & CF_MTYPE)
39
40 static int yy_defer_accept = 1;
41 static int yy_wsock = 0;
42
43 struct TopConf *conf_cur_block;
44 static char *conf_cur_block_name = NULL;
45
46 static rb_dlink_list conf_items;
47
48 static struct ConfItem *yy_aconf = NULL;
49
50 static struct Class *yy_class = NULL;
51
52 static struct remote_conf *yy_shared = NULL;
53 static struct server_conf *yy_server = NULL;
54
55 static rb_dlink_list yy_aconf_list;
56 static rb_dlink_list yy_oper_list;
57 static rb_dlink_list yy_cluster_list;
58 static struct oper_conf *yy_oper = NULL;
59
60 static struct alias_entry *yy_alias = NULL;
61
62 static char *yy_dnsbl_entry_host = NULL;
63 static char *yy_dnsbl_entry_reason = NULL;
64 static uint8_t yy_dnsbl_entry_iptype = 0;
65 static rb_dlink_list yy_dnsbl_entry_filters = { NULL, NULL, 0 };
66
67 static char *yy_opm_address_ipv4 = NULL;
68 static char *yy_opm_address_ipv6 = NULL;
69 static uint16_t yy_opm_port_ipv4 = 0;
70 static uint16_t yy_opm_port_ipv6 = 0;
71 static int yy_opm_timeout = 0;
72 static rb_dlink_list yy_opm_scanner_list;
73
74 static char *yy_privset_extends = NULL;
75
76 static const char *
77 conf_strtype(int type)
78 {
79 switch (CF_TYPE(type))
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
96 int
97 add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
98 int (*efunc) (struct TopConf *), struct ConfEntry *items)
99 {
100 struct TopConf *tc;
101
102 tc = rb_malloc(sizeof(struct TopConf));
103
104 tc->tc_name = name;
105 tc->tc_sfunc = sfunc;
106 tc->tc_efunc = efunc;
107 tc->tc_entries = items;
108
109 rb_dlinkAddAlloc(tc, &conf_items);
110 return 0;
111 }
112
113 struct TopConf *
114 find_top_conf(const char *name)
115 {
116 rb_dlink_node *d;
117 struct TopConf *tc;
118
119 RB_DLINK_FOREACH(d, conf_items.head)
120 {
121 tc = d->data;
122 if(rb_strcasecmp(tc->tc_name, name) == 0)
123 return tc;
124 }
125
126 return NULL;
127 }
128
129
130 struct ConfEntry *
131 find_conf_item(const struct TopConf *top, const char *name)
132 {
133 struct ConfEntry *cf;
134 rb_dlink_node *d;
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
144 if(!rb_strcasecmp(cf->cf_name, name))
145 return cf;
146 }
147 }
148
149 RB_DLINK_FOREACH(d, top->tc_items.head)
150 {
151 cf = d->data;
152 if(rb_strcasecmp(cf->cf_name, name) == 0)
153 return cf;
154 }
155
156 return NULL;
157 }
158
159 int
160 remove_top_conf(char *name)
161 {
162 struct TopConf *tc;
163 rb_dlink_node *ptr;
164
165 if((tc = find_top_conf(name)) == NULL)
166 return -1;
167
168 if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL)
169 return -1;
170
171 rb_dlinkDestroy(ptr, &conf_items);
172 rb_free(tc);
173
174 return 0;
175 }
176
177 static void
178 conf_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)
213 ServerInfo.name = rb_strdup((char *) data);
214 }
215 }
216
217 static void
218 conf_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
232 rb_strlcpy(ServerInfo.sid, sid, sizeof(ServerInfo.sid));
233 }
234 }
235
236 static void
237 conf_set_serverinfo_network_name(void *data)
238 {
239 char *p;
240
241 if((p = strchr((char *) data, ' ')))
242 *p = '\0';
243
244 rb_free(ServerInfo.network_name);
245 ServerInfo.network_name = rb_strdup((char *) data);
246 }
247
248 static void
249 conf_set_serverinfo_vhost(void *data)
250 {
251 struct rb_sockaddr_storage addr;
252
253 if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET)
254 {
255 conf_report_error("Invalid IPv4 address for server vhost (%s)", (char *) data);
256 return;
257 }
258
259 ServerInfo.bind4 = addr;
260 }
261
262 static void
263 conf_set_serverinfo_vhost6(void *data)
264 {
265
266 struct rb_sockaddr_storage addr;
267
268 if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET6)
269 {
270 conf_report_error("Invalid IPv6 address for server vhost (%s)", (char *) data);
271 return;
272 }
273
274 ServerInfo.bind6 = addr;
275 }
276
277 static void
278 conf_set_serverinfo_nicklen(void *data)
279 {
280 ConfigFileEntry.nicklen = (*(unsigned int *) data) + 1;
281
282 if (ConfigFileEntry.nicklen > NICKLEN)
283 {
284 conf_report_error("Warning -- ignoring serverinfo::nicklen -- provided nicklen (%u) is greater than allowed nicklen (%u)",
285 ConfigFileEntry.nicklen - 1, NICKLEN - 1);
286 ConfigFileEntry.nicklen = NICKLEN;
287 }
288 else if (ConfigFileEntry.nicklen < 9 + 1)
289 {
290 conf_report_error("Warning -- serverinfo::nicklen is too low (%u) -- forcing 9",
291 ConfigFileEntry.nicklen - 1);
292 ConfigFileEntry.nicklen = 9 + 1;
293 }
294 }
295
296 static void
297 conf_set_modules_module(void *data)
298 {
299 char *m_bn;
300
301 m_bn = rb_basename((char *) data);
302
303 if(findmodule_byname(m_bn) == NULL)
304 load_one_module((char *) data, MAPI_ORIGIN_EXTENSION, false);
305
306 rb_free(m_bn);
307 }
308
309 static void
310 conf_set_modules_path(void *data)
311 {
312 mod_add_path((char *) data);
313 }
314
315 struct mode_table
316 {
317 const char *name;
318 int mode;
319 };
320
321 /* *INDENT-OFF* */
322 static struct mode_table umode_table[] = {
323 {"deaf", UMODE_DEAF },
324 {"invisible", UMODE_INVISIBLE },
325 {"locops", UMODE_LOCOPS },
326 {"noforward", UMODE_NOFORWARD },
327 {"servnotice", UMODE_SERVNOTICE},
328 {"wallop", UMODE_WALLOP },
329 {"operwall", UMODE_OPERWALL },
330 {NULL, 0}
331 };
332
333 static struct mode_table oper_table[] = {
334 {"encrypted", OPER_ENCRYPTED },
335 {"need_ssl", OPER_NEEDSSL },
336 {NULL, 0}
337 };
338
339 static struct mode_table auth_table[] = {
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 },
357 {"allow_sctp", CONF_FLAGS_ALLOW_SCTP },
358 {"kline_spoof_ip", CONF_FLAGS_KLINE_SPOOF },
359 {NULL, 0}
360 };
361
362 static struct mode_table connect_table[] = {
363 { "autoconn", SERVER_AUTOCONN },
364 { "compressed", 0 },
365 { "encrypted", SERVER_ENCRYPTED },
366 { "topicburst", SERVER_TB },
367 { "sctp", SERVER_SCTP },
368 { "ssl", SERVER_SSL },
369 { "no-export", SERVER_NO_EXPORT },
370 { NULL, 0 },
371 };
372
373 static 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 };
387 /* *INDENT-ON* */
388
389 static int
390 find_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
403 static void
404 set_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
412 if(CF_TYPE(args->type) != CF_STRING)
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
446 static void
447 parse_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
493 static void
494 conf_set_privset_extends(void *data)
495 {
496 yy_privset_extends = rb_strdup((char *) data);
497 }
498
499 static void
500 conf_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);
514 strcpy(privs, privs_old);
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 {
530 conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name);
531
532 set = privilegeset_get("default");
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
547 static int
548 conf_begin_oper(struct TopConf *tc)
549 {
550 rb_dlink_node *ptr;
551 rb_dlink_node *next_ptr;
552
553 if(yy_oper != NULL)
554 {
555 free_oper_conf(yy_oper);
556 yy_oper = NULL;
557 }
558
559 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
560 {
561 free_oper_conf(ptr->data);
562 rb_dlinkDestroy(ptr, &yy_oper_list);
563 }
564
565 yy_oper = make_oper_conf();
566 yy_oper->flags |= OPER_ENCRYPTED;
567
568 return 0;
569 }
570
571 static int
572 conf_end_oper(struct TopConf *tc)
573 {
574 struct oper_conf *yy_tmpoper;
575 rb_dlink_node *ptr;
576 rb_dlink_node *next_ptr;
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
583 yy_oper->name = rb_strdup(conf_cur_block_name);
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
603
604 if (!yy_oper->privset)
605 yy_oper->privset = privilegeset_get("default");
606
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 */
611 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
612 {
613 yy_tmpoper = ptr->data;
614
615 yy_tmpoper->name = rb_strdup(yy_oper->name);
616
617 /* could be an rsa key instead.. */
618 if(!EmptyString(yy_oper->passwd))
619 yy_tmpoper->passwd = rb_strdup(yy_oper->passwd);
620
621 yy_tmpoper->flags = yy_oper->flags;
622 yy_tmpoper->umodes = yy_oper->umodes;
623 yy_tmpoper->snomask = yy_oper->snomask;
624 yy_tmpoper->privset = yy_oper->privset;
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 }
638
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
656 yy_tmpoper->rsa_pubkey =
657 (RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL);
658 #endif
659
660 (void)BIO_set_close(file, BIO_CLOSE);
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 }
671
672 if(!EmptyString(yy_oper->certfp))
673 yy_tmpoper->certfp = rb_strdup(yy_oper->certfp);
674 #endif
675
676 /* all is ok, put it on oper_conf_list */
677 rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list);
678 }
679
680 free_oper_conf(yy_oper);
681 yy_oper = NULL;
682
683 return 0;
684 }
685
686 static void
687 conf_set_oper_flags(void *data)
688 {
689 conf_parm_t *args = data;
690
691 set_modes_from_table(&yy_oper->flags, "flag", oper_table, args);
692 }
693
694 static void
695 conf_set_oper_fingerprint(void *data)
696 {
697 if (yy_oper->certfp)
698 rb_free(yy_oper->certfp);
699 yy_oper->certfp = rb_strdup((char *) data);
700 }
701
702 static void
703 conf_set_oper_privset(void *data)
704 {
705 yy_oper->privset = privilegeset_get((char *) data);
706 }
707
708 static void
709 conf_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
721 yy_tmpoper->username = rb_strdup(host);
722 yy_tmpoper->host = rb_strdup(p);
723 }
724 else
725 {
726
727 yy_tmpoper->username = rb_strdup("*");
728 yy_tmpoper->host = rb_strdup(host);
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
738 rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list);
739 }
740
741 static void
742 conf_set_oper_password(void *data)
743 {
744 if(yy_oper->passwd)
745 {
746 memset(yy_oper->passwd, 0, strlen(yy_oper->passwd));
747 rb_free(yy_oper->passwd);
748 }
749
750 yy_oper->passwd = rb_strdup((char *) data);
751 }
752
753 static void
754 conf_set_oper_rsa_public_key_file(void *data)
755 {
756 #ifdef HAVE_LIBCRYPTO
757 rb_free(yy_oper->rsa_pubkey_file);
758 yy_oper->rsa_pubkey_file = rb_strdup((char *) data);
759 #else
760 conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available");
761 #endif
762 }
763
764 static void
765 conf_set_oper_umodes(void *data)
766 {
767 set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data);
768 }
769
770 static void
771 conf_set_oper_snomask(void *data)
772 {
773 yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data);
774 }
775
776 static int
777 conf_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
786 static int
787 conf_end_class(struct TopConf *tc)
788 {
789 if(conf_cur_block_name != NULL)
790 yy_class->class_name = rb_strdup(conf_cur_block_name);
791
792 if(EmptyString(yy_class->class_name))
793 {
794 conf_report_error("Ignoring class block -- missing name.");
795 return 0;
796 }
797
798 add_class(yy_class);
799 yy_class = NULL;
800 return 0;
801 }
802
803 static void
804 conf_set_class_ping_time(void *data)
805 {
806 yy_class->ping_freq = *(unsigned int *) data;
807 }
808
809 static void
810 conf_set_class_cidr_ipv4_bitlen(void *data)
811 {
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
822 static void
823 conf_set_class_cidr_ipv6_bitlen(void *data)
824 {
825 unsigned int maxsize = 128;
826 if(*(unsigned int *) data > maxsize)
827 conf_report_error
828 ("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
829 *(unsigned int *) data, maxsize);
830 else
831 yy_class->cidr_ipv6_bitlen = *(unsigned int *) data;
832
833 }
834
835 static void
836 conf_set_class_number_per_cidr(void *data)
837 {
838 yy_class->cidr_amount = *(unsigned int *) data;
839 }
840
841 static void
842 conf_set_class_number_per_ip(void *data)
843 {
844 yy_class->max_local = *(unsigned int *) data;
845 }
846
847
848 static void
849 conf_set_class_number_per_ip_global(void *data)
850 {
851 yy_class->max_global = *(unsigned int *) data;
852 }
853
854 static void
855 conf_set_class_number_per_ident(void *data)
856 {
857 yy_class->max_ident = *(unsigned int *) data;
858 }
859
860 static void
861 conf_set_class_connectfreq(void *data)
862 {
863 yy_class->con_freq = *(unsigned int *) data;
864 }
865
866 static void
867 conf_set_class_max_number(void *data)
868 {
869 yy_class->max_total = *(unsigned int *) data;
870 }
871
872 static void
873 conf_set_class_max_autoconn(void *data)
874 {
875 yy_class->max_autoconn = *(unsigned int *) data;
876 }
877
878 static void
879 conf_set_class_sendq(void *data)
880 {
881 yy_class->max_sendq = *(unsigned int *) data;
882 }
883
884 static char *listener_address[2];
885
886 static int
887 conf_begin_listen(struct TopConf *tc)
888 {
889 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
890 rb_free(listener_address[i]);
891 listener_address[i] = NULL;
892 }
893 yy_wsock = 0;
894 yy_defer_accept = 0;
895 return 0;
896 }
897
898 static int
899 conf_end_listen(struct TopConf *tc)
900 {
901 for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
902 rb_free(listener_address[i]);
903 listener_address[i] = NULL;
904 }
905 yy_wsock = 0;
906 yy_defer_accept = 0;
907 return 0;
908 }
909
910 static void
911 conf_set_listen_defer_accept(void *data)
912 {
913 yy_defer_accept = *(unsigned int *) data;
914 }
915
916 static void
917 conf_set_listen_wsock(void *data)
918 {
919 yy_wsock = *(unsigned int *) data;
920 }
921
922 static void
923 conf_set_listen_port_both(void *data, int ssl, int sctp)
924 {
925 conf_parm_t *args = data;
926 for (; args; args = args->next)
927 {
928 if(CF_TYPE(args->type) != CF_INT)
929 {
930 conf_report_error("listener::port argument is not an integer -- ignoring.");
931 continue;
932 }
933 if(listener_address[0] == NULL)
934 {
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 }
941 }
942 else
943 {
944 int family;
945 if(strchr(listener_address[0], ':') != NULL)
946 family = AF_INET6;
947 else
948 family = AF_INET;
949
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 }
959 }
960 }
961 }
962
963 static void
964 conf_set_listen_port(void *data)
965 {
966 conf_set_listen_port_both(data, 0, 0);
967 }
968
969 static void
970 conf_set_listen_sslport(void *data)
971 {
972 conf_set_listen_port_both(data, 1, 0 );
973 }
974
975 static void
976 conf_set_listen_sctp_port(void *data)
977 {
978 conf_set_listen_port_both(data, 0, 1);
979 }
980
981 static void
982 conf_set_listen_sctp_sslport(void *data)
983 {
984 conf_set_listen_port_both(data, 1, 1);
985 }
986
987 static void
988 conf_set_listen_address(void *data)
989 {
990 rb_free(listener_address[1]);
991 listener_address[1] = listener_address[0];
992 listener_address[0] = rb_strdup(data);
993 }
994
995 static int
996 conf_begin_auth(struct TopConf *tc)
997 {
998 rb_dlink_node *ptr;
999 rb_dlink_node *next_ptr;
1000
1001 if(yy_aconf)
1002 free_conf(yy_aconf);
1003
1004 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
1005 {
1006 free_conf(ptr->data);
1007 rb_dlinkDestroy(ptr, &yy_aconf_list);
1008 }
1009
1010 yy_aconf = make_conf();
1011 yy_aconf->status = CONF_CLIENT;
1012
1013 return 0;
1014 }
1015
1016 static int
1017 conf_end_auth(struct TopConf *tc)
1018 {
1019 struct ConfItem *yy_tmp, *found_conf;
1020 rb_dlink_node *ptr;
1021 rb_dlink_node *next_ptr;
1022
1023 if(EmptyString(yy_aconf->info.name))
1024 yy_aconf->info.name = rb_strdup("NOMATCH");
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);
1037 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
1038 conf_report_error("Ignoring redundant auth block (after *@*)");
1039 else if ((found_conf = find_exact_conf_by_address(yy_aconf->host, CONF_CLIENT, yy_aconf->user)) &&
1040 (!found_conf->spasswd || (yy_aconf->spasswd &&
1041 0 == irccmp(found_conf->spasswd, yy_aconf->spasswd))))
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);
1046
1047 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
1048 {
1049 yy_tmp = ptr->data;
1050
1051 if(yy_aconf->passwd)
1052 yy_tmp->passwd = rb_strdup(yy_aconf->passwd);
1053
1054 if(yy_aconf->spasswd)
1055 yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
1056
1057 /* this will always exist.. */
1058 yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
1059
1060 if(yy_aconf->className)
1061 yy_tmp->className = rb_strdup(yy_aconf->className);
1062
1063 if(yy_aconf->desc)
1064 yy_tmp->desc = rb_strdup(yy_aconf->desc);
1065
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
1074 if ((found_conf = find_exact_conf_by_address("*", CONF_CLIENT, "*")) && found_conf->spasswd == NULL)
1075 conf_report_error("Ignoring redundant auth block (after *@*)");
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))))
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);
1083 rb_dlinkDestroy(ptr, &yy_aconf_list);
1084 }
1085
1086 yy_aconf = NULL;
1087 return 0;
1088 }
1089
1090 static void
1091 conf_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
1109 yy_tmp->user = rb_strdup(data);
1110 yy_tmp->host = rb_strdup(p);
1111 }
1112 else
1113 {
1114 yy_tmp->user = rb_strdup("*");
1115 yy_tmp->host = rb_strdup(data);
1116 }
1117
1118 if(yy_aconf != yy_tmp)
1119 rb_dlinkAddAlloc(yy_tmp, &yy_aconf_list);
1120 }
1121
1122 static void
1123 conf_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
1131 static void
1132 conf_set_auth_passwd(void *data)
1133 {
1134 if(yy_aconf->passwd)
1135 memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd));
1136 rb_free(yy_aconf->passwd);
1137 yy_aconf->passwd = rb_strdup(data);
1138 }
1139
1140 static void
1141 conf_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
1196 rb_free(yy_aconf->info.name);
1197 yy_aconf->info.name = rb_strdup(data);
1198 yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
1199 }
1200
1201 static void
1202 conf_set_auth_desc(void *data)
1203 {
1204 rb_free(yy_aconf->desc);
1205 yy_aconf->desc = rb_strdup(data);
1206 }
1207
1208 static void
1209 conf_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
1216 static void
1217 conf_set_auth_redir_serv(void *data)
1218 {
1219 yy_aconf->flags |= CONF_FLAGS_REDIR;
1220 rb_free(yy_aconf->info.name);
1221 yy_aconf->info.name = rb_strdup(data);
1222 }
1223
1224 static void
1225 conf_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
1233 static void
1234 conf_set_auth_class(void *data)
1235 {
1236 rb_free(yy_aconf->className);
1237 yy_aconf->className = rb_strdup(data);
1238 }
1239
1240 static void
1241 conf_set_auth_umodes(void *data)
1242 {
1243 char *umodes = data;
1244
1245 parse_umodes(umodes, &yy_aconf->umodes, &yy_aconf->umodes_mask);
1246 }
1247
1248 static int
1249 conf_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;
1256 yy_server->flags |= SERVER_TB;
1257
1258 if(conf_cur_block_name != NULL)
1259 yy_server->name = rb_strdup(conf_cur_block_name);
1260
1261 return 0;
1262 }
1263
1264 static int
1265 conf_end_connect(struct TopConf *tc)
1266 {
1267 if (EmptyString(yy_server->name))
1268 {
1269 conf_report_error("Ignoring connect block -- missing name.");
1270 return 0;
1271 }
1272
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))
1282 {
1283 conf_report_error("Ignoring connect block for %s -- no "
1284 "fingerprint or password credentials "
1285 "provided.", yy_server->name);
1286 return 0;
1287 }
1288
1289 if ((yy_server->flags & SERVER_SSL) && EmptyString(yy_server->certfp))
1290 {
1291 conf_report_error("Ignoring connect block for %s -- no "
1292 "fingerprint provided for SSL "
1293 "connection.", yy_server->name);
1294 return 0;
1295 }
1296
1297 if (! (yy_server->flags & SERVER_SSL) && ! EmptyString(yy_server->certfp))
1298 {
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);
1303 return 0;
1304 }
1305
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)
1309 {
1310 conf_report_error("Ignoring connect block for %s -- missing "
1311 "host.", yy_server->name);
1312 return 0;
1313 }
1314
1315 add_server_conf(yy_server);
1316 rb_dlinkAdd(yy_server, &yy_server->node, &server_conf_list);
1317
1318 yy_server = NULL;
1319 return 0;
1320 }
1321
1322 static void
1323 conf_set_connect_host(void *data)
1324 {
1325 struct rb_sockaddr_storage addr;
1326
1327 if(rb_inet_pton_sock(data, &addr) <= 0)
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 }
1336 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1337 {
1338 yy_server->connect6 = addr;
1339 }
1340 else
1341 {
1342 conf_report_error("Unsupported IP address for server connect host (%s)",
1343 (char *)data);
1344 return;
1345 }
1346 }
1347
1348 static void
1349 conf_set_connect_vhost(void *data)
1350 {
1351 struct rb_sockaddr_storage addr;
1352
1353 if(rb_inet_pton_sock(data, &addr) <= 0)
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)
1359 {
1360 yy_server->bind4 = addr;
1361 }
1362 else if(GET_SS_FAMILY(&addr) == AF_INET6)
1363 {
1364 yy_server->bind6 = addr;
1365 }
1366 else
1367 {
1368 conf_report_error("Unsupported IP address for server connect vhost (%s)",
1369 (char *)data);
1370 return;
1371 }
1372 }
1373
1374 static void
1375 conf_set_connect_send_password(void *data)
1376 {
1377 if(yy_server->spasswd)
1378 {
1379 memset(yy_server->spasswd, 0, strlen(yy_server->spasswd));
1380 rb_free(yy_server->spasswd);
1381 }
1382
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);
1397 }
1398
1399 static void
1400 conf_set_connect_accept_password(void *data)
1401 {
1402 if(yy_server->passwd)
1403 {
1404 memset(yy_server->passwd, 0, strlen(yy_server->passwd));
1405 rb_free(yy_server->passwd);
1406 }
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);
1422 }
1423
1424 static void
1425 conf_set_connect_fingerprint(void *data)
1426 {
1427 if (yy_server->certfp)
1428 rb_free(yy_server->certfp);
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
1435 static void
1436 conf_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
1446 static void
1447 conf_set_connect_aftype(void *data)
1448 {
1449 char *aft = data;
1450
1451 if(rb_strcasecmp(aft, "ipv4") == 0)
1452 yy_server->aftype = AF_INET;
1453 else if(rb_strcasecmp(aft, "ipv6") == 0)
1454 yy_server->aftype = AF_INET6;
1455 else
1456 conf_report_error("connect::aftype '%s' is unknown.", aft);
1457 }
1458
1459 static void
1460 conf_set_connect_flags(void *data)
1461 {
1462 conf_parm_t *args = data;
1463
1464 set_modes_from_table(&yy_server->flags, "flag", connect_table, args);
1465 }
1466
1467 static void
1468 conf_set_connect_class(void *data)
1469 {
1470 rb_free(yy_server->class_name);
1471 yy_server->class_name = rb_strdup(data);
1472 }
1473
1474 static void
1475 conf_set_exempt_ip(void *data)
1476 {
1477 struct ConfItem *yy_tmp;
1478 int masktype = parse_netmask_strict(data, NULL, NULL);
1479
1480 if(masktype != HM_IPV4 && masktype != HM_IPV6)
1481 {
1482 conf_report_error("Ignoring exempt -- invalid exempt::ip.");
1483 return;
1484 }
1485
1486 yy_tmp = make_conf();
1487 yy_tmp->passwd = rb_strdup("*");
1488 yy_tmp->host = rb_strdup(data);
1489 yy_tmp->status = CONF_EXEMPTDLINE;
1490 add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, NULL, yy_tmp);
1491 }
1492
1493 static void
1494 conf_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
1512 static int
1513 conf_cleanup_cluster(struct TopConf *tc)
1514 {
1515 rb_dlink_node *ptr, *next_ptr;
1516
1517 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1518 {
1519 free_remote_conf(ptr->data);
1520 rb_dlinkDestroy(ptr, &yy_cluster_list);
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
1532 static void
1533 conf_set_cluster_name(void *data)
1534 {
1535 if(yy_shared != NULL)
1536 free_remote_conf(yy_shared);
1537
1538 yy_shared = make_remote_conf();
1539 yy_shared->server = rb_strdup(data);
1540 rb_dlinkAddAlloc(yy_shared, &yy_cluster_list);
1541
1542 yy_shared = NULL;
1543 }
1544
1545 static void
1546 conf_set_cluster_flags(void *data)
1547 {
1548 conf_parm_t *args = data;
1549 int flags = 0;
1550 rb_dlink_node *ptr, *next_ptr;
1551
1552 if(yy_shared != NULL)
1553 free_remote_conf(yy_shared);
1554
1555 set_modes_from_table(&flags, "flag", cluster_table, args);
1556
1557 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_cluster_list.head)
1558 {
1559 yy_shared = ptr->data;
1560 yy_shared->flags = flags;
1561 rb_dlinkAddTail(yy_shared, &yy_shared->node, &cluster_conf_list);
1562 rb_dlinkDestroy(ptr, &yy_cluster_list);
1563 }
1564
1565 yy_shared = NULL;
1566 }
1567
1568 static void
1569 conf_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
1583 static void
1584 conf_set_general_hide_error_messages(void *data)
1585 {
1586 char *val = data;
1587
1588 if(rb_strcasecmp(val, "yes") == 0)
1589 ConfigFileEntry.hide_error_messages = 2;
1590 else if(rb_strcasecmp(val, "opers") == 0)
1591 ConfigFileEntry.hide_error_messages = 1;
1592 else if(rb_strcasecmp(val, "no") == 0)
1593 ConfigFileEntry.hide_error_messages = 0;
1594 else
1595 conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val);
1596 }
1597
1598 static void
1599 conf_set_general_stats_k_oper_only(void *data)
1600 {
1601 char *val = data;
1602
1603 if(rb_strcasecmp(val, "yes") == 0)
1604 ConfigFileEntry.stats_k_oper_only = 2;
1605 else if(rb_strcasecmp(val, "masked") == 0)
1606 ConfigFileEntry.stats_k_oper_only = 1;
1607 else if(rb_strcasecmp(val, "no") == 0)
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
1613 static void
1614 conf_set_general_stats_i_oper_only(void *data)
1615 {
1616 char *val = data;
1617
1618 if(rb_strcasecmp(val, "yes") == 0)
1619 ConfigFileEntry.stats_i_oper_only = 2;
1620 else if(rb_strcasecmp(val, "masked") == 0)
1621 ConfigFileEntry.stats_i_oper_only = 1;
1622 else if(rb_strcasecmp(val, "no") == 0)
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
1628 static void
1629 conf_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
1643 static void
1644 conf_set_general_default_umodes(void *data)
1645 {
1646 char *umodes = data;
1647
1648 parse_umodes(umodes, &ConfigFileEntry.default_umodes, NULL);
1649 }
1650
1651 static void
1652 conf_set_general_oper_umodes(void *data)
1653 {
1654 set_modes_from_table(&ConfigFileEntry.oper_umodes, "umode", umode_table, data);
1655 }
1656
1657 static void
1658 conf_set_general_certfp_method(void *data)
1659 {
1660 char *method = data;
1661
1662 if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA1))
1663 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
1664 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA256))
1665 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA256;
1666 else if (!rb_strcasecmp(method, CERTFP_NAME_CERT_SHA512))
1667 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA512;
1668 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA256))
1669 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA256;
1670 else if (!rb_strcasecmp(method, CERTFP_NAME_SPKI_SHA512))
1671 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SPKI_SHA512;
1672 else
1673 {
1674 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
1675 conf_report_error("Ignoring general::certfp_method -- bogus certfp method %s", method);
1676 }
1677 }
1678
1679 static void
1680 conf_set_general_oper_only_umodes(void *data)
1681 {
1682 set_modes_from_table(&ConfigFileEntry.oper_only_umodes, "umode", umode_table, data);
1683 }
1684
1685 static void
1686 conf_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
1716 static void
1717 conf_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
1740 static void
1741 conf_set_serverhide_links_delay(void *data)
1742 {
1743 int val = *(unsigned int *) data;
1744
1745 ConfigServerHide.links_delay = val;
1746 }
1747
1748 static void
1749 conf_set_service_name(void *data)
1750 {
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
1773 tmp = rb_strdup(data);
1774 rb_dlinkAddAlloc(tmp, &service_list);
1775 }
1776
1777 static int
1778 conf_begin_alias(struct TopConf *tc)
1779 {
1780 yy_alias = rb_malloc(sizeof(struct alias_entry));
1781
1782 if (conf_cur_block_name != NULL)
1783 yy_alias->name = rb_strdup(conf_cur_block_name);
1784
1785 yy_alias->flags = 0;
1786
1787 return 0;
1788 }
1789
1790 static int
1791 conf_end_alias(struct TopConf *tc)
1792 {
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
1800 rb_free(yy_alias);
1801
1802 return -1;
1803 }
1804
1805 if (yy_alias->target == NULL)
1806 {
1807 conf_report_error("Ignoring alias -- must have a target.");
1808
1809 rb_free(yy_alias);
1810
1811 return -1;
1812 }
1813
1814 rb_dictionary_add(alias_dict, yy_alias->name, yy_alias);
1815
1816 return 0;
1817 }
1818
1819 static void
1820 conf_set_alias_name(void *data)
1821 {
1822 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1823 return;
1824
1825 yy_alias->name = rb_strdup(data);
1826 }
1827
1828 static void
1829 conf_set_alias_target(void *data)
1830 {
1831 if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */
1832 return;
1833
1834 yy_alias->target = rb_strdup(data);
1835 }
1836
1837 static void
1838 conf_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 {
1865 conf_report_error("channel::autochanmodes -- Invalid channel mode %c", *pm);
1866 continue;
1867 }
1868 break;
1869 }
1870 }
1871 }
1872
1873 /* XXX for below */
1874 static void conf_set_dnsbl_entry_reason(void *data);
1875
1876 #define IPTYPE_IPV4 1
1877 #define IPTYPE_IPV6 2
1878
1879 static int
1880 conf_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
1886 static void
1887 conf_set_dnsbl_entry_host(void *data)
1888 {
1889 if (yy_dnsbl_entry_host)
1890 {
1891 conf_report_error("dnsbl::host %s overlaps existing host %s",
1892 (char *)data, yy_dnsbl_entry_host);
1893
1894 /* Cleanup */
1895 conf_set_dnsbl_entry_reason(NULL);
1896 return;
1897 }
1898
1899 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1900 yy_dnsbl_entry_host = rb_strdup(data);
1901 }
1902
1903 static void
1904 conf_set_dnsbl_entry_type(void *data)
1905 {
1906 conf_parm_t *args = data;
1907
1908 /* Don't assume we have either if we got here */
1909 yy_dnsbl_entry_iptype = 0;
1910
1911 for (; args; args = args->next)
1912 {
1913 if (!rb_strcasecmp(args->v.string, "ipv4"))
1914 yy_dnsbl_entry_iptype |= IPTYPE_IPV4;
1915 else if (!rb_strcasecmp(args->v.string, "ipv6"))
1916 yy_dnsbl_entry_iptype |= IPTYPE_IPV6;
1917 else
1918 conf_report_error("dnsbl::type has unknown address family %s",
1919 args->v.string);
1920 }
1921
1922 /* If we have neither, just default to IPv4 */
1923 if (!yy_dnsbl_entry_iptype)
1924 {
1925 conf_report_warning("dnsbl::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
1926 yy_dnsbl_entry_iptype = IPTYPE_IPV4;
1927 }
1928 }
1929
1930 static void
1931 conf_set_dnsbl_entry_matches(void *data)
1932 {
1933 conf_parm_t *args = data;
1934 enum filter_t { FILTER_NONE, FILTER_ALL, FILTER_LAST };
1935
1936 for (; args; args = args->next)
1937 {
1938 char *str = args->v.string;
1939 char *p;
1940 enum filter_t type = FILTER_LAST;
1941
1942 if (CF_TYPE(args->type) != CF_QSTRING)
1943 {
1944 conf_report_error("dnsbl::matches -- must be quoted string");
1945 continue;
1946 }
1947
1948 if (str == NULL)
1949 {
1950 conf_report_error("dnsbl::matches -- invalid entry");
1951 continue;
1952 }
1953
1954 if (strlen(str) > HOSTIPLEN)
1955 {
1956 conf_report_error("dnsbl::matches has an entry too long: %s",
1957 str);
1958 continue;
1959 }
1960
1961 for (p = str; *p != '\0'; p++)
1962 {
1963 /* Check for validity */
1964 if (*p == '.')
1965 type = FILTER_ALL;
1966 else if (!isdigit((unsigned char)*p))
1967 {
1968 conf_report_error("dnsbl::matches has invalid IP match entry %s",
1969 str);
1970 type = FILTER_NONE;
1971 break;
1972 }
1973 }
1974
1975 if (type == FILTER_ALL)
1976 {
1977 /* Basic IP sanity check */
1978 struct rb_sockaddr_storage tmp;
1979 if (rb_inet_pton(AF_INET, str, &tmp) <= 0)
1980 {
1981 conf_report_error("dnsbl::matches has invalid IP match entry %s",
1982 str);
1983 continue;
1984 }
1985 }
1986 else if (type == FILTER_LAST)
1987 {
1988 /* Verify it's the correct length */
1989 if (strlen(str) > 3)
1990 {
1991 conf_report_error("dnsbl::matches has invalid octet match entry %s",
1992 str);
1993 continue;
1994 }
1995 }
1996 else
1997 {
1998 continue; /* Invalid entry */
1999 }
2000
2001 rb_dlinkAddAlloc(rb_strdup(str), &yy_dnsbl_entry_filters);
2002 }
2003 }
2004
2005 static void
2006 conf_set_dnsbl_entry_reason(void *data)
2007 {
2008 rb_dlink_node *ptr, *nptr;
2009
2010 if (yy_dnsbl_entry_host && data)
2011 {
2012 yy_dnsbl_entry_reason = rb_strdup(data);
2013 if (yy_dnsbl_entry_iptype & IPTYPE_IPV6)
2014 {
2015 /* Make sure things fit (magic number 64 = alnum count + dots)
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 */
2018 if ((64 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
2019 {
2020 conf_report_error("dnsbl::host %s results in IPv6 queries that are too long",
2021 yy_dnsbl_entry_host);
2022 goto cleanup_bl;
2023 }
2024 }
2025 /* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
2026 if ((yy_dnsbl_entry_iptype & IPTYPE_IPV4) && !(yy_dnsbl_entry_iptype & IPTYPE_IPV6))
2027 {
2028 /* Make sure things fit for worst case (magic number 16 = number of nums + dots)
2029 * Example: 127.127.127.127.in-addr.arpa
2030 */
2031 if ((16 + strlen(yy_dnsbl_entry_host)) > IRCD_RES_HOSTLEN)
2032 {
2033 conf_report_error("dnsbl::host %s results in IPv4 queries that are too long",
2034 yy_dnsbl_entry_host);
2035 goto cleanup_bl;
2036 }
2037 }
2038
2039 add_dnsbl_entry(yy_dnsbl_entry_host, yy_dnsbl_entry_reason, yy_dnsbl_entry_iptype, &yy_dnsbl_entry_filters);
2040 }
2041
2042 cleanup_bl:
2043 RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_dnsbl_entry_filters.head)
2044 {
2045 rb_free(ptr->data);
2046 rb_dlinkDestroy(ptr, &yy_dnsbl_entry_filters);
2047 }
2048
2049 yy_dnsbl_entry_filters = (rb_dlink_list){ NULL, NULL, 0 };
2050
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;
2056 }
2057
2058
2059 struct opm_scanner
2060 {
2061 const char *type;
2062 uint16_t port;
2063
2064 rb_dlink_node node;
2065 };
2066
2067 static int
2068 conf_begin_opm(struct TopConf *tc)
2069 {
2070 yy_opm_address_ipv4 = yy_opm_address_ipv6 = NULL;
2071 yy_opm_port_ipv4 = yy_opm_port_ipv6 = yy_opm_timeout = 0;
2072 delete_opm_proxy_scanner_all();
2073 delete_opm_listener_all();
2074 return 0;
2075 }
2076
2077 static int
2078 conf_end_opm(struct TopConf *tc)
2079 {
2080 rb_dlink_node *ptr, *nptr;
2081 bool fail = false;
2082
2083 if(rb_dlink_list_length(&yy_opm_scanner_list) == 0)
2084 {
2085 conf_report_error("No opm scanners configured -- disabling opm.");
2086 fail = true;
2087 goto end;
2088 }
2089
2090 if(yy_opm_port_ipv4 > 0)
2091 {
2092 if(yy_opm_address_ipv4 != NULL)
2093 conf_create_opm_listener(yy_opm_address_ipv4, yy_opm_port_ipv4);
2094 else
2095 {
2096 char ip[HOSTIPLEN];
2097 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind4, ip, sizeof(ip)))
2098 conf_report_error("No opm::listen_ipv4 nor serverinfo::vhost directive; cannot listen on IPv4");
2099 else
2100 conf_create_opm_listener(ip, yy_opm_port_ipv4);
2101 }
2102 }
2103
2104 if(yy_opm_port_ipv6 > 0)
2105 {
2106 if(yy_opm_address_ipv6 != NULL)
2107 conf_create_opm_listener(yy_opm_address_ipv6, yy_opm_port_ipv6);
2108 else
2109 {
2110 char ip[HOSTIPLEN];
2111 if(!rb_inet_ntop_sock((struct sockaddr *)&ServerInfo.bind6, ip, sizeof(ip)))
2112 conf_report_error("No opm::listen_ipv6 nor serverinfo::vhost directive; cannot listen on IPv6");
2113 else
2114 conf_create_opm_listener(ip, yy_opm_port_ipv6);
2115 }
2116 }
2117
2118 /* If there's no listeners... */
2119 fail = (yy_opm_port_ipv4 == 0 || yy_opm_port_ipv6 == 0);
2120 if(!fail && yy_opm_timeout > 0 && yy_opm_timeout < 60)
2121 /* Send timeout */
2122 set_authd_timeout("opm_timeout", yy_opm_timeout);
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");
2127
2128 end:
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
2140 if(!fail)
2141 opm_check_enable(true);
2142
2143 rb_free(yy_opm_address_ipv4);
2144 rb_free(yy_opm_address_ipv6);
2145 return 0;
2146 }
2147
2148 static void
2149 conf_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 }
2161
2162 static void
2163 conf_set_opm_listen_address_both(void *data, bool ipv6)
2164 {
2165 struct rb_sockaddr_storage addr;
2166 const char *confstr = (ipv6 ? "opm::listen_ipv6" : "opm::listen_ipv4");
2167 char *ip = data;
2168
2169 if(!rb_inet_pton_sock(ip, &addr))
2170 {
2171 conf_report_error("%s is an invalid address: %s", confstr, ip);
2172 return;
2173 }
2174
2175 if(ipv6)
2176 {
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);
2190 }
2191 else
2192 {
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);
2206 }
2207 }
2208
2209 static void
2210 conf_set_opm_listen_address_ipv4(void *data)
2211 {
2212 conf_set_opm_listen_address_both(data, false);
2213 }
2214
2215 static void
2216 conf_set_opm_listen_address_ipv6(void *data)
2217 {
2218 conf_set_opm_listen_address_both(data, true);
2219 }
2220
2221 static void
2222 conf_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");
2226
2227 if(port > 65535 || port <= 0)
2228 {
2229 conf_report_error("%s is out of range: %d", confstr, port);
2230 return;
2231 }
2232
2233 if(ipv6)
2234 {
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;
2243 }
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 }
2252
2253 yy_opm_port_ipv6 = port;
2254 }
2255 }
2256
2257 static void
2258 conf_set_opm_listen_port_ipv4(void *data)
2259 {
2260 conf_set_opm_listen_port_both(data, false);
2261 }
2262
2263 static void
2264 conf_set_opm_listen_port_ipv6(void *data)
2265 {
2266 conf_set_opm_listen_port_both(data, true);
2267 }
2268
2269 static void
2270 conf_set_opm_listen_port(void *data)
2271 {
2272 conf_set_opm_listen_port_both(data, true);
2273 conf_set_opm_listen_port_both(data, false);
2274 }
2275
2276 static void
2277 conf_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)
2281 {
2282 rb_dlink_node *ptr;
2283 bool dup = false;
2284
2285 if(CF_TYPE(args->type) != CF_INT)
2286 {
2287 conf_report_error("%s argument is not an integer -- ignoring.", node);
2288 continue;
2289 }
2290
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 }
2296
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 }
2317 }
2318 }
2319
2320 static void
2321 conf_set_opm_scan_ports_socks4(void *data)
2322 {
2323 conf_set_opm_scan_ports_all(data, "opm::socks4_ports", "socks4");
2324 }
2325
2326 static void
2327 conf_set_opm_scan_ports_socks5(void *data)
2328 {
2329 conf_set_opm_scan_ports_all(data, "opm::socks5_ports", "socks5");
2330 }
2331
2332 static void
2333 conf_set_opm_scan_ports_httpconnect(void *data)
2334 {
2335 conf_set_opm_scan_ports_all(data, "opm::httpconnect_ports", "httpconnect");
2336 }
2337
2338 static void
2339 conf_set_opm_scan_ports_httpsconnect(void *data)
2340 {
2341 conf_set_opm_scan_ports_all(data, "opm::httpsconnect_ports", "httpsconnect");
2342 }
2343
2344 /* public functions */
2345
2346
2347 void
2348 conf_report_error(const char *fmt, ...)
2349 {
2350 va_list ap;
2351 char msg[BUFSIZE + 1] = { 0 };
2352
2353 va_start(ap, fmt);
2354 vsnprintf(msg, sizeof msg, fmt, ap);
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);
2364 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "error: \"%s\", line %d: %s", current_file, lineno + 1, msg);
2365 }
2366
2367 void
2368 conf_report_warning(const char *fmt, ...)
2369 {
2370 va_list ap;
2371 char msg[BUFSIZE + 1] = { 0 };
2372
2373 va_start(ap, fmt);
2374 vsnprintf(msg, sizeof msg, fmt, ap);
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);
2384 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "warning: \"%s\", line %d: %s", current_file, lineno + 1, msg);
2385 }
2386
2387 int
2388 conf_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)
2397 conf_cur_block_name = rb_strdup(name);
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
2408 int
2409 conf_end_block(struct TopConf *tc)
2410 {
2411 int ret = 0;
2412 if(tc->tc_efunc)
2413 ret = tc->tc_efunc(tc);
2414
2415 rb_free(conf_cur_block_name);
2416 conf_cur_block_name = NULL;
2417 return ret;
2418 }
2419
2420 static void
2421 conf_set_generic_int(void *data, void *location)
2422 {
2423 *((int *) location) = *((unsigned int *) data);
2424 }
2425
2426 static void
2427 conf_set_generic_string(void *data, int len, void *location)
2428 {
2429 char **loc = location;
2430 char *input = data;
2431
2432 if(len && strlen(input) > (unsigned int)len)
2433 input[len] = '\0';
2434
2435 rb_free(*loc);
2436 *loc = rb_strdup(input);
2437 }
2438
2439 int
2440 conf_call_set(struct TopConf *tc, char *item, conf_parm_t * value)
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
2451 ("Non-existent configuration setting %s::%s.", tc->tc_name, (char *) item);
2452 return -1;
2453 }
2454
2455 /* if it takes one thing, make sure they only passed one thing,
2456 and handle as needed. */
2457 if((value->v.list->type & CF_FLIST) && !(cf->cf_type & CF_FLIST))
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 {
2469 /* if it expects a string value, but we got a yesno,
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)
2478 cp->v.string = rb_strdup("yes");
2479 else
2480 cp->v.string = rb_strdup("no");
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
2536 int
2537 add_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
2545 if(find_conf_item(tc, name) != NULL)
2546 return -1;
2547
2548 cf = rb_malloc(sizeof(struct ConfEntry));
2549
2550 cf->cf_name = name;
2551 cf->cf_type = type;
2552 cf->cf_func = func;
2553 cf->cf_arg = NULL;
2554
2555 rb_dlinkAddAlloc(cf, &tc->tc_items);
2556
2557 return 0;
2558 }
2559
2560 int
2561 remove_conf_item(const char *topconf, const char *name)
2562 {
2563 struct TopConf *tc;
2564 struct ConfEntry *cf;
2565 rb_dlink_node *ptr;
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
2573 if((ptr = rb_dlinkFind(cf, &tc->tc_items)) == NULL)
2574 return -1;
2575
2576 rb_dlinkDestroy(ptr, &tc->tc_items);
2577 rb_free(cf);
2578
2579 return 0;
2580 }
2581
2582 /* *INDENT-OFF* */
2583 static struct ConfEntry conf_serverinfo_table[] =
2584 {
2585 { "description", CF_QSTRING, NULL, 0, &ServerInfo.description },
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
2593 { "ssl_private_key", CF_QSTRING, NULL, 0, &ServerInfo.ssl_private_key },
2594 { "ssl_ca_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_ca_cert },
2595 { "ssl_cert", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cert },
2596 { "ssl_dh_params", CF_QSTRING, NULL, 0, &ServerInfo.ssl_dh_params },
2597 { "ssl_cipher_list", CF_QSTRING, NULL, 0, &ServerInfo.ssl_cipher_list },
2598 { "ssld_count", CF_INT, NULL, 0, &ServerInfo.ssld_count },
2599
2600 { "default_max_clients",CF_INT, NULL, 0, &ServerInfo.default_max_clients },
2601
2602 { "nicklen", CF_INT, conf_set_serverinfo_nicklen, 0, NULL },
2603
2604 { "\0", 0, NULL, 0, NULL }
2605 };
2606
2607 static 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
2615 static struct ConfEntry conf_log_table[] =
2616 {
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 },
2626 { "\0", 0, NULL, 0, NULL }
2627 };
2628
2629 static 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 },
2634 { "privset", CF_QSTRING, conf_set_oper_privset, 0, NULL },
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 },
2638 { "fingerprint", CF_QSTRING, conf_set_oper_fingerprint, 0, NULL },
2639 { "\0", 0, NULL, 0, NULL }
2640 };
2641
2642 static 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
2649 static struct ConfEntry conf_class_table[] =
2650 {
2651 { "ping_time", CF_TIME, conf_set_class_ping_time, 0, NULL },
2652 { "cidr_ipv4_bitlen", CF_INT, conf_set_class_cidr_ipv4_bitlen, 0, NULL },
2653 { "cidr_ipv6_bitlen", CF_INT, conf_set_class_cidr_ipv6_bitlen, 0, NULL },
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 },
2660 { "max_autoconn", CF_INT, conf_set_class_max_autoconn, 0, NULL },
2661 { "sendq", CF_TIME, conf_set_class_sendq, 0, NULL },
2662 { "\0", 0, NULL, 0, NULL }
2663 };
2664
2665 static struct ConfEntry conf_auth_table[] =
2666 {
2667 { "user", CF_QSTRING, conf_set_auth_user, 0, NULL },
2668 { "auth_user", CF_QSTRING, conf_set_auth_auth_user, 0, NULL },
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 },
2675 { "umodes", CF_QSTRING, conf_set_auth_umodes, 0, NULL},
2676 { "description",CF_QSTRING, conf_set_auth_desc, 0, NULL},
2677 { "\0", 0, NULL, 0, NULL }
2678 };
2679
2680 static 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 },
2684 { "fingerprint", CF_QSTRING, conf_set_connect_fingerprint, 0, NULL },
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 },
2690 { "class", CF_QSTRING, conf_set_connect_class, 0, NULL },
2691 { "\0", 0, NULL, 0, NULL }
2692 };
2693
2694 static 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 },
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 },
2701 { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL },
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 },
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 },
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 },
2712 { "sasl_service", CF_QSTRING, NULL, REALLEN, &ConfigFileEntry.sasl_service },
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
2720 { "hidden_caps", CF_QSTRING | CF_FLIST, conf_set_general_hidden_caps, 0, NULL },
2721
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 },
2726 { "collision_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.collision_fnc },
2727 { "resv_fnc", CF_YESNO, NULL, 0, &ConfigFileEntry.resv_fnc },
2728 { "post_registration_delay", CF_TIME, NULL, 0, &ConfigFileEntry.post_registration_delay },
2729 { "connect_timeout", CF_TIME, NULL, 0, &ConfigFileEntry.connect_timeout },
2730 { "default_floodcount", CF_INT, NULL, 0, &ConfigFileEntry.default_floodcount },
2731 { "default_ident_timeout", CF_INT, NULL, 0, &ConfigFileEntry.default_ident_timeout },
2732 { "disable_auth", CF_YESNO, NULL, 0, &ConfigFileEntry.disable_auth },
2733 { "dots_in_ident", CF_INT, NULL, 0, &ConfigFileEntry.dots_in_ident },
2734 { "failed_oper_notice", CF_YESNO, NULL, 0, &ConfigFileEntry.failed_oper_notice },
2735 { "global_snotices", CF_YESNO, NULL, 0, &ConfigFileEntry.global_snotices },
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 },
2739 { "hide_tkdline_duration", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_tkdline_duration },
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 },
2757 { "throttle_count", CF_INT, NULL, 0, &ConfigFileEntry.throttle_count },
2758 { "throttle_duration", CF_TIME, NULL, 0, &ConfigFileEntry.throttle_duration },
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 },
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 },
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 },
2770 { "use_propagated_bans",CF_YESNO, NULL, 0, &ConfigFileEntry.use_propagated_bans },
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 },
2776 { "max_ratelimit_tokens", CF_INT, NULL, 0, &ConfigFileEntry.max_ratelimit_tokens },
2777 { "away_interval", CF_INT, NULL, 0, &ConfigFileEntry.away_interval },
2778 { "hide_opers_in_whois", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers_in_whois },
2779 { "hide_opers", CF_YESNO, NULL, 0, &ConfigFileEntry.hide_opers },
2780 { "certfp_method", CF_STRING, conf_set_general_certfp_method, 0, NULL },
2781 { "drain_reason", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.drain_reason },
2782 { "sasl_only_client_message", CF_QSTRING, NULL, BUFSIZE, &ConfigFileEntry.sasl_only_client_message },
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 },
2791 { "tls_ciphers_oper_only", CF_YESNO, NULL, 0, &ConfigFileEntry.tls_ciphers_oper_only },
2792 { "oper_secure_only", CF_YESNO, NULL, 0, &ConfigFileEntry.oper_secure_only },
2793 { "\0", 0, NULL, 0, NULL }
2794 };
2795
2796 static 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 },
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 },
2807 { "max_chans_per_user_large", CF_INT, NULL, 0, &ConfigChannel.max_chans_per_user_large },
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 },
2810 { "only_ascii_channels", CF_YESNO, NULL, 0, &ConfigChannel.only_ascii_channels },
2811 { "use_except", CF_YESNO, NULL, 0, &ConfigChannel.use_except },
2812 { "use_invex", CF_YESNO, NULL, 0, &ConfigChannel.use_invex },
2813 { "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
2814 { "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
2815 { "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
2816 { "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
2817 { "disable_local_channels", CF_YESNO, NULL, 0, &ConfigChannel.disable_local_channels },
2818 { "autochanmodes", CF_QSTRING, conf_set_channel_autochanmodes, 0, NULL },
2819 { "displayed_usercount", CF_INT, NULL, 0, &ConfigChannel.displayed_usercount },
2820 { "strip_topic_colors", CF_YESNO, NULL, 0, &ConfigChannel.strip_topic_colors },
2821 { "opmod_send_statusmsg", CF_YESNO, NULL, 0, &ConfigChannel.opmod_send_statusmsg },
2822 { "ip_bans_through_vhost", CF_YESNO, NULL, 0, &ConfigChannel.ip_bans_through_vhost },
2823 { "\0", 0, NULL, 0, NULL }
2824 };
2825
2826 static 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
2836 void
2837 newconf_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);
2848 add_top_conf("privset", NULL, NULL, conf_privset_table);
2849
2850 add_top_conf("listen", conf_begin_listen, conf_end_listen, NULL);
2851 add_conf_item("listen", "defer_accept", CF_YESNO, conf_set_listen_defer_accept);
2852 add_conf_item("listen", "wsock", CF_YESNO, conf_set_listen_wsock);
2853 add_conf_item("listen", "port", CF_INT | CF_FLIST, conf_set_listen_port);
2854 add_conf_item("listen", "sslport", CF_INT | CF_FLIST, conf_set_listen_sslport);
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);
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
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
2867 add_top_conf("secure", NULL, NULL, NULL);
2868 add_conf_item("secure", "ip", CF_QSTRING, conf_set_secure_ip);
2869
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
2878 add_top_conf("service", NULL, NULL, NULL);
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
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);
2896
2897 add_top_conf("opm", conf_begin_opm, conf_end_opm, NULL);
2898 add_conf_item("opm", "timeout", CF_INT, conf_set_opm_timeout);
2899 add_conf_item("opm", "listen_ipv4", CF_QSTRING, conf_set_opm_listen_address_ipv4);
2900 add_conf_item("opm", "listen_ipv6", CF_QSTRING, conf_set_opm_listen_address_ipv6);
2901 add_conf_item("opm", "port_v4", CF_INT, conf_set_opm_listen_port_ipv4);
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);
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);
2906 add_conf_item("opm", "httpconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpconnect);
2907 add_conf_item("opm", "httpsconnect_ports", CF_INT | CF_FLIST, conf_set_opm_scan_ports_httpsconnect);
2908 }