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