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