]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_conf.c
[svn] Remove invite_ops_only, forcing it to YES.
[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 *
307328bb 24 * $Id: s_conf.c 3257 2007-03-13 16:09:28Z jilles $
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;
212380e3 833 ConfigChannel.kick_on_split_riding = NO;
834
835 ConfigChannel.default_split_user_count = 15000;
836 ConfigChannel.default_split_server_count = 10;
837 ConfigChannel.no_join_on_split = NO;
838 ConfigChannel.no_create_on_split = YES;
839
840 ConfigServerHide.flatten_links = 0;
841 ConfigServerHide.links_delay = 300;
842 ConfigServerHide.hidden = 0;
843 ConfigServerHide.disable_hidden = 0;
844
845 ConfigFileEntry.min_nonwildcard = 4;
846 ConfigFileEntry.min_nonwildcard_simple = 3;
847 ConfigFileEntry.default_floodcount = 8;
848 ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
849 ConfigFileEntry.tkline_expire_notices = 0;
850
851 ConfigFileEntry.reject_after_count = 5;
852 ConfigFileEntry.reject_ban_time = 300;
853 ConfigFileEntry.reject_duration = 120;
c2d96fcb 854
855 ServerInfo.max_clients = MAXCONNECTIONS;
212380e3 856}
857
858#undef YES
859#undef NO
860
861/*
862 * read_conf()
863 *
864 *
865 * inputs - file descriptor pointing to config file to use
866 * output - None
867 * side effects - Read configuration file.
868 */
869static void
870read_conf(FILE * file)
871{
872 lineno = 0;
873
874 set_default_conf(); /* Set default values prior to conf parsing */
875 yyparse(); /* Load the values from the conf */
876 validate_conf(); /* Check to make sure some values are still okay. */
877 /* Some global values are also loaded here. */
878 check_class(); /* Make sure classes are valid */
879}
880
881static void
882validate_conf(void)
883{
884 if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
885 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
886
887 if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
888 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
889
890 if(ConfigFileEntry.servlink_path == NULL)
891 DupString(ConfigFileEntry.servlink_path, SLPATH);
892
893 if(ServerInfo.network_name == NULL)
894 DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
895
896 if(ServerInfo.network_desc == NULL)
897 DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
898
899 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
900 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
901 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
902
903 GlobalSetOptions.idletime = (ConfigFileEntry.idletime * 60);
904
905 if(!split_users || !split_servers ||
906 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
907 {
908 eventDelete(check_splitmode, NULL);
909 splitmode = 0;
910 splitchecking = 0;
911 }
912}
913
914/*
915 * lookup_confhost - start DNS lookups of all hostnames in the conf
916 * line and convert an IP addresses in a.b.c.d number for to IP#s.
917 *
918 */
919
920/*
921 * conf_connect_allowed
922 *
923 * inputs - pointer to inaddr
924 * - int type ipv4 or ipv6
925 * output - ban info or NULL
926 * side effects - none
927 */
928struct ConfItem *
929conf_connect_allowed(struct sockaddr *addr, int aftype)
930{
931 struct ConfItem *aconf = find_dline(addr, aftype);
932
933 /* DLINE exempt also gets you out of static limits/pacing... */
934 if(aconf && (aconf->status & CONF_EXEMPTDLINE))
935 return NULL;
936
937 if(aconf != NULL)
938 return aconf;
939
940 return NULL;
941}
942
943/* add_temp_kline()
944 *
945 * inputs - pointer to struct ConfItem
946 * output - none
947 * Side effects - links in given struct ConfItem into
948 * temporary kline link list
949 */
950void
951add_temp_kline(struct ConfItem *aconf)
952{
953 if(aconf->hold >= CurrentTime + (10080 * 60))
954 {
955 dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
956 aconf->port = TEMP_WEEK;
957 }
958 else if(aconf->hold >= CurrentTime + (1440 * 60))
959 {
960 dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
961 aconf->port = TEMP_DAY;
962 }
963 else if(aconf->hold >= CurrentTime + (60 * 60))
964 {
965 dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
966 aconf->port = TEMP_HOUR;
967 }
968 else
969 {
970 dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
971 aconf->port = TEMP_MIN;
972 }
973
974 aconf->flags |= CONF_FLAGS_TEMPORARY;
975 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf);
976}
977
978/* add_temp_dline()
979 *
980 * input - pointer to struct ConfItem
981 * output - none
982 * side effects - added to tdline link list and address hash
983 */
984void
985add_temp_dline(struct ConfItem *aconf)
986{
987 if(aconf->hold >= CurrentTime + (10080 * 60))
988 {
989 dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
990 aconf->port = TEMP_WEEK;
991 }
992 else if(aconf->hold >= CurrentTime + (1440 * 60))
993 {
994 dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
995 aconf->port = TEMP_DAY;
996 }
997 else if(aconf->hold >= CurrentTime + (60 * 60))
998 {
999 dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
1000 aconf->port = TEMP_HOUR;
1001 }
1002 else
1003 {
1004 dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
1005 aconf->port = TEMP_MIN;
1006 }
1007
1008 aconf->flags |= CONF_FLAGS_TEMPORARY;
1009 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, aconf);
1010}
1011
1012/* expire_tkline()
1013 *
1014 * inputs - list pointer
1015 * - type
1016 * output - NONE
1017 * side effects - expire tklines and moves them between lists
1018 */
1019static void
1020expire_temp_kd(void *list)
1021{
1022 dlink_node *ptr;
1023 dlink_node *next_ptr;
1024 struct ConfItem *aconf;
1025
1026 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1027 {
1028 aconf = ptr->data;
1029
1030 if(aconf->hold <= CurrentTime)
1031 {
1032 /* Alert opers that a TKline expired - Hwy */
1033 if(ConfigFileEntry.tkline_expire_notices)
1034 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1035 "Temporary K-line for [%s@%s] expired",
1036 (aconf->user) ? aconf->
1037 user : "*", (aconf->host) ? aconf->host : "*");
1038
1039 delete_one_address_conf(aconf->host, aconf);
1040 dlinkDestroy(ptr, list);
1041 }
1042 }
1043}
1044
1045static void
1046reorganise_temp_kd(void *list)
1047{
1048 struct ConfItem *aconf;
1049 dlink_node *ptr, *next_ptr;
1050
1051 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1052 {
1053 aconf = ptr->data;
1054
1055 if(aconf->hold < (CurrentTime + (60 * 60)))
1056 {
1057 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1058 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1059 aconf->port = TEMP_MIN;
1060 }
1061 else if(aconf->port > TEMP_HOUR)
1062 {
1063 if(aconf->hold < (CurrentTime + (1440 * 60)))
1064 {
1065 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1066 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1067 aconf->port = TEMP_HOUR;
1068 }
1069 else if(aconf->port > TEMP_DAY &&
1070 (aconf->hold < (CurrentTime + (10080 * 60))))
1071 {
1072 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1073 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1074 aconf->port = TEMP_DAY;
1075 }
1076 }
1077 }
1078}
1079
1080
1081/* const char* get_oper_name(struct Client *client_p)
1082 * Input: A client to find the active oper{} name for.
1083 * Output: The nick!user@host{oper} of the oper.
1084 * "oper" is server name for remote opers
1085 * Side effects: None.
1086 */
1087char *
1088get_oper_name(struct Client *client_p)
1089{
1090 /* +5 for !,@,{,} and null */
1091 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1092
1093 if(MyOper(client_p))
1094 {
1095 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1096 client_p->name, client_p->username,
1097 client_p->host, client_p->localClient->opername);
1098 return buffer;
1099 }
1100
1101 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1102 client_p->name, client_p->username,
1103 client_p->host, client_p->servptr->name);
1104 return buffer;
1105}
1106
1107/*
1108 * get_printable_conf
1109 *
1110 * inputs - struct ConfItem
1111 *
1112 * output - name
1113 * - host
1114 * - pass
1115 * - user
1116 * - port
1117 *
1118 * side effects -
1119 * Examine the struct struct ConfItem, setting the values
1120 * of name, host, pass, user to values either
1121 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1122 */
1123void
1124get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1125 char **pass, char **user, int *port, char **classname)
1126{
1127 static char null[] = "<NULL>";
1128 static char zero[] = "default";
1129
1130 *name = EmptyString(aconf->name) ? null : aconf->name;
1131 *host = EmptyString(aconf->host) ? null : aconf->host;
1132 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1133 *user = EmptyString(aconf->user) ? null : aconf->user;
1134 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1135 *port = (int) aconf->port;
1136}
1137
1138void
1139get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1140 char **host, char **reason,
1141 char **user, char **oper_reason)
1142{
1143 static char null[] = "<NULL>";
1144
1145 *host = EmptyString(aconf->host) ? null : aconf->host;
1146 *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
1147 *user = EmptyString(aconf->user) ? null : aconf->user;
1148
1149 if(EmptyString(aconf->spasswd) || !IsOper(source_p))
1150 *oper_reason = NULL;
1151 else
1152 *oper_reason = aconf->spasswd;
1153}
1154
1155/*
1156 * read_conf_files
1157 *
1158 * inputs - cold start YES or NO
1159 * output - none
1160 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1161 */
1162void
1163read_conf_files(int cold)
1164{
1165 const char *filename;
1166
1167 conf_fbfile_in = NULL;
1168
1169 filename = get_conf_name(CONF_TYPE);
1170
1171 /* We need to know the initial filename for the yyerror() to report
1172 FIXME: The full path is in conffilenamebuf first time since we
1173 dont know anything else
1174
1175 - Gozem 2002-07-21
1176 */
1177 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1178
1179 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1180 {
1181 if(cold)
1182 {
1183 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1184 exit(-1);
1185 }
1186 else
1187 {
1188 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1189 "Can't open file '%s' - aborting rehash!", filename);
1190 return;
1191 }
1192 }
1193
1194 if(!cold)
1195 {
1196 clear_out_old_conf();
1197 }
1198
1199 read_conf(conf_fbfile_in);
1200 fclose(conf_fbfile_in);
1201}
1202
1203/*
1204 * clear_out_old_conf
1205 *
1206 * inputs - none
1207 * output - none
1208 * side effects - Clear out the old configuration
1209 */
1210static void
1211clear_out_old_conf(void)
1212{
1213 struct Class *cltmp;
1214 dlink_node *ptr;
1215 dlink_node *next_ptr;
1216 int i;
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 */
1222 DLINK_FOREACH(ptr, class_list.head)
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 */
1239 MyFree(ServerInfo.description);
1240 ServerInfo.description = NULL;
1241 MyFree(ServerInfo.network_name);
1242 ServerInfo.network_name = NULL;
1243 MyFree(ServerInfo.network_desc);
1244 ServerInfo.network_desc = NULL;
1245
1246 /* clean out AdminInfo */
1247 MyFree(AdminInfo.name);
1248 AdminInfo.name = NULL;
1249 MyFree(AdminInfo.email);
1250 AdminInfo.email = NULL;
1251 MyFree(AdminInfo.description);
1252 AdminInfo.description = NULL;
1253
1254 /* operator{} and class{} blocks are freed above */
1255 /* clean out listeners */
1256 close_listeners();
1257
1258 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1259 * and gecos{} blocks are freed above too
1260 */
1261
1262 /* clean out general */
1263 MyFree(ConfigFileEntry.servlink_path);
1264 ConfigFileEntry.servlink_path = NULL;
1265
1266 DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
1267 {
1268 MyFree(ptr->data);
1269 dlinkDestroy(ptr, &service_list);
1270 }
1271
1272 /* remove any aliases... -- nenolod */
1273 for (i = 0; i < MAX_MSG_HASH; i++)
1274 {
1275 DLINK_FOREACH_SAFE(ptr, next_ptr, alias_hash_table[i].head)
1276 {
1277 struct alias_entry *aptr = ptr->data;
1278
1279 MyFree(aptr->name);
1280 MyFree(aptr->target);
1281 MyFree(aptr);
1282
1283 dlinkDestroy(ptr, &alias_hash_table[i]);
1284 }
1285 }
1286
1287 destroy_blacklists();
1288
1289 /* OK, that should be everything... */
1290}
1291
1292
1293/* write_confitem()
1294 *
1295 * inputs - kline, dline or resv type flag
1296 * - client pointer to report to
1297 * - user name of target
1298 * - host name of target
1299 * - reason for target
1300 * - time string
1301 * - type of xline
1302 * output - NONE
1303 * side effects - This function takes care of finding the right conf
1304 * file and adding the line to it, as well as notifying
1305 * opers and the user.
1306 */
1307void
1308write_confitem(KlineType type, struct Client *source_p, char *user,
1309 char *host, const char *reason, const char *oper_reason,
1310 const char *current_date, int xtype)
1311{
1312 char buffer[1024];
1313 FILE *out;
1314 const char *filename; /* filename to use for kline */
1315
1316 filename = get_conf_name(type);
1317
1318 if(type == KLINE_TYPE)
1319 {
1320 if(EmptyString(oper_reason))
1321 {
1322 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1323 "%s added K-Line for [%s@%s] [%s]",
1324 get_oper_name(source_p), user,
1325 host, reason);
1326 ilog(L_KLINE, "K %s 0 %s %s %s",
1327 get_oper_name(source_p), user, host, reason);
1328 }
1329 else
1330 {
1331 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1332 "%s added K-Line for [%s@%s] [%s|%s]",
1333 get_oper_name(source_p), user,
1334 host, reason, oper_reason);
1335 ilog(L_KLINE, "K %s 0 %s %s %s|%s",
1336 get_oper_name(source_p), user, host,
1337 reason, oper_reason);
1338 }
1339
1340 sendto_one_notice(source_p, ":Added K-Line [%s@%s]",
1341 user, host);
1342 }
1343 else if(type == DLINE_TYPE)
1344 {
1345 if(EmptyString(oper_reason))
1346 {
1347 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1348 "%s added D-Line for [%s] [%s]",
1349 get_oper_name(source_p), host, reason);
1350 ilog(L_KLINE, "D %s 0 %s %s",
1351 get_oper_name(source_p), host, reason);
1352 }
1353 else
1354 {
1355 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1356 "%s added D-Line for [%s] [%s|%s]",
1357 get_oper_name(source_p), host,
1358 reason, oper_reason);
1359 ilog(L_KLINE, "D %s 0 %s %s|%s",
1360 get_oper_name(source_p), host,
1361 reason, oper_reason);
1362 }
1363
5366977b 1364 sendto_one_notice(source_p, ":Added D-Line [%s] to %s", host, filename);
212380e3 1365
1366 }
1367 else if(type == RESV_TYPE)
1368 {
1369 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1370 "%s added RESV for [%s] [%s]",
1371 get_oper_name(source_p), host, reason);
1372 ilog(L_KLINE, "R %s 0 %s %s",
1373 get_oper_name(source_p), host, reason);
1374
1375 sendto_one_notice(source_p, ":Added RESV for [%s] [%s]",
1376 host, reason);
1377 }
1378
1379 if((out = fopen(filename, "a")) == NULL)
1380 {
1381 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename);
1382 sendto_one_notice(source_p, ":*** Problem opening file, added temporarily only");
1383 return;
1384 }
1385
1386 if(oper_reason == NULL)
1387 oper_reason = "";
1388
1389 if(type == KLINE_TYPE)
1390 {
1391 ircsnprintf(buffer, sizeof(buffer),
1392 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1393 user, host, reason, oper_reason, current_date,
1394 get_oper_name(source_p), CurrentTime);
1395 }
1396 else if(type == DLINE_TYPE)
1397 {
1398 ircsnprintf(buffer, sizeof(buffer),
1399 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host,
1400 reason, oper_reason, current_date, get_oper_name(source_p), CurrentTime);
1401 }
1402 else if(type == RESV_TYPE)
1403 {
1404 ircsnprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n",
1405 host, reason, get_oper_name(source_p), CurrentTime);
1406 }
1407
1408 if(fputs(buffer, out) == -1)
1409 {
1410 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1411 sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only");
1412 fclose(out);
1413 return;
1414 }
1415
1416 if (fclose(out))
1417 {
1418 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1419 sendto_one_notice(source_p, ":*** Problem writing to file, added temporarily only");
1420 return;
1421 }
1422}
1423
1424/* get_conf_name
1425 *
1426 * inputs - type of conf file to return name of file for
1427 * output - pointer to filename for type of conf
1428 * side effects - none
1429 */
1430const char *
1431get_conf_name(KlineType type)
1432{
1433 if(type == CONF_TYPE)
1434 {
1435 return (ConfigFileEntry.configfile);
1436 }
1437 else if(type == DLINE_TYPE)
1438 {
1439 return (ConfigFileEntry.dlinefile);
1440 }
1441 else if(type == RESV_TYPE)
1442 {
1443 return (ConfigFileEntry.resvfile);
1444 }
1445
1446 return ConfigFileEntry.klinefile;
1447}
1448
1449/*
1450 * conf_add_class_to_conf
1451 * inputs - pointer to config item
1452 * output - NONE
1453 * side effects - Add a class pointer to a conf
1454 */
1455
1456void
1457conf_add_class_to_conf(struct ConfItem *aconf)
1458{
1459 if(aconf->className == NULL)
1460 {
1461 DupString(aconf->className, "default");
1462 ClassPtr(aconf) = default_class;
1463 return;
1464 }
1465
1466 ClassPtr(aconf) = find_class(aconf->className);
1467
1468 if(ClassPtr(aconf) == default_class)
1469 {
1470 if(aconf->status == CONF_CLIENT)
1471 {
1472 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1473 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1474 aconf->className, aconf->user, aconf->host);
1475 }
1476
1477 MyFree(aconf->className);
1478 DupString(aconf->className, "default");
1479 return;
1480 }
1481
1482 if(ConfMaxUsers(aconf) < 0)
1483 {
1484 ClassPtr(aconf) = default_class;
1485 MyFree(aconf->className);
1486 DupString(aconf->className, "default");
1487 return;
1488 }
1489}
1490
1491/*
1492 * conf_add_d_conf
1493 * inputs - pointer to config item
1494 * output - NONE
1495 * side effects - Add a d/D line
1496 */
1497void
1498conf_add_d_conf(struct ConfItem *aconf)
1499{
1500 if(aconf->host == NULL)
1501 return;
1502
1503 aconf->user = NULL;
1504
1505 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1506 * need this anyway, so I will disable it for now... -A1kmm
1507 */
1508
1509 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1510 {
1511 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1512 free_conf(aconf);
1513 }
1514 else
1515 {
1516 add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf);
1517 }
1518}
1519
1520
1521/*
1522 * yyerror
1523 *
1524 * inputs - message from parser
1525 * output - none
1526 * side effects - message to opers and log file entry is made
1527 */
1528void
1529yyerror(const char *msg)
1530{
1531 char newlinebuf[BUFSIZE];
1532
1533 strip_tabs(newlinebuf, (const unsigned char *) linebuf, strlen(linebuf));
1534
1535 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",
1536 conffilebuf, lineno + 1, msg, newlinebuf);
1537
1538 ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
1539}
1540
1541int
1542conf_fgets(char *lbuf, int max_size, FILE * fb)
1543{
1544 char *buff;
1545
1546 if((buff = fgets(lbuf, max_size, fb)) == NULL)
1547 return (0);
1548
1549 return (strlen(lbuf));
1550}
1551
1552int
1553conf_yy_fatal_error(const char *msg)
1554{
1555 return (0);
1556}