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"
30 #include "s_newconf.h"
38 #include "irc_string.h"
39 #include "sprintf_irc.h"
49 #include "blacklist.h"
52 struct config_server_hide ConfigServerHide
;
54 extern int yyparse(); /* defined in y.tab.c */
55 extern char linebuf
[];
58 #define INADDR_NONE ((unsigned int) 0xffffffff)
61 static rb_bh
*confitem_heap
= NULL
;
63 rb_dlink_list temp_klines
[LAST_TEMP_TYPE
];
64 rb_dlink_list temp_dlines
[LAST_TEMP_TYPE
];
65 rb_dlink_list service_list
;
67 /* internally defined functions */
68 static void set_default_conf(void);
69 static void validate_conf(void);
70 static void read_conf(FILE *);
71 static void clear_out_old_conf(void);
73 static void expire_temp_kd(void *list
);
74 static void reorganise_temp_kd(void *list
);
79 static int verify_access(struct Client
*client_p
, const char *username
);
80 static int attach_iline(struct Client
*, struct ConfItem
*);
85 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
, "confitem_heap");
87 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
88 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
90 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
91 &temp_klines
[TEMP_HOUR
], 3600);
92 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
93 &temp_dlines
[TEMP_HOUR
], 3600);
94 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
95 &temp_klines
[TEMP_DAY
], 86400);
96 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
97 &temp_dlines
[TEMP_DAY
], 86400);
98 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
99 &temp_klines
[TEMP_WEEK
], 604800);
100 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
101 &temp_dlines
[TEMP_WEEK
], 604800);
108 * output - pointer to new conf entry
109 * side effects - none
114 struct ConfItem
*aconf
;
116 aconf
= rb_bh_alloc(confitem_heap
);
117 aconf
->status
= CONF_ILLEGAL
;
124 * inputs - pointer to conf to free
126 * side effects - crucial password fields are zeroed, conf is freed
129 free_conf(struct ConfItem
*aconf
)
131 s_assert(aconf
!= NULL
);
137 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
139 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
141 rb_free(aconf
->passwd
);
142 rb_free(aconf
->spasswd
);
143 rb_free(aconf
->name
);
144 rb_free(aconf
->className
);
145 rb_free(aconf
->user
);
146 rb_free(aconf
->host
);
148 rb_bh_free(confitem_heap
, aconf
);
154 * inputs - pointer to client
155 * output - 0 = Success
156 * NOT_AUTHORISED (-1) = Access denied (no I line match)
157 * SOCKET_ERROR (-2) = Bad socket.
158 * I_LINE_FULL (-3) = I-line is full
159 * TOO_MANY (-4) = Too many connections from hostname
160 * BANNED_CLIENT (-5) = K-lined
161 * side effects - Ordinary client access check.
162 * Look for conf lines which have the same
163 * status as the flags passed.
166 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
170 if((i
= verify_access(source_p
, username
)))
172 ilog(L_FUSER
, "Access denied: %s[%s]",
173 source_p
->name
, source_p
->sockhost
);
179 exit_client(client_p
, source_p
, &me
, "Socket Error");
183 /* Note that these notices are sent to opers on other
184 * servers also, so even if local opers are allowed to
185 * see the IP, we still cannot send it.
187 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
188 "Too many local connections for %s!%s%s@%s",
189 source_p
->name
, IsGotId(source_p
) ? "" : "~",
191 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
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)");
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
) ? "" : "~",
206 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
207 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
208 source_p
->name
, IsGotId(source_p
) ? "" : "~",
209 source_p
->username
, source_p
->sockhost
);
211 ServerStats
.is_ref
++;
212 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
216 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
217 "Too many user connections for %s!%s%s@%s",
218 source_p
->name
, IsGotId(source_p
) ? "" : "~",
220 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
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)");
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 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
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");
249 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
250 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
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 */
260 static char ipaddr
[HOSTIPLEN
];
261 inetntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
263 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
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
,
269 source_p
->localClient
->listener
->name
, port
);
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
, NULL
, NULL
);
277 exit_client(client_p
, source_p
, &me
,
278 "You are not authorised to use this server");
282 exit_client(client_p
, client_p
, &me
, "*** Banned ");
283 ServerStats
.is_ref
++;
296 * inputs - pointer to client to verify
297 * - pointer to proposed username
298 * output - 0 if success -'ve if not
299 * side effect - find the first (best) I line to attach.
302 verify_access(struct Client
*client_p
, const char *username
)
304 struct ConfItem
*aconf
;
305 char non_ident
[USERLEN
+ 1];
307 if(IsGotId(client_p
))
309 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
310 client_p
->username
, client_p
->username
,
311 (struct sockaddr
*) &client_p
->localClient
->ip
,
312 client_p
->localClient
->ip
.ss_family
);
316 rb_strlcpy(non_ident
, "~", sizeof(non_ident
));
317 rb_strlcat(non_ident
, username
, sizeof(non_ident
));
318 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
319 non_ident
, client_p
->username
,
320 (struct sockaddr
*) &client_p
->localClient
->ip
,
321 client_p
->localClient
->ip
.ss_family
);
325 return NOT_AUTHORISED
;
327 if(aconf
->status
& CONF_CLIENT
)
329 if(aconf
->flags
& CONF_FLAGS_REDIR
)
331 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
332 aconf
->name
? aconf
->name
: "", aconf
->port
);
333 return (NOT_AUTHORISED
);
336 /* Thanks for spoof idea amm */
337 if(IsConfDoSpoofIp(aconf
))
341 /* show_ip() depends on this --fl */
342 SetIPSpoof(client_p
);
344 if(IsConfSpoofNotice(aconf
))
346 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
347 "%s spoofing: %s as %s",
349 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
353 /* user@host spoof */
354 if((p
= strchr(aconf
->name
, '@')) != NULL
)
359 rb_strlcpy(client_p
->username
, aconf
->name
,
360 sizeof(client_p
->username
));
361 rb_strlcpy(client_p
->host
, host
,
362 sizeof(client_p
->host
));
366 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
368 return (attach_iline(client_p
, aconf
));
370 else if(aconf
->status
& CONF_KILL
)
372 if(ConfigFileEntry
.kline_with_reason
)
375 form_str(ERR_YOUREBANNEDCREEP
),
376 me
.name
, client_p
->name
, aconf
->passwd
);
378 add_reject(client_p
, aconf
->user
, aconf
->host
);
379 return (BANNED_CLIENT
);
382 return NOT_AUTHORISED
;
389 * Returns 1 if successful 0 if not
391 * This checks if the user has exceed the limits for their class
392 * unless of course they are exempt..
396 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
398 rb_patricia_node_t
*pnode
;
400 /* If the limits are 0 don't do anything.. */
401 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
404 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
407 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
409 s_assert(pnode
!= NULL
);
413 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
414 && !IsConfExemptLimits(aconf
))
416 /* This should only happen if the limits are set to 0 */
417 if((unsigned long) pnode
->data
== 0)
419 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
430 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
432 rb_patricia_node_t
*pnode
;
434 /* If the limits are 0 don't do anything.. */
435 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
438 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
443 if(((unsigned long) pnode
->data
) == 0)
445 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
453 * inputs - client pointer
456 * side effects - do actual attach
459 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
461 struct Client
*target_p
;
464 int global_count
= 0;
468 if(IsConfExemptLimits(aconf
))
469 return (attach_conf(client_p
, aconf
));
471 if(*client_p
->username
== '~')
475 /* find_hostname() returns the head of the list to search */
476 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
478 target_p
= ptr
->data
;
480 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
483 if(MyConnect(target_p
))
490 if(*target_p
->username
== '~')
493 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
496 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
497 return (TOO_MANY_LOCAL
);
498 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
499 return (TOO_MANY_GLOBAL
);
500 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
501 return (TOO_MANY_IDENT
);
505 return (attach_conf(client_p
, aconf
));
511 * inputs - pointer to client to detach
512 * output - 0 for success, -1 for failure
513 * side effects - Disassociate configuration from the client.
514 * Also removes a class from the list if marked for deleting.
517 detach_conf(struct Client
*client_p
)
519 struct ConfItem
*aconf
;
521 aconf
= client_p
->localClient
->att_conf
;
527 remove_ip_limit(client_p
, aconf
);
529 if(ConfCurrUsers(aconf
) > 0)
530 --ConfCurrUsers(aconf
);
532 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
534 free_class(ClassPtr(aconf
));
535 ClassPtr(aconf
) = NULL
;
541 if(!aconf
->clients
&& IsIllegal(aconf
))
544 client_p
->localClient
->att_conf
= NULL
;
554 * inputs - client pointer
557 * side effects - Associate a specific configuration entry to a *local*
558 * client (this is the one which used in accepting the
559 * connection). Note, that this automatically changes the
560 * attachment if there was an old one...
563 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
566 return (NOT_AUTHORISED
);
570 if(!add_ip_limit(client_p
, aconf
))
571 return (TOO_MANY_LOCAL
);
574 if((aconf
->status
& CONF_CLIENT
) &&
575 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
577 if(!IsConfExemptLimits(aconf
))
579 return (I_LINE_FULL
);
583 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
588 if(client_p
->localClient
->att_conf
!= NULL
)
589 detach_conf(client_p
);
591 client_p
->localClient
->att_conf
= aconf
;
594 ConfCurrUsers(aconf
)++;
601 * Actual REHASH service routine. Called with sig == 0 if it has been called
602 * as a result of an operator issuing this command, else assume it has been
603 * called as a result of the server receiving a HUP signal.
610 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
611 "Got signal SIGHUP, reloading ircd conf. file");
615 /* don't close listeners until we know we can go ahead with the rehash */
618 if(ServerInfo
.description
!= NULL
)
619 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
621 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
627 static struct banconf_entry
629 const char **filename
;
630 void (*func
) (FILE *);
633 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
634 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
635 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
636 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
637 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
638 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
639 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
640 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
648 char buf
[MAXPATHLEN
];
652 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
653 "Got signal SIGUSR2, reloading ban confs");
655 clear_out_address_conf_bans();
656 clear_s_newconf_bans();
658 for(i
= 0; banconfs
[i
].filename
; i
++)
661 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
663 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
665 if((file
= fopen(buf
, "r")) == NULL
)
670 ilog(L_MAIN
, "Failed reading ban file %s",
671 *banconfs
[i
].filename
);
672 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
673 "Can't open %s file bans could be missing!",
674 *banconfs
[i
].filename
);
678 (banconfs
[i
].func
)(file
);
683 check_banned_lines();
691 * side effects - Set default values here.
692 * This is called **PRIOR** to parsing the
693 * configuration file. If you want to do some validation
694 * of values later, put them in validate_conf().
702 set_default_conf(void)
704 /* ServerInfo.name is not rehashable */
705 /* ServerInfo.name = ServerInfo.name; */
706 ServerInfo
.description
= NULL
;
707 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
708 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
710 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
711 ServerInfo
.specific_ipv4_vhost
= 0;
713 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
714 ServerInfo
.specific_ipv6_vhost
= 0;
717 /* Don't reset hub, as that will break lazylinks */
718 /* ServerInfo.hub = NO; */
719 AdminInfo
.name
= NULL
;
720 AdminInfo
.email
= NULL
;
721 AdminInfo
.description
= NULL
;
723 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
724 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
725 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
727 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
728 ConfigFileEntry
.failed_oper_notice
= YES
;
729 ConfigFileEntry
.anti_nick_flood
= NO
;
730 ConfigFileEntry
.disable_fake_channels
= NO
;
731 ConfigFileEntry
.max_nick_time
= 20;
732 ConfigFileEntry
.max_nick_changes
= 5;
733 ConfigFileEntry
.max_accept
= 20;
734 ConfigFileEntry
.max_monitor
= 60;
735 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
736 ConfigFileEntry
.target_change
= YES
;
737 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
738 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
739 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
740 ConfigFileEntry
.client_exit
= YES
;
741 ConfigFileEntry
.dline_with_reason
= YES
;
742 ConfigFileEntry
.kline_with_reason
= YES
;
743 ConfigFileEntry
.kline_delay
= 0;
744 ConfigFileEntry
.warn_no_nline
= YES
;
745 ConfigFileEntry
.non_redundant_klines
= YES
;
746 ConfigFileEntry
.stats_e_disabled
= NO
;
747 ConfigFileEntry
.stats_o_oper_only
= NO
;
748 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
749 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
750 ConfigFileEntry
.stats_P_oper_only
= NO
;
751 ConfigFileEntry
.stats_c_oper_only
= NO
;
752 ConfigFileEntry
.stats_y_oper_only
= NO
;
753 ConfigFileEntry
.stats_h_oper_only
= NO
;
754 ConfigFileEntry
.map_oper_only
= YES
;
755 ConfigFileEntry
.operspy_admin_only
= NO
;
756 ConfigFileEntry
.pace_wait
= 10;
757 ConfigFileEntry
.caller_id_wait
= 60;
758 ConfigFileEntry
.pace_wait_simple
= 1;
759 ConfigFileEntry
.short_motd
= NO
;
760 ConfigFileEntry
.no_oper_flood
= NO
;
761 ConfigFileEntry
.fname_userlog
= NULL
;
762 ConfigFileEntry
.fname_fuserlog
= NULL
;
763 ConfigFileEntry
.fname_operlog
= NULL
;
764 ConfigFileEntry
.fname_foperlog
= NULL
;
765 ConfigFileEntry
.fname_serverlog
= NULL
;
766 ConfigFileEntry
.fname_klinelog
= NULL
;
767 ConfigFileEntry
.fname_operspylog
= NULL
;
768 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
769 ConfigFileEntry
.use_egd
= NO
;
770 ConfigFileEntry
.hide_spoof_ips
= YES
;
771 ConfigFileEntry
.hide_error_messages
= 1;
772 ConfigFileEntry
.dots_in_ident
= 0;
773 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
774 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
775 ConfigFileEntry
.egdpool_path
= NULL
;
776 ConfigFileEntry
.use_whois_actually
= YES
;
777 ConfigFileEntry
.burst_away
= NO
;
778 ConfigFileEntry
.collision_fnc
= YES
;
779 ConfigFileEntry
.global_snotices
= YES
;
780 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
783 ConfigFileEntry
.compression_level
= 4;
786 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
787 UMODE_OPERWALL
| UMODE_WALLOP
;
788 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
789 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
791 ConfigChannel
.use_except
= YES
;
792 ConfigChannel
.use_invex
= YES
;
793 ConfigChannel
.use_knock
= YES
;
794 ConfigChannel
.use_forward
= YES
;
795 ConfigChannel
.knock_delay
= 300;
796 ConfigChannel
.knock_delay_channel
= 60;
797 ConfigChannel
.max_chans_per_user
= 15;
798 ConfigChannel
.max_bans
= 25;
799 ConfigChannel
.max_bans_large
= 500;
800 ConfigChannel
.burst_topicwho
= NO
;
801 ConfigChannel
.kick_on_split_riding
= NO
;
803 ConfigChannel
.default_split_user_count
= 15000;
804 ConfigChannel
.default_split_server_count
= 10;
805 ConfigChannel
.no_join_on_split
= NO
;
806 ConfigChannel
.no_create_on_split
= YES
;
808 ConfigServerHide
.flatten_links
= 0;
809 ConfigServerHide
.links_delay
= 300;
810 ConfigServerHide
.hidden
= 0;
811 ConfigServerHide
.disable_hidden
= 0;
813 ConfigFileEntry
.min_nonwildcard
= 4;
814 ConfigFileEntry
.min_nonwildcard_simple
= 3;
815 ConfigFileEntry
.default_floodcount
= 8;
816 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
817 ConfigFileEntry
.tkline_expire_notices
= 0;
819 ConfigFileEntry
.reject_after_count
= 5;
820 ConfigFileEntry
.reject_ban_time
= 300;
821 ConfigFileEntry
.reject_duration
= 120;
822 ConfigFileEntry
.max_unknown_ip
= 2;
824 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
834 * inputs - file descriptor pointing to config file to use
836 * side effects - Read configuration file.
839 read_conf(FILE * file
)
843 set_default_conf(); /* Set default values prior to conf parsing */
844 yyparse(); /* Load the values from the conf */
845 validate_conf(); /* Check to make sure some values are still okay. */
846 /* Some global values are also loaded here. */
847 check_class(); /* Make sure classes are valid */
853 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
854 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
856 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
857 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
859 if(ConfigFileEntry
.servlink_path
== NULL
)
860 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
862 if(ServerInfo
.network_name
== NULL
)
863 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
865 if(ServerInfo
.network_desc
== NULL
)
866 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
868 if(ServerInfo
.ssld_count
< 1)
869 ServerInfo
.ssld_count
= 1;
871 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
873 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
877 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
880 if(ServerInfo
.ssld_count
> get_ssld_count())
882 int start
= ServerInfo
.ssld_count
- get_ssld_count();
883 /* start up additional ssld if needed */
884 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
888 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
889 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
890 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
892 if(!split_users
|| !split_servers
||
893 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
895 rb_event_delete(check_splitmode_ev
);
896 check_splitmode_ev
= NULL
;
903 * lookup_confhost - start DNS lookups of all hostnames in the conf
904 * line and convert an IP addresses in a.b.c.d number for to IP#s.
909 * conf_connect_allowed
911 * inputs - pointer to inaddr
912 * - int type ipv4 or ipv6
913 * output - ban info or NULL
914 * side effects - none
917 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
919 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
921 /* DLINE exempt also gets you out of static limits/pacing... */
922 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
933 * inputs - pointer to struct ConfItem
935 * Side effects - links in given struct ConfItem into
936 * temporary kline link list
939 add_temp_kline(struct ConfItem
*aconf
)
941 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
943 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
944 aconf
->port
= TEMP_WEEK
;
946 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
948 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
949 aconf
->port
= TEMP_DAY
;
951 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
953 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
954 aconf
->port
= TEMP_HOUR
;
958 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
959 aconf
->port
= TEMP_MIN
;
962 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
963 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
968 * input - pointer to struct ConfItem
970 * side effects - added to tdline link list and address hash
973 add_temp_dline(struct ConfItem
*aconf
)
975 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
977 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
978 aconf
->port
= TEMP_WEEK
;
980 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
982 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
983 aconf
->port
= TEMP_DAY
;
985 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
987 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
988 aconf
->port
= TEMP_HOUR
;
992 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
993 aconf
->port
= TEMP_MIN
;
996 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
997 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
1002 * inputs - list pointer
1005 * side effects - expire tklines and moves them between lists
1008 expire_temp_kd(void *list
)
1011 rb_dlink_node
*next_ptr
;
1012 struct ConfItem
*aconf
;
1014 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1018 if(aconf
->hold
<= rb_current_time())
1020 /* Alert opers that a TKline expired - Hwy */
1021 if(ConfigFileEntry
.tkline_expire_notices
)
1022 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1023 "Temporary K-line for [%s@%s] expired",
1024 (aconf
->user
) ? aconf
->
1025 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1027 delete_one_address_conf(aconf
->host
, aconf
);
1028 rb_dlinkDestroy(ptr
, list
);
1034 reorganise_temp_kd(void *list
)
1036 struct ConfItem
*aconf
;
1037 rb_dlink_node
*ptr
, *next_ptr
;
1039 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1043 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1045 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1046 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1047 aconf
->port
= TEMP_MIN
;
1049 else if(aconf
->port
> TEMP_HOUR
)
1051 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1053 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1054 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1055 aconf
->port
= TEMP_HOUR
;
1057 else if(aconf
->port
> TEMP_DAY
&&
1058 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1060 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1061 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1062 aconf
->port
= TEMP_DAY
;
1069 /* const char* get_oper_name(struct Client *client_p)
1070 * Input: A client to find the active oper{} name for.
1071 * Output: The nick!user@host{oper} of the oper.
1072 * "oper" is server name for remote opers
1073 * Side effects: None.
1076 get_oper_name(struct Client
*client_p
)
1078 /* +5 for !,@,{,} and null */
1079 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1081 if(MyOper(client_p
))
1083 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1084 client_p
->name
, client_p
->username
,
1085 client_p
->host
, client_p
->localClient
->opername
);
1089 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1090 client_p
->name
, client_p
->username
,
1091 client_p
->host
, client_p
->servptr
->name
);
1096 * get_printable_conf
1098 * inputs - struct ConfItem
1107 * Examine the struct struct ConfItem, setting the values
1108 * of name, host, pass, user to values either
1109 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1112 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1113 char **pass
, char **user
, int *port
, char **classname
)
1115 static char null
[] = "<NULL>";
1116 static char zero
[] = "default";
1118 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1119 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1120 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1121 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1122 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1123 *port
= (int) aconf
->port
;
1127 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1128 char **host
, char **reason
,
1129 char **user
, char **oper_reason
)
1131 static char null
[] = "<NULL>";
1133 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1134 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1135 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1137 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1138 *oper_reason
= NULL
;
1140 *oper_reason
= aconf
->spasswd
;
1146 * inputs - cold start YES or NO
1148 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1151 read_conf_files(int cold
)
1153 const char *filename
;
1155 conf_fbfile_in
= NULL
;
1157 filename
= get_conf_name(CONF_TYPE
);
1159 /* We need to know the initial filename for the yyerror() to report
1160 FIXME: The full path is in conffilenamebuf first time since we
1161 dont know anything else
1165 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1167 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1171 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1176 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1177 "Can't open file '%s' - aborting rehash!", filename
);
1184 clear_out_old_conf();
1187 read_conf(conf_fbfile_in
);
1188 fclose(conf_fbfile_in
);
1192 * free an alias{} entry.
1195 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1197 struct alias_entry
*aptr
= ptr
->data
;
1199 rb_free(aptr
->name
);
1200 rb_free(aptr
->target
);
1205 * clear_out_old_conf
1209 * side effects - Clear out the old configuration
1212 clear_out_old_conf(void)
1214 struct Class
*cltmp
;
1216 rb_dlink_node
*next_ptr
;
1219 * don't delete the class table, rather mark all entries
1220 * for deletion. The table is cleaned up by check_class. - avalon
1222 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1225 MaxUsers(cltmp
) = -1;
1228 clear_out_address_conf();
1231 /* clean out module paths */
1232 #ifndef STATIC_MODULES
1234 mod_add_path(MODULE_DIR
);
1235 mod_add_path(MODULE_DIR
"/autoload");
1238 /* clean out ServerInfo */
1239 rb_free(ServerInfo
.description
);
1240 ServerInfo
.description
= NULL
;
1241 rb_free(ServerInfo
.network_name
);
1242 ServerInfo
.network_name
= NULL
;
1243 rb_free(ServerInfo
.network_desc
);
1244 ServerInfo
.network_desc
= NULL
;
1246 ServerInfo
.ssld_count
= 1;
1248 /* clean out AdminInfo */
1249 rb_free(AdminInfo
.name
);
1250 AdminInfo
.name
= NULL
;
1251 rb_free(AdminInfo
.email
);
1252 AdminInfo
.email
= NULL
;
1253 rb_free(AdminInfo
.description
);
1254 AdminInfo
.description
= NULL
;
1256 /* operator{} and class{} blocks are freed above */
1257 /* clean out listeners */
1260 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1261 * and gecos{} blocks are freed above too
1264 /* clean out general */
1265 rb_free(ConfigFileEntry
.servlink_path
);
1266 ConfigFileEntry
.servlink_path
= NULL
;
1268 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1271 rb_dlinkDestroy(ptr
, &service_list
);
1274 /* remove any aliases... -- nenolod */
1275 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1278 destroy_blacklists();
1280 /* OK, that should be everything... */
1286 * inputs - kline, dline or resv type flag
1287 * - client pointer to report to
1288 * - user name of target
1289 * - host name of target
1290 * - reason for target
1294 * side effects - This function takes care of finding the right conf
1295 * file and adding the line to it, as well as notifying
1296 * opers and the user.
1299 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1300 char *host
, const char *reason
, const char *oper_reason
,
1301 const char *current_date
, int xtype
)
1305 const char *filename
; /* filename to use for kline */
1307 filename
= get_conf_name(type
);
1309 if(type
== KLINE_TYPE
)
1311 if(EmptyString(oper_reason
))
1313 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1314 "%s added K-Line for [%s@%s] [%s]",
1315 get_oper_name(source_p
), user
,
1317 ilog(L_KLINE
, "K %s 0 %s %s %s",
1318 get_oper_name(source_p
), user
, host
, reason
);
1322 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1323 "%s added K-Line for [%s@%s] [%s|%s]",
1324 get_oper_name(source_p
), user
,
1325 host
, reason
, oper_reason
);
1326 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1327 get_oper_name(source_p
), user
, host
,
1328 reason
, oper_reason
);
1331 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1334 else if(type
== DLINE_TYPE
)
1336 if(EmptyString(oper_reason
))
1338 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1339 "%s added D-Line for [%s] [%s]",
1340 get_oper_name(source_p
), host
, reason
);
1341 ilog(L_KLINE
, "D %s 0 %s %s",
1342 get_oper_name(source_p
), host
, reason
);
1346 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1347 "%s added D-Line for [%s] [%s|%s]",
1348 get_oper_name(source_p
), host
,
1349 reason
, oper_reason
);
1350 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1351 get_oper_name(source_p
), host
,
1352 reason
, oper_reason
);
1355 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1358 else if(type
== RESV_TYPE
)
1360 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1361 "%s added RESV for [%s] [%s]",
1362 get_oper_name(source_p
), host
, reason
);
1363 ilog(L_KLINE
, "R %s 0 %s %s",
1364 get_oper_name(source_p
), host
, reason
);
1366 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1370 if((out
= fopen(filename
, "a")) == NULL
)
1372 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1373 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1377 if(oper_reason
== NULL
)
1380 if(type
== KLINE_TYPE
)
1382 rb_snprintf(buffer
, sizeof(buffer
),
1383 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1384 user
, host
, reason
, oper_reason
, current_date
,
1385 get_oper_name(source_p
), (long int)rb_current_time());
1387 else if(type
== DLINE_TYPE
)
1389 rb_snprintf(buffer
, sizeof(buffer
),
1390 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1391 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1393 else if(type
== RESV_TYPE
)
1395 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1396 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1399 if(fputs(buffer
, out
) == -1)
1401 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1402 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1409 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1410 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1417 * inputs - type of conf file to return name of file for
1418 * output - pointer to filename for type of conf
1419 * side effects - none
1422 get_conf_name(KlineType type
)
1424 if(type
== CONF_TYPE
)
1426 return (ConfigFileEntry
.configfile
);
1428 else if(type
== DLINE_TYPE
)
1430 return (ConfigFileEntry
.dlinefile
);
1432 else if(type
== RESV_TYPE
)
1434 return (ConfigFileEntry
.resvfile
);
1437 return ConfigFileEntry
.klinefile
;
1441 * conf_add_class_to_conf
1442 * inputs - pointer to config item
1444 * side effects - Add a class pointer to a conf
1448 conf_add_class_to_conf(struct ConfItem
*aconf
)
1450 if(aconf
->className
== NULL
)
1452 aconf
->className
= rb_strdup("default");
1453 ClassPtr(aconf
) = default_class
;
1457 ClassPtr(aconf
) = find_class(aconf
->className
);
1459 if(ClassPtr(aconf
) == default_class
)
1461 if(aconf
->status
== CONF_CLIENT
)
1463 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1464 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1465 aconf
->className
, aconf
->user
, aconf
->host
);
1468 rb_free(aconf
->className
);
1469 aconf
->className
= rb_strdup("default");
1473 if(ConfMaxUsers(aconf
) < 0)
1475 ClassPtr(aconf
) = default_class
;
1476 rb_free(aconf
->className
);
1477 aconf
->className
= rb_strdup("default");
1484 * inputs - pointer to config item
1486 * side effects - Add a d/D line
1489 conf_add_d_conf(struct ConfItem
*aconf
)
1491 if(aconf
->host
== NULL
)
1496 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1497 * need this anyway, so I will disable it for now... -A1kmm
1500 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1502 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1507 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1515 * inputs - message from parser
1517 * side effects - message to opers and log file entry is made
1520 yyerror(const char *msg
)
1522 char newlinebuf
[BUFSIZE
];
1524 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1526 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1527 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1529 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1533 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1537 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1540 return (strlen(lbuf
));
1544 conf_yy_fatal_error(const char *msg
)