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