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