]> jfr.im git - solanum.git/blob - ircd/s_conf.c
ircd/authproc.c: avoid crash on lack of any configured DNSBLs
[solanum.git] / ircd / s_conf.c
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_conf.c: Configuration file functions.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25 #include "stdinc.h"
26 #include "ircd_defs.h"
27 #include "s_conf.h"
28 #include "s_user.h"
29 #include "s_newconf.h"
30 #include "newconf.h"
31 #include "s_serv.h"
32 #include "s_stats.h"
33 #include "channel.h"
34 #include "class.h"
35 #include "client.h"
36 #include "hash.h"
37 #include "match.h"
38 #include "ircd.h"
39 #include "listener.h"
40 #include "hostmask.h"
41 #include "modules.h"
42 #include "numeric.h"
43 #include "logger.h"
44 #include "send.h"
45 #include "reject.h"
46 #include "cache.h"
47 #include "privilege.h"
48 #include "sslproc.h"
49 #include "wsproc.h"
50 #include "bandbi.h"
51 #include "operhash.h"
52 #include "chmode.h"
53 #include "hook.h"
54 #include "s_assert.h"
55 #include "authproc.h"
56 #include "supported.h"
57
58 struct config_server_hide ConfigServerHide;
59
60 extern int yyparse(void); /* defined in y.tab.c */
61 extern char yy_linebuf[16384]; /* defined in ircd_lexer.l */
62
63 static rb_bh *confitem_heap = NULL;
64
65 rb_dlink_list temp_klines[LAST_TEMP_TYPE];
66 rb_dlink_list temp_dlines[LAST_TEMP_TYPE];
67 rb_dlink_list service_list;
68
69 rb_dictionary *prop_bans_dict;
70
71 /* internally defined functions */
72 static void set_default_conf(void);
73 static void validate_conf(void);
74 static void read_conf(void);
75 static void clear_out_old_conf(void);
76
77 static void expire_prop_bans(void *);
78 static void expire_temp_kd(void *list);
79 static void reorganise_temp_kd(void *list);
80
81 static int cmp_prop_ban(const void *, const void *);
82
83 FILE *conf_fbfile_in;
84 extern char yytext[];
85
86 static int verify_access(struct Client *client_p, const char *username);
87 static struct ConfItem *find_address_conf_by_client(struct Client *client_p, const char *username);
88 static int attach_iline(struct Client *, struct ConfItem *);
89
90 void
91 init_s_conf(void)
92 {
93 confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap");
94 prop_bans_dict = rb_dictionary_create("prop_bans", cmp_prop_ban);
95
96 rb_event_addish("expire_prop_bans", expire_prop_bans, NULL, 60);
97
98 rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60);
99 rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60);
100
101 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd,
102 &temp_klines[TEMP_HOUR], 3600);
103 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd,
104 &temp_dlines[TEMP_HOUR], 3600);
105 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd,
106 &temp_klines[TEMP_DAY], 86400);
107 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd,
108 &temp_dlines[TEMP_DAY], 86400);
109 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd,
110 &temp_klines[TEMP_WEEK], 604800);
111 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd,
112 &temp_dlines[TEMP_WEEK], 604800);
113 }
114
115 /*
116 * make_conf
117 *
118 * inputs - none
119 * output - pointer to new conf entry
120 * side effects - none
121 */
122 struct ConfItem *
123 make_conf()
124 {
125 struct ConfItem *aconf;
126
127 aconf = rb_bh_alloc(confitem_heap);
128 aconf->status = CONF_ILLEGAL;
129 return (aconf);
130 }
131
132 /*
133 * free_conf
134 *
135 * inputs - pointer to conf to free
136 * output - none
137 * side effects - crucial password fields are zeroed, conf is freed
138 */
139 void
140 free_conf(struct ConfItem *aconf)
141 {
142 s_assert(aconf != NULL);
143 if(aconf == NULL)
144 return;
145
146 /* security.. */
147 if(aconf->passwd)
148 memset(aconf->passwd, 0, strlen(aconf->passwd));
149 if(aconf->spasswd)
150 memset(aconf->spasswd, 0, strlen(aconf->spasswd));
151
152 rb_free(aconf->passwd);
153 rb_free(aconf->spasswd);
154 rb_free(aconf->className);
155 rb_free(aconf->user);
156 rb_free(aconf->host);
157 rb_free(aconf->desc);
158
159 if(IsConfBan(aconf))
160 operhash_delete(aconf->info.oper);
161 else
162 rb_free(aconf->info.name);
163
164 rb_bh_free(confitem_heap, aconf);
165 }
166
167 /*
168 * check_client
169 *
170 * inputs - pointer to client
171 * output - 0 = Success
172 * NOT_AUTHORISED (-1) = Access denied (no I line match)
173 * I_SOCKET_ERROR (-2) = Bad socket.
174 * I_LINE_FULL (-3) = I-line is full
175 * TOO_MANY (-4) = Too many connections from hostname
176 * BANNED_CLIENT (-5) = K-lined
177 * side effects - Ordinary client access check.
178 * Look for conf lines which have the same
179 * status as the flags passed.
180 */
181 int
182 check_client(struct Client *client_p, struct Client *source_p, const char *username)
183 {
184 int i;
185
186 if((i = verify_access(source_p, username)))
187 {
188 ilog(L_FUSER, "Access denied: %s[%s]",
189 source_p->name, source_p->sockhost);
190 }
191
192 switch (i)
193 {
194 case I_SOCKET_ERROR:
195 exit_client(client_p, source_p, &me, "Socket Error");
196 break;
197
198 case TOO_MANY_LOCAL:
199 /* Note that these notices are sent to opers on other
200 * servers also, so even if local opers are allowed to
201 * see the IP, we still cannot send it.
202 */
203 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
204 "Too many local connections for %s[%s%s@%s] [%s]",
205 source_p->name, IsGotId(source_p) ? "" : "~",
206 source_p->username, source_p->host,
207 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "0");
208
209 ilog(L_FUSER, "Too many local connections from %s!%s%s@%s",
210 source_p->name, IsGotId(source_p) ? "" : "~",
211 source_p->username, source_p->sockhost);
212
213 ServerStats.is_ref++;
214 exit_client(client_p, source_p, &me, "Too many host connections (local)");
215 break;
216
217 case TOO_MANY_GLOBAL:
218 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
219 "Too many global connections for %s[%s%s@%s] [%s]",
220 source_p->name, IsGotId(source_p) ? "" : "~",
221 source_p->username, source_p->host,
222 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "0");
223 ilog(L_FUSER, "Too many global connections from %s!%s%s@%s",
224 source_p->name, IsGotId(source_p) ? "" : "~",
225 source_p->username, source_p->sockhost);
226
227 ServerStats.is_ref++;
228 exit_client(client_p, source_p, &me, "Too many host connections (global)");
229 break;
230
231 case TOO_MANY_IDENT:
232 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
233 "Too many user connections for %s[%s%s@%s] [%s]",
234 source_p->name, IsGotId(source_p) ? "" : "~",
235 source_p->username, source_p->host,
236 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "0");
237 ilog(L_FUSER, "Too many user connections from %s!%s%s@%s",
238 source_p->name, IsGotId(source_p) ? "" : "~",
239 source_p->username, source_p->sockhost);
240
241 ServerStats.is_ref++;
242 exit_client(client_p, source_p, &me, "Too many user connections (global)");
243 break;
244
245 case I_LINE_FULL:
246 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
247 "I-line is full for %s[%s%s@%s] [%s]",
248 source_p->name, IsGotId(source_p) ? "" : "~",
249 source_p->username, source_p->host,
250 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "0");
251
252 ilog(L_FUSER, "Too many connections from %s!%s%s@%s.",
253 source_p->name, IsGotId(source_p) ? "" : "~",
254 source_p->username, source_p->sockhost);
255
256 ServerStats.is_ref++;
257 exit_client(client_p, source_p, &me,
258 "No more connections allowed in your connection class");
259 break;
260
261 case NOT_AUTHORISED:
262 {
263 int port = -1;
264 port = ntohs(GET_SS_PORT(&source_p->localClient->listener->addr[0]));
265
266 ServerStats.is_ref++;
267 /* jdc - lists server name & port connections are on */
268 /* a purely cosmetical change */
269 /* why ipaddr, and not just source_p->sockhost? --fl */
270 #if 0
271 static char ipaddr[HOSTIPLEN];
272 rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
273 #endif
274 sendto_realops_snomask(SNO_UNAUTH, L_NETWIDE,
275 "Unauthorised client connection from "
276 "%s!%s%s@%s [%s] on [%s/%u].",
277 source_p->name, IsGotId(source_p) ? "" : "~",
278 source_p->username, source_p->host,
279 source_p->sockhost,
280 source_p->localClient->listener->name, port);
281
282 ilog(L_FUSER,
283 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
284 source_p->name, IsGotId(source_p) ? "" : "~",
285 source_p->username, source_p->sockhost,
286 source_p->localClient->listener->name, port);
287 add_reject(client_p, NULL, NULL, NULL, "You are not authorised to use this server.");
288 exit_client(client_p, source_p, &me, "You are not authorised to use this server.");
289 break;
290 }
291 case BANNED_CLIENT:
292 exit_client(client_p, client_p, &me, "*** Banned ");
293 ServerStats.is_ref++;
294 break;
295
296 case 0:
297 default:
298 break;
299 }
300 return (i);
301 }
302
303 /*
304 * verify_access
305 *
306 * inputs - pointer to client to verify
307 * - pointer to proposed username
308 * output - 0 if success -'ve if not
309 * side effect - find the first (best) I line to attach.
310 */
311 static int
312 verify_access(struct Client *client_p, const char *username)
313 {
314 struct ConfItem *aconf;
315
316 aconf = find_address_conf_by_client(client_p, username);
317 if(aconf == NULL)
318 return NOT_AUTHORISED;
319
320 if(aconf->status & CONF_CLIENT)
321 {
322 if(aconf->flags & CONF_FLAGS_REDIR)
323 {
324 sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR),
325 aconf->info.name ? aconf->info.name : "", aconf->port);
326 return (NOT_AUTHORISED);
327 }
328
329 /* Thanks for spoof idea amm */
330 if(IsConfDoSpoofIp(aconf))
331 {
332 char *p;
333
334 /* show_ip() depends on this --fl */
335 SetIPSpoof(client_p);
336
337 if(IsConfSpoofNotice(aconf))
338 {
339 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
340 "%s spoofing: %s as %s",
341 client_p->name,
342 show_ip(NULL, client_p) ? client_p->host : aconf->info.name,
343 aconf->info.name);
344 }
345
346 /* user@host spoof */
347 if((p = strchr(aconf->info.name, '@')) != NULL)
348 {
349 char *host = p+1;
350 *p = '\0';
351
352 rb_strlcpy(client_p->username, aconf->info.name,
353 sizeof(client_p->username));
354 rb_strlcpy(client_p->host, host,
355 sizeof(client_p->host));
356 *p = '@';
357 }
358 else
359 rb_strlcpy(client_p->host, aconf->info.name, sizeof(client_p->host));
360 }
361 return (attach_iline(client_p, aconf));
362 }
363 else if(aconf->status & CONF_KILL)
364 {
365 if(ConfigFileEntry.kline_with_reason)
366 sendto_one(client_p,
367 form_str(ERR_YOUREBANNEDCREEP),
368 me.name, client_p->name,
369 get_user_ban_reason(aconf));
370
371 sendto_realops_snomask(SNO_BANNED, L_NETWIDE,
372 "Rejecting K-Lined user %s [%s] (%s@%s)", get_client_name(client_p, HIDE_IP),
373 show_ip(NULL, client_p) ? client_p->sockhost : "255.255.255.255", aconf->user, aconf->host);
374 add_reject(client_p, aconf->user, aconf->host, aconf, NULL);
375 return (BANNED_CLIENT);
376 }
377
378 return NOT_AUTHORISED;
379 }
380
381
382 /*
383 * find_address_conf_by_client
384 */
385 static struct ConfItem *
386 find_address_conf_by_client(struct Client *client_p, const char *username)
387 {
388 struct ConfItem *aconf;
389 char non_ident[USERLEN + 1];
390
391 if(IsGotId(client_p))
392 {
393 aconf = find_address_conf(client_p->host, client_p->sockhost,
394 client_p->username, client_p->username,
395 (struct sockaddr *) &client_p->localClient->ip,
396 GET_SS_FAMILY(&client_p->localClient->ip),
397 client_p->localClient->auth_user);
398 }
399 else
400 {
401 rb_strlcpy(non_ident, "~", sizeof(non_ident));
402 rb_strlcat(non_ident, username, sizeof(non_ident));
403 aconf = find_address_conf(client_p->host, client_p->sockhost,
404 non_ident, client_p->username,
405 (struct sockaddr *) &client_p->localClient->ip,
406 GET_SS_FAMILY(&client_p->localClient->ip),
407 client_p->localClient->auth_user);
408 }
409 return aconf;
410 }
411
412
413 /*
414 * add_ip_limit
415 *
416 * Returns 1 if successful 0 if not
417 *
418 * This checks if the user has exceed the limits for their class
419 * unless of course they are exempt..
420 */
421
422 static int
423 add_ip_limit(struct Client *client_p, struct ConfItem *aconf)
424 {
425 rb_patricia_node_t *pnode;
426 int bitlen;
427
428 /* If the limits are 0 don't do anything.. */
429 if(ConfCidrAmount(aconf) == 0
430 || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0))
431 return -1;
432
433 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
434
435 if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET)
436 bitlen = ConfCidrIpv4Bitlen(aconf);
437 else
438 bitlen = ConfCidrIpv6Bitlen(aconf);
439
440 if(pnode == NULL)
441 pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen);
442
443 s_assert(pnode != NULL);
444
445 if(pnode != NULL)
446 {
447 if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf))
448 {
449 /* This should only happen if the limits are set to 0 */
450 if((intptr_t)pnode->data == 0)
451 {
452 rb_patricia_remove(ConfIpLimits(aconf), pnode);
453 }
454 return (0);
455 }
456
457 pnode->data = (void *)(((intptr_t)pnode->data) + 1);
458 }
459 return 1;
460 }
461
462 static void
463 remove_ip_limit(struct Client *client_p, struct ConfItem *aconf)
464 {
465 rb_patricia_node_t *pnode;
466
467 /* If the limits are 0 don't do anything.. */
468 if(ConfCidrAmount(aconf) == 0
469 || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0))
470 return;
471
472 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
473 if(pnode == NULL)
474 return;
475
476 pnode->data = (void *)(((intptr_t)pnode->data) - 1);
477 if(((intptr_t)pnode->data) == 0)
478 {
479 rb_patricia_remove(ConfIpLimits(aconf), pnode);
480 }
481
482 }
483
484 /*
485 * attach_iline
486 *
487 * inputs - client pointer
488 * - conf pointer
489 * output -
490 * side effects - do actual attach
491 */
492 static int
493 attach_iline(struct Client *client_p, struct ConfItem *aconf)
494 {
495 struct Client *target_p;
496 rb_dlink_node *ptr;
497 int local_count = 0;
498 int global_count = 0;
499 int ident_count = 0;
500 int unidented;
501
502 if(IsConfExemptLimits(aconf))
503 return (attach_conf(client_p, aconf));
504
505 unidented = !IsGotId(client_p) && !IsNoTilde(aconf) &&
506 (!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@'));
507
508 /* find_hostname() returns the head of the list to search */
509 RB_DLINK_FOREACH(ptr, find_hostname(client_p->host))
510 {
511 target_p = ptr->data;
512
513 if(irccmp(client_p->host, target_p->orighost) != 0)
514 continue;
515
516 if(MyConnect(target_p))
517 local_count++;
518
519 global_count++;
520
521 if(unidented)
522 {
523 if(*target_p->username == '~')
524 ident_count++;
525 }
526 else if(irccmp(target_p->username, client_p->username) == 0)
527 ident_count++;
528
529 if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf))
530 return (TOO_MANY_LOCAL);
531 else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf))
532 return (TOO_MANY_GLOBAL);
533 else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf))
534 return (TOO_MANY_IDENT);
535 }
536
537
538 return (attach_conf(client_p, aconf));
539 }
540
541 /*
542 * deref_conf
543 *
544 * inputs - ConfItem that is referenced by something other than a client
545 * side effects - Decrement and free ConfItem if appropriate
546 */
547 void
548 deref_conf(struct ConfItem *aconf)
549 {
550 aconf->clients--;
551 if(!aconf->clients && IsIllegal(aconf) && !lookup_prop_ban(aconf))
552 free_conf(aconf);
553 }
554
555 /*
556 * detach_conf
557 *
558 * inputs - pointer to client to detach
559 * output - 0 for success, -1 for failure
560 * side effects - Disassociate configuration from the client.
561 * Also removes a class from the list if marked for deleting.
562 */
563 int
564 detach_conf(struct Client *client_p)
565 {
566 struct ConfItem *aconf;
567
568 aconf = client_p->localClient->att_conf;
569
570 if(aconf != NULL)
571 {
572 if(ClassPtr(aconf))
573 {
574 remove_ip_limit(client_p, aconf);
575
576 if(ConfCurrUsers(aconf) > 0)
577 --ConfCurrUsers(aconf);
578
579 if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0)
580 {
581 free_class(ClassPtr(aconf));
582 ClassPtr(aconf) = NULL;
583 }
584
585 }
586
587 aconf->clients--;
588 if(!aconf->clients && IsIllegal(aconf))
589 free_conf(aconf);
590
591 client_p->localClient->att_conf = NULL;
592 return 0;
593 }
594
595 return -1;
596 }
597
598 /*
599 * attach_conf
600 *
601 * inputs - client pointer
602 * - conf pointer
603 * output -
604 * side effects - Associate a specific configuration entry to a *local*
605 * client (this is the one which used in accepting the
606 * connection). Note, that this automatically changes the
607 * attachment if there was an old one...
608 */
609 int
610 attach_conf(struct Client *client_p, struct ConfItem *aconf)
611 {
612 if(IsIllegal(aconf))
613 return (NOT_AUTHORISED);
614
615 if(s_assert(ClassPtr(aconf)))
616 return (NOT_AUTHORISED);
617
618 if(!add_ip_limit(client_p, aconf))
619 return (TOO_MANY_LOCAL);
620
621 if((aconf->status & CONF_CLIENT) &&
622 ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0)
623 {
624 if(!IsConfExemptLimits(aconf))
625 {
626 return (I_LINE_FULL);
627 }
628 else
629 {
630 sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!");
631 }
632
633 }
634
635 if(client_p->localClient->att_conf != NULL)
636 detach_conf(client_p);
637
638 client_p->localClient->att_conf = aconf;
639
640 aconf->clients++;
641 ConfCurrUsers(aconf)++;
642 return (0);
643 }
644
645 /*
646 * rehash
647 *
648 * Actual REHASH service routine. Called with sig == 0 if it has been called
649 * as a result of an operator issuing this command, else assume it has been
650 * called as a result of the server receiving a HUP signal.
651 */
652 bool
653 rehash(bool sig)
654 {
655 rb_dlink_node *n;
656
657 hook_data_rehash hdata = { sig };
658
659 if(sig)
660 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
661 "Got signal SIGHUP, reloading ircd conf. file");
662
663 rehash_authd();
664
665 privilegeset_prepare_rehash();
666
667 /* don't close listeners until we know we can go ahead with the rehash */
668 read_conf_files(false);
669
670 if(ServerInfo.description != NULL)
671 rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
672 else
673 rb_strlcpy(me.info, "unknown", sizeof(me.info));
674
675 open_logfiles();
676
677 RB_DLINK_FOREACH(n, local_oper_list.head)
678 {
679 struct Client *oper = n->data;
680 struct PrivilegeSet *privset = oper->user->privset;
681 report_priv_change(oper, privset ? privset->shadow : NULL, privset);
682 }
683
684 privilegeset_cleanup_rehash();
685
686 call_hook(h_rehash, &hdata);
687 return false;
688 }
689
690 void
691 rehash_bans(void)
692 {
693 bandb_rehash_bans();
694 }
695
696 /*
697 * set_default_conf()
698 *
699 * inputs - NONE
700 * output - NONE
701 * side effects - Set default values here.
702 * This is called **PRIOR** to parsing the
703 * configuration file. If you want to do some validation
704 * of values later, put them in validate_conf().
705 */
706
707 static void
708 set_default_conf(void)
709 {
710 /* ServerInfo.name is not rehashable */
711 /* ServerInfo.name = ServerInfo.name; */
712 ServerInfo.description = NULL;
713 ServerInfo.network_name = NULL;
714
715 memset(&ServerInfo.bind4, 0, sizeof(ServerInfo.bind4));
716 SET_SS_FAMILY(&ServerInfo.bind4, AF_UNSPEC);
717 memset(&ServerInfo.bind6, 0, sizeof(ServerInfo.bind6));
718 SET_SS_FAMILY(&ServerInfo.bind6, AF_UNSPEC);
719
720 AdminInfo.name = NULL;
721 AdminInfo.email = NULL;
722 AdminInfo.description = NULL;
723
724 ConfigFileEntry.default_operstring = NULL;
725 ConfigFileEntry.default_adminstring = NULL;
726 ConfigFileEntry.servicestring = NULL;
727 ConfigFileEntry.sasl_service = NULL;
728
729 ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
730 ConfigFileEntry.failed_oper_notice = true;
731 ConfigFileEntry.anti_nick_flood = false;
732 ConfigFileEntry.disable_fake_channels = false;
733 ConfigFileEntry.max_nick_time = 20;
734 ConfigFileEntry.max_nick_changes = 5;
735 ConfigFileEntry.max_accept = 20;
736 ConfigFileEntry.max_monitor = 60;
737 ConfigFileEntry.nick_delay = 900; /* 15 minutes */
738 ConfigFileEntry.target_change = true;
739 ConfigFileEntry.anti_spam_exit_message_time = 0;
740 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
741 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
742 ConfigFileEntry.client_exit = true;
743 ConfigFileEntry.dline_with_reason = true;
744 ConfigFileEntry.kline_with_reason = true;
745 ConfigFileEntry.warn_no_nline = true;
746 ConfigFileEntry.non_redundant_klines = true;
747 ConfigFileEntry.stats_e_disabled = false;
748 ConfigFileEntry.stats_o_oper_only = false;
749 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
750 ConfigFileEntry.stats_l_oper_only = 1; /* self */
751 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
752 ConfigFileEntry.stats_P_oper_only = false;
753 ConfigFileEntry.stats_c_oper_only = false;
754 ConfigFileEntry.stats_y_oper_only = false;
755 ConfigFileEntry.map_oper_only = true;
756 ConfigFileEntry.operspy_admin_only = false;
757 ConfigFileEntry.pace_wait = 10;
758 ConfigFileEntry.caller_id_wait = 60;
759 ConfigFileEntry.pace_wait_simple = 1;
760 ConfigFileEntry.short_motd = false;
761 ConfigFileEntry.no_oper_flood = false;
762 ConfigFileEntry.fname_userlog = NULL;
763 ConfigFileEntry.fname_fuserlog = NULL;
764 ConfigFileEntry.fname_operlog = NULL;
765 ConfigFileEntry.fname_foperlog = NULL;
766 ConfigFileEntry.fname_serverlog = NULL;
767 ConfigFileEntry.fname_killlog = NULL;
768 ConfigFileEntry.fname_klinelog = NULL;
769 ConfigFileEntry.fname_operspylog = NULL;
770 ConfigFileEntry.fname_ioerrorlog = NULL;
771 ConfigFileEntry.hide_spoof_ips = true;
772 ConfigFileEntry.hide_error_messages = 1;
773 ConfigFileEntry.dots_in_ident = 0;
774 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
775 ConfigFileEntry.use_whois_actually = true;
776 ConfigFileEntry.burst_away = false;
777 ConfigFileEntry.collision_fnc = true;
778 ConfigFileEntry.resv_fnc = true;
779 ConfigFileEntry.global_snotices = true;
780 ConfigFileEntry.operspy_dont_care_user_info = false;
781 ConfigFileEntry.use_propagated_bans = true;
782 ConfigFileEntry.max_ratelimit_tokens = 30;
783 ConfigFileEntry.away_interval = 30;
784 ConfigFileEntry.tls_ciphers_oper_only = false;
785 ConfigFileEntry.oper_secure_only = false;
786
787 ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
788 UMODE_OPERWALL | UMODE_WALLOP;
789 ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
790 ConfigFileEntry.oper_snomask = SNO_GENERAL;
791
792 ConfigChannel.use_except = true;
793 ConfigChannel.use_invex = true;
794 ConfigChannel.use_forward = true;
795 ConfigChannel.use_knock = true;
796 ConfigChannel.knock_delay = 300;
797 ConfigChannel.knock_delay_channel = 60;
798 ConfigChannel.max_chans_per_user = 15;
799 ConfigChannel.max_chans_per_user_large = 60;
800 ConfigChannel.max_bans = 25;
801 ConfigChannel.max_bans_large = 500;
802 ConfigChannel.only_ascii_channels = false;
803 ConfigChannel.burst_topicwho = false;
804 ConfigChannel.kick_on_split_riding = false;
805
806 ConfigChannel.default_split_user_count = 15000;
807 ConfigChannel.default_split_server_count = 10;
808 ConfigChannel.no_join_on_split = false;
809 ConfigChannel.no_create_on_split = true;
810 ConfigChannel.resv_forcepart = true;
811 ConfigChannel.channel_target_change = true;
812 ConfigChannel.disable_local_channels = false;
813 ConfigChannel.displayed_usercount = 3;
814 ConfigChannel.opmod_send_statusmsg = false;
815 ConfigChannel.ip_bans_through_vhost= true;
816
817 ConfigChannel.autochanmodes = MODE_TOPICLIMIT | MODE_NOPRIVMSGS;
818
819 ConfigServerHide.flatten_links = 0;
820 ConfigServerHide.links_delay = 300;
821 ConfigServerHide.hidden = 0;
822 ConfigServerHide.disable_hidden = 0;
823
824 ConfigFileEntry.min_nonwildcard = 4;
825 ConfigFileEntry.min_nonwildcard_simple = 3;
826 ConfigFileEntry.default_floodcount = 8;
827 ConfigFileEntry.default_ident_timeout = IDENT_TIMEOUT_DEFAULT;
828 ConfigFileEntry.tkline_expire_notices = 0;
829
830 ConfigFileEntry.reject_after_count = 5;
831 ConfigFileEntry.reject_ban_time = 300;
832 ConfigFileEntry.reject_duration = 120;
833 ConfigFileEntry.throttle_count = 4;
834 ConfigFileEntry.throttle_duration = 60;
835
836 ConfigFileEntry.client_flood_max_lines = CLIENT_FLOOD_DEFAULT;
837 ConfigFileEntry.client_flood_burst_rate = 5;
838 ConfigFileEntry.client_flood_burst_max = 5;
839 ConfigFileEntry.client_flood_message_time = 1;
840 ConfigFileEntry.client_flood_message_num = 2;
841
842 ServerInfo.default_max_clients = MAXCONNECTIONS;
843
844 ConfigFileEntry.nicklen = NICKLEN;
845 ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
846 ConfigFileEntry.hide_opers_in_whois = 0;
847 ConfigFileEntry.hide_opers = 0;
848
849 if (!alias_dict)
850 alias_dict = rb_dictionary_create("alias", rb_strcasecmp);
851 }
852
853 /*
854 * read_conf()
855 *
856 *
857 * inputs - None
858 * output - None
859 * side effects - Read configuration file.
860 */
861 static void
862 read_conf(void)
863 {
864 lineno = 0;
865
866 set_default_conf(); /* Set default values prior to conf parsing */
867 yyparse(); /* Load the values from the conf */
868 validate_conf(); /* Check to make sure some values are still okay. */
869 /* Some global values are also loaded here. */
870 check_class(); /* Make sure classes are valid */
871 construct_cflags_strings();
872 }
873
874 static void
875 validate_conf(void)
876 {
877 if(ConfigFileEntry.default_ident_timeout < 1)
878 ConfigFileEntry.default_ident_timeout = IDENT_TIMEOUT_DEFAULT;
879
880 if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
881 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
882
883 if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
884 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
885
886 if(ServerInfo.network_name == NULL)
887 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
888
889 if(ServerInfo.ssld_count < 1)
890 ServerInfo.ssld_count = 1;
891
892 /* XXX: configurable? */
893 ServerInfo.wsockd_count = 1;
894
895 if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list))
896 {
897 ilog(L_MAIN, "WARNING: Unable to setup SSL.");
898 ircd_ssl_ok = false;
899 } else {
900 ircd_ssl_ok = true;
901 ssld_update_config();
902 }
903
904 if(ServerInfo.ssld_count > get_ssld_count())
905 {
906 int start = ServerInfo.ssld_count - get_ssld_count();
907 /* start up additional ssld if needed */
908 start_ssldaemon(start);
909 }
910
911 if(ServerInfo.wsockd_count > get_wsockd_count())
912 {
913 int start = ServerInfo.wsockd_count - get_wsockd_count();
914 start_wsockd(start);
915 }
916
917 /* General conf */
918 if (ConfigFileEntry.default_operstring == NULL)
919 ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator");
920
921 if (ConfigFileEntry.default_adminstring == NULL)
922 ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator");
923
924 if (ConfigFileEntry.servicestring == NULL)
925 ConfigFileEntry.servicestring = rb_strdup("is a Network Service");
926
927 if (ConfigFileEntry.sasl_service == NULL)
928 ConfigFileEntry.sasl_service = rb_strdup("SaslServ");
929
930 /* RFC 1459 says 1 message per 2 seconds on average and bursts of
931 * 5 messages are acceptable, so allow at least that.
932 */
933 if(ConfigFileEntry.client_flood_burst_rate < 5)
934 ConfigFileEntry.client_flood_burst_rate = 5;
935 if(ConfigFileEntry.client_flood_burst_max < 5)
936 ConfigFileEntry.client_flood_burst_max = 5;
937 if(ConfigFileEntry.client_flood_message_time >
938 ConfigFileEntry.client_flood_message_num * 2)
939 ConfigFileEntry.client_flood_message_time =
940 ConfigFileEntry.client_flood_message_num * 2;
941
942 if((ConfigFileEntry.client_flood_max_lines < CLIENT_FLOOD_MIN) ||
943 (ConfigFileEntry.client_flood_max_lines > CLIENT_FLOOD_MAX))
944 ConfigFileEntry.client_flood_max_lines = CLIENT_FLOOD_MAX;
945
946 if(!split_users || !split_servers ||
947 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
948 {
949 rb_event_delete(check_splitmode_ev);
950 check_splitmode_ev = NULL;
951 splitmode = 0;
952 splitchecking = 0;
953 }
954
955 CharAttrs['&'] |= CHANPFX_C;
956 if (ConfigChannel.disable_local_channels)
957 CharAttrs['&'] &= ~CHANPFX_C;
958
959 chantypes_update();
960 }
961
962 /* add_temp_kline()
963 *
964 * inputs - pointer to struct ConfItem
965 * output - none
966 * Side effects - links in given struct ConfItem into
967 * temporary kline link list
968 */
969 void
970 add_temp_kline(struct ConfItem *aconf)
971 {
972 if(aconf->hold >= rb_current_time() + (10080 * 60))
973 {
974 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
975 aconf->port = TEMP_WEEK;
976 }
977 else if(aconf->hold >= rb_current_time() + (1440 * 60))
978 {
979 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
980 aconf->port = TEMP_DAY;
981 }
982 else if(aconf->hold >= rb_current_time() + (60 * 60))
983 {
984 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
985 aconf->port = TEMP_HOUR;
986 }
987 else
988 {
989 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
990 aconf->port = TEMP_MIN;
991 }
992
993 aconf->flags |= CONF_FLAGS_TEMPORARY;
994 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
995 }
996
997 /* add_temp_dline()
998 *
999 * input - pointer to struct ConfItem
1000 * output - none
1001 * side effects - added to tdline link list and address hash
1002 */
1003 void
1004 add_temp_dline(struct ConfItem *aconf)
1005 {
1006 if(aconf->hold >= rb_current_time() + (10080 * 60))
1007 {
1008 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
1009 aconf->port = TEMP_WEEK;
1010 }
1011 else if(aconf->hold >= rb_current_time() + (1440 * 60))
1012 {
1013 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
1014 aconf->port = TEMP_DAY;
1015 }
1016 else if(aconf->hold >= rb_current_time() + (60 * 60))
1017 {
1018 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
1019 aconf->port = TEMP_HOUR;
1020 }
1021 else
1022 {
1023 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
1024 aconf->port = TEMP_MIN;
1025 }
1026
1027 aconf->flags |= CONF_FLAGS_TEMPORARY;
1028 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf);
1029 }
1030
1031 /* valid_wild_card()
1032 *
1033 * input - user buffer, host buffer
1034 * output - 0 if invalid, 1 if valid
1035 * side effects -
1036 */
1037 int
1038 valid_wild_card(const char *luser, const char *lhost)
1039 {
1040 const char *p;
1041 char tmpch;
1042 int nonwild = 0;
1043 int bitlen;
1044
1045 /* user has no wildcards, always accept -- jilles */
1046 if(!strchr(luser, '?') && !strchr(luser, '*'))
1047 return 1;
1048
1049 /* check there are enough non wildcard chars */
1050 p = luser;
1051 while((tmpch = *p++))
1052 {
1053 if(!IsKWildChar(tmpch))
1054 {
1055 /* found enough chars, return */
1056 if(++nonwild >= ConfigFileEntry.min_nonwildcard)
1057 return 1;
1058 }
1059 }
1060
1061 /* try host, as user didnt contain enough */
1062 /* special case for cidr masks -- jilles */
1063 if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1]))
1064 {
1065 bitlen = atoi(p + 1);
1066 /* much like non-cidr for ipv6, rather arbitrary for ipv4 */
1067 if(bitlen > 0
1068 && bitlen >=
1069 (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 -
1070 2 * nonwild))
1071 return 1;
1072 }
1073 else
1074 {
1075 p = lhost;
1076 while((tmpch = *p++))
1077 {
1078 if(!IsKWildChar(tmpch))
1079 if(++nonwild >= ConfigFileEntry.min_nonwildcard)
1080 return 1;
1081 }
1082 }
1083
1084 return 0;
1085 }
1086
1087
1088 int cmp_prop_ban(const void *a_, const void *b_)
1089 {
1090 const struct ConfItem *a = a_, *b = b_;
1091 int r;
1092
1093 if ((a->status & ~CONF_ILLEGAL) > (int)(b->status & ~CONF_ILLEGAL)) return 1;
1094 if ((a->status & ~CONF_ILLEGAL) < (int)(b->status & ~CONF_ILLEGAL)) return -1;
1095
1096 r = irccmp(a->host, b->host);
1097 if (r) return r;
1098
1099 if (a->user && b->user)
1100 return irccmp(a->user, b->user);
1101
1102 return 0;
1103 }
1104
1105 void
1106 add_prop_ban(struct ConfItem *aconf)
1107 {
1108 rb_dictionary_add(prop_bans_dict, aconf, aconf);
1109 }
1110
1111 struct ConfItem *
1112 find_prop_ban(unsigned status, const char *user, const char *host)
1113 {
1114 struct ConfItem key = {.status = status, .user = (char *)user, .host = (char *)host};
1115 return rb_dictionary_retrieve(prop_bans_dict, &key);
1116 }
1117
1118 void
1119 remove_prop_ban(struct ConfItem *aconf)
1120 {
1121 rb_dictionary_delete(prop_bans_dict, aconf);
1122 }
1123
1124 bool lookup_prop_ban(struct ConfItem *aconf)
1125 {
1126 return rb_dictionary_retrieve(prop_bans_dict, aconf) == aconf;
1127 }
1128
1129 void
1130 deactivate_conf(struct ConfItem *aconf, time_t now)
1131 {
1132 int i;
1133
1134 switch (aconf->status)
1135 {
1136 case CONF_KILL:
1137 if (aconf->lifetime == 0 &&
1138 aconf->flags & CONF_FLAGS_TEMPORARY)
1139 for (i = 0; i < LAST_TEMP_TYPE; i++)
1140 rb_dlinkFindDestroy(aconf, &temp_klines[i]);
1141 /* Make sure delete_one_address_conf() does not
1142 * free the aconf.
1143 */
1144 aconf->clients++;
1145 delete_one_address_conf(aconf->host, aconf);
1146 aconf->clients--;
1147 break;
1148 case CONF_DLINE:
1149 if (aconf->lifetime == 0 &&
1150 aconf->flags & CONF_FLAGS_TEMPORARY)
1151 for (i = 0; i < LAST_TEMP_TYPE; i++)
1152 rb_dlinkFindDestroy(aconf, &temp_dlines[i]);
1153 aconf->clients++;
1154 delete_one_address_conf(aconf->host, aconf);
1155 aconf->clients--;
1156 break;
1157 case CONF_XLINE:
1158 rb_dlinkFindDestroy(aconf, &xline_conf_list);
1159 break;
1160 case CONF_RESV_NICK:
1161 rb_dlinkFindDestroy(aconf, &resv_conf_list);
1162 break;
1163 case CONF_RESV_CHANNEL:
1164 del_from_resv_hash(aconf->host, aconf);
1165 break;
1166 }
1167 if (aconf->lifetime != 0 && now < aconf->lifetime)
1168 {
1169 aconf->status |= CONF_ILLEGAL;
1170 }
1171 else
1172 {
1173 if (aconf->lifetime != 0)
1174 remove_prop_ban(aconf);
1175 if (aconf->clients == 0)
1176 free_conf(aconf);
1177 else
1178 aconf->status |= CONF_ILLEGAL;
1179 }
1180 }
1181
1182 /* Given a new ban ConfItem, look for any matching ban, update the lifetime
1183 * from it and delete it.
1184 */
1185 void
1186 replace_old_ban(struct ConfItem *aconf)
1187 {
1188 struct ConfItem *oldconf;
1189
1190 oldconf = find_prop_ban(aconf->status, aconf->user, aconf->host);
1191 if (oldconf != NULL)
1192 {
1193 /* Remember at least as long as the old one. */
1194 if(oldconf->lifetime > aconf->lifetime)
1195 aconf->lifetime = oldconf->lifetime;
1196 /* Force creation time to increase. */
1197 if(oldconf->created >= aconf->created)
1198 aconf->created = oldconf->created + 1;
1199 /* Leave at least one second of validity. */
1200 if(aconf->hold <= aconf->created)
1201 aconf->hold = aconf->created + 1;
1202 if(aconf->lifetime < aconf->hold)
1203 aconf->lifetime = aconf->hold;
1204 /* Tell deactivate_conf() to destroy it. */
1205 oldconf->lifetime = rb_current_time();
1206 deactivate_conf(oldconf, oldconf->lifetime);
1207 }
1208 }
1209
1210 static void
1211 expire_prop_bans(void *unused)
1212 {
1213 struct ConfItem *aconf;
1214 time_t now;
1215 rb_dictionary_iter state;
1216
1217 now = rb_current_time();
1218
1219 RB_DICTIONARY_FOREACH(aconf, &state, prop_bans_dict)
1220 {
1221 if(aconf->lifetime <= now ||
1222 (aconf->hold <= now &&
1223 !(aconf->status & CONF_ILLEGAL)))
1224 {
1225 /* Alert opers that a TKline expired - Hwy */
1226 /* XXX show what type of ban it is */
1227 if(ConfigFileEntry.tkline_expire_notices &&
1228 !(aconf->status & CONF_ILLEGAL))
1229 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1230 "Propagated ban for [%s%s%s] expired",
1231 aconf->user ? aconf->user : "",
1232 aconf->user ? "@" : "",
1233 aconf->host ? aconf->host : "*");
1234
1235 /* will destroy or mark illegal */
1236 deactivate_conf(aconf, now);
1237 }
1238 }
1239 }
1240
1241 /* expire_tkline()
1242 *
1243 * inputs - list pointer
1244 * - type
1245 * output - NONE
1246 * side effects - expire tklines and moves them between lists
1247 */
1248 static void
1249 expire_temp_kd(void *list)
1250 {
1251 rb_dlink_node *ptr;
1252 rb_dlink_node *next_ptr;
1253 struct ConfItem *aconf;
1254
1255 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
1256 {
1257 aconf = ptr->data;
1258
1259 if(aconf->hold <= rb_current_time())
1260 {
1261 /* Alert opers that a TKline expired - Hwy */
1262 if(ConfigFileEntry.tkline_expire_notices)
1263 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1264 "Temporary K-line for [%s@%s] expired",
1265 (aconf->user) ? aconf->
1266 user : "*", (aconf->host) ? aconf->host : "*");
1267
1268 delete_one_address_conf(aconf->host, aconf);
1269 rb_dlinkDestroy(ptr, list);
1270 }
1271 }
1272 }
1273
1274 static void
1275 reorganise_temp_kd(void *list)
1276 {
1277 struct ConfItem *aconf;
1278 rb_dlink_node *ptr, *next_ptr;
1279
1280 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
1281 {
1282 aconf = ptr->data;
1283
1284 if(aconf->hold < (rb_current_time() + (60 * 60)))
1285 {
1286 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1287 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1288 aconf->port = TEMP_MIN;
1289 }
1290 else if(aconf->port > TEMP_HOUR)
1291 {
1292 if(aconf->hold < (rb_current_time() + (1440 * 60)))
1293 {
1294 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1295 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1296 aconf->port = TEMP_HOUR;
1297 }
1298 else if(aconf->port > TEMP_DAY &&
1299 (aconf->hold < (rb_current_time() + (10080 * 60))))
1300 {
1301 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1302 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1303 aconf->port = TEMP_DAY;
1304 }
1305 }
1306 }
1307 }
1308
1309
1310 /* const char* get_oper_name(struct Client *client_p)
1311 * Input: A client to find the active oper{} name for.
1312 * Output: The nick!user@host{oper} of the oper.
1313 * "oper" is server name for unknown opers
1314 * Side effects: None.
1315 */
1316 const char *
1317 get_oper_name(struct Client *client_p)
1318 {
1319 /* +5 for !,@,{,} and null */
1320 static char buffer[NAMELEN + USERLEN + HOSTLEN + MAX(HOSTLEN, OPERNICKLEN) + 5];
1321
1322 const char *opername = EmptyString(client_p->user->opername)
1323 ? client_p->servptr->name
1324 : client_p->user->opername;
1325
1326 snprintf(buffer, sizeof buffer, "%s!%s@%s{%s}",
1327 client_p->name, client_p->username,
1328 client_p->host, opername);
1329 return buffer;
1330 }
1331
1332 /*
1333 * get_printable_conf
1334 *
1335 * inputs - struct ConfItem
1336 *
1337 * output - name
1338 * - host
1339 * - pass
1340 * - user
1341 * - port
1342 *
1343 * side effects -
1344 * Examine the struct struct ConfItem, setting the values
1345 * of name, host, pass, user to values either
1346 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1347 */
1348 void
1349 get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1350 const char **pass, char **user, int *port,
1351 char **classname, char **desc)
1352 {
1353 static char null[] = "<NULL>";
1354 static char zero[] = "default";
1355
1356 *name = EmptyString(aconf->info.name) ? null : aconf->info.name;
1357 *host = EmptyString(aconf->host) ? null : aconf->host;
1358 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1359 *user = EmptyString(aconf->user) ? null : aconf->user;
1360 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1361 *desc = CheckEmpty(aconf->desc);
1362 *port = (int) aconf->port;
1363 }
1364
1365 char *
1366 get_user_ban_reason(struct ConfItem *aconf)
1367 {
1368 static char reasonbuf[BUFSIZE];
1369
1370 if (!ConfigFileEntry.hide_tkdline_duration &&
1371 aconf->flags & CONF_FLAGS_TEMPORARY &&
1372 (aconf->status == CONF_KILL || aconf->status == CONF_DLINE))
1373 snprintf(reasonbuf, sizeof reasonbuf,
1374 "Temporary %c-line %d min. - ",
1375 aconf->status == CONF_DLINE ? 'D' : 'K',
1376 (int)((aconf->hold - aconf->created) / 60));
1377 else
1378 reasonbuf[0] = '\0';
1379 if (aconf->passwd)
1380 rb_strlcat(reasonbuf, aconf->passwd, sizeof reasonbuf);
1381 else
1382 rb_strlcat(reasonbuf, "No Reason", sizeof reasonbuf);
1383 if (aconf->created)
1384 {
1385 rb_strlcat(reasonbuf, " (", sizeof reasonbuf);
1386 rb_strlcat(reasonbuf, smalldate(aconf->created),
1387 sizeof reasonbuf);
1388 rb_strlcat(reasonbuf, ")", sizeof reasonbuf);
1389 }
1390 return reasonbuf;
1391 }
1392
1393 void
1394 get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1395 char **host, char **reason,
1396 char **user, char **oper_reason)
1397 {
1398 static char null[] = "<NULL>";
1399 static char operreasonbuf[BUFSIZE];
1400
1401 *host = EmptyString(aconf->host) ? null : aconf->host;
1402 *user = EmptyString(aconf->user) ? null : aconf->user;
1403 *reason = get_user_ban_reason(aconf);
1404
1405 if(!IsOperGeneral(source_p))
1406 *oper_reason = NULL;
1407 else
1408 {
1409 snprintf(operreasonbuf, sizeof operreasonbuf, "%s%s(%s)",
1410 EmptyString(aconf->spasswd) ? "" : aconf->spasswd,
1411 EmptyString(aconf->spasswd) ? "" : " ",
1412 aconf->info.oper);
1413 *oper_reason = operreasonbuf;
1414 }
1415 }
1416
1417 /*
1418 * read_conf_files
1419 *
1420 * inputs - cold start
1421 * output - none
1422 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1423 */
1424 void
1425 read_conf_files(bool cold)
1426 {
1427 const char *filename;
1428
1429 conf_fbfile_in = NULL;
1430
1431 filename = ConfigFileEntry.configfile;
1432
1433 /* We need to know the initial filename for the yyerror() to report
1434 FIXME: The full path is in conffilenamebuf first time since we
1435 dont know anything else
1436
1437 - Gozem 2002-07-21
1438
1439
1440 */
1441 rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1442
1443 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1444 {
1445 if(cold)
1446 {
1447 inotice("Failed in reading configuration file %s, aborting", filename);
1448 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1449
1450 int e;
1451 e = errno;
1452
1453 inotice("FATAL: %s %s", strerror(e), filename);
1454 ilog(L_MAIN, "FATAL: %s %s", strerror(e), filename);
1455
1456 exit(-1);
1457 }
1458 else
1459 {
1460 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1461 "Can't open file '%s' - aborting rehash!", filename);
1462 return;
1463 }
1464 }
1465
1466 if(!cold)
1467 {
1468 clear_out_old_conf();
1469 }
1470
1471 call_hook(h_conf_read_start, NULL);
1472 read_conf();
1473 call_hook(h_conf_read_end, NULL);
1474
1475 fclose(conf_fbfile_in);
1476 }
1477
1478 /*
1479 * free an alias{} entry.
1480 */
1481 static void
1482 free_alias_cb(rb_dictionary_element *ptr, void *unused)
1483 {
1484 struct alias_entry *aptr = ptr->data;
1485
1486 rb_free(aptr->name);
1487 rb_free(aptr->target);
1488 rb_free(aptr);
1489 }
1490
1491 /*
1492 * clear_out_old_conf
1493 *
1494 * inputs - none
1495 * output - none
1496 * side effects - Clear out the old configuration
1497 */
1498 static void
1499 clear_out_old_conf(void)
1500 {
1501 struct Class *cltmp;
1502 rb_dlink_node *ptr;
1503 rb_dlink_node *next_ptr;
1504
1505 /*
1506 * don't delete the class table, rather mark all entries
1507 * for deletion. The table is cleaned up by check_class. - avalon
1508 */
1509 RB_DLINK_FOREACH(ptr, class_list.head)
1510 {
1511 cltmp = ptr->data;
1512 MaxUsers(cltmp) = -1;
1513 }
1514
1515 clear_out_address_conf(AC_CONFIG);
1516 clear_s_newconf();
1517
1518 /* clean out module paths */
1519 mod_clear_paths();
1520 mod_add_path(MODULE_DIR);
1521 mod_add_path(MODULE_DIR "/autoload");
1522
1523 /* clean out ServerInfo */
1524 rb_free(ServerInfo.description);
1525 ServerInfo.description = NULL;
1526 rb_free(ServerInfo.network_name);
1527 ServerInfo.network_name = NULL;
1528
1529 ServerInfo.ssld_count = 1;
1530
1531 /* clean out AdminInfo */
1532 rb_free(AdminInfo.name);
1533 AdminInfo.name = NULL;
1534 rb_free(AdminInfo.email);
1535 AdminInfo.email = NULL;
1536 rb_free(AdminInfo.description);
1537 AdminInfo.description = NULL;
1538
1539 /* operator{} and class{} blocks are freed above */
1540 /* clean out listeners */
1541 close_listeners();
1542
1543 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1544 * and gecos{} blocks are freed above too
1545 */
1546
1547 /* clean out general */
1548 rb_free(ConfigFileEntry.default_operstring);
1549 ConfigFileEntry.default_operstring = NULL;
1550 rb_free(ConfigFileEntry.default_adminstring);
1551 ConfigFileEntry.default_adminstring = NULL;
1552 rb_free(ConfigFileEntry.servicestring);
1553 ConfigFileEntry.servicestring = NULL;
1554 rb_free(ConfigFileEntry.kline_reason);
1555 ConfigFileEntry.kline_reason = NULL;
1556 rb_free(ConfigFileEntry.sasl_service);
1557 ConfigFileEntry.sasl_service = NULL;
1558 rb_free(ConfigFileEntry.drain_reason);
1559 ConfigFileEntry.drain_reason = NULL;
1560 rb_free(ConfigFileEntry.sasl_only_client_message);
1561 ConfigFileEntry.sasl_only_client_message = NULL;
1562 rb_free(ConfigFileEntry.identd_only_client_message);
1563 ConfigFileEntry.identd_only_client_message = NULL;
1564 rb_free(ConfigFileEntry.sctp_forbidden_client_message);
1565 ConfigFileEntry.sctp_forbidden_client_message = NULL;
1566 rb_free(ConfigFileEntry.ssltls_only_client_message);
1567 ConfigFileEntry.ssltls_only_client_message = NULL;
1568 rb_free(ConfigFileEntry.not_authorised_client_message);
1569 ConfigFileEntry.not_authorised_client_message = NULL;
1570 rb_free(ConfigFileEntry.illegal_hostname_client_message);
1571 ConfigFileEntry.illegal_hostname_client_message = NULL;
1572 rb_free(ConfigFileEntry.server_full_client_message);
1573 ConfigFileEntry.server_full_client_message = NULL;
1574 rb_free(ConfigFileEntry.illegal_name_long_client_message);
1575 ConfigFileEntry.illegal_name_long_client_message = NULL;
1576 rb_free(ConfigFileEntry.illegal_name_short_client_message);
1577 ConfigFileEntry.illegal_name_short_client_message = NULL;
1578
1579 if (ConfigFileEntry.hidden_caps != NULL)
1580 {
1581 for (size_t i = 0; ConfigFileEntry.hidden_caps[i] != NULL; i++)
1582 rb_free(ConfigFileEntry.hidden_caps[i]);
1583 rb_free(ConfigFileEntry.hidden_caps);
1584 }
1585 ConfigFileEntry.hidden_caps = NULL;
1586
1587 /* clean out log */
1588 rb_free(ConfigFileEntry.fname_userlog);
1589 ConfigFileEntry.fname_userlog = NULL;
1590 rb_free(ConfigFileEntry.fname_fuserlog);
1591 ConfigFileEntry.fname_fuserlog = NULL;
1592 rb_free(ConfigFileEntry.fname_operlog);
1593 ConfigFileEntry.fname_operlog = NULL;
1594 rb_free(ConfigFileEntry.fname_foperlog);
1595 ConfigFileEntry.fname_foperlog = NULL;
1596 rb_free(ConfigFileEntry.fname_serverlog);
1597 ConfigFileEntry.fname_serverlog = NULL;
1598 rb_free(ConfigFileEntry.fname_killlog);
1599 ConfigFileEntry.fname_killlog = NULL;
1600 rb_free(ConfigFileEntry.fname_klinelog);
1601 ConfigFileEntry.fname_klinelog = NULL;
1602 rb_free(ConfigFileEntry.fname_operspylog);
1603 ConfigFileEntry.fname_operspylog = NULL;
1604 rb_free(ConfigFileEntry.fname_ioerrorlog);
1605 ConfigFileEntry.fname_ioerrorlog = NULL;
1606
1607 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
1608 {
1609 rb_free(ptr->data);
1610 rb_dlinkDestroy(ptr, &service_list);
1611 }
1612
1613 /* remove any aliases... -- nenolod */
1614 if (alias_dict != NULL)
1615 {
1616 rb_dictionary_destroy(alias_dict, free_alias_cb, NULL);
1617 alias_dict = NULL;
1618 }
1619
1620 del_dnsbl_entry_all();
1621
1622 /* OK, that should be everything... */
1623 }
1624
1625
1626 /*
1627 * conf_add_class_to_conf
1628 * inputs - pointer to config item
1629 * output - NONE
1630 * side effects - Add a class pointer to a conf
1631 */
1632
1633 void
1634 conf_add_class_to_conf(struct ConfItem *aconf)
1635 {
1636 if(aconf->className == NULL)
1637 {
1638 aconf->className = rb_strdup("default");
1639 ClassPtr(aconf) = default_class;
1640 return;
1641 }
1642
1643 ClassPtr(aconf) = find_class(aconf->className);
1644
1645 if(ClassPtr(aconf) == default_class)
1646 {
1647 if(aconf->status == CONF_CLIENT)
1648 {
1649 conf_report_error(
1650 "Using default class for missing class \"%s\" in auth{} for %s@%s",
1651 aconf->className, aconf->user, aconf->host);
1652 }
1653
1654 rb_free(aconf->className);
1655 aconf->className = rb_strdup("default");
1656 return;
1657 }
1658
1659 if(ConfMaxUsers(aconf) < 0)
1660 {
1661 ClassPtr(aconf) = default_class;
1662 rb_free(aconf->className);
1663 aconf->className = rb_strdup("default");
1664 return;
1665 }
1666 }
1667
1668 /*
1669 * conf_add_d_conf
1670 * inputs - pointer to config item
1671 * output - NONE
1672 * side effects - Add a d/D line
1673 */
1674 void
1675 conf_add_d_conf(struct ConfItem *aconf)
1676 {
1677 if(aconf->host == NULL)
1678 return;
1679
1680 aconf->user = NULL;
1681
1682 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1683 * need this anyway, so I will disable it for now... -A1kmm
1684 */
1685
1686 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1687 {
1688 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1689 free_conf(aconf);
1690 }
1691 else
1692 {
1693 add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
1694 }
1695 }
1696
1697 static void
1698 strip_tabs(char *dest, const char *src, size_t size)
1699 {
1700 char *d = dest;
1701
1702 if(dest == NULL || src == NULL)
1703 return;
1704
1705 rb_strlcpy(dest, src, size);
1706
1707 while(*d)
1708 {
1709 if(*d == '\t')
1710 *d = ' ';
1711 d++;
1712 }
1713 }
1714
1715 /*
1716 * yyerror
1717 *
1718 * inputs - message from parser
1719 * output - none
1720 * side effects - message to opers and log file entry is made
1721 */
1722 void
1723 yyerror(const char *msg)
1724 {
1725 char newlinebuf[BUFSIZE];
1726
1727 strip_tabs(newlinebuf, yy_linebuf, sizeof(newlinebuf));
1728
1729 ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
1730 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "\"%s\", line %d: %s at '%s'",
1731 conffilebuf, lineno + 1, msg, newlinebuf);
1732
1733 }
1734
1735 int
1736 conf_fgets(char *lbuf, int max_size, FILE * fb)
1737 {
1738 if(fgets(lbuf, max_size, fb) == NULL)
1739 return (0);
1740
1741 return (strlen(lbuf));
1742 }
1743
1744 int
1745 conf_yy_fatal_error(const char *msg)
1746 {
1747 return (0);
1748 }