Import from http://svn.freenode.net/ircd-seven/private/beu/seven (r196).
[seven-1.x.git] / src / s_conf.c
blob4462f26a91876ecd8b1e1b218bfcb94059ad1fa4
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * s_conf.c: Configuration file functions.
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
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.
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.
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
24 * $Id: s_conf.c 195 2006-12-19 01:11:35Z beu $
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 "memory.h"
51 #include "balloc.h"
52 #include "patricia.h"
53 #include "reject.h"
54 #include "cache.h"
55 #include "blacklist.h"
57 struct config_server_hide ConfigServerHide;
59 extern int yyparse(); /* defined in y.tab.c */
60 extern char linebuf[];
62 #ifndef INADDR_NONE
63 #define INADDR_NONE ((unsigned int) 0xffffffff)
64 #endif
66 static BlockHeap *confitem_heap = NULL;
68 dlink_list temp_klines[LAST_TEMP_TYPE];
69 dlink_list temp_dlines[LAST_TEMP_TYPE];
70 dlink_list service_list;
72 /* internally defined functions */
73 static void set_default_conf(void);
74 static void validate_conf(void);
75 static void read_conf(FILE *);
76 static void clear_out_old_conf(void);
78 static void expire_temp_kd(void *list);
79 static void reorganise_temp_kd(void *list);
81 FILE *conf_fbfile_in;
82 extern char yytext[];
84 static int verify_access(struct Client *client_p, const char *username);
85 static int attach_iline(struct Client *, struct ConfItem *);
87 void
88 init_s_conf(void)
90 confitem_heap = BlockHeapCreate(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE);
92 eventAddIsh("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60);
93 eventAddIsh("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60);
95 eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd,
96 &temp_klines[TEMP_HOUR], 3600);
97 eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd,
98 &temp_dlines[TEMP_HOUR], 3600);
99 eventAddIsh("expire_temp_klines_day", reorganise_temp_kd,
100 &temp_klines[TEMP_DAY], 86400);
101 eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd,
102 &temp_dlines[TEMP_DAY], 86400);
103 eventAddIsh("expire_temp_klines_week", reorganise_temp_kd,
104 &temp_klines[TEMP_WEEK], 604800);
105 eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd,
106 &temp_dlines[TEMP_WEEK], 604800);
110 * make_conf
112 * inputs - none
113 * output - pointer to new conf entry
114 * side effects - none
116 struct ConfItem *
117 make_conf()
119 struct ConfItem *aconf;
121 aconf = BlockHeapAlloc(confitem_heap);
122 aconf->status = CONF_ILLEGAL;
123 return (aconf);
127 * free_conf
129 * inputs - pointer to conf to free
130 * output - none
131 * side effects - crucial password fields are zeroed, conf is freed
133 void
134 free_conf(struct ConfItem *aconf)
136 s_assert(aconf != NULL);
137 if(aconf == NULL)
138 return;
140 /* security.. */
141 if(aconf->passwd)
142 memset(aconf->passwd, 0, strlen(aconf->passwd));
143 if(aconf->spasswd)
144 memset(aconf->spasswd, 0, strlen(aconf->spasswd));
146 MyFree(aconf->passwd);
147 MyFree(aconf->spasswd);
148 MyFree(aconf->name);
149 MyFree(aconf->className);
150 MyFree(aconf->user);
151 MyFree(aconf->host);
153 BlockHeapFree(confitem_heap, aconf);
157 * check_client
159 * inputs - pointer to client
160 * output - 0 = Success
161 * NOT_AUTHORISED (-1) = Access denied (no I line match)
162 * SOCKET_ERROR (-2) = Bad socket.
163 * I_LINE_FULL (-3) = I-line is full
164 * TOO_MANY (-4) = Too many connections from hostname
165 * BANNED_CLIENT (-5) = K-lined
166 * side effects - Ordinary client access check.
167 * Look for conf lines which have the same
168 * status as the flags passed.
171 check_client(struct Client *client_p, struct Client *source_p, const char *username)
173 int i;
175 ClearAccess(source_p);
177 if((i = verify_access(source_p, username)))
179 ilog(L_FUSER, "Access denied: %s[%s]",
180 source_p->name, source_p->sockhost);
183 switch (i)
185 case SOCKET_ERROR:
186 exit_client(client_p, source_p, &me, "Socket Error");
187 break;
189 case TOO_MANY_LOCAL:
190 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
191 "Too many local connections for %s!%s%s@%s",
192 source_p->name, IsGotId(source_p) ? "" : "~",
193 source_p->username, source_p->sockhost);
195 ilog(L_FUSER, "Too many local connections from %s!%s%s@%s",
196 source_p->name, IsGotId(source_p) ? "" : "~",
197 source_p->username, source_p->sockhost);
199 ServerStats->is_ref++;
200 exit_client(client_p, source_p, &me, "Too many host connections (local)");
201 break;
203 case TOO_MANY_GLOBAL:
204 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
205 "Too many global connections for %s!%s%s@%s",
206 source_p->name, IsGotId(source_p) ? "" : "~",
207 source_p->username, source_p->sockhost);
208 ilog(L_FUSER, "Too many global connections from %s!%s%s@%s",
209 source_p->name, IsGotId(source_p) ? "" : "~",
210 source_p->username, source_p->sockhost);
212 ServerStats->is_ref++;
213 exit_client(client_p, source_p, &me, "Too many host connections (global)");
214 break;
216 case TOO_MANY_IDENT:
217 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
218 "Too many user connections for %s!%s%s@%s",
219 source_p->name, IsGotId(source_p) ? "" : "~",
220 source_p->username, source_p->sockhost);
221 ilog(L_FUSER, "Too many user connections from %s!%s%s@%s",
222 source_p->name, IsGotId(source_p) ? "" : "~",
223 source_p->username, source_p->sockhost);
225 ServerStats->is_ref++;
226 exit_client(client_p, source_p, &me, "Too many user connections (global)");
227 break;
229 case I_LINE_FULL:
230 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
231 "I-line is full for %s!%s%s@%s (%s).",
232 source_p->name, IsGotId(source_p) ? "" : "~",
233 source_p->username, source_p->host,
234 source_p->sockhost);
236 ilog(L_FUSER, "Too many connections from %s!%s%s@%s.",
237 source_p->name, IsGotId(source_p) ? "" : "~",
238 source_p->username, source_p->sockhost);
240 ServerStats->is_ref++;
241 exit_client(client_p, source_p, &me,
242 "No more connections allowed in your connection class");
243 break;
245 case NOT_AUTHORISED:
247 int port = -1;
248 #ifdef IPV6
249 if(source_p->localClient->ip.ss_family == AF_INET6)
250 port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port);
251 else
252 #endif
253 port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port);
255 ServerStats->is_ref++;
256 /* jdc - lists server name & port connections are on */
257 /* a purely cosmetical change */
258 /* why ipaddr, and not just source_p->sockhost? --fl */
259 #if 0
260 static char ipaddr[HOSTIPLEN];
261 inetntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
262 #endif
263 sendto_realops_snomask(SNO_UNAUTH, L_NETWIDE,
264 "Unauthorised client connection from "
265 "%s!%s%s@%s [%s] on [%s/%u].",
266 source_p->name, IsGotId(source_p) ? "" : "~",
267 source_p->username, source_p->host,
268 source_p->sockhost,
269 source_p->localClient->listener->name, port);
271 ilog(L_FUSER,
272 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
273 source_p->name, IsGotId(source_p) ? "" : "~",
274 source_p->username, source_p->sockhost,
275 source_p->localClient->listener->name, port);
276 add_reject(client_p);
277 exit_client(client_p, source_p, &me,
278 "You are not authorised to use this server");
279 break;
281 case BANNED_CLIENT:
282 add_reject(client_p);
283 exit_client(client_p, client_p, &me, "*** Banned ");
284 ServerStats->is_ref++;
285 break;
287 case 0:
288 default:
289 break;
291 return (i);
295 * verify_access
297 * inputs - pointer to client to verify
298 * - pointer to proposed username
299 * output - 0 if success -'ve if not
300 * side effect - find the first (best) I line to attach.
302 static int
303 verify_access(struct Client *client_p, const char *username)
305 struct ConfItem *aconf;
306 char non_ident[USERLEN + 1];
308 if(IsGotId(client_p))
310 aconf = find_address_conf(client_p->host, client_p->sockhost,
311 client_p->username,
312 (struct sockaddr *) &client_p->localClient->ip,
313 client_p->localClient->ip.ss_family);
315 else
317 strlcpy(non_ident, "~", sizeof(non_ident));
318 strlcat(non_ident, username, sizeof(non_ident));
319 aconf = find_address_conf(client_p->host, client_p->sockhost,
320 non_ident,
321 (struct sockaddr *) &client_p->localClient->ip,
322 client_p->localClient->ip.ss_family);
325 if(aconf == NULL)
326 return NOT_AUTHORISED;
328 if(aconf->status & CONF_CLIENT)
330 if(aconf->flags & CONF_FLAGS_REDIR)
332 sendto_one(client_p, form_str(RPL_REDIR),
333 me.name, client_p->name,
334 aconf->name ? aconf->name : "", aconf->port);
335 return (NOT_AUTHORISED);
339 if(IsConfDoIdentd(aconf))
340 SetNeedId(client_p);
342 /* Thanks for spoof idea amm */
343 if(IsConfDoSpoofIp(aconf))
345 char *p;
347 /* show_ip() depends on this --fl */
348 SetIPSpoof(client_p);
350 if(IsConfSpoofNotice(aconf))
352 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
353 "%s spoofing: %s as %s",
354 client_p->name,
355 show_ip(NULL, client_p) ? client_p->host : aconf->name,
356 aconf->name);
359 /* user@host spoof */
360 if((p = strchr(aconf->name, '@')) != NULL)
362 char *host = p+1;
363 *p = '\0';
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 = '@';
371 else
372 strlcpy(client_p->host, aconf->name, sizeof(client_p->host));
374 return (attach_iline(client_p, aconf));
376 else if(aconf->status & CONF_KILL)
378 if(ConfigFileEntry.kline_with_reason)
380 sendto_one(client_p,
381 ":%s NOTICE %s :*** Banned %s",
382 me.name, client_p->name, aconf->passwd);
384 return (BANNED_CLIENT);
387 return NOT_AUTHORISED;
392 * add_ip_limit
394 * Returns 1 if successful 0 if not
396 * This checks if the user has exceed the limits for their class
397 * unless of course they are exempt..
400 static int
401 add_ip_limit(struct Client *client_p, struct ConfItem *aconf)
403 patricia_node_t *pnode;
405 /* If the limits are 0 don't do anything.. */
406 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
407 return -1;
409 pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
411 if(pnode == NULL)
412 pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, ConfCidrBitlen(aconf));
414 s_assert(pnode != NULL);
416 if(pnode != NULL)
418 if(((long) pnode->data) >= ConfCidrAmount(aconf)
419 && !IsConfExemptLimits(aconf))
421 /* This should only happen if the limits are set to 0 */
422 if((unsigned long) pnode->data == 0)
424 patricia_remove(ConfIpLimits(aconf), pnode);
426 return (0);
429 pnode->data++;
431 return 1;
434 static void
435 remove_ip_limit(struct Client *client_p, struct ConfItem *aconf)
437 patricia_node_t *pnode;
439 /* If the limits are 0 don't do anything.. */
440 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
441 return;
443 pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
444 if(pnode == NULL)
445 return;
447 pnode->data--;
448 if(((unsigned long) pnode->data) == 0)
450 patricia_remove(ConfIpLimits(aconf), pnode);
456 * attach_iline
458 * inputs - client pointer
459 * - conf pointer
460 * output -
461 * side effects - do actual attach
463 static int
464 attach_iline(struct Client *client_p, struct ConfItem *aconf)
466 struct Client *target_p;
467 dlink_node *ptr;
468 int local_count = 0;
469 int global_count = 0;
470 int ident_count = 0;
471 int unidented = 0;
473 if(IsConfExemptLimits(aconf))
474 return (attach_conf(client_p, aconf));
476 if(*client_p->username == '~')
477 unidented = 1;
480 /* find_hostname() returns the head of the list to search */
481 DLINK_FOREACH(ptr, find_hostname(client_p->host))
483 target_p = ptr->data;
485 if(irccmp(client_p->host, target_p->orighost) != 0)
486 continue;
488 if(MyConnect(target_p))
489 local_count++;
491 global_count++;
493 if(unidented)
495 if(*target_p->username == '~')
496 ident_count++;
498 else if(irccmp(target_p->username, client_p->username) == 0)
499 ident_count++;
501 if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf))
502 return (TOO_MANY_LOCAL);
503 else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf))
504 return (TOO_MANY_GLOBAL);
505 else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf))
506 return (TOO_MANY_IDENT);
510 return (attach_conf(client_p, aconf));
514 * detach_conf
516 * inputs - pointer to client to detach
517 * output - 0 for success, -1 for failure
518 * side effects - Disassociate configuration from the client.
519 * Also removes a class from the list if marked for deleting.
522 detach_conf(struct Client *client_p)
524 struct ConfItem *aconf;
526 aconf = client_p->localClient->att_conf;
528 if(aconf != NULL)
530 if(ClassPtr(aconf))
532 remove_ip_limit(client_p, aconf);
534 if(ConfCurrUsers(aconf) > 0)
535 --ConfCurrUsers(aconf);
537 if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0)
539 free_class(ClassPtr(aconf));
540 ClassPtr(aconf) = NULL;
545 aconf->clients--;
546 if(!aconf->clients && IsIllegal(aconf))
547 free_conf(aconf);
549 client_p->localClient->att_conf = NULL;
550 return 0;
553 return -1;
557 * attach_conf
559 * inputs - client pointer
560 * - conf pointer
561 * output -
562 * side effects - Associate a specific configuration entry to a *local*
563 * client (this is the one which used in accepting the
564 * connection). Note, that this automatically changes the
565 * attachment if there was an old one...
568 attach_conf(struct Client *client_p, struct ConfItem *aconf)
570 if(IsIllegal(aconf))
571 return (NOT_AUTHORISED);
573 if(ClassPtr(aconf))
575 if(!add_ip_limit(client_p, aconf))
576 return (TOO_MANY_LOCAL);
579 if((aconf->status & CONF_CLIENT) &&
580 ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0)
582 if(!IsConfExemptLimits(aconf))
584 return (I_LINE_FULL);
586 else
588 sendto_one(client_p, ":%s NOTICE %s :*** I: line is full, but you have an >I: line!",
589 me.name, client_p->name);
590 SetExemptLimits(client_p);
595 if(client_p->localClient->att_conf != NULL)
596 detach_conf(client_p);
598 client_p->localClient->att_conf = aconf;
600 aconf->clients++;
601 ConfCurrUsers(aconf)++;
602 return (0);
606 * rehash
608 * Actual REHASH service routine. Called with sig == 0 if it has been called
609 * as a result of an operator issuing this command, else assume it has been
610 * called as a result of the server receiving a HUP signal.
613 rehash(int sig)
615 if(sig != 0)
617 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
618 "Got signal SIGHUP, reloading ircd conf. file");
621 restart_resolver();
622 /* don't close listeners until we know we can go ahead with the rehash */
623 read_conf_files(NO);
625 if(ServerInfo.description != NULL)
626 strlcpy(me.info, ServerInfo.description, sizeof(me.info));
627 else
628 strlcpy(me.info, "unknown", sizeof(me.info));
630 open_logfiles();
631 return (0);
634 static struct banconf_entry
636 const char **filename;
637 void (*func) (FILE *);
638 int perm;
639 } banconfs[] = {
640 { &ConfigFileEntry.klinefile, parse_k_file, 0 },
641 { &ConfigFileEntry.klinefile, parse_k_file, 1 },
642 { &ConfigFileEntry.dlinefile, parse_d_file, 0 },
643 { &ConfigFileEntry.dlinefile, parse_d_file, 1 },
644 { &ConfigFileEntry.xlinefile, parse_x_file, 0 },
645 { &ConfigFileEntry.xlinefile, parse_x_file, 1 },
646 { &ConfigFileEntry.resvfile, parse_resv_file,0 },
647 { &ConfigFileEntry.resvfile, parse_resv_file,1 },
648 { NULL, NULL, 0 }
651 void
652 rehash_bans(int sig)
654 FILE *file;
655 char buf[MAXPATHLEN];
656 int i;
658 if(sig != 0)
659 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
660 "Got signal SIGUSR2, reloading ban confs");
662 clear_out_address_conf_bans();
663 clear_s_newconf_bans();
665 for(i = 0; banconfs[i].filename; i++)
667 if(banconfs[i].perm)
668 snprintf(buf, sizeof(buf), "%s.perm", *banconfs[i].filename);
669 else
670 snprintf(buf, sizeof(buf), "%s", *banconfs[i].filename);
672 if((file = fopen(buf, "r")) == NULL)
674 if(banconfs[i].perm)
675 continue;
677 ilog(L_MAIN, "Failed reading ban file %s",
678 *banconfs[i].filename);
679 sendto_realops_snomask(SNO_GENERAL, L_ALL,
680 "Can't open %s file bans could be missing!",
681 *banconfs[i].filename);
683 else
685 (banconfs[i].func)(file);
686 fclose(file);
690 check_banned_lines();
694 * set_default_conf()
696 * inputs - NONE
697 * output - NONE
698 * side effects - Set default values here.
699 * This is called **PRIOR** to parsing the
700 * configuration file. If you want to do some validation
701 * of values later, put them in validate_conf().
704 #define YES 1
705 #define NO 0
706 #define UNSET -1
708 static void
709 set_default_conf(void)
711 /* ServerInfo.name is not rehashable */
712 /* ServerInfo.name = ServerInfo.name; */
713 ServerInfo.description = NULL;
714 DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
715 DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
717 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
718 ServerInfo.specific_ipv4_vhost = 0;
719 #ifdef IPV6
720 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
721 ServerInfo.specific_ipv6_vhost = 0;
722 #endif
723 ServerInfo.use_ts6 = YES;
725 /* Don't reset hub, as that will break lazylinks */
726 /* ServerInfo.hub = NO; */
727 AdminInfo.name = NULL;
728 AdminInfo.email = NULL;
729 AdminInfo.description = NULL;
731 DupString(ConfigFileEntry.default_operstring, "is an IRC operator");
732 DupString(ConfigFileEntry.default_adminstring, "is a Server Administrator");
733 DupString(ConfigFileEntry.servicestring, "is a Network Service");
735 ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
736 ConfigFileEntry.failed_oper_notice = YES;
737 ConfigFileEntry.anti_nick_flood = NO;
738 ConfigFileEntry.disable_fake_channels = NO;
739 ConfigFileEntry.max_nick_time = 20;
740 ConfigFileEntry.max_nick_changes = 5;
741 ConfigFileEntry.max_accept = 20;
742 ConfigFileEntry.max_monitor = 60;
743 ConfigFileEntry.nick_delay = 900; /* 15 minutes */
744 ConfigFileEntry.target_change = YES;
745 ConfigFileEntry.anti_spam_exit_message_time = 0;
746 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
747 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
748 ConfigFileEntry.client_exit = YES;
749 ConfigFileEntry.dline_with_reason = YES;
750 ConfigFileEntry.kline_with_reason = YES;
751 ConfigFileEntry.kline_delay = 0;
752 ConfigFileEntry.warn_no_nline = YES;
753 ConfigFileEntry.non_redundant_klines = YES;
754 ConfigFileEntry.stats_e_disabled = NO;
755 ConfigFileEntry.stats_o_oper_only = NO;
756 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
757 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
758 ConfigFileEntry.stats_P_oper_only = NO;
759 ConfigFileEntry.stats_c_oper_only = NO;
760 ConfigFileEntry.stats_y_oper_only = NO;
761 ConfigFileEntry.stats_h_oper_only = NO;
762 ConfigFileEntry.map_oper_only = YES;
763 ConfigFileEntry.pace_wait = 10;
764 ConfigFileEntry.caller_id_wait = 60;
765 ConfigFileEntry.pace_wait_simple = 1;
766 ConfigFileEntry.short_motd = NO;
767 ConfigFileEntry.no_oper_flood = NO;
768 ConfigFileEntry.fname_userlog = NULL;
769 ConfigFileEntry.fname_fuserlog = NULL;
770 ConfigFileEntry.fname_operlog = NULL;
771 ConfigFileEntry.fname_foperlog = NULL;
772 ConfigFileEntry.fname_serverlog = NULL;
773 ConfigFileEntry.fname_klinelog = NULL;
774 ConfigFileEntry.fname_ioerrorlog = NULL;
775 ConfigFileEntry.use_egd = NO;
776 ConfigFileEntry.hide_spoof_ips = YES;
777 ConfigFileEntry.hide_error_messages = 1;
778 ConfigFileEntry.idletime = 0;
779 ConfigFileEntry.dots_in_ident = 0;
780 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
781 DupString(ConfigFileEntry.servlink_path, SLPATH);
782 ConfigFileEntry.egdpool_path = NULL;
783 ConfigFileEntry.use_whois_actually = YES;
784 ConfigFileEntry.burst_away = NO;
785 ConfigFileEntry.collision_fnc = YES;
786 ConfigFileEntry.global_snotices = YES;
787 ConfigFileEntry.remote_die = NO;
788 ConfigFileEntry.remote_restart = NO;
790 #ifdef HAVE_LIBZ
791 ConfigFileEntry.compression_level = 4;
792 #endif
794 ConfigFileEntry.oper_umodes = UMODE_SERVNOTICE |
795 UMODE_OPERWALL | UMODE_WALLOP;
796 ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
797 ConfigFileEntry.oper_snomask = SNO_GENERAL;
799 ConfigChannel.use_except = YES;
800 ConfigChannel.use_invex = YES;
801 ConfigChannel.use_knock = YES;
802 ConfigChannel.knock_delay = 300;
803 ConfigChannel.knock_delay_channel = 60;
804 ConfigChannel.max_chans_per_user = 15;
805 ConfigChannel.max_chans_per_user_large = 60;
806 ConfigChannel.max_bans = 25;
807 ConfigChannel.max_bans_large = 500;
808 ConfigChannel.burst_topicwho = NO;
809 ConfigChannel.invite_ops_only = YES;
810 ConfigChannel.kick_on_split_riding = NO;
812 ConfigChannel.default_split_user_count = 15000;
813 ConfigChannel.default_split_server_count = 10;
814 ConfigChannel.no_join_on_split = NO;
815 ConfigChannel.no_create_on_split = YES;
817 ConfigServerHide.flatten_links = 0;
818 ConfigServerHide.links_delay = 300;
819 ConfigServerHide.hidden = 0;
820 ConfigServerHide.disable_hidden = 0;
822 ConfigFileEntry.min_nonwildcard = 4;
823 ConfigFileEntry.min_nonwildcard_simple = 3;
824 ConfigFileEntry.default_floodcount = 8;
825 ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
826 ConfigFileEntry.tkline_expire_notices = 0;
828 ConfigFileEntry.reject_after_count = 5;
829 ConfigFileEntry.reject_ban_time = 300;
830 ConfigFileEntry.reject_duration = 120;
834 #undef YES
835 #undef NO
838 * read_conf()
841 * inputs - file descriptor pointing to config file to use
842 * output - None
843 * side effects - Read configuration file.
845 static void
846 read_conf(FILE * file)
848 lineno = 0;
850 set_default_conf(); /* Set default values prior to conf parsing */
851 yyparse(); /* Load the values from the conf */
852 validate_conf(); /* Check to make sure some values are still okay. */
853 /* Some global values are also loaded here. */
854 check_class(); /* Make sure classes are valid */
857 static void
858 validate_conf(void)
860 if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
861 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
863 if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
864 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
866 if(ConfigFileEntry.servlink_path == NULL)
867 DupString(ConfigFileEntry.servlink_path, SLPATH);
869 if(ServerInfo.network_name == NULL)
870 DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
872 if(ServerInfo.network_desc == NULL)
873 DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
875 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
876 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
877 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
879 GlobalSetOptions.idletime = (ConfigFileEntry.idletime * 60);
881 if(!split_users || !split_servers ||
882 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
884 eventDelete(check_splitmode, NULL);
885 splitmode = 0;
886 splitchecking = 0;
891 * lookup_confhost - start DNS lookups of all hostnames in the conf
892 * line and convert an IP addresses in a.b.c.d number for to IP#s.
897 * conf_connect_allowed
899 * inputs - pointer to inaddr
900 * - int type ipv4 or ipv6
901 * output - ban info or NULL
902 * side effects - none
904 struct ConfItem *
905 conf_connect_allowed(struct sockaddr *addr, int aftype)
907 struct ConfItem *aconf = find_dline(addr, aftype);
909 /* DLINE exempt also gets you out of static limits/pacing... */
910 if(aconf && (aconf->status & CONF_EXEMPTDLINE))
911 return NULL;
913 if(aconf != NULL)
914 return aconf;
916 return NULL;
919 /* add_temp_kline()
921 * inputs - pointer to struct ConfItem
922 * output - none
923 * Side effects - links in given struct ConfItem into
924 * temporary kline link list
926 void
927 add_temp_kline(struct ConfItem *aconf)
929 if(aconf->hold >= CurrentTime + (10080 * 60))
931 dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
932 aconf->port = TEMP_WEEK;
934 else if(aconf->hold >= CurrentTime + (1440 * 60))
936 dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
937 aconf->port = TEMP_DAY;
939 else if(aconf->hold >= CurrentTime + (60 * 60))
941 dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
942 aconf->port = TEMP_HOUR;
944 else
946 dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
947 aconf->port = TEMP_MIN;
950 aconf->flags |= CONF_FLAGS_TEMPORARY;
951 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf);
954 /* add_temp_dline()
956 * input - pointer to struct ConfItem
957 * output - none
958 * side effects - added to tdline link list and address hash
960 void
961 add_temp_dline(struct ConfItem *aconf)
963 if(aconf->hold >= CurrentTime + (10080 * 60))
965 dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
966 aconf->port = TEMP_WEEK;
968 else if(aconf->hold >= CurrentTime + (1440 * 60))
970 dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
971 aconf->port = TEMP_DAY;
973 else if(aconf->hold >= CurrentTime + (60 * 60))
975 dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
976 aconf->port = TEMP_HOUR;
978 else
980 dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
981 aconf->port = TEMP_MIN;
984 aconf->flags |= CONF_FLAGS_TEMPORARY;
985 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, aconf);
988 /* expire_tkline()
990 * inputs - list pointer
991 * - type
992 * output - NONE
993 * side effects - expire tklines and moves them between lists
995 static void
996 expire_temp_kd(void *list)
998 dlink_node *ptr;
999 dlink_node *next_ptr;
1000 struct ConfItem *aconf;
1002 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1004 aconf = ptr->data;
1006 if(aconf->hold <= CurrentTime)
1008 /* Alert opers that a TKline expired - Hwy */
1009 if(ConfigFileEntry.tkline_expire_notices)
1010 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1011 "Temporary K-line for [%s@%s] expired",
1012 (aconf->user) ? aconf->
1013 user : "*", (aconf->host) ? aconf->host : "*");
1015 delete_one_address_conf(aconf->host, aconf);
1016 dlinkDestroy(ptr, list);
1021 static void
1022 reorganise_temp_kd(void *list)
1024 struct ConfItem *aconf;
1025 dlink_node *ptr, *next_ptr;
1027 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1029 aconf = ptr->data;
1031 if(aconf->hold < (CurrentTime + (60 * 60)))
1033 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1034 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1035 aconf->port = TEMP_MIN;
1037 else if(aconf->port > TEMP_HOUR)
1039 if(aconf->hold < (CurrentTime + (1440 * 60)))
1041 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1042 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1043 aconf->port = TEMP_HOUR;
1045 else if(aconf->port > TEMP_DAY &&
1046 (aconf->hold < (CurrentTime + (10080 * 60))))
1048 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1049 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1050 aconf->port = TEMP_DAY;
1057 /* const char* get_oper_name(struct Client *client_p)
1058 * Input: A client to find the active oper{} name for.
1059 * Output: The nick!user@host{oper} of the oper.
1060 * "oper" is server name for remote opers
1061 * Side effects: None.
1063 char *
1064 get_oper_name(struct Client *client_p)
1066 /* +5 for !,@,{,} and null */
1067 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1069 if(MyOper(client_p))
1071 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1072 client_p->name, client_p->username,
1073 client_p->host, client_p->localClient->opername);
1074 return buffer;
1077 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1078 client_p->name, client_p->username,
1079 client_p->host, client_p->servptr->name);
1080 return buffer;
1084 * get_printable_conf
1086 * inputs - struct ConfItem
1088 * output - name
1089 * - host
1090 * - pass
1091 * - user
1092 * - port
1094 * side effects -
1095 * Examine the struct struct ConfItem, setting the values
1096 * of name, host, pass, user to values either
1097 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1099 void
1100 get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1101 char **pass, char **user, int *port, char **classname)
1103 static char null[] = "<NULL>";
1104 static char zero[] = "default";
1106 *name = EmptyString(aconf->name) ? null : aconf->name;
1107 *host = EmptyString(aconf->host) ? null : aconf->host;
1108 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1109 *user = EmptyString(aconf->user) ? null : aconf->user;
1110 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1111 *port = (int) aconf->port;
1114 void
1115 get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1116 char **host, char **reason,
1117 char **user, char **oper_reason)
1119 static char null[] = "<NULL>";
1121 *host = EmptyString(aconf->host) ? null : aconf->host;
1122 *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
1123 *user = EmptyString(aconf->user) ? null : aconf->user;
1125 if(EmptyString(aconf->spasswd) || !IsOper(source_p))
1126 *oper_reason = NULL;
1127 else
1128 *oper_reason = aconf->spasswd;
1132 * read_conf_files
1134 * inputs - cold start YES or NO
1135 * output - none
1136 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1138 void
1139 read_conf_files(int cold)
1141 const char *filename;
1143 conf_fbfile_in = NULL;
1145 filename = get_conf_name(CONF_TYPE);
1147 /* We need to know the initial filename for the yyerror() to report
1148 FIXME: The full path is in conffilenamebuf first time since we
1149 dont know anything else
1151 - Gozem 2002-07-21
1153 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1155 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1157 if(cold)
1159 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1160 exit(-1);
1162 else
1164 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1165 "Can't open file '%s' - aborting rehash!", filename);
1166 return;
1170 if(!cold)
1172 clear_out_old_conf();
1175 read_conf(conf_fbfile_in);
1176 fclose(conf_fbfile_in);
1180 * clear_out_old_conf
1182 * inputs - none
1183 * output - none
1184 * side effects - Clear out the old configuration
1186 static void
1187 clear_out_old_conf(void)
1189 struct Class *cltmp;
1190 dlink_node *ptr;
1191 dlink_node *next_ptr;
1192 int i;
1195 * don't delete the class table, rather mark all entries
1196 * for deletion. The table is cleaned up by check_class. - avalon
1198 DLINK_FOREACH(ptr, class_list.head)
1200 cltmp = ptr->data;
1201 MaxUsers(cltmp) = -1;
1204 clear_out_address_conf();
1205 clear_s_newconf();
1207 /* clean out module paths */
1208 #ifndef STATIC_MODULES
1209 mod_clear_paths();
1210 mod_add_path(MODULE_DIR);
1211 mod_add_path(MODULE_DIR "/autoload");
1212 #endif
1214 /* clean out ServerInfo */
1215 MyFree(ServerInfo.description);
1216 ServerInfo.description = NULL;
1217 MyFree(ServerInfo.network_name);
1218 ServerInfo.network_name = NULL;
1219 MyFree(ServerInfo.network_desc);
1220 ServerInfo.network_desc = NULL;
1222 /* clean out AdminInfo */
1223 MyFree(AdminInfo.name);
1224 AdminInfo.name = NULL;
1225 MyFree(AdminInfo.email);
1226 AdminInfo.email = NULL;
1227 MyFree(AdminInfo.description);
1228 AdminInfo.description = NULL;
1230 /* operator{} and class{} blocks are freed above */
1231 /* clean out listeners */
1232 close_listeners();
1234 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1235 * and gecos{} blocks are freed above too
1238 /* clean out general */
1239 MyFree(ConfigFileEntry.servlink_path);
1240 ConfigFileEntry.servlink_path = NULL;
1242 DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
1244 MyFree(ptr->data);
1245 dlinkDestroy(ptr, &service_list);
1248 /* remove any aliases... -- nenolod */
1249 for (i = 0; i < MAX_MSG_HASH; i++)
1251 DLINK_FOREACH_SAFE(ptr, next_ptr, alias_hash_table[i].head)
1253 struct alias_entry *aptr = ptr->data;
1255 MyFree(aptr->name);
1256 MyFree(aptr->target);
1257 MyFree(aptr);
1259 dlinkDestroy(ptr, &alias_hash_table[i]);
1263 destroy_blacklists();
1265 /* OK, that should be everything... */
1269 /* write_confitem()
1271 * inputs - kline, dline or resv type flag
1272 * - client pointer to report to
1273 * - user name of target
1274 * - host name of target
1275 * - reason for target
1276 * - time string
1277 * - type of xline
1278 * output - NONE
1279 * side effects - This function takes care of finding the right conf
1280 * file and adding the line to it, as well as notifying
1281 * opers and the user.
1283 void
1284 write_confitem(KlineType type, struct Client *source_p, char *user,
1285 char *host, const char *reason, const char *oper_reason,
1286 const char *current_date, int xtype)
1288 char buffer[1024];
1289 FILE *out;
1290 const char *filename; /* filename to use for kline */
1292 filename = get_conf_name(type);
1295 if((out = fopen(filename, "a")) == NULL)
1297 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename);
1298 return;
1301 if(oper_reason == NULL)
1302 oper_reason = "";
1304 if(type == KLINE_TYPE)
1306 ircsnprintf(buffer, sizeof(buffer),
1307 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1308 user, host, reason, oper_reason, current_date,
1309 get_oper_name(source_p), CurrentTime);
1311 else if(type == DLINE_TYPE)
1313 ircsnprintf(buffer, sizeof(buffer),
1314 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host,
1315 reason, oper_reason, current_date, get_oper_name(source_p), CurrentTime);
1317 else if(type == RESV_TYPE)
1319 ircsnprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n",
1320 host, reason, get_oper_name(source_p), CurrentTime);
1323 if(fputs(buffer, out) == -1)
1325 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1326 fclose(out);
1327 return;
1330 fclose(out);
1332 if(type == KLINE_TYPE)
1334 if(EmptyString(oper_reason))
1336 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1337 "%s added K-Line for [%s@%s] [%s]",
1338 get_oper_name(source_p), user,
1339 host, reason);
1340 ilog(L_KLINE, "K %s 0 %s %s %s",
1341 get_oper_name(source_p), user, host, reason);
1343 else
1345 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1346 "%s added K-Line for [%s@%s] [%s|%s]",
1347 get_oper_name(source_p), user,
1348 host, reason, oper_reason);
1349 ilog(L_KLINE, "K %s 0 %s %s %s|%s",
1350 get_oper_name(source_p), user, host,
1351 reason, oper_reason);
1354 sendto_one_notice(source_p, ":Added K-Line [%s@%s]",
1355 user, host);
1357 else if(type == DLINE_TYPE)
1359 if(EmptyString(oper_reason))
1361 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1362 "%s added D-Line for [%s] [%s]",
1363 get_oper_name(source_p), host, reason);
1364 ilog(L_KLINE, "D %s 0 %s %s",
1365 get_oper_name(source_p), host, reason);
1367 else
1369 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1370 "%s added D-Line for [%s] [%s|%s]",
1371 get_oper_name(source_p), host,
1372 reason, oper_reason);
1373 ilog(L_KLINE, "D %s 0 %s %s|%s",
1374 get_oper_name(source_p), host,
1375 reason, oper_reason);
1378 sendto_one(source_p,
1379 ":%s NOTICE %s :Added D-Line [%s] to %s", me.name,
1380 source_p->name, host, filename);
1383 else if(type == RESV_TYPE)
1385 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1386 "%s added RESV for [%s] [%s]",
1387 get_oper_name(source_p), host, reason);
1388 ilog(L_KLINE, "R %s 0 %s %s",
1389 get_oper_name(source_p), host, reason);
1391 sendto_one_notice(source_p, ":Added RESV for [%s] [%s]",
1392 host, reason);
1396 /* get_conf_name
1398 * inputs - type of conf file to return name of file for
1399 * output - pointer to filename for type of conf
1400 * side effects - none
1402 const char *
1403 get_conf_name(KlineType type)
1405 if(type == CONF_TYPE)
1407 return (ConfigFileEntry.configfile);
1409 else if(type == DLINE_TYPE)
1411 return (ConfigFileEntry.dlinefile);
1413 else if(type == RESV_TYPE)
1415 return (ConfigFileEntry.resvfile);
1418 return ConfigFileEntry.klinefile;
1422 * conf_add_class_to_conf
1423 * inputs - pointer to config item
1424 * output - NONE
1425 * side effects - Add a class pointer to a conf
1428 void
1429 conf_add_class_to_conf(struct ConfItem *aconf)
1431 if(aconf->className == NULL)
1433 DupString(aconf->className, "default");
1434 ClassPtr(aconf) = default_class;
1435 return;
1438 ClassPtr(aconf) = find_class(aconf->className);
1440 if(ClassPtr(aconf) == default_class)
1442 if(aconf->status == CONF_CLIENT)
1444 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1445 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1446 aconf->className, aconf->user, aconf->host);
1449 MyFree(aconf->className);
1450 DupString(aconf->className, "default");
1451 return;
1454 if(ConfMaxUsers(aconf) < 0)
1456 ClassPtr(aconf) = default_class;
1457 MyFree(aconf->className);
1458 DupString(aconf->className, "default");
1459 return;
1464 * conf_add_d_conf
1465 * inputs - pointer to config item
1466 * output - NONE
1467 * side effects - Add a d/D line
1469 void
1470 conf_add_d_conf(struct ConfItem *aconf)
1472 if(aconf->host == NULL)
1473 return;
1475 aconf->user = NULL;
1477 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1478 * need this anyway, so I will disable it for now... -A1kmm
1481 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1483 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1484 free_conf(aconf);
1486 else
1488 add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf);
1494 * yyerror
1496 * inputs - message from parser
1497 * output - none
1498 * side effects - message to opers and log file entry is made
1500 void
1501 yyerror(const char *msg)
1503 char newlinebuf[BUFSIZE];
1505 strip_tabs(newlinebuf, (const unsigned char *) linebuf, strlen(linebuf));
1507 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",
1508 conffilebuf, lineno + 1, msg, newlinebuf);
1510 ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
1514 conf_fgets(char *lbuf, int max_size, FILE * fb)
1516 char *buff;
1518 if((buff = fgets(lbuf, max_size, fb)) == NULL)
1519 return (0);
1521 return (strlen(lbuf));
1525 conf_yy_fatal_error(const char *msg)
1527 return (0);