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