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