]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_conf.c
Add use_part_messages config option. When disabled, this will show
[irc/rqf/shadowircd.git] / src / s_conf.c
CommitLineData
212380e3 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 *
cda8e9b8 24 * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $
212380e3 25 */
26
27#include "stdinc.h"
28#include "ircd_defs.h"
212380e3 29#include "s_conf.h"
30#include "s_newconf.h"
12c4f819 31#include "newconf.h"
212380e3 32#include "s_serv.h"
55f5eaa1 33#include "s_user.h"
212380e3 34#include "s_stats.h"
35#include "channel.h"
36#include "class.h"
37#include "client.h"
38#include "common.h"
212380e3 39#include "hash.h"
13ae2f4b 40#include "match.h"
212380e3 41#include "ircd.h"
42#include "listener.h"
43#include "hostmask.h"
44#include "modules.h"
45#include "numeric.h"
d3455e2c 46#include "logger.h"
212380e3 47#include "send.h"
212380e3 48#include "reject.h"
49#include "cache.h"
50#include "blacklist.h"
543b8c39 51#include "privilege.h"
8db00894 52#include "sslproc.h"
9f025822 53#include "bandbi.h"
212380e3 54
55struct config_server_hide ConfigServerHide;
56
b9f46fc5 57extern int yyparse(void); /* defined in y.tab.c */
212380e3 58extern char linebuf[];
59
60#ifndef INADDR_NONE
61#define INADDR_NONE ((unsigned int) 0xffffffff)
62#endif
63
6e9b4415 64static rb_bh *confitem_heap = NULL;
212380e3 65
af81d5a0
WP
66rb_dlink_list temp_klines[LAST_TEMP_TYPE];
67rb_dlink_list temp_dlines[LAST_TEMP_TYPE];
68rb_dlink_list service_list;
212380e3 69
70/* internally defined functions */
71static void set_default_conf(void);
72static void validate_conf(void);
73static void read_conf(FILE *);
74static void clear_out_old_conf(void);
75
76static void expire_temp_kd(void *list);
77static void reorganise_temp_kd(void *list);
78
79FILE *conf_fbfile_in;
80extern char yytext[];
81
82static int verify_access(struct Client *client_p, const char *username);
83static int attach_iline(struct Client *, struct ConfItem *);
84
85void
86init_s_conf(void)
87{
0cca1f52 88 confitem_heap = rb_bh_create(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE, "confitem_heap");
212380e3 89
9e29fe51
VY
90 rb_event_addish("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60);
91 rb_event_addish("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60);
212380e3 92
9e29fe51 93 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd,
212380e3 94 &temp_klines[TEMP_HOUR], 3600);
9e29fe51 95 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd,
212380e3 96 &temp_dlines[TEMP_HOUR], 3600);
9e29fe51 97 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd,
212380e3 98 &temp_klines[TEMP_DAY], 86400);
9e29fe51 99 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd,
212380e3 100 &temp_dlines[TEMP_DAY], 86400);
9e29fe51 101 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd,
212380e3 102 &temp_klines[TEMP_WEEK], 604800);
9e29fe51 103 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd,
212380e3 104 &temp_dlines[TEMP_WEEK], 604800);
105}
106
107/*
108 * make_conf
109 *
110 * inputs - none
111 * output - pointer to new conf entry
112 * side effects - none
113 */
114struct ConfItem *
115make_conf()
116{
117 struct ConfItem *aconf;
118
6e9b4415 119 aconf = rb_bh_alloc(confitem_heap);
212380e3 120 aconf->status = CONF_ILLEGAL;
121 return (aconf);
122}
123
124/*
125 * free_conf
126 *
127 * inputs - pointer to conf to free
128 * output - none
129 * side effects - crucial password fields are zeroed, conf is freed
130 */
131void
132free_conf(struct ConfItem *aconf)
133{
134 s_assert(aconf != NULL);
135 if(aconf == NULL)
136 return;
137
138 /* security.. */
139 if(aconf->passwd)
140 memset(aconf->passwd, 0, strlen(aconf->passwd));
141 if(aconf->spasswd)
142 memset(aconf->spasswd, 0, strlen(aconf->spasswd));
143
90a3c35b
VY
144 rb_free(aconf->passwd);
145 rb_free(aconf->spasswd);
146 rb_free(aconf->name);
147 rb_free(aconf->className);
148 rb_free(aconf->user);
149 rb_free(aconf->host);
212380e3 150
6e9b4415 151 rb_bh_free(confitem_heap, aconf);
212380e3 152}
153
154/*
155 * check_client
156 *
157 * inputs - pointer to client
158 * output - 0 = Success
159 * NOT_AUTHORISED (-1) = Access denied (no I line match)
160 * SOCKET_ERROR (-2) = Bad socket.
161 * I_LINE_FULL (-3) = I-line is full
162 * TOO_MANY (-4) = Too many connections from hostname
163 * BANNED_CLIENT (-5) = K-lined
164 * side effects - Ordinary client access check.
165 * Look for conf lines which have the same
166 * status as the flags passed.
167 */
168int
169check_client(struct Client *client_p, struct Client *source_p, const char *username)
170{
171 int i;
172
212380e3 173 if((i = verify_access(source_p, username)))
174 {
175 ilog(L_FUSER, "Access denied: %s[%s]",
176 source_p->name, source_p->sockhost);
177 }
178
179 switch (i)
180 {
181 case SOCKET_ERROR:
182 exit_client(client_p, source_p, &me, "Socket Error");
183 break;
184
185 case TOO_MANY_LOCAL:
606384ae 186 /* Note that these notices are sent to opers on other
187 * servers also, so even if local opers are allowed to
188 * see the IP, we still cannot send it.
189 */
212380e3 190 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
191 "Too many local connections for %s!%s%s@%s",
192 source_p->name, IsGotId(source_p) ? "" : "~",
606384ae 193 source_p->username,
194 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
212380e3 195
196 ilog(L_FUSER, "Too many local connections from %s!%s%s@%s",
197 source_p->name, IsGotId(source_p) ? "" : "~",
198 source_p->username, source_p->sockhost);
199
83251205 200 ServerStats.is_ref++;
212380e3 201 exit_client(client_p, source_p, &me, "Too many host connections (local)");
202 break;
203
204 case TOO_MANY_GLOBAL:
205 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
206 "Too many global connections for %s!%s%s@%s",
207 source_p->name, IsGotId(source_p) ? "" : "~",
606384ae 208 source_p->username,
209 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
212380e3 210 ilog(L_FUSER, "Too many global connections from %s!%s%s@%s",
211 source_p->name, IsGotId(source_p) ? "" : "~",
212 source_p->username, source_p->sockhost);
213
83251205 214 ServerStats.is_ref++;
212380e3 215 exit_client(client_p, source_p, &me, "Too many host connections (global)");
216 break;
217
218 case TOO_MANY_IDENT:
219 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
220 "Too many user connections for %s!%s%s@%s",
221 source_p->name, IsGotId(source_p) ? "" : "~",
606384ae 222 source_p->username,
223 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : source_p->host);
212380e3 224 ilog(L_FUSER, "Too many user connections from %s!%s%s@%s",
225 source_p->name, IsGotId(source_p) ? "" : "~",
226 source_p->username, source_p->sockhost);
227
83251205 228 ServerStats.is_ref++;
212380e3 229 exit_client(client_p, source_p, &me, "Too many user connections (global)");
230 break;
231
232 case I_LINE_FULL:
233 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
234 "I-line is full for %s!%s%s@%s (%s).",
235 source_p->name, IsGotId(source_p) ? "" : "~",
236 source_p->username, source_p->host,
4b7e6904 237 show_ip(NULL, source_p) && !IsIPSpoof(source_p) ? source_p->sockhost : "255.255.255.255");
212380e3 238
239 ilog(L_FUSER, "Too many connections from %s!%s%s@%s.",
240 source_p->name, IsGotId(source_p) ? "" : "~",
241 source_p->username, source_p->sockhost);
242
83251205 243 ServerStats.is_ref++;
212380e3 244 exit_client(client_p, source_p, &me,
245 "No more connections allowed in your connection class");
246 break;
247
248 case NOT_AUTHORISED:
249 {
250 int port = -1;
2c2e0aa9 251#ifdef RB_IPV6
212380e3 252 if(source_p->localClient->ip.ss_family == AF_INET6)
253 port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port);
254 else
255#endif
256 port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port);
257
83251205 258 ServerStats.is_ref++;
212380e3 259 /* jdc - lists server name & port connections are on */
260 /* a purely cosmetical change */
261 /* why ipaddr, and not just source_p->sockhost? --fl */
262#if 0
263 static char ipaddr[HOSTIPLEN];
9879cd59 264 rb_inet_ntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
212380e3 265#endif
266 sendto_realops_snomask(SNO_UNAUTH, L_ALL,
267 "Unauthorised client connection from "
268 "%s!%s%s@%s [%s] on [%s/%u].",
269 source_p->name, IsGotId(source_p) ? "" : "~",
270 source_p->username, source_p->host,
271 source_p->sockhost,
272 source_p->localClient->listener->name, port);
273
274 ilog(L_FUSER,
275 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
276 source_p->name, IsGotId(source_p) ? "" : "~",
277 source_p->username, source_p->sockhost,
278 source_p->localClient->listener->name, port);
35f6f850 279 add_reject(client_p, NULL, NULL);
212380e3 280 exit_client(client_p, source_p, &me,
281 "You are not authorised to use this server");
282 break;
283 }
284 case BANNED_CLIENT:
212380e3 285 exit_client(client_p, client_p, &me, "*** Banned ");
83251205 286 ServerStats.is_ref++;
212380e3 287 break;
288
289 case 0:
290 default:
291 break;
292 }
293 return (i);
294}
295
296/*
297 * verify_access
298 *
299 * inputs - pointer to client to verify
300 * - pointer to proposed username
301 * output - 0 if success -'ve if not
302 * side effect - find the first (best) I line to attach.
303 */
304static int
305verify_access(struct Client *client_p, const char *username)
306{
307 struct ConfItem *aconf;
308 char non_ident[USERLEN + 1];
309
310 if(IsGotId(client_p))
311 {
312 aconf = find_address_conf(client_p->host, client_p->sockhost,
313 client_p->username, client_p->username,
314 (struct sockaddr *) &client_p->localClient->ip,
969a1ae6
VY
315 client_p->localClient->ip.ss_family,
316 client_p->localClient->auth_user);
212380e3 317 }
318 else
319 {
907468c4 320 rb_strlcpy(non_ident, "~", sizeof(non_ident));
a64c5173 321 rb_strlcat(non_ident, username, sizeof(non_ident));
212380e3 322 aconf = find_address_conf(client_p->host, client_p->sockhost,
323 non_ident, client_p->username,
324 (struct sockaddr *) &client_p->localClient->ip,
969a1ae6
VY
325 client_p->localClient->ip.ss_family,
326 client_p->localClient->auth_user);
212380e3 327 }
328
329 if(aconf == NULL)
330 return NOT_AUTHORISED;
331
332 if(aconf->status & CONF_CLIENT)
333 {
334 if(aconf->flags & CONF_FLAGS_REDIR)
335 {
88520303 336 sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR),
212380e3 337 aconf->name ? aconf->name : "", aconf->port);
338 return (NOT_AUTHORISED);
339 }
340
212380e3 341 /* Thanks for spoof idea amm */
342 if(IsConfDoSpoofIp(aconf))
343 {
344 char *p;
345
346 /* show_ip() depends on this --fl */
347 SetIPSpoof(client_p);
348
349 if(IsConfSpoofNotice(aconf))
350 {
351 sendto_realops_snomask(SNO_GENERAL, L_ALL,
352 "%s spoofing: %s as %s",
353 client_p->name,
354 show_ip(NULL, client_p) ? client_p->host : aconf->name,
355 aconf->name);
356 }
357
358 /* user@host spoof */
359 if((p = strchr(aconf->name, '@')) != NULL)
360 {
361 char *host = p+1;
362 *p = '\0';
363
907468c4 364 rb_strlcpy(client_p->username, aconf->name,
212380e3 365 sizeof(client_p->username));
907468c4 366 rb_strlcpy(client_p->host, host,
212380e3 367 sizeof(client_p->host));
368 *p = '@';
369 }
370 else
907468c4 371 rb_strlcpy(client_p->host, aconf->name, sizeof(client_p->host));
212380e3 372 }
373 return (attach_iline(client_p, aconf));
374 }
375 else if(aconf->status & CONF_KILL)
376 {
377 if(ConfigFileEntry.kline_with_reason)
378 {
379 sendto_one(client_p,
92fb5c31 380 form_str(ERR_YOUREBANNEDCREEP),
212380e3 381 me.name, client_p->name, aconf->passwd);
382 }
35f6f850 383 add_reject(client_p, aconf->user, aconf->host);
212380e3 384 return (BANNED_CLIENT);
385 }
212380e3 386
387 return NOT_AUTHORISED;
388}
389
390
391/*
392 * add_ip_limit
393 *
394 * Returns 1 if successful 0 if not
395 *
396 * This checks if the user has exceed the limits for their class
397 * unless of course they are exempt..
398 */
399
400static int
401add_ip_limit(struct Client *client_p, struct ConfItem *aconf)
402{
0cca1f52 403 rb_patricia_node_t *pnode;
c8d85889 404 int bitlen;
212380e3 405
406 /* If the limits are 0 don't do anything.. */
c8d85889
JT
407 if(ConfCidrAmount(aconf) == 0
408 || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0))
212380e3 409 return -1;
410
0cca1f52 411 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
212380e3 412
c8d85889
JT
413 if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET)
414 bitlen = ConfCidrIpv4Bitlen(aconf);
415 else
416 bitlen = ConfCidrIpv6Bitlen(aconf);
417
212380e3 418 if(pnode == NULL)
c8d85889 419 pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, bitlen);
212380e3 420
421 s_assert(pnode != NULL);
422
423 if(pnode != NULL)
424 {
c8d85889 425 if(((intptr_t)pnode->data) >= ConfCidrAmount(aconf) && !IsConfExemptLimits(aconf))
212380e3 426 {
427 /* This should only happen if the limits are set to 0 */
c8d85889 428 if((intptr_t)pnode->data == 0)
212380e3 429 {
0cca1f52 430 rb_patricia_remove(ConfIpLimits(aconf), pnode);
212380e3 431 }
432 return (0);
433 }
434
c8d85889 435 pnode->data = (void *)(((intptr_t)pnode->data) + 1);
212380e3 436 }
437 return 1;
438}
439
440static void
441remove_ip_limit(struct Client *client_p, struct ConfItem *aconf)
442{
0cca1f52 443 rb_patricia_node_t *pnode;
212380e3 444
445 /* If the limits are 0 don't do anything.. */
c8d85889
JT
446 if(ConfCidrAmount(aconf) == 0
447 || (ConfCidrIpv4Bitlen(aconf) == 0 && ConfCidrIpv6Bitlen(aconf) == 0))
212380e3 448 return;
449
0cca1f52 450 pnode = rb_match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
212380e3 451 if(pnode == NULL)
452 return;
453
c8d85889
JT
454 pnode->data = (void *)(((intptr_t)pnode->data) - 1);
455 if(((intptr_t)pnode->data) == 0)
212380e3 456 {
0cca1f52 457 rb_patricia_remove(ConfIpLimits(aconf), pnode);
212380e3 458 }
459
460}
461
462/*
463 * attach_iline
464 *
465 * inputs - client pointer
466 * - conf pointer
467 * output -
468 * side effects - do actual attach
469 */
470static int
471attach_iline(struct Client *client_p, struct ConfItem *aconf)
472{
473 struct Client *target_p;
af81d5a0 474 rb_dlink_node *ptr;
212380e3 475 int local_count = 0;
476 int global_count = 0;
477 int ident_count = 0;
478 int unidented = 0;
479
480 if(IsConfExemptLimits(aconf))
481 return (attach_conf(client_p, aconf));
482
483 if(*client_p->username == '~')
484 unidented = 1;
485
486
487 /* find_hostname() returns the head of the list to search */
8e69bb4e 488 RB_DLINK_FOREACH(ptr, find_hostname(client_p->host))
212380e3 489 {
490 target_p = ptr->data;
491
492 if(irccmp(client_p->host, target_p->orighost) != 0)
493 continue;
494
495 if(MyConnect(target_p))
496 local_count++;
497
498 global_count++;
499
500 if(unidented)
501 {
502 if(*target_p->username == '~')
503 ident_count++;
504 }
505 else if(irccmp(target_p->username, client_p->username) == 0)
506 ident_count++;
507
508 if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf))
509 return (TOO_MANY_LOCAL);
510 else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf))
511 return (TOO_MANY_GLOBAL);
512 else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf))
513 return (TOO_MANY_IDENT);
514 }
515
516
517 return (attach_conf(client_p, aconf));
518}
519
520/*
521 * detach_conf
522 *
523 * inputs - pointer to client to detach
524 * output - 0 for success, -1 for failure
525 * side effects - Disassociate configuration from the client.
526 * Also removes a class from the list if marked for deleting.
527 */
528int
529detach_conf(struct Client *client_p)
530{
531 struct ConfItem *aconf;
532
533 aconf = client_p->localClient->att_conf;
534
535 if(aconf != NULL)
536 {
537 if(ClassPtr(aconf))
538 {
539 remove_ip_limit(client_p, aconf);
540
541 if(ConfCurrUsers(aconf) > 0)
542 --ConfCurrUsers(aconf);
543
544 if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0)
545 {
546 free_class(ClassPtr(aconf));
547 ClassPtr(aconf) = NULL;
548 }
549
550 }
551
552 aconf->clients--;
553 if(!aconf->clients && IsIllegal(aconf))
554 free_conf(aconf);
555
556 client_p->localClient->att_conf = NULL;
557 return 0;
558 }
559
560 return -1;
561}
562
563/*
564 * attach_conf
565 *
566 * inputs - client pointer
567 * - conf pointer
568 * output -
569 * side effects - Associate a specific configuration entry to a *local*
570 * client (this is the one which used in accepting the
571 * connection). Note, that this automatically changes the
572 * attachment if there was an old one...
573 */
574int
575attach_conf(struct Client *client_p, struct ConfItem *aconf)
576{
577 if(IsIllegal(aconf))
578 return (NOT_AUTHORISED);
579
580 if(ClassPtr(aconf))
581 {
582 if(!add_ip_limit(client_p, aconf))
583 return (TOO_MANY_LOCAL);
584 }
585
586 if((aconf->status & CONF_CLIENT) &&
587 ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0)
588 {
589 if(!IsConfExemptLimits(aconf))
590 {
591 return (I_LINE_FULL);
592 }
593 else
594 {
5366977b 595 sendto_one_notice(client_p, ":*** I: line is full, but you have an >I: line!");
212380e3 596 }
597
598 }
599
600 if(client_p->localClient->att_conf != NULL)
601 detach_conf(client_p);
602
603 client_p->localClient->att_conf = aconf;
604
605 aconf->clients++;
606 ConfCurrUsers(aconf)++;
607 return (0);
608}
609
610/*
611 * rehash
612 *
613 * Actual REHASH service routine. Called with sig == 0 if it has been called
614 * as a result of an operator issuing this command, else assume it has been
615 * called as a result of the server receiving a HUP signal.
616 */
617int
618rehash(int sig)
619{
620 if(sig != 0)
621 {
622 sendto_realops_snomask(SNO_GENERAL, L_ALL,
623 "Got signal SIGHUP, reloading ircd conf. file");
624 }
625
626 restart_resolver();
627 /* don't close listeners until we know we can go ahead with the rehash */
628 read_conf_files(NO);
629
630 if(ServerInfo.description != NULL)
907468c4 631 rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
212380e3 632 else
907468c4 633 rb_strlcpy(me.info, "unknown", sizeof(me.info));
212380e3 634
635 open_logfiles();
636 return (0);
637}
638
212380e3 639void
640rehash_bans(int sig)
641{
9f025822 642 bandb_rehash_bans();
212380e3 643}
644
645/*
646 * set_default_conf()
647 *
648 * inputs - NONE
649 * output - NONE
650 * side effects - Set default values here.
651 * This is called **PRIOR** to parsing the
652 * configuration file. If you want to do some validation
653 * of values later, put them in validate_conf().
654 */
655
656#define YES 1
657#define NO 0
658#define UNSET -1
659
660static void
661set_default_conf(void)
662{
663 /* ServerInfo.name is not rehashable */
664 /* ServerInfo.name = ServerInfo.name; */
665 ServerInfo.description = NULL;
62d28946
VY
666 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
667 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
212380e3 668
669 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
670 ServerInfo.specific_ipv4_vhost = 0;
2c2e0aa9 671#ifdef RB_IPV6
212380e3 672 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
673 ServerInfo.specific_ipv6_vhost = 0;
674#endif
212380e3 675
676 /* Don't reset hub, as that will break lazylinks */
677 /* ServerInfo.hub = NO; */
678 AdminInfo.name = NULL;
679 AdminInfo.email = NULL;
680 AdminInfo.description = NULL;
681
62d28946
VY
682 ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator");
683 ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator");
220c9db5 684 ConfigFileEntry.default_operhost = rb_strdup("");
c0e2aa60 685 ConfigFileEntry.static_quit = rb_strdup("");
62d28946 686 ConfigFileEntry.servicestring = rb_strdup("is a Network Service");
212380e3 687
688 ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
689 ConfigFileEntry.failed_oper_notice = YES;
690 ConfigFileEntry.anti_nick_flood = NO;
691 ConfigFileEntry.disable_fake_channels = NO;
692 ConfigFileEntry.max_nick_time = 20;
693 ConfigFileEntry.max_nick_changes = 5;
694 ConfigFileEntry.max_accept = 20;
695 ConfigFileEntry.max_monitor = 60;
696 ConfigFileEntry.nick_delay = 900; /* 15 minutes */
697 ConfigFileEntry.target_change = YES;
698 ConfigFileEntry.anti_spam_exit_message_time = 0;
e78f6850 699 ConfigFileEntry.use_part_messages = YES;
212380e3 700 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
701 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
702 ConfigFileEntry.client_exit = YES;
703 ConfigFileEntry.dline_with_reason = YES;
704 ConfigFileEntry.kline_with_reason = YES;
705 ConfigFileEntry.kline_delay = 0;
706 ConfigFileEntry.warn_no_nline = YES;
707 ConfigFileEntry.non_redundant_klines = YES;
708 ConfigFileEntry.stats_e_disabled = NO;
709 ConfigFileEntry.stats_o_oper_only = NO;
710 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
711 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
712 ConfigFileEntry.stats_P_oper_only = NO;
713 ConfigFileEntry.stats_c_oper_only = NO;
714 ConfigFileEntry.stats_y_oper_only = NO;
715 ConfigFileEntry.stats_h_oper_only = NO;
716 ConfigFileEntry.map_oper_only = YES;
717 ConfigFileEntry.operspy_admin_only = NO;
718 ConfigFileEntry.pace_wait = 10;
719 ConfigFileEntry.caller_id_wait = 60;
720 ConfigFileEntry.pace_wait_simple = 1;
721 ConfigFileEntry.short_motd = NO;
722 ConfigFileEntry.no_oper_flood = NO;
723 ConfigFileEntry.fname_userlog = NULL;
724 ConfigFileEntry.fname_fuserlog = NULL;
725 ConfigFileEntry.fname_operlog = NULL;
726 ConfigFileEntry.fname_foperlog = NULL;
727 ConfigFileEntry.fname_serverlog = NULL;
212380e3 728 ConfigFileEntry.fname_klinelog = NULL;
729 ConfigFileEntry.fname_operspylog = NULL;
730 ConfigFileEntry.fname_ioerrorlog = NULL;
212380e3 731 ConfigFileEntry.use_egd = NO;
212380e3 732 ConfigFileEntry.hide_spoof_ips = YES;
733 ConfigFileEntry.hide_error_messages = 1;
212380e3 734 ConfigFileEntry.dots_in_ident = 0;
735 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
212380e3 736 ConfigFileEntry.egdpool_path = NULL;
737 ConfigFileEntry.use_whois_actually = YES;
738 ConfigFileEntry.burst_away = NO;
739 ConfigFileEntry.collision_fnc = YES;
740 ConfigFileEntry.global_snotices = YES;
741 ConfigFileEntry.operspy_dont_care_user_info = NO;
837a020a 742 ConfigFileEntry.secret_channels_in_whois = NO;
212380e3 743
744#ifdef HAVE_LIBZ
745 ConfigFileEntry.compression_level = 4;
746#endif
747
748 ConfigFileEntry.oper_umodes = UMODE_LOCOPS | UMODE_SERVNOTICE |
749 UMODE_OPERWALL | UMODE_WALLOP;
750 ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
751 ConfigFileEntry.oper_snomask = SNO_GENERAL;
752
13ec57db 753 ConfigChannel.autochanmodes = rb_strdup("nt");
5ad94b50 754 ConfigChannel.exemptchanops = rb_strdup("");
46f0c518 755 ConfigChannel.use_halfop = YES;
c1c91f94 756 ConfigChannel.use_admin = YES;
212380e3 757 ConfigChannel.use_except = YES;
758 ConfigChannel.use_invex = YES;
759 ConfigChannel.use_knock = YES;
760 ConfigChannel.use_forward = YES;
0eceaff1 761 ConfigChannel.use_local_channels = YES;
212380e3 762 ConfigChannel.knock_delay = 300;
763 ConfigChannel.knock_delay_channel = 60;
764 ConfigChannel.max_chans_per_user = 15;
765 ConfigChannel.max_bans = 25;
766 ConfigChannel.max_bans_large = 500;
dea418e9 767 ConfigChannel.only_ascii_channels = NO;
c3a0fde2 768 ConfigChannel.cycle_host_change = YES;
45b9f1cb 769 ConfigChannel.host_in_topic = YES;
212380e3 770 ConfigChannel.burst_topicwho = NO;
212380e3 771 ConfigChannel.kick_on_split_riding = NO;
772
773 ConfigChannel.default_split_user_count = 15000;
774 ConfigChannel.default_split_server_count = 10;
775 ConfigChannel.no_join_on_split = NO;
776 ConfigChannel.no_create_on_split = YES;
100563e8 777 ConfigChannel.resv_forcepart = YES;
846aa234 778 ConfigChannel.kick_no_rejoin_time = 30;
212380e3 779
5ad94b50
G
780 ConfigChannel.exempt_cmode_c = NO;
781 ConfigChannel.exempt_cmode_C = NO;
782 ConfigChannel.exempt_cmode_D = NO;
783 ConfigChannel.exempt_cmode_T = NO;
784 ConfigChannel.exempt_cmode_N = NO;
785 ConfigChannel.exempt_cmode_G = NO;
786 ConfigChannel.exempt_cmode_K = NO;
787
212380e3 788 ConfigServerHide.flatten_links = 0;
789 ConfigServerHide.links_delay = 300;
790 ConfigServerHide.hidden = 0;
791 ConfigServerHide.disable_hidden = 0;
792
793 ConfigFileEntry.min_nonwildcard = 4;
794 ConfigFileEntry.min_nonwildcard_simple = 3;
795 ConfigFileEntry.default_floodcount = 8;
796 ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
797 ConfigFileEntry.tkline_expire_notices = 0;
798
799 ConfigFileEntry.reject_after_count = 5;
800 ConfigFileEntry.reject_ban_time = 300;
801 ConfigFileEntry.reject_duration = 120;
d1275a8f
JT
802 ConfigFileEntry.throttle_count = 4;
803 ConfigFileEntry.throttle_duration = 60;
9ace21a7 804 ConfigFileEntry.expire_override_time = 300;
c2d96fcb 805
3fe90825 806 ServerInfo.default_max_clients = MAXCONNECTIONS;
22544e37
JT
807
808 if (!alias_dict)
809 alias_dict = irc_dictionary_create(strcasecmp);
212380e3 810}
811
812#undef YES
813#undef NO
814
815/*
816 * read_conf()
817 *
818 *
819 * inputs - file descriptor pointing to config file to use
820 * output - None
821 * side effects - Read configuration file.
822 */
823static void
824read_conf(FILE * file)
825{
826 lineno = 0;
827
828 set_default_conf(); /* Set default values prior to conf parsing */
829 yyparse(); /* Load the values from the conf */
830 validate_conf(); /* Check to make sure some values are still okay. */
831 /* Some global values are also loaded here. */
832 check_class(); /* Make sure classes are valid */
543b8c39 833 privilegeset_delete_all_illegal();
212380e3 834}
835
836static void
837validate_conf(void)
838{
839 if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
840 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
841
842 if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
843 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
844
212380e3 845 if(ServerInfo.network_name == NULL)
62d28946 846 ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT);
212380e3 847
848 if(ServerInfo.network_desc == NULL)
62d28946 849 ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT);
212380e3 850
b717a466 851 if(ServerInfo.ssld_count < 1)
8db00894
VY
852 ServerInfo.ssld_count = 1;
853
b717a466
JT
854 if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params))
855 {
856 ilog(L_MAIN, "WARNING: Unable to setup SSL.");
857 ssl_ok = 0;
858 } else {
859 ssl_ok = 1;
860 send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
861 }
862
863 if(ServerInfo.ssld_count > get_ssld_count())
864 {
865 int start = ServerInfo.ssld_count - get_ssld_count();
866 /* start up additional ssld if needed */
867 start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params);
868
8db00894
VY
869 }
870
212380e3 871 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
872 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
873 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
874
212380e3 875 if(!split_users || !split_servers ||
876 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
877 {
0cca1f52
JT
878 rb_event_delete(check_splitmode_ev);
879 check_splitmode_ev = NULL;
212380e3 880 splitmode = 0;
881 splitchecking = 0;
882 }
5ad94b50 883
220c9db5
G
884 if(!valid_hostname(ConfigFileEntry.default_operhost))
885 {
886 conf_report_error("Warning -- invalid default_operhost specified, ignoring.");
887 ConfigFileEntry.default_operhost = rb_strdup("");
888 }
889
5ad94b50
G
890 /* Parse the exemptchanops option and set the internal variables
891 * that we will use. */
892 char * ech;
893
894 for(ech = ConfigChannel.exemptchanops; *ech; ech++)
895 {
896 if(*ech == 'c')
897 {
898 ConfigChannel.exempt_cmode_c = 1;
899 continue;
900 }
901 if(*ech == 'C')
902 {
903 ConfigChannel.exempt_cmode_C = 1;
904 continue;
905 }
906 if(*ech == 'D')
907 {
908 ConfigChannel.exempt_cmode_D = 1;
909 continue;
910 }
911 if(*ech == 'T')
912 {
913 ConfigChannel.exempt_cmode_T = 1;
914 continue;
915 }
916 if(*ech == 'N')
917 {
918 ConfigChannel.exempt_cmode_N = 1;
919 continue;
920 }
921 if(*ech == 'G')
922 {
923 ConfigChannel.exempt_cmode_G = 1;
924 continue;
925 }
926 if(*ech == 'K')
927 ConfigChannel.exempt_cmode_K = 1;
928 }
212380e3 929}
930
212380e3 931/* add_temp_kline()
932 *
933 * inputs - pointer to struct ConfItem
934 * output - none
935 * Side effects - links in given struct ConfItem into
936 * temporary kline link list
937 */
938void
939add_temp_kline(struct ConfItem *aconf)
940{
9f6bbe3c 941 if(aconf->hold >= rb_current_time() + (10080 * 60))
212380e3 942 {
af81d5a0 943 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
212380e3 944 aconf->port = TEMP_WEEK;
945 }
9f6bbe3c 946 else if(aconf->hold >= rb_current_time() + (1440 * 60))
212380e3 947 {
af81d5a0 948 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
212380e3 949 aconf->port = TEMP_DAY;
950 }
9f6bbe3c 951 else if(aconf->hold >= rb_current_time() + (60 * 60))
212380e3 952 {
af81d5a0 953 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
212380e3 954 aconf->port = TEMP_HOUR;
955 }
956 else
957 {
af81d5a0 958 rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
212380e3 959 aconf->port = TEMP_MIN;
960 }
961
962 aconf->flags |= CONF_FLAGS_TEMPORARY;
969a1ae6 963 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
212380e3 964}
965
966/* add_temp_dline()
967 *
968 * input - pointer to struct ConfItem
969 * output - none
970 * side effects - added to tdline link list and address hash
971 */
972void
973add_temp_dline(struct ConfItem *aconf)
974{
9f6bbe3c 975 if(aconf->hold >= rb_current_time() + (10080 * 60))
212380e3 976 {
af81d5a0 977 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
212380e3 978 aconf->port = TEMP_WEEK;
979 }
9f6bbe3c 980 else if(aconf->hold >= rb_current_time() + (1440 * 60))
212380e3 981 {
af81d5a0 982 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
212380e3 983 aconf->port = TEMP_DAY;
984 }
9f6bbe3c 985 else if(aconf->hold >= rb_current_time() + (60 * 60))
212380e3 986 {
af81d5a0 987 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
212380e3 988 aconf->port = TEMP_HOUR;
989 }
990 else
991 {
af81d5a0 992 rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
212380e3 993 aconf->port = TEMP_MIN;
994 }
995
996 aconf->flags |= CONF_FLAGS_TEMPORARY;
969a1ae6 997 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, NULL, aconf);
212380e3 998}
999
1000/* expire_tkline()
1001 *
1002 * inputs - list pointer
1003 * - type
1004 * output - NONE
1005 * side effects - expire tklines and moves them between lists
1006 */
1007static void
1008expire_temp_kd(void *list)
1009{
af81d5a0 1010 rb_dlink_node *ptr;
90a3c35b 1011 rb_dlink_node *next_ptr;
212380e3 1012 struct ConfItem *aconf;
1013
90a3c35b 1014 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
212380e3 1015 {
1016 aconf = ptr->data;
1017
9f6bbe3c 1018 if(aconf->hold <= rb_current_time())
212380e3 1019 {
1020 /* Alert opers that a TKline expired - Hwy */
1021 if(ConfigFileEntry.tkline_expire_notices)
1022 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1023 "Temporary K-line for [%s@%s] expired",
1024 (aconf->user) ? aconf->
1025 user : "*", (aconf->host) ? aconf->host : "*");
1026
1027 delete_one_address_conf(aconf->host, aconf);
af81d5a0 1028 rb_dlinkDestroy(ptr, list);
212380e3 1029 }
1030 }
1031}
1032
1033static void
1034reorganise_temp_kd(void *list)
1035{
1036 struct ConfItem *aconf;
90a3c35b 1037 rb_dlink_node *ptr, *next_ptr;
212380e3 1038
90a3c35b 1039 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, ((rb_dlink_list *) list)->head)
212380e3 1040 {
1041 aconf = ptr->data;
1042
9f6bbe3c 1043 if(aconf->hold < (rb_current_time() + (60 * 60)))
212380e3 1044 {
af81d5a0 1045 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1046 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1047 aconf->port = TEMP_MIN;
1048 }
1049 else if(aconf->port > TEMP_HOUR)
1050 {
9f6bbe3c 1051 if(aconf->hold < (rb_current_time() + (1440 * 60)))
212380e3 1052 {
af81d5a0 1053 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1054 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1055 aconf->port = TEMP_HOUR;
1056 }
1057 else if(aconf->port > TEMP_DAY &&
9f6bbe3c 1058 (aconf->hold < (rb_current_time() + (10080 * 60))))
212380e3 1059 {
af81d5a0 1060 rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
212380e3 1061 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1062 aconf->port = TEMP_DAY;
1063 }
1064 }
1065 }
1066}
1067
1068
1069/* const char* get_oper_name(struct Client *client_p)
1070 * Input: A client to find the active oper{} name for.
1071 * Output: The nick!user@host{oper} of the oper.
1072 * "oper" is server name for remote opers
1073 * Side effects: None.
1074 */
1075char *
1076get_oper_name(struct Client *client_p)
1077{
1078 /* +5 for !,@,{,} and null */
1079 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1080
1081 if(MyOper(client_p))
1082 {
38e6acdd 1083 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
212380e3 1084 client_p->name, client_p->username,
1085 client_p->host, client_p->localClient->opername);
1086 return buffer;
1087 }
1088
38e6acdd 1089 rb_snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
212380e3 1090 client_p->name, client_p->username,
1091 client_p->host, client_p->servptr->name);
1092 return buffer;
1093}
1094
1095/*
1096 * get_printable_conf
1097 *
1098 * inputs - struct ConfItem
1099 *
1100 * output - name
1101 * - host
1102 * - pass
1103 * - user
1104 * - port
1105 *
1106 * side effects -
1107 * Examine the struct struct ConfItem, setting the values
1108 * of name, host, pass, user to values either
1109 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1110 */
1111void
1112get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1113 char **pass, char **user, int *port, char **classname)
1114{
1115 static char null[] = "<NULL>";
1116 static char zero[] = "default";
1117
1118 *name = EmptyString(aconf->name) ? null : aconf->name;
1119 *host = EmptyString(aconf->host) ? null : aconf->host;
1120 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1121 *user = EmptyString(aconf->user) ? null : aconf->user;
1122 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1123 *port = (int) aconf->port;
1124}
1125
21c9d815
VY
1126void
1127get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1128 char **host, char **reason,
1129 char **user, char **oper_reason)
1130{
1131 static char null[] = "<NULL>";
1132
1133 *host = EmptyString(aconf->host) ? null : aconf->host;
1134 *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
1135 *user = EmptyString(aconf->user) ? null : aconf->user;
1136
1137 if(EmptyString(aconf->spasswd) || !IsOper(source_p))
1138 *oper_reason = NULL;
1139 else
1140 *oper_reason = aconf->spasswd;
212380e3 1141}
1142
1143/*
1144 * read_conf_files
1145 *
1146 * inputs - cold start YES or NO
1147 * output - none
1148 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1149 */
1150void
1151read_conf_files(int cold)
1152{
1153 const char *filename;
1154
1155 conf_fbfile_in = NULL;
1156
918a0e1d 1157 filename = ConfigFileEntry.configfile;
212380e3 1158
1159 /* We need to know the initial filename for the yyerror() to report
1160 FIXME: The full path is in conffilenamebuf first time since we
1161 dont know anything else
1162
1163 - Gozem 2002-07-21
1164 */
907468c4 1165 rb_strlcpy(conffilebuf, filename, sizeof(conffilebuf));
212380e3 1166
1167 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1168 {
1169 if(cold)
1170 {
1171 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1172 exit(-1);
1173 }
1174 else
1175 {
1176 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1177 "Can't open file '%s' - aborting rehash!", filename);
1178 return;
1179 }
1180 }
1181
1182 if(!cold)
1183 {
1184 clear_out_old_conf();
1185 }
1186
1187 read_conf(conf_fbfile_in);
1188 fclose(conf_fbfile_in);
1189}
1190
8ac75529
WP
1191/*
1192 * free an alias{} entry.
1193 */
1194static void
1195free_alias_cb(struct DictionaryElement *ptr, void *unused)
1196{
1197 struct alias_entry *aptr = ptr->data;
1198
90a3c35b
VY
1199 rb_free(aptr->name);
1200 rb_free(aptr->target);
1201 rb_free(aptr);
8ac75529
WP
1202}
1203
212380e3 1204/*
1205 * clear_out_old_conf
1206 *
1207 * inputs - none
1208 * output - none
1209 * side effects - Clear out the old configuration
1210 */
1211static void
1212clear_out_old_conf(void)
1213{
1214 struct Class *cltmp;
af81d5a0 1215 rb_dlink_node *ptr;
90a3c35b 1216 rb_dlink_node *next_ptr;
212380e3 1217
1218 /*
1219 * don't delete the class table, rather mark all entries
1220 * for deletion. The table is cleaned up by check_class. - avalon
1221 */
8e69bb4e 1222 RB_DLINK_FOREACH(ptr, class_list.head)
212380e3 1223 {
1224 cltmp = ptr->data;
1225 MaxUsers(cltmp) = -1;
1226 }
1227
1228 clear_out_address_conf();
1229 clear_s_newconf();
1230
1231 /* clean out module paths */
1232#ifndef STATIC_MODULES
1233 mod_clear_paths();
1234 mod_add_path(MODULE_DIR);
1235 mod_add_path(MODULE_DIR "/autoload");
1236#endif
1237
1238 /* clean out ServerInfo */
90a3c35b 1239 rb_free(ServerInfo.description);
212380e3 1240 ServerInfo.description = NULL;
90a3c35b 1241 rb_free(ServerInfo.network_name);
212380e3 1242 ServerInfo.network_name = NULL;
90a3c35b 1243 rb_free(ServerInfo.network_desc);
212380e3 1244 ServerInfo.network_desc = NULL;
1245
8db00894
VY
1246 ServerInfo.ssld_count = 1;
1247
212380e3 1248 /* clean out AdminInfo */
90a3c35b 1249 rb_free(AdminInfo.name);
212380e3 1250 AdminInfo.name = NULL;
90a3c35b 1251 rb_free(AdminInfo.email);
212380e3 1252 AdminInfo.email = NULL;
90a3c35b 1253 rb_free(AdminInfo.description);
212380e3 1254 AdminInfo.description = NULL;
1255
1256 /* operator{} and class{} blocks are freed above */
1257 /* clean out listeners */
1258 close_listeners();
1259
1260 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1261 * and gecos{} blocks are freed above too
1262 */
1263
1264 /* clean out general */
4f2b6c0b
JT
1265 rb_free(ConfigFileEntry.kline_reason);
1266 ConfigFileEntry.kline_reason = NULL;
1267
90a3c35b 1268 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
212380e3 1269 {
90a3c35b 1270 rb_free(ptr->data);
af81d5a0 1271 rb_dlinkDestroy(ptr, &service_list);
212380e3 1272 }
1273
1274 /* remove any aliases... -- nenolod */
ba29286a
WP
1275 if (alias_dict != NULL)
1276 {
1277 irc_dictionary_destroy(alias_dict, free_alias_cb, NULL);
1278 alias_dict = NULL;
1279 }
212380e3 1280
1281 destroy_blacklists();
1282
543b8c39
JT
1283 privilegeset_mark_all_illegal();
1284
212380e3 1285 /* OK, that should be everything... */
1286}
1287
1288
212380e3 1289/*
1290 * conf_add_class_to_conf
1291 * inputs - pointer to config item
1292 * output - NONE
1293 * side effects - Add a class pointer to a conf
1294 */
1295
1296void
1297conf_add_class_to_conf(struct ConfItem *aconf)
1298{
1299 if(aconf->className == NULL)
1300 {
62d28946 1301 aconf->className = rb_strdup("default");
212380e3 1302 ClassPtr(aconf) = default_class;
1303 return;
1304 }
1305
1306 ClassPtr(aconf) = find_class(aconf->className);
1307
1308 if(ClassPtr(aconf) == default_class)
1309 {
1310 if(aconf->status == CONF_CLIENT)
1311 {
12c4f819
JT
1312 conf_report_error(
1313 "Using default class for missing class \"%s\" in auth{} for %s@%s",
212380e3 1314 aconf->className, aconf->user, aconf->host);
1315 }
1316
90a3c35b 1317 rb_free(aconf->className);
62d28946 1318 aconf->className = rb_strdup("default");
212380e3 1319 return;
1320 }
1321
1322 if(ConfMaxUsers(aconf) < 0)
1323 {
1324 ClassPtr(aconf) = default_class;
90a3c35b 1325 rb_free(aconf->className);
62d28946 1326 aconf->className = rb_strdup("default");
212380e3 1327 return;
1328 }
1329}
1330
1331/*
1332 * conf_add_d_conf
1333 * inputs - pointer to config item
1334 * output - NONE
1335 * side effects - Add a d/D line
1336 */
1337void
1338conf_add_d_conf(struct ConfItem *aconf)
1339{
1340 if(aconf->host == NULL)
1341 return;
1342
1343 aconf->user = NULL;
1344
1345 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1346 * need this anyway, so I will disable it for now... -A1kmm
1347 */
1348
1349 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1350 {
1351 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1352 free_conf(aconf);
1353 }
1354 else
1355 {
969a1ae6 1356 add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
212380e3 1357 }
1358}
1359
5f4f1d05
VY
1360static char *
1361strip_tabs(char *dest, const char *src, size_t len)
1362{
1363 char *d = dest;
1364
1365 if(dest == NULL || src == NULL)
1366 return NULL;
1367
1368 rb_strlcpy(dest, src, len);
1369
1370 while(*d)
1371 {
1372 if(*d == '\t')
1373 *d = ' ';
1374 d++;
1375 }
1376 return dest;
1377}
212380e3 1378
1379/*
1380 * yyerror
1381 *
1382 * inputs - message from parser
1383 * output - none
1384 * side effects - message to opers and log file entry is made
1385 */
1386void
1387yyerror(const char *msg)
1388{
1389 char newlinebuf[BUFSIZE];
1390
78a47af0 1391 strip_tabs(newlinebuf, linebuf, strlen(linebuf));
212380e3 1392
fe86a70d 1393 ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
212380e3 1394 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",
1395 conffilebuf, lineno + 1, msg, newlinebuf);
1396
212380e3 1397}
1398
1399int
1400conf_fgets(char *lbuf, int max_size, FILE * fb)
1401{
1402 char *buff;
1403
1404 if((buff = fgets(lbuf, max_size, fb)) == NULL)
1405 return (0);
1406
1407 return (strlen(lbuf));
1408}
1409
1410int
1411conf_yy_fatal_error(const char *msg)
1412{
1413 return (0);
1414}