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