Restore stats_spy hook that was removed in commit 401f2454671ca233e35b0e6e4f3fa4c43cd...
[seven-1.x.git] / src / s_conf.c
blobf470fe012cd03facab1787aff1d729746b6574af
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
25 #include "stdinc.h"
26 #include "ircd_defs.h"
27 #include "tools.h"
28 #include "s_conf.h"
29 #include "s_newconf.h"
30 #include "s_serv.h"
31 #include "s_stats.h"
32 #include "channel.h"
33 #include "class.h"
34 #include "client.h"
35 #include "common.h"
36 #include "event.h"
37 #include "hash.h"
38 #include "irc_string.h"
39 #include "sprintf_irc.h"
40 #include "ircd.h"
41 #include "listener.h"
42 #include "hostmask.h"
43 #include "modules.h"
44 #include "numeric.h"
45 #include "commio.h"
46 #include "s_log.h"
47 #include "send.h"
48 #include "memory.h"
49 #include "balloc.h"
50 #include "patricia.h"
51 #include "reject.h"
52 #include "cache.h"
53 #include "blacklist.h"
55 struct config_server_hide ConfigServerHide;
57 extern int yyparse(); /* defined in y.tab.c */
58 extern char linebuf[];
60 #ifndef INADDR_NONE
61 #define INADDR_NONE ((unsigned int) 0xffffffff)
62 #endif
64 static BlockHeap *confitem_heap = NULL;
66 dlink_list temp_klines[LAST_TEMP_TYPE];
67 dlink_list temp_dlines[LAST_TEMP_TYPE];
68 dlink_list service_list;
70 /* internally defined functions */
71 static void set_default_conf(void);
72 static void validate_conf(void);
73 static void read_conf(FILE *);
74 static void clear_out_old_conf(void);
76 static void expire_temp_kd(void *list);
77 static void reorganise_temp_kd(void *list);
79 FILE *conf_fbfile_in;
80 extern char yytext[];
82 static int verify_access(struct Client *client_p, const char *username);
83 static int attach_iline(struct Client *, struct ConfItem *);
85 void
86 init_s_conf(void)
88 confitem_heap = BlockHeapCreate(sizeof(struct ConfItem), CONFITEM_HEAP_SIZE);
90 eventAddIsh("expire_temp_klines", expire_temp_kd, &temp_klines[TEMP_MIN], 60);
91 eventAddIsh("expire_temp_dlines", expire_temp_kd, &temp_dlines[TEMP_MIN], 60);
93 eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd,
94 &temp_klines[TEMP_HOUR], 3600);
95 eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd,
96 &temp_dlines[TEMP_HOUR], 3600);
97 eventAddIsh("expire_temp_klines_day", reorganise_temp_kd,
98 &temp_klines[TEMP_DAY], 86400);
99 eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd,
100 &temp_dlines[TEMP_DAY], 86400);
101 eventAddIsh("expire_temp_klines_week", reorganise_temp_kd,
102 &temp_klines[TEMP_WEEK], 604800);
103 eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd,
104 &temp_dlines[TEMP_WEEK], 604800);
108 * make_conf
110 * inputs - none
111 * output - pointer to new conf entry
112 * side effects - none
114 struct ConfItem *
115 make_conf()
117 struct ConfItem *aconf;
119 aconf = BlockHeapAlloc(confitem_heap);
120 aconf->status = CONF_ILLEGAL;
121 return (aconf);
125 * free_conf
127 * inputs - pointer to conf to free
128 * output - none
129 * side effects - crucial password fields are zeroed, conf is freed
131 void
132 free_conf(struct ConfItem *aconf)
134 s_assert(aconf != NULL);
135 if(aconf == NULL)
136 return;
138 /* security.. */
139 if(aconf->passwd)
140 memset(aconf->passwd, 0, strlen(aconf->passwd));
141 if(aconf->spasswd)
142 memset(aconf->spasswd, 0, strlen(aconf->spasswd));
144 MyFree(aconf->passwd);
145 MyFree(aconf->spasswd);
146 MyFree(aconf->name);
147 MyFree(aconf->className);
148 MyFree(aconf->user);
149 MyFree(aconf->host);
151 BlockHeapFree(confitem_heap, aconf);
155 * check_client
157 * inputs - pointer to client
158 * output - 0 = Success
159 * NOT_AUTHORISED (-1) = Access denied (no I line match)
160 * SOCKET_ERROR (-2) = Bad socket.
161 * I_LINE_FULL (-3) = I-line is full
162 * TOO_MANY (-4) = Too many connections from hostname
163 * BANNED_CLIENT (-5) = K-lined
164 * side effects - Ordinary client access check.
165 * Look for conf lines which have the same
166 * status as the flags passed.
169 check_client(struct Client *client_p, struct Client *source_p, const char *username)
171 int i;
173 ClearAccess(source_p);
175 if((i = verify_access(source_p, username)))
177 ilog(L_FUSER, "Access denied: %s[%s]",
178 source_p->name, source_p->sockhost);
181 switch (i)
183 case SOCKET_ERROR:
184 exit_client(client_p, source_p, &me, "Socket Error");
185 break;
187 case TOO_MANY_LOCAL:
188 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
189 "Too many local connections for %s!%s%s@%s",
190 source_p->name, IsGotId(source_p) ? "" : "~",
191 source_p->username, source_p->sockhost);
193 ilog(L_FUSER, "Too many local connections from %s!%s%s@%s",
194 source_p->name, IsGotId(source_p) ? "" : "~",
195 source_p->username, source_p->sockhost);
197 ServerStats->is_ref++;
198 exit_client(client_p, source_p, &me, "Too many host connections (local)");
199 break;
201 case TOO_MANY_GLOBAL:
202 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
203 "Too many global connections for %s!%s%s@%s",
204 source_p->name, IsGotId(source_p) ? "" : "~",
205 source_p->username, source_p->sockhost);
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);
210 ServerStats->is_ref++;
211 exit_client(client_p, source_p, &me, "Too many host connections (global)");
212 break;
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, source_p->sockhost);
219 ilog(L_FUSER, "Too many user connections from %s!%s%s@%s",
220 source_p->name, IsGotId(source_p) ? "" : "~",
221 source_p->username, source_p->sockhost);
223 ServerStats->is_ref++;
224 exit_client(client_p, source_p, &me, "Too many user connections (global)");
225 break;
227 case I_LINE_FULL:
228 sendto_realops_snomask(SNO_FULL, L_NETWIDE,
229 "I-line is full for %s!%s%s@%s (%s).",
230 source_p->name, IsGotId(source_p) ? "" : "~",
231 source_p->username, source_p->host,
232 source_p->sockhost);
234 ilog(L_FUSER, "Too many connections from %s!%s%s@%s.",
235 source_p->name, IsGotId(source_p) ? "" : "~",
236 source_p->username, source_p->sockhost);
238 ServerStats->is_ref++;
239 exit_client(client_p, source_p, &me,
240 "No more connections allowed in your connection class");
241 break;
243 case NOT_AUTHORISED:
245 int port = -1;
246 #ifdef IPV6
247 if(source_p->localClient->ip.ss_family == AF_INET6)
248 port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port);
249 else
250 #endif
251 port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port);
253 ServerStats->is_ref++;
254 /* jdc - lists server name & port connections are on */
255 /* a purely cosmetical change */
256 /* why ipaddr, and not just source_p->sockhost? --fl */
257 #if 0
258 static char ipaddr[HOSTIPLEN];
259 inetntop_sock(&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
260 #endif
261 sendto_realops_snomask(SNO_UNAUTH, L_NETWIDE,
262 "Unauthorised client connection from "
263 "%s!%s%s@%s [%s] on [%s/%u].",
264 source_p->name, IsGotId(source_p) ? "" : "~",
265 source_p->username, source_p->host,
266 source_p->sockhost,
267 source_p->localClient->listener->name, port);
269 ilog(L_FUSER,
270 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
271 source_p->name, IsGotId(source_p) ? "" : "~",
272 source_p->username, source_p->sockhost,
273 source_p->localClient->listener->name, port);
274 add_reject(client_p);
275 exit_client(client_p, source_p, &me,
276 "You are not authorised to use this server");
277 break;
279 case BANNED_CLIENT:
280 add_reject(client_p);
281 exit_client(client_p, client_p, &me, "*** Banned ");
282 ServerStats->is_ref++;
283 break;
285 case 0:
286 default:
287 break;
289 return (i);
293 * verify_access
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.
300 static int
301 verify_access(struct Client *client_p, const char *username)
303 struct ConfItem *aconf;
304 char non_ident[USERLEN + 1];
306 if(IsGotId(client_p))
308 aconf = find_address_conf(client_p->host, client_p->sockhost,
309 client_p->username,
310 (struct sockaddr *) &client_p->localClient->ip,
311 client_p->localClient->ip.ss_family);
313 else
315 strlcpy(non_ident, "~", sizeof(non_ident));
316 strlcat(non_ident, username, sizeof(non_ident));
317 aconf = find_address_conf(client_p->host, client_p->sockhost,
318 non_ident,
319 (struct sockaddr *) &client_p->localClient->ip,
320 client_p->localClient->ip.ss_family);
323 if(aconf == NULL)
324 return NOT_AUTHORISED;
326 if(aconf->status & CONF_CLIENT)
328 if(aconf->flags & CONF_FLAGS_REDIR)
330 sendto_one(client_p, form_str(RPL_REDIR),
331 me.name, client_p->name,
332 aconf->name ? aconf->name : "", aconf->port);
333 return (NOT_AUTHORISED);
337 if(IsConfDoIdentd(aconf))
338 SetNeedId(client_p);
340 /* Thanks for spoof idea amm */
341 if(IsConfDoSpoofIp(aconf))
343 char *p;
345 /* show_ip() depends on this --fl */
346 SetIPSpoof(client_p);
348 if(IsConfSpoofNotice(aconf))
350 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
351 "%s spoofing: %s as %s",
352 client_p->name,
353 show_ip(NULL, client_p) ? client_p->host : aconf->name,
354 aconf->name);
357 /* user@host spoof */
358 if((p = strchr(aconf->name, '@')) != NULL)
360 char *host = p+1;
361 *p = '\0';
363 strlcpy(client_p->username, aconf->name,
364 sizeof(client_p->username));
365 strlcpy(client_p->host, host,
366 sizeof(client_p->host));
367 *p = '@';
369 else
370 strlcpy(client_p->host, aconf->name, sizeof(client_p->host));
372 return (attach_iline(client_p, aconf));
374 else if(aconf->status & CONF_KILL)
376 if(ConfigFileEntry.kline_with_reason)
378 sendto_one(client_p,
379 ":%s NOTICE %s :*** Banned %s",
380 me.name, client_p->name, aconf->passwd);
382 return (BANNED_CLIENT);
385 return NOT_AUTHORISED;
390 * add_ip_limit
392 * Returns 1 if successful 0 if not
394 * This checks if the user has exceed the limits for their class
395 * unless of course they are exempt..
398 static int
399 add_ip_limit(struct Client *client_p, struct ConfItem *aconf)
401 patricia_node_t *pnode;
403 /* If the limits are 0 don't do anything.. */
404 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
405 return -1;
407 pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
409 if(pnode == NULL)
410 pnode = make_and_lookup_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip, ConfCidrBitlen(aconf));
412 s_assert(pnode != NULL);
414 if(pnode != NULL)
416 if(((long) pnode->data) >= ConfCidrAmount(aconf)
417 && !IsConfExemptLimits(aconf))
419 /* This should only happen if the limits are set to 0 */
420 if((unsigned long) pnode->data == 0)
422 patricia_remove(ConfIpLimits(aconf), pnode);
424 return (0);
427 pnode->data++;
429 return 1;
432 static void
433 remove_ip_limit(struct Client *client_p, struct ConfItem *aconf)
435 patricia_node_t *pnode;
437 /* If the limits are 0 don't do anything.. */
438 if(ConfCidrAmount(aconf) == 0 || ConfCidrBitlen(aconf) == 0)
439 return;
441 pnode = match_ip(ConfIpLimits(aconf), (struct sockaddr *)&client_p->localClient->ip);
442 if(pnode == NULL)
443 return;
445 pnode->data--;
446 if(((unsigned long) pnode->data) == 0)
448 patricia_remove(ConfIpLimits(aconf), pnode);
454 * attach_iline
456 * inputs - client pointer
457 * - conf pointer
458 * output -
459 * side effects - do actual attach
461 static int
462 attach_iline(struct Client *client_p, struct ConfItem *aconf)
464 struct Client *target_p;
465 dlink_node *ptr;
466 int local_count = 0;
467 int global_count = 0;
468 int ident_count = 0;
469 int unidented = 0;
471 if(IsConfExemptLimits(aconf))
472 return (attach_conf(client_p, aconf));
474 if(*client_p->username == '~')
475 unidented = 1;
478 /* find_hostname() returns the head of the list to search */
479 DLINK_FOREACH(ptr, find_hostname(client_p->host))
481 target_p = ptr->data;
483 if(irccmp(client_p->host, target_p->orighost) != 0)
484 continue;
486 if(MyConnect(target_p))
487 local_count++;
489 global_count++;
491 if(unidented)
493 if(*target_p->username == '~')
494 ident_count++;
496 else if(irccmp(target_p->username, client_p->username) == 0)
497 ident_count++;
499 if(ConfMaxLocal(aconf) && local_count >= ConfMaxLocal(aconf))
500 return (TOO_MANY_LOCAL);
501 else if(ConfMaxGlobal(aconf) && global_count >= ConfMaxGlobal(aconf))
502 return (TOO_MANY_GLOBAL);
503 else if(ConfMaxIdent(aconf) && ident_count >= ConfMaxIdent(aconf))
504 return (TOO_MANY_IDENT);
508 return (attach_conf(client_p, aconf));
512 * detach_conf
514 * inputs - pointer to client to detach
515 * output - 0 for success, -1 for failure
516 * side effects - Disassociate configuration from the client.
517 * Also removes a class from the list if marked for deleting.
520 detach_conf(struct Client *client_p)
522 struct ConfItem *aconf;
524 aconf = client_p->localClient->att_conf;
526 if(aconf != NULL)
528 if(ClassPtr(aconf))
530 remove_ip_limit(client_p, aconf);
532 if(ConfCurrUsers(aconf) > 0)
533 --ConfCurrUsers(aconf);
535 if(ConfMaxUsers(aconf) == -1 && ConfCurrUsers(aconf) == 0)
537 free_class(ClassPtr(aconf));
538 ClassPtr(aconf) = NULL;
543 aconf->clients--;
544 if(!aconf->clients && IsIllegal(aconf))
545 free_conf(aconf);
547 client_p->localClient->att_conf = NULL;
548 return 0;
551 return -1;
555 * attach_conf
557 * inputs - client pointer
558 * - conf pointer
559 * output -
560 * side effects - Associate a specific configuration entry to a *local*
561 * client (this is the one which used in accepting the
562 * connection). Note, that this automatically changes the
563 * attachment if there was an old one...
566 attach_conf(struct Client *client_p, struct ConfItem *aconf)
568 if(IsIllegal(aconf))
569 return (NOT_AUTHORISED);
571 if(ClassPtr(aconf))
573 if(!add_ip_limit(client_p, aconf))
574 return (TOO_MANY_LOCAL);
577 if((aconf->status & CONF_CLIENT) &&
578 ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0)
580 if(!IsConfExemptLimits(aconf))
582 return (I_LINE_FULL);
584 else
586 sendto_one(client_p, ":%s NOTICE %s :*** I: line is full, but you have an >I: line!",
587 me.name, client_p->name);
588 SetExemptLimits(client_p);
593 if(client_p->localClient->att_conf != NULL)
594 detach_conf(client_p);
596 client_p->localClient->att_conf = aconf;
598 aconf->clients++;
599 ConfCurrUsers(aconf)++;
600 return (0);
604 * rehash
606 * Actual REHASH service routine. Called with sig == 0 if it has been called
607 * as a result of an operator issuing this command, else assume it has been
608 * called as a result of the server receiving a HUP signal.
611 rehash(int sig)
613 if(sig != 0)
615 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
616 "Got signal SIGHUP, reloading ircd conf. file");
619 restart_resolver();
620 /* don't close listeners until we know we can go ahead with the rehash */
621 read_conf_files(NO);
623 if(ServerInfo.description != NULL)
624 strlcpy(me.info, ServerInfo.description, sizeof(me.info));
625 else
626 strlcpy(me.info, "unknown", sizeof(me.info));
628 open_logfiles();
629 return (0);
632 static struct banconf_entry
634 const char **filename;
635 void (*func) (FILE *);
636 int perm;
637 } banconfs[] = {
638 { &ConfigFileEntry.klinefile, parse_k_file, 0 },
639 { &ConfigFileEntry.klinefile, parse_k_file, 1 },
640 { &ConfigFileEntry.dlinefile, parse_d_file, 0 },
641 { &ConfigFileEntry.dlinefile, parse_d_file, 1 },
642 { &ConfigFileEntry.xlinefile, parse_x_file, 0 },
643 { &ConfigFileEntry.xlinefile, parse_x_file, 1 },
644 { &ConfigFileEntry.resvfile, parse_resv_file,0 },
645 { &ConfigFileEntry.resvfile, parse_resv_file,1 },
646 { NULL, NULL, 0 }
649 void
650 rehash_bans(int sig)
652 FILE *file;
653 char buf[MAXPATHLEN];
654 int i;
656 if(sig != 0)
657 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
658 "Got signal SIGUSR2, reloading ban confs");
660 clear_out_address_conf_bans();
661 clear_s_newconf_bans();
663 for(i = 0; banconfs[i].filename; i++)
665 if(banconfs[i].perm)
666 snprintf(buf, sizeof(buf), "%s.perm", *banconfs[i].filename);
667 else
668 snprintf(buf, sizeof(buf), "%s", *banconfs[i].filename);
670 if((file = fopen(buf, "r")) == NULL)
672 if(banconfs[i].perm)
673 continue;
675 ilog(L_MAIN, "Failed reading ban file %s",
676 *banconfs[i].filename);
677 sendto_realops_snomask(SNO_GENERAL, L_ALL,
678 "Can't open %s file bans could be missing!",
679 *banconfs[i].filename);
681 else
683 (banconfs[i].func)(file);
684 fclose(file);
688 check_banned_lines();
692 * set_default_conf()
694 * inputs - NONE
695 * output - NONE
696 * side effects - Set default values here.
697 * This is called **PRIOR** to parsing the
698 * configuration file. If you want to do some validation
699 * of values later, put them in validate_conf().
702 #define YES 1
703 #define NO 0
704 #define UNSET -1
706 static void
707 set_default_conf(void)
709 /* ServerInfo.name is not rehashable */
710 /* ServerInfo.name = ServerInfo.name; */
711 ServerInfo.description = NULL;
712 DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
713 DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
715 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
716 ServerInfo.specific_ipv4_vhost = 0;
717 #ifdef IPV6
718 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
719 ServerInfo.specific_ipv6_vhost = 0;
720 #endif
721 ServerInfo.use_ts6 = YES;
723 /* Don't reset hub, as that will break lazylinks */
724 /* ServerInfo.hub = NO; */
725 AdminInfo.name = NULL;
726 AdminInfo.email = NULL;
727 AdminInfo.description = NULL;
729 DupString(ConfigFileEntry.default_operstring, "is an IRC operator");
730 DupString(ConfigFileEntry.default_adminstring, "is a Server Administrator");
731 DupString(ConfigFileEntry.servicestring, "is a Network Service");
733 ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
734 ConfigFileEntry.failed_oper_notice = YES;
735 ConfigFileEntry.anti_nick_flood = NO;
736 ConfigFileEntry.disable_fake_channels = NO;
737 ConfigFileEntry.max_nick_time = 20;
738 ConfigFileEntry.max_nick_changes = 5;
739 ConfigFileEntry.max_accept = 20;
740 ConfigFileEntry.max_monitor = 60;
741 ConfigFileEntry.nick_delay = 900; /* 15 minutes */
742 ConfigFileEntry.target_change = YES;
743 ConfigFileEntry.anti_spam_exit_message_time = 0;
744 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
745 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
746 ConfigFileEntry.client_exit = YES;
747 ConfigFileEntry.dline_with_reason = YES;
748 ConfigFileEntry.kline_with_reason = YES;
749 ConfigFileEntry.kline_delay = 0;
750 ConfigFileEntry.warn_no_nline = YES;
751 ConfigFileEntry.non_redundant_klines = YES;
752 ConfigFileEntry.stats_e_disabled = NO;
753 ConfigFileEntry.stats_o_oper_only = NO;
754 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
755 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
756 ConfigFileEntry.stats_P_oper_only = NO;
757 ConfigFileEntry.stats_c_oper_only = NO;
758 ConfigFileEntry.stats_y_oper_only = NO;
759 ConfigFileEntry.stats_h_oper_only = NO;
760 ConfigFileEntry.map_oper_only = YES;
761 ConfigFileEntry.pace_wait = 10;
762 ConfigFileEntry.caller_id_wait = 60;
763 ConfigFileEntry.pace_wait_simple = 1;
764 ConfigFileEntry.short_motd = NO;
765 ConfigFileEntry.no_oper_flood = NO;
766 ConfigFileEntry.fname_userlog = NULL;
767 ConfigFileEntry.fname_fuserlog = NULL;
768 ConfigFileEntry.fname_operlog = NULL;
769 ConfigFileEntry.fname_foperlog = NULL;
770 ConfigFileEntry.fname_serverlog = NULL;
771 ConfigFileEntry.fname_klinelog = NULL;
772 ConfigFileEntry.fname_ioerrorlog = NULL;
773 ConfigFileEntry.use_egd = NO;
774 ConfigFileEntry.hide_spoof_ips = YES;
775 ConfigFileEntry.hide_error_messages = 1;
776 ConfigFileEntry.idletime = 0;
777 ConfigFileEntry.dots_in_ident = 0;
778 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
779 DupString(ConfigFileEntry.servlink_path, SLPATH);
780 ConfigFileEntry.egdpool_path = NULL;
781 ConfigFileEntry.use_whois_actually = YES;
782 ConfigFileEntry.burst_away = NO;
783 ConfigFileEntry.collision_fnc = YES;
784 ConfigFileEntry.global_snotices = YES;
785 ConfigFileEntry.remote_die = NO;
786 ConfigFileEntry.remote_restart = NO;
788 #ifdef HAVE_LIBZ
789 ConfigFileEntry.compression_level = 4;
790 #endif
792 ConfigFileEntry.oper_umodes = UMODE_SERVNOTICE |
793 UMODE_OPERWALL | UMODE_WALLOP;
794 ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
795 ConfigFileEntry.oper_snomask = SNO_GENERAL;
797 ConfigChannel.use_except = YES;
798 ConfigChannel.use_invex = YES;
799 ConfigChannel.use_knock = YES;
800 ConfigChannel.knock_delay = 300;
801 ConfigChannel.knock_delay_channel = 60;
802 ConfigChannel.max_chans_per_user = 15;
803 ConfigChannel.max_chans_per_user_large = 60;
804 ConfigChannel.max_bans = 25;
805 ConfigChannel.max_bans_large = 500;
806 ConfigChannel.burst_topicwho = NO;
807 ConfigChannel.invite_ops_only = YES;
808 ConfigChannel.kick_on_split_riding = NO;
810 ConfigChannel.default_split_user_count = 15000;
811 ConfigChannel.default_split_server_count = 10;
812 ConfigChannel.no_join_on_split = NO;
813 ConfigChannel.no_create_on_split = YES;
815 ConfigServerHide.flatten_links = 0;
816 ConfigServerHide.links_delay = 300;
817 ConfigServerHide.hidden = 0;
818 ConfigServerHide.disable_hidden = 0;
820 ConfigFileEntry.min_nonwildcard = 4;
821 ConfigFileEntry.min_nonwildcard_simple = 3;
822 ConfigFileEntry.default_floodcount = 8;
823 ConfigFileEntry.client_flood = CLIENT_FLOOD_DEFAULT;
824 ConfigFileEntry.tkline_expire_notices = 0;
826 ConfigFileEntry.reject_after_count = 5;
827 ConfigFileEntry.reject_ban_time = 300;
828 ConfigFileEntry.reject_duration = 120;
830 DupString(ConfigFileEntry.idented_user_prefix, "");
833 #undef YES
834 #undef NO
837 * read_conf()
840 * inputs - file descriptor pointing to config file to use
841 * output - None
842 * side effects - Read configuration file.
844 static void
845 read_conf(FILE * file)
847 lineno = 0;
849 set_default_conf(); /* Set default values prior to conf parsing */
850 yyparse(); /* Load the values from the conf */
851 validate_conf(); /* Check to make sure some values are still okay. */
852 /* Some global values are also loaded here. */
853 check_class(); /* Make sure classes are valid */
856 static void
857 validate_conf(void)
859 if(ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
860 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
862 if(ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
863 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
865 if(ConfigFileEntry.servlink_path == NULL)
866 DupString(ConfigFileEntry.servlink_path, SLPATH);
868 if(ServerInfo.network_name == NULL)
869 DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT);
871 if(ServerInfo.network_desc == NULL)
872 DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT);
874 if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) ||
875 (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX))
876 ConfigFileEntry.client_flood = CLIENT_FLOOD_MAX;
878 GlobalSetOptions.idletime = (ConfigFileEntry.idletime * 60);
880 if(!split_users || !split_servers ||
881 (!ConfigChannel.no_create_on_split && !ConfigChannel.no_join_on_split))
883 eventDelete(check_splitmode, NULL);
884 splitmode = 0;
885 splitchecking = 0;
890 * lookup_confhost - start DNS lookups of all hostnames in the conf
891 * line and convert an IP addresses in a.b.c.d number for to IP#s.
896 * conf_connect_allowed
898 * inputs - pointer to inaddr
899 * - int type ipv4 or ipv6
900 * output - ban info or NULL
901 * side effects - none
903 struct ConfItem *
904 conf_connect_allowed(struct sockaddr *addr, int aftype)
906 struct ConfItem *aconf = find_dline(addr, aftype);
908 /* DLINE exempt also gets you out of static limits/pacing... */
909 if(aconf && (aconf->status & CONF_EXEMPTDLINE))
910 return NULL;
912 if(aconf != NULL)
913 return aconf;
915 return NULL;
918 /* add_temp_kline()
920 * inputs - pointer to struct ConfItem
921 * output - none
922 * Side effects - links in given struct ConfItem into
923 * temporary kline link list
925 void
926 add_temp_kline(struct ConfItem *aconf)
928 if(aconf->hold >= CurrentTime + (10080 * 60))
930 dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]);
931 aconf->port = TEMP_WEEK;
933 else if(aconf->hold >= CurrentTime + (1440 * 60))
935 dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]);
936 aconf->port = TEMP_DAY;
938 else if(aconf->hold >= CurrentTime + (60 * 60))
940 dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]);
941 aconf->port = TEMP_HOUR;
943 else
945 dlinkAddAlloc(aconf, &temp_klines[TEMP_MIN]);
946 aconf->port = TEMP_MIN;
949 aconf->flags |= CONF_FLAGS_TEMPORARY;
950 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf);
953 /* add_temp_dline()
955 * input - pointer to struct ConfItem
956 * output - none
957 * side effects - added to tdline link list and address hash
959 void
960 add_temp_dline(struct ConfItem *aconf)
962 if(aconf->hold >= CurrentTime + (10080 * 60))
964 dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]);
965 aconf->port = TEMP_WEEK;
967 else if(aconf->hold >= CurrentTime + (1440 * 60))
969 dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]);
970 aconf->port = TEMP_DAY;
972 else if(aconf->hold >= CurrentTime + (60 * 60))
974 dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]);
975 aconf->port = TEMP_HOUR;
977 else
979 dlinkAddAlloc(aconf, &temp_dlines[TEMP_MIN]);
980 aconf->port = TEMP_MIN;
983 aconf->flags |= CONF_FLAGS_TEMPORARY;
984 add_conf_by_address(aconf->host, CONF_DLINE, aconf->user, aconf);
987 /* expire_tkline()
989 * inputs - list pointer
990 * - type
991 * output - NONE
992 * side effects - expire tklines and moves them between lists
994 static void
995 expire_temp_kd(void *list)
997 dlink_node *ptr;
998 dlink_node *next_ptr;
999 struct ConfItem *aconf;
1001 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1003 aconf = ptr->data;
1005 if(aconf->hold <= CurrentTime)
1007 /* Alert opers that a TKline expired - Hwy */
1008 if(ConfigFileEntry.tkline_expire_notices)
1009 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1010 "Temporary K-line for [%s@%s] expired",
1011 (aconf->user) ? aconf->
1012 user : "*", (aconf->host) ? aconf->host : "*");
1014 delete_one_address_conf(aconf->host, aconf);
1015 dlinkDestroy(ptr, list);
1020 static void
1021 reorganise_temp_kd(void *list)
1023 struct ConfItem *aconf;
1024 dlink_node *ptr, *next_ptr;
1026 DLINK_FOREACH_SAFE(ptr, next_ptr, ((dlink_list *) list)->head)
1028 aconf = ptr->data;
1030 if(aconf->hold < (CurrentTime + (60 * 60)))
1032 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1033 &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]);
1034 aconf->port = TEMP_MIN;
1036 else if(aconf->port > TEMP_HOUR)
1038 if(aconf->hold < (CurrentTime + (1440 * 60)))
1040 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1041 &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]);
1042 aconf->port = TEMP_HOUR;
1044 else if(aconf->port > TEMP_DAY &&
1045 (aconf->hold < (CurrentTime + (10080 * 60))))
1047 dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ?
1048 &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]);
1049 aconf->port = TEMP_DAY;
1056 /* const char* get_oper_name(struct Client *client_p)
1057 * Input: A client to find the active oper{} name for.
1058 * Output: The nick!user@host{oper} of the oper.
1059 * "oper" is server name for remote opers
1060 * Side effects: None.
1062 char *
1063 get_oper_name(struct Client *client_p)
1065 /* +5 for !,@,{,} and null */
1066 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1068 if(MyOper(client_p))
1070 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1071 client_p->name, client_p->username,
1072 client_p->host, client_p->localClient->opername);
1073 return buffer;
1076 ircsnprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
1077 client_p->name, client_p->username,
1078 client_p->host, client_p->servptr->name);
1079 return buffer;
1083 * get_printable_conf
1085 * inputs - struct ConfItem
1087 * output - name
1088 * - host
1089 * - pass
1090 * - user
1091 * - port
1093 * side effects -
1094 * Examine the struct struct ConfItem, setting the values
1095 * of name, host, pass, user to values either
1096 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1098 void
1099 get_printable_conf(struct ConfItem *aconf, char **name, char **host,
1100 char **pass, char **user, int *port, char **classname)
1102 static char null[] = "<NULL>";
1103 static char zero[] = "default";
1105 *name = EmptyString(aconf->name) ? null : aconf->name;
1106 *host = EmptyString(aconf->host) ? null : aconf->host;
1107 *pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
1108 *user = EmptyString(aconf->user) ? null : aconf->user;
1109 *classname = EmptyString(aconf->className) ? zero : aconf->className;
1110 *port = (int) aconf->port;
1113 void
1114 get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
1115 char **host, char **reason,
1116 char **user, char **oper_reason)
1118 static char null[] = "<NULL>";
1120 *host = EmptyString(aconf->host) ? null : aconf->host;
1121 *reason = EmptyString(aconf->passwd) ? null : aconf->passwd;
1122 *user = EmptyString(aconf->user) ? null : aconf->user;
1124 if(EmptyString(aconf->spasswd) || !IsOper(source_p))
1125 *oper_reason = NULL;
1126 else
1127 *oper_reason = aconf->spasswd;
1131 * read_conf_files
1133 * inputs - cold start YES or NO
1134 * output - none
1135 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1137 void
1138 read_conf_files(int cold)
1140 const char *filename;
1142 conf_fbfile_in = NULL;
1144 filename = get_conf_name(CONF_TYPE);
1146 /* We need to know the initial filename for the yyerror() to report
1147 FIXME: The full path is in conffilenamebuf first time since we
1148 dont know anything else
1150 - Gozem 2002-07-21
1152 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1154 if((conf_fbfile_in = fopen(filename, "r")) == NULL)
1156 if(cold)
1158 ilog(L_MAIN, "Failed in reading configuration file %s", filename);
1159 exit(-1);
1161 else
1163 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1164 "Can't open file '%s' - aborting rehash!", filename);
1165 return;
1169 if(!cold)
1171 clear_out_old_conf();
1174 read_conf(conf_fbfile_in);
1175 fclose(conf_fbfile_in);
1179 * clear_out_old_conf
1181 * inputs - none
1182 * output - none
1183 * side effects - Clear out the old configuration
1185 static void
1186 clear_out_old_conf(void)
1188 struct Class *cltmp;
1189 dlink_node *ptr;
1190 dlink_node *next_ptr;
1191 int i;
1194 * don't delete the class table, rather mark all entries
1195 * for deletion. The table is cleaned up by check_class. - avalon
1197 DLINK_FOREACH(ptr, class_list.head)
1199 cltmp = ptr->data;
1200 MaxUsers(cltmp) = -1;
1203 clear_out_address_conf();
1204 clear_s_newconf();
1206 /* clean out module paths */
1207 #ifndef STATIC_MODULES
1208 mod_clear_paths();
1209 mod_add_path(MODULE_DIR);
1210 mod_add_path(MODULE_DIR "/autoload");
1211 #endif
1213 /* clean out ServerInfo */
1214 MyFree(ServerInfo.description);
1215 ServerInfo.description = NULL;
1216 MyFree(ServerInfo.network_name);
1217 ServerInfo.network_name = NULL;
1218 MyFree(ServerInfo.network_desc);
1219 ServerInfo.network_desc = NULL;
1221 /* clean out AdminInfo */
1222 MyFree(AdminInfo.name);
1223 AdminInfo.name = NULL;
1224 MyFree(AdminInfo.email);
1225 AdminInfo.email = NULL;
1226 MyFree(AdminInfo.description);
1227 AdminInfo.description = NULL;
1229 /* operator{} and class{} blocks are freed above */
1230 /* clean out listeners */
1231 close_listeners();
1233 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1234 * and gecos{} blocks are freed above too
1237 /* clean out general */
1238 MyFree(ConfigFileEntry.servlink_path);
1239 ConfigFileEntry.servlink_path = NULL;
1241 DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head)
1243 MyFree(ptr->data);
1244 dlinkDestroy(ptr, &service_list);
1247 /* remove any aliases... -- nenolod */
1248 for (i = 0; i < MAX_MSG_HASH; i++)
1250 DLINK_FOREACH_SAFE(ptr, next_ptr, alias_hash_table[i].head)
1252 struct alias_entry *aptr = ptr->data;
1254 MyFree(aptr->name);
1255 MyFree(aptr->target);
1256 MyFree(aptr);
1258 dlinkDestroy(ptr, &alias_hash_table[i]);
1262 destroy_blacklists();
1264 /* OK, that should be everything... */
1268 /* write_confitem()
1270 * inputs - kline, dline or resv type flag
1271 * - client pointer to report to
1272 * - user name of target
1273 * - host name of target
1274 * - reason for target
1275 * - time string
1276 * - type of xline
1277 * output - NONE
1278 * side effects - This function takes care of finding the right conf
1279 * file and adding the line to it, as well as notifying
1280 * opers and the user.
1282 void
1283 write_confitem(KlineType type, struct Client *source_p, char *user,
1284 char *host, const char *reason, const char *oper_reason,
1285 const char *current_date, int xtype)
1287 char buffer[1024];
1288 FILE *out;
1289 const char *filename; /* filename to use for kline */
1291 filename = get_conf_name(type);
1294 if((out = fopen(filename, "a")) == NULL)
1296 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename);
1297 return;
1300 if(oper_reason == NULL)
1301 oper_reason = "";
1303 if(type == KLINE_TYPE)
1305 ircsnprintf(buffer, sizeof(buffer),
1306 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1307 user, host, reason, oper_reason, current_date,
1308 get_oper_name(source_p), CurrentTime);
1310 else if(type == DLINE_TYPE)
1312 ircsnprintf(buffer, sizeof(buffer),
1313 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host,
1314 reason, oper_reason, current_date, get_oper_name(source_p), CurrentTime);
1316 else if(type == RESV_TYPE)
1318 ircsnprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n",
1319 host, reason, get_oper_name(source_p), CurrentTime);
1322 if(fputs(buffer, out) == -1)
1324 sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
1325 fclose(out);
1326 return;
1329 fclose(out);
1331 if(type == KLINE_TYPE)
1333 if(EmptyString(oper_reason))
1335 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1336 "%s added K-Line for [%s@%s] [%s]",
1337 get_oper_name(source_p), user,
1338 host, reason);
1339 ilog(L_KLINE, "K %s 0 %s %s %s",
1340 get_oper_name(source_p), user, host, reason);
1342 else
1344 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1345 "%s added K-Line for [%s@%s] [%s|%s]",
1346 get_oper_name(source_p), user,
1347 host, reason, oper_reason);
1348 ilog(L_KLINE, "K %s 0 %s %s %s|%s",
1349 get_oper_name(source_p), user, host,
1350 reason, oper_reason);
1353 sendto_one_notice(source_p, ":Added K-Line [%s@%s]",
1354 user, host);
1356 else if(type == DLINE_TYPE)
1358 if(EmptyString(oper_reason))
1360 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1361 "%s added D-Line for [%s] [%s]",
1362 get_oper_name(source_p), host, reason);
1363 ilog(L_KLINE, "D %s 0 %s %s",
1364 get_oper_name(source_p), host, reason);
1366 else
1368 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
1369 "%s added D-Line for [%s] [%s|%s]",
1370 get_oper_name(source_p), host,
1371 reason, oper_reason);
1372 ilog(L_KLINE, "D %s 0 %s %s|%s",
1373 get_oper_name(source_p), host,
1374 reason, oper_reason);
1377 sendto_one(source_p,
1378 ":%s NOTICE %s :Added D-Line [%s] to %s", me.name,
1379 source_p->name, host, filename);
1382 else if(type == RESV_TYPE)
1384 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1385 "%s added RESV for [%s] [%s]",
1386 get_oper_name(source_p), host, reason);
1387 ilog(L_KLINE, "R %s 0 %s %s",
1388 get_oper_name(source_p), host, reason);
1390 sendto_one_notice(source_p, ":Added RESV for [%s] [%s]",
1391 host, reason);
1395 /* get_conf_name
1397 * inputs - type of conf file to return name of file for
1398 * output - pointer to filename for type of conf
1399 * side effects - none
1401 const char *
1402 get_conf_name(KlineType type)
1404 if(type == CONF_TYPE)
1406 return (ConfigFileEntry.configfile);
1408 else if(type == DLINE_TYPE)
1410 return (ConfigFileEntry.dlinefile);
1412 else if(type == RESV_TYPE)
1414 return (ConfigFileEntry.resvfile);
1417 return ConfigFileEntry.klinefile;
1421 * conf_add_class_to_conf
1422 * inputs - pointer to config item
1423 * output - NONE
1424 * side effects - Add a class pointer to a conf
1427 void
1428 conf_add_class_to_conf(struct ConfItem *aconf)
1430 if(aconf->className == NULL)
1432 DupString(aconf->className, "default");
1433 ClassPtr(aconf) = default_class;
1434 return;
1437 ClassPtr(aconf) = find_class(aconf->className);
1439 if(ClassPtr(aconf) == default_class)
1441 if(aconf->status == CONF_CLIENT)
1443 sendto_realops_snomask(SNO_GENERAL, L_ALL,
1444 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1445 aconf->className, aconf->user, aconf->host);
1448 MyFree(aconf->className);
1449 DupString(aconf->className, "default");
1450 return;
1453 if(ConfMaxUsers(aconf) < 0)
1455 ClassPtr(aconf) = default_class;
1456 MyFree(aconf->className);
1457 DupString(aconf->className, "default");
1458 return;
1463 * conf_add_d_conf
1464 * inputs - pointer to config item
1465 * output - NONE
1466 * side effects - Add a d/D line
1468 void
1469 conf_add_d_conf(struct ConfItem *aconf)
1471 if(aconf->host == NULL)
1472 return;
1474 aconf->user = NULL;
1476 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1477 * need this anyway, so I will disable it for now... -A1kmm
1480 if(parse_netmask(aconf->host, NULL, NULL) == HM_HOST)
1482 ilog(L_MAIN, "Invalid Dline %s ignored", aconf->host);
1483 free_conf(aconf);
1485 else
1487 add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf);
1493 * yyerror
1495 * inputs - message from parser
1496 * output - none
1497 * side effects - message to opers and log file entry is made
1499 void
1500 yyerror(const char *msg)
1502 char newlinebuf[BUFSIZE];
1504 strip_tabs(newlinebuf, (const unsigned char *) linebuf, strlen(linebuf));
1506 sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",
1507 conffilebuf, lineno + 1, msg, newlinebuf);
1509 ilog(L_MAIN, "\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
1513 conf_fgets(char *lbuf, int max_size, FILE * fb)
1515 char *buff;
1517 if((buff = fgets(lbuf, max_size, fb)) == NULL)
1518 return (0);
1520 return (strlen(lbuf));
1524 conf_yy_fatal_error(const char *msg)
1526 return (0);