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