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
24 * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $
28 #include "ircd_defs.h"
31 #include "s_newconf.h"
40 #include "irc_string.h"
41 #include "sprintf_irc.h"
56 #include "blacklist.h"
58 struct config_server_hide ConfigServerHide
;
60 extern int yyparse(); /* defined in y.tab.c */
61 extern char linebuf
[];
64 #define INADDR_NONE ((unsigned int) 0xffffffff)
67 static BlockHeap
*confitem_heap
= NULL
;
69 dlink_list temp_klines
[LAST_TEMP_TYPE
];
70 dlink_list temp_dlines
[LAST_TEMP_TYPE
];
71 dlink_list service_list
;
73 /* internally defined functions */
74 static void set_default_conf(void);
75 static void validate_conf(void);
76 static void read_conf(FILE *);
77 static void clear_out_old_conf(void);
79 static void expire_temp_kd(void *list
);
80 static void reorganise_temp_kd(void *list
);
85 static int verify_access(struct Client
*client_p
, const char *username
);
86 static int attach_iline(struct Client
*, struct ConfItem
*);
91 confitem_heap
= BlockHeapCreate(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
);
93 eventAddIsh("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
94 eventAddIsh("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
96 eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd
,
97 &temp_klines
[TEMP_HOUR
], 3600);
98 eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd
,
99 &temp_dlines
[TEMP_HOUR
], 3600);
100 eventAddIsh("expire_temp_klines_day", reorganise_temp_kd
,
101 &temp_klines
[TEMP_DAY
], 86400);
102 eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd
,
103 &temp_dlines
[TEMP_DAY
], 86400);
104 eventAddIsh("expire_temp_klines_week", reorganise_temp_kd
,
105 &temp_klines
[TEMP_WEEK
], 604800);
106 eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd
,
107 &temp_dlines
[TEMP_WEEK
], 604800);
114 * output - pointer to new conf entry
115 * side effects - none
120 struct ConfItem
*aconf
;
122 aconf
= BlockHeapAlloc(confitem_heap
);
123 aconf
->status
= CONF_ILLEGAL
;
130 * inputs - pointer to conf to free
132 * side effects - crucial password fields are zeroed, conf is freed
135 free_conf(struct ConfItem
*aconf
)
137 s_assert(aconf
!= NULL
);
143 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
145 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
147 MyFree(aconf
->passwd
);
148 MyFree(aconf
->spasswd
);
150 MyFree(aconf
->className
);
154 BlockHeapFree(confitem_heap
, aconf
);
160 * inputs - pointer to client
161 * output - 0 = Success
162 * NOT_AUTHORISED (-1) = Access denied (no I line match)
163 * SOCKET_ERROR (-2) = Bad socket.
164 * I_LINE_FULL (-3) = I-line is full
165 * TOO_MANY (-4) = Too many connections from hostname
166 * BANNED_CLIENT (-5) = K-lined
167 * side effects - Ordinary client access check.
168 * Look for conf lines which have the same
169 * status as the flags passed.
172 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
176 ClearAccess(source_p
);
178 if((i
= verify_access(source_p
, username
)))
180 ilog(L_FUSER
, "Access denied: %s[%s]",
181 source_p
->name
, source_p
->sockhost
);
187 exit_client(client_p
, source_p
, &me
, "Socket Error");
191 /* Note that these notices are sent to opers on other
192 * servers also, so even if local opers are allowed to
193 * see the IP, we still cannot send it.
195 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
196 "Too many local connections for %s!%s%s@%s",
197 source_p
->name
, IsGotId(source_p
) ? "" : "~",
199 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
201 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
202 source_p
->name
, IsGotId(source_p
) ? "" : "~",
203 source_p
->username
, source_p
->sockhost
);
205 ServerStats
->is_ref
++;
206 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
209 case TOO_MANY_GLOBAL
:
210 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
211 "Too many global connections for %s!%s%s@%s",
212 source_p
->name
, IsGotId(source_p
) ? "" : "~",
214 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
215 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
216 source_p
->name
, IsGotId(source_p
) ? "" : "~",
217 source_p
->username
, source_p
->sockhost
);
219 ServerStats
->is_ref
++;
220 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
224 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
225 "Too many user connections for %s!%s%s@%s",
226 source_p
->name
, IsGotId(source_p
) ? "" : "~",
228 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
229 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
230 source_p
->name
, IsGotId(source_p
) ? "" : "~",
231 source_p
->username
, source_p
->sockhost
);
233 ServerStats
->is_ref
++;
234 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
238 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
239 "I-line is full for %s!%s%s@%s (%s).",
240 source_p
->name
, IsGotId(source_p
) ? "" : "~",
241 source_p
->username
, source_p
->host
,
242 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
244 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
245 source_p
->name
, IsGotId(source_p
) ? "" : "~",
246 source_p
->username
, source_p
->sockhost
);
248 ServerStats
->is_ref
++;
249 exit_client(client_p
, source_p
, &me
,
250 "No more connections allowed in your connection class");
257 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
258 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
261 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
263 ServerStats
->is_ref
++;
264 /* jdc - lists server name & port connections are on */
265 /* a purely cosmetical change */
266 /* why ipaddr, and not just source_p->sockhost? --fl */
268 static char ipaddr
[HOSTIPLEN
];
269 inetntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
271 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
272 "Unauthorised client connection from "
273 "%s!%s%s@%s [%s] on [%s/%u].",
274 source_p
->name
, IsGotId(source_p
) ? "" : "~",
275 source_p
->username
, source_p
->host
,
277 source_p
->localClient
->listener
->name
, port
);
280 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
281 source_p
->name
, IsGotId(source_p
) ? "" : "~",
282 source_p
->username
, source_p
->sockhost
,
283 source_p
->localClient
->listener
->name
, port
);
284 add_reject(client_p
);
285 exit_client(client_p
, source_p
, &me
,
286 "You are not authorised to use this server");
290 add_reject(client_p
);
291 exit_client(client_p
, client_p
, &me
, "*** Banned ");
292 ServerStats
->is_ref
++;
305 * inputs - pointer to client to verify
306 * - pointer to proposed username
307 * output - 0 if success -'ve if not
308 * side effect - find the first (best) I line to attach.
311 verify_access(struct Client
*client_p
, const char *username
)
313 struct ConfItem
*aconf
;
314 char non_ident
[USERLEN
+ 1];
316 if(IsGotId(client_p
))
318 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
319 client_p
->username
, client_p
->username
,
320 (struct sockaddr
*) &client_p
->localClient
->ip
,
321 client_p
->localClient
->ip
.ss_family
);
325 strlcpy(non_ident
, "~", sizeof(non_ident
));
326 strlcat(non_ident
, username
, sizeof(non_ident
));
327 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
328 non_ident
, client_p
->username
,
329 (struct sockaddr
*) &client_p
->localClient
->ip
,
330 client_p
->localClient
->ip
.ss_family
);
334 return NOT_AUTHORISED
;
336 if(aconf
->status
& CONF_CLIENT
)
338 if(aconf
->flags
& CONF_FLAGS_REDIR
)
340 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
341 aconf
->name
? aconf
->name
: "", aconf
->port
);
342 return (NOT_AUTHORISED
);
346 if(IsConfDoIdentd(aconf
))
349 /* Thanks for spoof idea amm */
350 if(IsConfDoSpoofIp(aconf
))
354 /* show_ip() depends on this --fl */
355 SetIPSpoof(client_p
);
357 if(IsConfSpoofNotice(aconf
))
359 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
360 "%s spoofing: %s as %s",
362 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
366 /* user@host spoof */
367 if((p
= strchr(aconf
->name
, '@')) != NULL
)
372 strlcpy(client_p
->username
, aconf
->name
,
373 sizeof(client_p
->username
));
374 strlcpy(client_p
->host
, host
,
375 sizeof(client_p
->host
));
379 strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
381 return (attach_iline(client_p
, aconf
));
383 else if(aconf
->status
& CONF_KILL
)
385 if(ConfigFileEntry
.kline_with_reason
)
388 form_str(ERR_YOUREBANNEDCREEP
),
389 me
.name
, client_p
->name
, aconf
->passwd
);
391 return (BANNED_CLIENT
);
393 else if(aconf
->status
& CONF_GLINE
)
395 sendto_one_notice(client_p
, ":*** G-lined");
397 if(ConfigFileEntry
.kline_with_reason
)
399 form_str(ERR_YOUREBANNEDCREEP
),
400 me
.name
, client_p
->name
, aconf
->passwd
);
402 return (BANNED_CLIENT
);
405 return NOT_AUTHORISED
;
412 * Returns 1 if successful 0 if not
414 * This checks if the user has exceed the limits for their class
415 * unless of course they are exempt..
419 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
421 patricia_node_t
*pnode
;
423 /* If the limits are 0 don't do anything.. */
424 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
427 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
430 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
432 s_assert(pnode
!= NULL
);
436 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
437 && !IsConfExemptLimits(aconf
))
439 /* This should only happen if the limits are set to 0 */
440 if((unsigned long) pnode
->data
== 0)
442 patricia_remove(ConfIpLimits(aconf
), pnode
);
453 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
455 patricia_node_t
*pnode
;
457 /* If the limits are 0 don't do anything.. */
458 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
461 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
466 if(((unsigned long) pnode
->data
) == 0)
468 patricia_remove(ConfIpLimits(aconf
), pnode
);
476 * inputs - client pointer
479 * side effects - do actual attach
482 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
484 struct Client
*target_p
;
487 int global_count
= 0;
491 if(IsConfExemptLimits(aconf
))
492 return (attach_conf(client_p
, aconf
));
494 if(*client_p
->username
== '~')
498 /* find_hostname() returns the head of the list to search */
499 DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
501 target_p
= ptr
->data
;
503 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
506 if(MyConnect(target_p
))
513 if(*target_p
->username
== '~')
516 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
519 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
520 return (TOO_MANY_LOCAL
);
521 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
522 return (TOO_MANY_GLOBAL
);
523 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
524 return (TOO_MANY_IDENT
);
528 return (attach_conf(client_p
, aconf
));
534 * inputs - pointer to client to detach
535 * output - 0 for success, -1 for failure
536 * side effects - Disassociate configuration from the client.
537 * Also removes a class from the list if marked for deleting.
540 detach_conf(struct Client
*client_p
)
542 struct ConfItem
*aconf
;
544 aconf
= client_p
->localClient
->att_conf
;
550 remove_ip_limit(client_p
, aconf
);
552 if(ConfCurrUsers(aconf
) > 0)
553 --ConfCurrUsers(aconf
);
555 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
557 free_class(ClassPtr(aconf
));
558 ClassPtr(aconf
) = NULL
;
564 if(!aconf
->clients
&& IsIllegal(aconf
))
567 client_p
->localClient
->att_conf
= NULL
;
577 * inputs - client pointer
580 * side effects - Associate a specific configuration entry to a *local*
581 * client (this is the one which used in accepting the
582 * connection). Note, that this automatically changes the
583 * attachment if there was an old one...
586 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
589 return (NOT_AUTHORISED
);
593 if(!add_ip_limit(client_p
, aconf
))
594 return (TOO_MANY_LOCAL
);
597 if((aconf
->status
& CONF_CLIENT
) &&
598 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
600 if(!IsConfExemptLimits(aconf
))
602 return (I_LINE_FULL
);
606 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
607 SetExemptLimits(client_p
);
612 if(client_p
->localClient
->att_conf
!= NULL
)
613 detach_conf(client_p
);
615 client_p
->localClient
->att_conf
= aconf
;
618 ConfCurrUsers(aconf
)++;
625 * Actual REHASH service routine. Called with sig == 0 if it has been called
626 * as a result of an operator issuing this command, else assume it has been
627 * called as a result of the server receiving a HUP signal.
634 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
635 "Got signal SIGHUP, reloading ircd conf. file");
639 /* don't close listeners until we know we can go ahead with the rehash */
642 if(ServerInfo
.description
!= NULL
)
643 strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
645 strlcpy(me
.info
, "unknown", sizeof(me
.info
));
651 static struct banconf_entry
653 const char **filename
;
654 void (*func
) (FILE *);
657 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
658 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
659 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
660 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
661 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
662 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
663 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
664 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
672 char buf
[MAXPATHLEN
];
676 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
677 "Got signal SIGUSR2, reloading ban confs");
679 clear_out_address_conf_bans();
680 clear_s_newconf_bans();
682 for(i
= 0; banconfs
[i
].filename
; i
++)
685 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
687 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
689 if((file
= fopen(buf
, "r")) == NULL
)
694 ilog(L_MAIN
, "Failed reading ban file %s",
695 *banconfs
[i
].filename
);
696 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
697 "Can't open %s file bans could be missing!",
698 *banconfs
[i
].filename
);
702 (banconfs
[i
].func
)(file
);
707 check_banned_lines();
715 * side effects - Set default values here.
716 * This is called **PRIOR** to parsing the
717 * configuration file. If you want to do some validation
718 * of values later, put them in validate_conf().
726 set_default_conf(void)
728 /* ServerInfo.name is not rehashable */
729 /* ServerInfo.name = ServerInfo.name; */
730 ServerInfo
.description
= NULL
;
731 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
732 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
734 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
735 ServerInfo
.specific_ipv4_vhost
= 0;
737 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
738 ServerInfo
.specific_ipv6_vhost
= 0;
741 /* Don't reset hub, as that will break lazylinks */
742 /* ServerInfo.hub = NO; */
743 AdminInfo
.name
= NULL
;
744 AdminInfo
.email
= NULL
;
745 AdminInfo
.description
= NULL
;
747 DupString(ConfigFileEntry
.default_operstring
, "is an IRC operator");
748 DupString(ConfigFileEntry
.default_adminstring
, "is a Server Administrator");
749 DupString(ConfigFileEntry
.servicestring
, "is a Network Service");
751 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
752 ConfigFileEntry
.failed_oper_notice
= YES
;
753 ConfigFileEntry
.anti_nick_flood
= NO
;
754 ConfigFileEntry
.disable_fake_channels
= NO
;
755 ConfigFileEntry
.max_nick_time
= 20;
756 ConfigFileEntry
.max_nick_changes
= 5;
757 ConfigFileEntry
.max_accept
= 20;
758 ConfigFileEntry
.max_monitor
= 60;
759 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
760 ConfigFileEntry
.target_change
= YES
;
761 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
762 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
763 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
764 ConfigFileEntry
.client_exit
= YES
;
765 ConfigFileEntry
.dline_with_reason
= YES
;
766 ConfigFileEntry
.kline_with_reason
= YES
;
767 ConfigFileEntry
.kline_delay
= 0;
768 ConfigFileEntry
.warn_no_nline
= YES
;
769 ConfigFileEntry
.non_redundant_klines
= YES
;
770 ConfigFileEntry
.stats_e_disabled
= NO
;
771 ConfigFileEntry
.stats_o_oper_only
= NO
;
772 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
773 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
774 ConfigFileEntry
.stats_P_oper_only
= NO
;
775 ConfigFileEntry
.stats_c_oper_only
= NO
;
776 ConfigFileEntry
.stats_y_oper_only
= NO
;
777 ConfigFileEntry
.stats_h_oper_only
= NO
;
778 ConfigFileEntry
.map_oper_only
= YES
;
779 ConfigFileEntry
.operspy_admin_only
= NO
;
780 ConfigFileEntry
.pace_wait
= 10;
781 ConfigFileEntry
.caller_id_wait
= 60;
782 ConfigFileEntry
.pace_wait_simple
= 1;
783 ConfigFileEntry
.short_motd
= NO
;
784 ConfigFileEntry
.no_oper_flood
= NO
;
785 ConfigFileEntry
.fname_userlog
= NULL
;
786 ConfigFileEntry
.fname_fuserlog
= NULL
;
787 ConfigFileEntry
.fname_operlog
= NULL
;
788 ConfigFileEntry
.fname_foperlog
= NULL
;
789 ConfigFileEntry
.fname_serverlog
= NULL
;
790 ConfigFileEntry
.fname_glinelog
= NULL
;
791 ConfigFileEntry
.fname_klinelog
= NULL
;
792 ConfigFileEntry
.fname_operspylog
= NULL
;
793 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
794 ConfigFileEntry
.glines
= NO
;
795 ConfigFileEntry
.use_egd
= NO
;
796 ConfigFileEntry
.gline_time
= 12 * 3600;
797 ConfigFileEntry
.gline_min_cidr
= 16;
798 ConfigFileEntry
.gline_min_cidr6
= 48;
799 ConfigFileEntry
.hide_spoof_ips
= YES
;
800 ConfigFileEntry
.hide_error_messages
= 1;
801 ConfigFileEntry
.idletime
= 0;
802 ConfigFileEntry
.dots_in_ident
= 0;
803 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
804 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
805 ConfigFileEntry
.egdpool_path
= NULL
;
806 ConfigFileEntry
.use_whois_actually
= YES
;
807 ConfigFileEntry
.burst_away
= NO
;
808 ConfigFileEntry
.collision_fnc
= YES
;
809 ConfigFileEntry
.global_snotices
= YES
;
810 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
813 ConfigFileEntry
.compression_level
= 4;
816 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
817 UMODE_OPERWALL
| UMODE_WALLOP
;
818 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
819 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
821 ConfigChannel
.use_except
= YES
;
822 ConfigChannel
.use_invex
= YES
;
823 ConfigChannel
.use_knock
= YES
;
824 ConfigChannel
.use_forward
= YES
;
825 ConfigChannel
.knock_delay
= 300;
826 ConfigChannel
.knock_delay_channel
= 60;
827 ConfigChannel
.max_chans_per_user
= 15;
828 ConfigChannel
.max_bans
= 25;
829 ConfigChannel
.max_bans_large
= 500;
830 ConfigChannel
.burst_topicwho
= NO
;
831 ConfigChannel
.kick_on_split_riding
= NO
;
833 ConfigChannel
.default_split_user_count
= 15000;
834 ConfigChannel
.default_split_server_count
= 10;
835 ConfigChannel
.no_join_on_split
= NO
;
836 ConfigChannel
.no_create_on_split
= YES
;
838 ConfigServerHide
.flatten_links
= 0;
839 ConfigServerHide
.links_delay
= 300;
840 ConfigServerHide
.hidden
= 0;
841 ConfigServerHide
.disable_hidden
= 0;
843 ConfigFileEntry
.min_nonwildcard
= 4;
844 ConfigFileEntry
.min_nonwildcard_simple
= 3;
845 ConfigFileEntry
.default_floodcount
= 8;
846 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
847 ConfigFileEntry
.tkline_expire_notices
= 0;
849 ConfigFileEntry
.reject_after_count
= 5;
850 ConfigFileEntry
.reject_ban_time
= 300;
851 ConfigFileEntry
.reject_duration
= 120;
852 ConfigFileEntry
.max_unknown_ip
= 2;
854 ServerInfo
.max_clients
= comm_get_maxconnections() - MAX_BUFFER
;
864 * inputs - file descriptor pointing to config file to use
866 * side effects - Read configuration file.
869 read_conf(FILE * file
)
873 set_default_conf(); /* Set default values prior to conf parsing */
874 yyparse(); /* Load the values from the conf */
875 validate_conf(); /* Check to make sure some values are still okay. */
876 /* Some global values are also loaded here. */
877 check_class(); /* Make sure classes are valid */
883 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
884 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
886 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
887 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
889 if(ConfigFileEntry
.servlink_path
== NULL
)
890 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
892 if(ServerInfo
.network_name
== NULL
)
893 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
895 if(ServerInfo
.network_desc
== NULL
)
896 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
898 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
899 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
900 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
902 GlobalSetOptions
.idletime
= (ConfigFileEntry
.idletime
* 60);
904 if(!split_users
|| !split_servers
||
905 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
907 eventDelete(check_splitmode
, NULL
);
914 * lookup_confhost - start DNS lookups of all hostnames in the conf
915 * line and convert an IP addresses in a.b.c.d number for to IP#s.
920 * conf_connect_allowed
922 * inputs - pointer to inaddr
923 * - int type ipv4 or ipv6
924 * output - ban info or NULL
925 * side effects - none
928 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
930 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
932 /* DLINE exempt also gets you out of static limits/pacing... */
933 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
944 * inputs - pointer to struct ConfItem
946 * Side effects - links in given struct ConfItem into
947 * temporary kline link list
950 add_temp_kline(struct ConfItem
*aconf
)
952 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
954 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
955 aconf
->port
= TEMP_WEEK
;
957 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
959 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
960 aconf
->port
= TEMP_DAY
;
962 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
964 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
965 aconf
->port
= TEMP_HOUR
;
969 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
970 aconf
->port
= TEMP_MIN
;
973 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
974 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
979 * input - pointer to struct ConfItem
981 * side effects - added to tdline link list and address hash
984 add_temp_dline(struct ConfItem
*aconf
)
986 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
988 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
989 aconf
->port
= TEMP_WEEK
;
991 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
993 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
994 aconf
->port
= TEMP_DAY
;
996 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
998 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
999 aconf
->port
= TEMP_HOUR
;
1003 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
1004 aconf
->port
= TEMP_MIN
;
1007 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
1008 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
1013 * inputs - list pointer
1016 * side effects - expire tklines and moves them between lists
1019 expire_temp_kd(void *list
)
1022 dlink_node
*next_ptr
;
1023 struct ConfItem
*aconf
;
1025 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1029 if(aconf
->hold
<= CurrentTime
)
1031 /* Alert opers that a TKline expired - Hwy */
1032 if(ConfigFileEntry
.tkline_expire_notices
)
1033 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1034 "Temporary K-line for [%s@%s] expired",
1035 (aconf
->user
) ? aconf
->
1036 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1038 delete_one_address_conf(aconf
->host
, aconf
);
1039 dlinkDestroy(ptr
, list
);
1045 reorganise_temp_kd(void *list
)
1047 struct ConfItem
*aconf
;
1048 dlink_node
*ptr
, *next_ptr
;
1050 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1054 if(aconf
->hold
< (CurrentTime
+ (60 * 60)))
1056 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1057 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1058 aconf
->port
= TEMP_MIN
;
1060 else if(aconf
->port
> TEMP_HOUR
)
1062 if(aconf
->hold
< (CurrentTime
+ (1440 * 60)))
1064 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1065 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1066 aconf
->port
= TEMP_HOUR
;
1068 else if(aconf
->port
> TEMP_DAY
&&
1069 (aconf
->hold
< (CurrentTime
+ (10080 * 60))))
1071 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1072 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1073 aconf
->port
= TEMP_DAY
;
1080 /* const char* get_oper_name(struct Client *client_p)
1081 * Input: A client to find the active oper{} name for.
1082 * Output: The nick!user@host{oper} of the oper.
1083 * "oper" is server name for remote opers
1084 * Side effects: None.
1087 get_oper_name(struct Client
*client_p
)
1089 /* +5 for !,@,{,} and null */
1090 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1092 if(MyOper(client_p
))
1094 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1095 client_p
->name
, client_p
->username
,
1096 client_p
->host
, client_p
->localClient
->opername
);
1100 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1101 client_p
->name
, client_p
->username
,
1102 client_p
->host
, client_p
->servptr
->name
);
1107 * get_printable_conf
1109 * inputs - struct ConfItem
1118 * Examine the struct struct ConfItem, setting the values
1119 * of name, host, pass, user to values either
1120 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1123 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1124 char **pass
, char **user
, int *port
, char **classname
)
1126 static char null
[] = "<NULL>";
1127 static char zero
[] = "default";
1129 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1130 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1131 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1132 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1133 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1134 *port
= (int) aconf
->port
;
1138 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1139 char **host
, char **reason
,
1140 char **user
, char **oper_reason
)
1142 static char null
[] = "<NULL>";
1144 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1145 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1146 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1148 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1149 *oper_reason
= NULL
;
1151 *oper_reason
= aconf
->spasswd
;
1157 * inputs - cold start YES or NO
1159 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1162 read_conf_files(int cold
)
1164 const char *filename
;
1166 conf_fbfile_in
= NULL
;
1168 filename
= get_conf_name(CONF_TYPE
);
1170 /* We need to know the initial filename for the yyerror() to report
1171 FIXME: The full path is in conffilenamebuf first time since we
1172 dont know anything else
1176 strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1178 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1182 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1187 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1188 "Can't open file '%s' - aborting rehash!", filename
);
1195 clear_out_old_conf();
1198 read_conf(conf_fbfile_in
);
1199 fclose(conf_fbfile_in
);
1203 * free an alias{} entry.
1206 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1208 struct alias_entry
*aptr
= ptr
->data
;
1211 MyFree(aptr
->target
);
1216 * clear_out_old_conf
1220 * side effects - Clear out the old configuration
1223 clear_out_old_conf(void)
1225 struct Class
*cltmp
;
1227 dlink_node
*next_ptr
;
1230 * don't delete the class table, rather mark all entries
1231 * for deletion. The table is cleaned up by check_class. - avalon
1233 DLINK_FOREACH(ptr
, class_list
.head
)
1236 MaxUsers(cltmp
) = -1;
1239 clear_out_address_conf();
1242 /* clean out module paths */
1243 #ifndef STATIC_MODULES
1245 mod_add_path(MODULE_DIR
);
1246 mod_add_path(MODULE_DIR
"/autoload");
1249 /* clean out ServerInfo */
1250 MyFree(ServerInfo
.description
);
1251 ServerInfo
.description
= NULL
;
1252 MyFree(ServerInfo
.network_name
);
1253 ServerInfo
.network_name
= NULL
;
1254 MyFree(ServerInfo
.network_desc
);
1255 ServerInfo
.network_desc
= NULL
;
1257 /* clean out AdminInfo */
1258 MyFree(AdminInfo
.name
);
1259 AdminInfo
.name
= NULL
;
1260 MyFree(AdminInfo
.email
);
1261 AdminInfo
.email
= NULL
;
1262 MyFree(AdminInfo
.description
);
1263 AdminInfo
.description
= NULL
;
1265 /* operator{} and class{} blocks are freed above */
1266 /* clean out listeners */
1269 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1270 * and gecos{} blocks are freed above too
1273 /* clean out general */
1274 MyFree(ConfigFileEntry
.servlink_path
);
1275 ConfigFileEntry
.servlink_path
= NULL
;
1277 DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1280 dlinkDestroy(ptr
, &service_list
);
1283 /* remove any aliases... -- nenolod */
1284 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1287 destroy_blacklists();
1289 /* OK, that should be everything... */
1295 * inputs - kline, dline or resv type flag
1296 * - client pointer to report to
1297 * - user name of target
1298 * - host name of target
1299 * - reason for target
1303 * side effects - This function takes care of finding the right conf
1304 * file and adding the line to it, as well as notifying
1305 * opers and the user.
1308 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1309 char *host
, const char *reason
, const char *oper_reason
,
1310 const char *current_date
, int xtype
)
1314 const char *filename
; /* filename to use for kline */
1316 filename
= get_conf_name(type
);
1318 if(type
== KLINE_TYPE
)
1320 if(EmptyString(oper_reason
))
1322 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1323 "%s added K-Line for [%s@%s] [%s]",
1324 get_oper_name(source_p
), user
,
1326 ilog(L_KLINE
, "K %s 0 %s %s %s",
1327 get_oper_name(source_p
), user
, host
, reason
);
1331 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1332 "%s added K-Line for [%s@%s] [%s|%s]",
1333 get_oper_name(source_p
), user
,
1334 host
, reason
, oper_reason
);
1335 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1336 get_oper_name(source_p
), user
, host
,
1337 reason
, oper_reason
);
1340 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1343 else if(type
== DLINE_TYPE
)
1345 if(EmptyString(oper_reason
))
1347 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1348 "%s added D-Line for [%s] [%s]",
1349 get_oper_name(source_p
), host
, reason
);
1350 ilog(L_KLINE
, "D %s 0 %s %s",
1351 get_oper_name(source_p
), host
, reason
);
1355 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1356 "%s added D-Line for [%s] [%s|%s]",
1357 get_oper_name(source_p
), host
,
1358 reason
, oper_reason
);
1359 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1360 get_oper_name(source_p
), host
,
1361 reason
, oper_reason
);
1364 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1367 else if(type
== RESV_TYPE
)
1369 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1370 "%s added RESV for [%s] [%s]",
1371 get_oper_name(source_p
), host
, reason
);
1372 ilog(L_KLINE
, "R %s 0 %s %s",
1373 get_oper_name(source_p
), host
, reason
);
1375 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1379 if((out
= fopen(filename
, "a")) == NULL
)
1381 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1382 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1386 if(oper_reason
== NULL
)
1389 if(type
== KLINE_TYPE
)
1391 ircsnprintf(buffer
, sizeof(buffer
),
1392 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1393 user
, host
, reason
, oper_reason
, current_date
,
1394 get_oper_name(source_p
), CurrentTime
);
1396 else if(type
== DLINE_TYPE
)
1398 ircsnprintf(buffer
, sizeof(buffer
),
1399 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1400 reason
, oper_reason
, current_date
, get_oper_name(source_p
), CurrentTime
);
1402 else if(type
== RESV_TYPE
)
1404 ircsnprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1405 host
, reason
, get_oper_name(source_p
), CurrentTime
);
1408 if(fputs(buffer
, out
) == -1)
1410 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1411 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1418 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1419 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1426 * inputs - type of conf file to return name of file for
1427 * output - pointer to filename for type of conf
1428 * side effects - none
1431 get_conf_name(KlineType type
)
1433 if(type
== CONF_TYPE
)
1435 return (ConfigFileEntry
.configfile
);
1437 else if(type
== DLINE_TYPE
)
1439 return (ConfigFileEntry
.dlinefile
);
1441 else if(type
== RESV_TYPE
)
1443 return (ConfigFileEntry
.resvfile
);
1446 return ConfigFileEntry
.klinefile
;
1450 * conf_add_class_to_conf
1451 * inputs - pointer to config item
1453 * side effects - Add a class pointer to a conf
1457 conf_add_class_to_conf(struct ConfItem
*aconf
)
1459 if(aconf
->className
== NULL
)
1461 DupString(aconf
->className
, "default");
1462 ClassPtr(aconf
) = default_class
;
1466 ClassPtr(aconf
) = find_class(aconf
->className
);
1468 if(ClassPtr(aconf
) == default_class
)
1470 if(aconf
->status
== CONF_CLIENT
)
1472 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1473 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1474 aconf
->className
, aconf
->user
, aconf
->host
);
1477 MyFree(aconf
->className
);
1478 DupString(aconf
->className
, "default");
1482 if(ConfMaxUsers(aconf
) < 0)
1484 ClassPtr(aconf
) = default_class
;
1485 MyFree(aconf
->className
);
1486 DupString(aconf
->className
, "default");
1493 * inputs - pointer to config item
1495 * side effects - Add a d/D line
1498 conf_add_d_conf(struct ConfItem
*aconf
)
1500 if(aconf
->host
== NULL
)
1505 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1506 * need this anyway, so I will disable it for now... -A1kmm
1509 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1511 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1516 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1524 * inputs - message from parser
1526 * side effects - message to opers and log file entry is made
1529 yyerror(const char *msg
)
1531 char newlinebuf
[BUFSIZE
];
1533 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1535 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1536 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1538 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1542 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1546 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1549 return (strlen(lbuf
));
1553 conf_yy_fatal_error(const char *msg
)