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