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