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