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