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