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