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