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