-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathnewconf.c
2886 lines (2429 loc) · 72 KB
/
newconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This code is in the public domain.
*/
#include "stdinc.h"
#ifdef HAVE_LIBCRYPTO
#include <openssl/pem.h>
#include <openssl/rsa.h>
#endif
#include "newconf.h"
#include "ircd_defs.h"
#include "logger.h"
#include "s_conf.h"
#include "s_user.h"
#include "s_newconf.h"
#include "send.h"
#include "setup.h"
#include "modules.h"
#include "listener.h"
#include "hostmask.h"
#include "s_serv.h"
#include "hash.h"
#include "cache.h"
#include "ircd.h"
#include "snomask.h"
#include "sslproc.h"
#include "wsproc.h"
#include "privilege.h"
#include "chmode.h"
#include "certfp.h"
#define CF_TYPE(x) ((x) & CF_MTYPE)
static int yy_defer_accept = 1;
static int yy_wsock = 0;
struct TopConf *conf_cur_block;
static char *conf_cur_block_name = NULL;
static rb_dlink_list conf_items;
static struct ConfItem *yy_aconf = NULL;
static struct Class *yy_class = NULL;
static struct remote_conf *yy_shared = NULL;
static struct server_conf *yy_server = NULL;
static rb_dlink_list yy_aconf_list;
static rb_dlink_list yy_oper_list;
static rb_dlink_list yy_cluster_list;
static struct oper_conf *yy_oper = NULL;
static struct alias_entry *yy_alias = NULL;
static char *yy_dnsbl_entry_host = NULL;
static char *yy_dnsbl_entry_reason = NULL;
static uint8_t yy_dnsbl_entry_iptype = 0;
static rb_dlink_list yy_dnsbl_entry_filters = { NULL, NULL, 0 };
static char *yy_opm_address_ipv4 = NULL;
static char *yy_opm_address_ipv6 = NULL;
static uint16_t yy_opm_port_ipv4 = 0;
static uint16_t yy_opm_port_ipv6 = 0;
static int yy_opm_timeout = 0;
static rb_dlink_list yy_opm_scanner_list;
static char *yy_privset_extends = NULL;
static const char *
conf_strtype(int type)
{
switch (CF_TYPE(type))
{
case CF_INT:
return "integer value";
case CF_STRING:
return "unquoted string";
case CF_YESNO:
return "yes/no value";
case CF_QSTRING:
return "quoted string";
case CF_TIME:
return "time/size value";
default:
return "unknown type";
}
}
int
add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
int (*efunc) (struct TopConf *), struct ConfEntry *items)
{
struct TopConf *tc;
tc = rb_malloc(sizeof(struct TopConf));
tc->tc_name = name;
tc->tc_sfunc = sfunc;
tc->tc_efunc = efunc;
tc->tc_entries = items;
rb_dlinkAddAlloc(tc, &conf_items);
return 0;
}
struct TopConf *
find_top_conf(const char *name)
{
rb_dlink_node *d;
struct TopConf *tc;
RB_DLINK_FOREACH(d, conf_items.head)
{
tc = d->data;
if(rb_strcasecmp(tc->tc_name, name) == 0)
return tc;
}
return NULL;
}
struct ConfEntry *
find_conf_item(const struct TopConf *top, const char *name)
{
struct ConfEntry *cf;
rb_dlink_node *d;
if(top->tc_entries)
{
int i;
for(i = 0; top->tc_entries[i].cf_type; i++)
{
cf = &top->tc_entries[i];
if(!rb_strcasecmp(cf->cf_name, name))
return cf;
}
}
RB_DLINK_FOREACH(d, top->tc_items.head)
{
cf = d->data;
if(rb_strcasecmp(cf->cf_name, name) == 0)
return cf;
}
return NULL;
}
int
remove_top_conf(char *name)
{
struct TopConf *tc;
rb_dlink_node *ptr;
if((tc = find_top_conf(name)) == NULL)
return -1;
if((ptr = rb_dlinkFind(tc, &conf_items)) == NULL)
return -1;
rb_dlinkDestroy(ptr, &conf_items);
rb_free(tc);
return 0;
}
static void
conf_set_serverinfo_name(void *data)
{
if(ServerInfo.name == NULL)
{
const char *s;
int dots = 0;
for(s = data; *s != '\0'; s++)
{
if(!IsServChar(*s))
{
conf_report_error("Ignoring serverinfo::name "
"-- bogus servername.");
return;
}
else if(*s == '.')
++dots;
}
if(!dots)
{
conf_report_error("Ignoring serverinfo::name -- must contain '.'");
return;
}
s = data;
if(IsDigit(*s))
{
conf_report_error("Ignoring serverinfo::name -- cannot begin with digit.");
return;
}
/* the ircd will exit() in main() if we dont set one */
if(strlen(s) <= HOSTLEN)
ServerInfo.name = rb_strdup((char *) data);
}
}
static void
conf_set_serverinfo_sid(void *data)
{
char *sid = data;
if(ServerInfo.sid[0] == '\0')
{
if(!IsDigit(sid[0]) || !IsIdChar(sid[1]) ||
!IsIdChar(sid[2]) || sid[3] != '\0')
{
conf_report_error("Ignoring serverinfo::sid "
"-- bogus sid.");
return;
}
rb_strlcpy(ServerInfo.sid, sid, sizeof(ServerInfo.sid));
}
}
static void
conf_set_serverinfo_network_name(void *data)
{
char *p;
if((p = strchr((char *) data, ' ')))
*p = '\0';
rb_free(ServerInfo.network_name);
ServerInfo.network_name = rb_strdup((char *) data);
}
static void
conf_set_serverinfo_vhost(void *data)
{
struct rb_sockaddr_storage addr;
if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET)
{
conf_report_error("Invalid IPv4 address for server vhost (%s)", (char *) data);
return;
}
ServerInfo.bind4 = addr;
}
static void
conf_set_serverinfo_vhost6(void *data)
{
struct rb_sockaddr_storage addr;
if(rb_inet_pton_sock(data, &addr) <= 0 || GET_SS_FAMILY(&addr) != AF_INET6)
{
conf_report_error("Invalid IPv6 address for server vhost (%s)", (char *) data);
return;
}
ServerInfo.bind6 = addr;
}
static void
conf_set_serverinfo_nicklen(void *data)
{
ConfigFileEntry.nicklen = (*(unsigned int *) data) + 1;
if (ConfigFileEntry.nicklen > NICKLEN)
{
conf_report_error("Warning -- ignoring serverinfo::nicklen -- provided nicklen (%u) is greater than allowed nicklen (%u)",
ConfigFileEntry.nicklen - 1, NICKLEN - 1);
ConfigFileEntry.nicklen = NICKLEN;
}
else if (ConfigFileEntry.nicklen < 9 + 1)
{
conf_report_error("Warning -- serverinfo::nicklen is too low (%u) -- forcing 9",
ConfigFileEntry.nicklen - 1);
ConfigFileEntry.nicklen = 9 + 1;
}
}
static void
conf_set_modules_module(void *data)
{
char *m_bn;
m_bn = rb_basename((char *) data);
if(findmodule_byname(m_bn) == NULL)
load_one_module((char *) data, MAPI_ORIGIN_EXTENSION, false);
rb_free(m_bn);
}
static void
conf_set_modules_path(void *data)
{
mod_add_path((char *) data);
}
struct mode_table
{
const char *name;
int mode;
};
/* *INDENT-OFF* */
static struct mode_table umode_table[] = {
{"deaf", UMODE_DEAF },
{"invisible", UMODE_INVISIBLE },
{"locops", UMODE_LOCOPS },
{"noforward", UMODE_NOFORWARD },
{"servnotice", UMODE_SERVNOTICE},
{"wallop", UMODE_WALLOP },
{"operwall", UMODE_OPERWALL },
{NULL, 0}
};
static struct mode_table oper_table[] = {
{"encrypted", OPER_ENCRYPTED },
{"need_ssl", OPER_NEEDSSL },
{NULL, 0}
};
static struct mode_table auth_table[] = {
{"encrypted", CONF_FLAGS_ENCRYPTED },
{"spoof_notice", CONF_FLAGS_SPOOF_NOTICE },
{"exceed_limit", CONF_FLAGS_NOLIMIT },
{"dnsbl_exempt", CONF_FLAGS_EXEMPTDNSBL },
{"proxy_exempt", CONF_FLAGS_EXEMPTPROXY },
{"kline_exempt", CONF_FLAGS_EXEMPTKLINE },
{"flood_exempt", CONF_FLAGS_EXEMPTFLOOD },
{"spambot_exempt", CONF_FLAGS_EXEMPTSPAMBOT },
{"shide_exempt", CONF_FLAGS_EXEMPTSHIDE },
{"jupe_exempt", CONF_FLAGS_EXEMPTJUPE },
{"resv_exempt", CONF_FLAGS_EXEMPTRESV },
{"no_tilde", CONF_FLAGS_NO_TILDE },
{"need_ident", CONF_FLAGS_NEED_IDENTD },
{"have_ident", CONF_FLAGS_NEED_IDENTD },
{"need_ssl", CONF_FLAGS_NEED_SSL },
{"need_sasl", CONF_FLAGS_NEED_SASL },
{"extend_chans", CONF_FLAGS_EXTEND_CHANS },
{"allow_sctp", CONF_FLAGS_ALLOW_SCTP },
{"kline_spoof_ip", CONF_FLAGS_KLINE_SPOOF },
{"spoof_ident", CONF_FLAGS_SPOOF_IDENT },
{NULL, 0}
};
static struct mode_table connect_table[] = {
{ "autoconn", SERVER_AUTOCONN },
{ "compressed", 0 },
{ "encrypted", SERVER_ENCRYPTED },
{ "topicburst", SERVER_TB },
{ "sctp", SERVER_SCTP },
{ "ssl", SERVER_SSL },
{ "no-export", SERVER_NO_EXPORT },
{ NULL, 0 },
};
static struct mode_table cluster_table[] = {
{ "kline", SHARED_PKLINE },
{ "tkline", SHARED_TKLINE },
{ "unkline", SHARED_UNKLINE },
{ "locops", SHARED_LOCOPS },
{ "xline", SHARED_PXLINE },
{ "txline", SHARED_TXLINE },
{ "unxline", SHARED_UNXLINE },
{ "resv", SHARED_PRESV },
{ "tresv", SHARED_TRESV },
{ "unresv", SHARED_UNRESV },
{ "all", CLUSTER_ALL },
{NULL, 0}
};
/* *INDENT-ON* */
static int
find_umode(struct mode_table *tab, const char *name)
{
int i;
for (i = 0; tab[i].name; i++)
{
if(strcmp(tab[i].name, name) == 0)
return tab[i].mode;
}
return -1;
}
static void
set_modes_from_table(int *modes, const char *whatis, struct mode_table *tab, conf_parm_t * args)
{
for (; args; args = args->next)
{
const char *umode;
int dir = 1;
int mode;
if(CF_TYPE(args->type) != CF_STRING)
{
conf_report_error("Warning -- %s is not a string; ignoring.", whatis);
continue;
}
umode = args->v.string;
if(*umode == '~')
{
dir = 0;
umode++;
}
mode = find_umode(tab, umode);
if(mode == -1)
{
conf_report_error("Warning -- unknown %s %s.", whatis, args->v.string);
continue;
}
if(mode)
{
if(dir)
*modes |= mode;
else
*modes &= ~mode;
}
else
*modes = 0;
}
}
static void
parse_umodes(const char *pm, int *values, int *mask)
{
int what = MODE_ADD, flag;
*values = 0;
if (NULL != mask)
*mask = 0;
for (; *pm; pm++)
{
switch (*pm)
{
case '+':
what = MODE_ADD;
break;
case '-':
what = MODE_DEL;
break;
/* don't allow +o */
case 'o':
case 'S':
case 'Z':
case ' ':
break;
default:
flag = user_modes[(unsigned char) *pm];
if (flag)
{
/* Proper value has probably not yet been set
* so don't check oper_only_umodes -- jilles */
if (what == MODE_ADD)
*values |= flag;
else
*values &= ~flag;
if (NULL != mask)
*mask |= flag;
}
break;
}
}
}
static void
conf_set_privset_extends(void *data)
{
yy_privset_extends = rb_strdup((char *) data);
}
static void
conf_set_privset_privs(void *data)
{
char *privs = NULL;
conf_parm_t *args = data;
for (; args; args = args->next)
{
if (privs == NULL)
privs = rb_strdup(args->v.string);
else
{
char *privs_old = privs;
privs = rb_malloc(strlen(privs_old) + 1 + strlen(args->v.string) + 1);
strcpy(privs, privs_old);
strcat(privs, " ");
strcat(privs, args->v.string);
rb_free(privs_old);
}
}
if (privs)
{
if (yy_privset_extends)
{
struct PrivilegeSet *set = privilegeset_get(yy_privset_extends);
if (!set)
{
conf_report_error("Warning -- unknown parent privilege set %s for %s; assuming defaults", yy_privset_extends, conf_cur_block_name);
set = privilegeset_get("default");
}
privilegeset_extend(set, conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
rb_free(yy_privset_extends);
yy_privset_extends = NULL;
}
else
privilegeset_set_new(conf_cur_block_name != NULL ? conf_cur_block_name : "<unknown>", privs, 0);
rb_free(privs);
}
}
static int
conf_begin_oper(struct TopConf *tc)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
if(yy_oper != NULL)
{
free_oper_conf(yy_oper);
yy_oper = NULL;
}
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
{
free_oper_conf(ptr->data);
rb_dlinkDestroy(ptr, &yy_oper_list);
}
yy_oper = make_oper_conf();
yy_oper->flags |= OPER_ENCRYPTED;
return 0;
}
static int
conf_end_oper(struct TopConf *tc)
{
struct oper_conf *yy_tmpoper;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
if(conf_cur_block_name != NULL)
{
if(strlen(conf_cur_block_name) > OPERNICKLEN)
conf_cur_block_name[OPERNICKLEN] = '\0';
yy_oper->name = rb_strdup(conf_cur_block_name);
}
if(EmptyString(yy_oper->name))
{
conf_report_error("Ignoring operator block -- missing name.");
return 0;
}
#ifdef HAVE_LIBCRYPTO
if(EmptyString(yy_oper->passwd) && EmptyString(yy_oper->rsa_pubkey_file))
#else
if(EmptyString(yy_oper->passwd))
#endif
{
conf_report_error("Ignoring operator block for %s -- missing password",
yy_oper->name);
return 0;
}
if (!yy_oper->privset)
yy_oper->privset = privilegeset_get("default");
/* now, yy_oper_list contains a stack of oper_conf's with just user
* and host in, yy_oper contains the rest of the information which
* we need to copy into each element in yy_oper_list
*/
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_oper_list.head)
{
yy_tmpoper = ptr->data;
yy_tmpoper->name = rb_strdup(yy_oper->name);
/* could be an rsa key instead.. */
if(!EmptyString(yy_oper->passwd))
yy_tmpoper->passwd = rb_strdup(yy_oper->passwd);
yy_tmpoper->flags = yy_oper->flags;
yy_tmpoper->umodes = yy_oper->umodes;
yy_tmpoper->snomask = yy_oper->snomask;
yy_tmpoper->privset = yy_oper->privset;
#ifdef HAVE_LIBCRYPTO
if(yy_oper->rsa_pubkey_file)
{
BIO *file;
if((file = BIO_new_file(yy_oper->rsa_pubkey_file, "r")) == NULL)
{
conf_report_error("Ignoring operator block for %s -- "
"rsa_public_key_file cant be opened",
yy_tmpoper->name);
return 0;
}
yy_tmpoper->rsa_pubkey =
(RSA *) PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL);
(void)BIO_set_close(file, BIO_CLOSE);
BIO_free(file);
if(yy_tmpoper->rsa_pubkey == NULL)
{
conf_report_error("Ignoring operator block for %s -- "
"rsa_public_key_file key invalid; check syntax",
yy_tmpoper->name);
return 0;
}
}
if(!EmptyString(yy_oper->certfp))
yy_tmpoper->certfp = rb_strdup(yy_oper->certfp);
#endif
/* all is ok, put it on oper_conf_list */
rb_dlinkMoveNode(ptr, &yy_oper_list, &oper_conf_list);
}
free_oper_conf(yy_oper);
yy_oper = NULL;
return 0;
}
static void
conf_set_oper_flags(void *data)
{
conf_parm_t *args = data;
set_modes_from_table(&yy_oper->flags, "flag", oper_table, args);
}
static void
conf_set_oper_fingerprint(void *data)
{
if (yy_oper->certfp)
rb_free(yy_oper->certfp);
yy_oper->certfp = rb_strdup((char *) data);
}
static void
conf_set_oper_privset(void *data)
{
yy_oper->privset = privilegeset_get((char *) data);
}
static void
conf_set_oper_user(void *data)
{
struct oper_conf *yy_tmpoper;
char *p;
char *host = (char *) data;
yy_tmpoper = make_oper_conf();
if((p = strchr(host, '@')))
{
*p++ = '\0';
yy_tmpoper->username = rb_strdup(host);
yy_tmpoper->host = rb_strdup(p);
}
else
{
yy_tmpoper->username = rb_strdup("*");
yy_tmpoper->host = rb_strdup(host);
}
if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host))
{
conf_report_error("Ignoring user -- missing username/host");
free_oper_conf(yy_tmpoper);
return;
}
rb_dlinkAddAlloc(yy_tmpoper, &yy_oper_list);
}
static void
conf_set_oper_password(void *data)
{
if(yy_oper->passwd)
{
memset(yy_oper->passwd, 0, strlen(yy_oper->passwd));
rb_free(yy_oper->passwd);
}
yy_oper->passwd = rb_strdup((char *) data);
}
static void
conf_set_oper_rsa_public_key_file(void *data)
{
#ifdef HAVE_LIBCRYPTO
rb_free(yy_oper->rsa_pubkey_file);
yy_oper->rsa_pubkey_file = rb_strdup((char *) data);
#else
conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available");
#endif
}
static void
conf_set_oper_umodes(void *data)
{
set_modes_from_table(&yy_oper->umodes, "umode", umode_table, data);
}
static void
conf_set_oper_snomask(void *data)
{
yy_oper->snomask = parse_snobuf_to_mask(0, (const char *) data);
}
static int
conf_begin_class(struct TopConf *tc)
{
if(yy_class)
free_class(yy_class);
yy_class = make_class();
return 0;
}
static int
conf_end_class(struct TopConf *tc)
{
if(conf_cur_block_name != NULL)
yy_class->class_name = rb_strdup(conf_cur_block_name);
if(EmptyString(yy_class->class_name))
{
conf_report_error("Ignoring class block -- missing name.");
return 0;
}
add_class(yy_class);
yy_class = NULL;
return 0;
}
static void
conf_set_class_ping_time(void *data)
{
yy_class->ping_freq = *(unsigned int *) data;
}
static void
conf_set_class_cidr_ipv4_bitlen(void *data)
{
unsigned int maxsize = 32;
if(*(unsigned int *) data > maxsize)
conf_report_error
("class::cidr_ipv4_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
*(unsigned int *) data, maxsize);
else
yy_class->cidr_ipv4_bitlen = *(unsigned int *) data;
}
static void
conf_set_class_cidr_ipv6_bitlen(void *data)
{
unsigned int maxsize = 128;
if(*(unsigned int *) data > maxsize)
conf_report_error
("class::cidr_ipv6_bitlen argument exceeds maxsize (%d > %d) - ignoring.",
*(unsigned int *) data, maxsize);
else
yy_class->cidr_ipv6_bitlen = *(unsigned int *) data;
}
static void
conf_set_class_number_per_cidr(void *data)
{
yy_class->cidr_amount = *(unsigned int *) data;
}
static void
conf_set_class_number_per_ip(void *data)
{
yy_class->max_local = *(unsigned int *) data;
}
static void
conf_set_class_number_per_ip_global(void *data)
{
yy_class->max_global = *(unsigned int *) data;
}
static void
conf_set_class_number_per_ident(void *data)
{
yy_class->max_ident = *(unsigned int *) data;
}
static void
conf_set_class_connectfreq(void *data)
{
yy_class->con_freq = *(unsigned int *) data;
}
static void
conf_set_class_max_number(void *data)
{
yy_class->max_total = *(unsigned int *) data;
}
static void
conf_set_class_max_autoconn(void *data)
{
yy_class->max_autoconn = *(unsigned int *) data;
}
static void
conf_set_class_sendq(void *data)
{
yy_class->max_sendq = *(unsigned int *) data;
}
static char *listener_address[2];
static int
conf_begin_listen(struct TopConf *tc)
{
for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
rb_free(listener_address[i]);
listener_address[i] = NULL;
}
yy_wsock = 0;
yy_defer_accept = 0;
return 0;
}
static int
conf_end_listen(struct TopConf *tc)
{
for (int i = 0; i < ARRAY_SIZE(listener_address); i++) {
rb_free(listener_address[i]);
listener_address[i] = NULL;
}
yy_wsock = 0;
yy_defer_accept = 0;
return 0;
}
static void
conf_set_listen_defer_accept(void *data)
{
yy_defer_accept = *(unsigned int *) data;
}
static void
conf_set_listen_wsock(void *data)
{
yy_wsock = *(unsigned int *) data;
}
static void
conf_set_listen_port_both(void *data, int ssl, int sctp)
{
conf_parm_t *args = data;
for (; args; args = args->next)
{
if(CF_TYPE(args->type) != CF_INT)
{
conf_report_error("listener::port argument is not an integer -- ignoring.");
continue;
}
if(listener_address[0] == NULL)
{
if (sctp) {
conf_report_error("listener::sctp_port has no addresses -- ignoring.");
} else {
add_tcp_listener(args->v.number, NULL, AF_INET, ssl, ssl || yy_defer_accept, yy_wsock);
add_tcp_listener(args->v.number, NULL, AF_INET6, ssl, ssl || yy_defer_accept, yy_wsock);
}
}
else
{
int family;
if(strchr(listener_address[0], ':') != NULL)
family = AF_INET6;
else
family = AF_INET;
if (sctp) {
#ifdef HAVE_LIBSCTP
add_sctp_listener(args->v.number, listener_address[0], listener_address[1], ssl, yy_wsock);
#else
conf_report_error("Warning -- ignoring listener::sctp_port -- SCTP support not available.");
#endif
} else {
add_tcp_listener(args->v.number, listener_address[0], family, ssl, ssl || yy_defer_accept, yy_wsock);
}
}
}
}
static void
conf_set_listen_port(void *data)
{
conf_set_listen_port_both(data, 0, 0);
}
static void
conf_set_listen_sslport(void *data)
{
conf_set_listen_port_both(data, 1, 0 );
}
static void
conf_set_listen_sctp_port(void *data)
{
conf_set_listen_port_both(data, 0, 1);
}
static void
conf_set_listen_sctp_sslport(void *data)
{
conf_set_listen_port_both(data, 1, 1);
}
static void
conf_set_listen_address(void *data)
{
rb_free(listener_address[1]);
listener_address[1] = listener_address[0];
listener_address[0] = rb_strdup(data);
}
static int
conf_begin_auth(struct TopConf *tc)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
if(yy_aconf)
free_conf(yy_aconf);
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, yy_aconf_list.head)
{
free_conf(ptr->data);
rb_dlinkDestroy(ptr, &yy_aconf_list);
}
yy_aconf = make_conf();
yy_aconf->status = CONF_CLIENT;
return 0;
}
static int
conf_end_auth(struct TopConf *tc)
{
struct ConfItem *yy_tmp, *found_conf;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;