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"
48 #include "blacklist.h"
51 struct config_server_hide ConfigServerHide
;
53 extern int yyparse(void); /* defined in y.tab.c */
54 extern char linebuf
[];
57 #define INADDR_NONE ((unsigned int) 0xffffffff)
60 static rb_bh
*confitem_heap
= NULL
;
62 rb_dlink_list temp_klines
[LAST_TEMP_TYPE
];
63 rb_dlink_list temp_dlines
[LAST_TEMP_TYPE
];
64 rb_dlink_list service_list
;
66 /* internally defined functions */
67 static void set_default_conf(void);
68 static void validate_conf(void);
69 static void read_conf(FILE *);
70 static void clear_out_old_conf(void);
72 static void expire_temp_kd(void *list
);
73 static void reorganise_temp_kd(void *list
);
78 static int verify_access(struct Client
*client_p
, const char *username
);
79 static int attach_iline(struct Client
*, struct ConfItem
*);
84 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
, "confitem_heap");
86 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
87 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
89 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
90 &temp_klines
[TEMP_HOUR
], 3600);
91 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
92 &temp_dlines
[TEMP_HOUR
], 3600);
93 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
94 &temp_klines
[TEMP_DAY
], 86400);
95 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
96 &temp_dlines
[TEMP_DAY
], 86400);
97 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
98 &temp_klines
[TEMP_WEEK
], 604800);
99 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
100 &temp_dlines
[TEMP_WEEK
], 604800);
107 * output - pointer to new conf entry
108 * side effects - none
113 struct ConfItem
*aconf
;
115 aconf
= rb_bh_alloc(confitem_heap
);
116 aconf
->status
= CONF_ILLEGAL
;
123 * inputs - pointer to conf to free
125 * side effects - crucial password fields are zeroed, conf is freed
128 free_conf(struct ConfItem
*aconf
)
130 s_assert(aconf
!= NULL
);
136 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
138 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
140 rb_free(aconf
->passwd
);
141 rb_free(aconf
->spasswd
);
142 rb_free(aconf
->name
);
143 rb_free(aconf
->className
);
144 rb_free(aconf
->user
);
145 rb_free(aconf
->host
);
147 rb_bh_free(confitem_heap
, aconf
);
153 * inputs - pointer to client
154 * output - 0 = Success
155 * NOT_AUTHORISED (-1) = Access denied (no I line match)
156 * SOCKET_ERROR (-2) = Bad socket.
157 * I_LINE_FULL (-3) = I-line is full
158 * TOO_MANY (-4) = Too many connections from hostname
159 * BANNED_CLIENT (-5) = K-lined
160 * side effects - Ordinary client access check.
161 * Look for conf lines which have the same
162 * status as the flags passed.
165 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
169 if((i
= verify_access(source_p
, username
)))
171 ilog(L_FUSER
, "Access denied: %s[%s]",
172 source_p
->name
, source_p
->sockhost
);
178 exit_client(client_p
, source_p
, &me
, "Socket Error");
182 /* Note that these notices are sent to opers on other
183 * servers also, so even if local opers are allowed to
184 * see the IP, we still cannot send it.
186 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
187 "Too many local connections for %s!%s%s@%s",
188 source_p
->name
, IsGotId(source_p
) ? "" : "~",
190 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
192 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
193 source_p
->name
, IsGotId(source_p
) ? "" : "~",
194 source_p
->username
, source_p
->sockhost
);
196 ServerStats
.is_ref
++;
197 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
200 case TOO_MANY_GLOBAL
:
201 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
202 "Too many global connections for %s!%s%s@%s",
203 source_p
->name
, IsGotId(source_p
) ? "" : "~",
205 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
206 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
207 source_p
->name
, IsGotId(source_p
) ? "" : "~",
208 source_p
->username
, source_p
->sockhost
);
210 ServerStats
.is_ref
++;
211 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
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
) ? "" : "~",
219 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
220 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
221 source_p
->name
, IsGotId(source_p
) ? "" : "~",
222 source_p
->username
, source_p
->sockhost
);
224 ServerStats
.is_ref
++;
225 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
229 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
230 "I-line is full for %s!%s%s@%s (%s).",
231 source_p
->name
, IsGotId(source_p
) ? "" : "~",
232 source_p
->username
, source_p
->host
,
233 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
235 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
236 source_p
->name
, IsGotId(source_p
) ? "" : "~",
237 source_p
->username
, source_p
->sockhost
);
239 ServerStats
.is_ref
++;
240 exit_client(client_p
, source_p
, &me
,
241 "No more connections allowed in your connection class");
248 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
249 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
252 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
254 ServerStats
.is_ref
++;
255 /* jdc - lists server name & port connections are on */
256 /* a purely cosmetical change */
257 /* why ipaddr, and not just source_p->sockhost? --fl */
259 static char ipaddr
[HOSTIPLEN
];
260 rb_inet_ntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
262 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
263 "Unauthorised client connection from "
264 "%s!%s%s@%s [%s] on [%s/%u].",
265 source_p
->name
, IsGotId(source_p
) ? "" : "~",
266 source_p
->username
, source_p
->host
,
268 source_p
->localClient
->listener
->name
, port
);
271 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
272 source_p
->name
, IsGotId(source_p
) ? "" : "~",
273 source_p
->username
, source_p
->sockhost
,
274 source_p
->localClient
->listener
->name
, port
);
275 add_reject(client_p
, NULL
, NULL
);
276 exit_client(client_p
, source_p
, &me
,
277 "You are not authorised to use this server");
281 exit_client(client_p
, client_p
, &me
, "*** Banned ");
282 ServerStats
.is_ref
++;
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.
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
, client_p
->username
,
310 (struct sockaddr
*) &client_p
->localClient
->ip
,
311 client_p
->localClient
->ip
.ss_family
,
312 client_p
->localClient
->auth_user
);
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
,
322 client_p
->localClient
->auth_user
);
326 return NOT_AUTHORISED
;
328 if(aconf
->status
& CONF_CLIENT
)
330 if(aconf
->flags
& CONF_FLAGS_REDIR
)
332 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
333 aconf
->name
? aconf
->name
: "", aconf
->port
);
334 return (NOT_AUTHORISED
);
337 /* Thanks for spoof idea amm */
338 if(IsConfDoSpoofIp(aconf
))
342 /* show_ip() depends on this --fl */
343 SetIPSpoof(client_p
);
345 if(IsConfSpoofNotice(aconf
))
347 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
348 "%s spoofing: %s as %s",
350 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
354 /* user@host spoof */
355 if((p
= strchr(aconf
->name
, '@')) != NULL
)
360 rb_strlcpy(client_p
->username
, aconf
->name
,
361 sizeof(client_p
->username
));
362 rb_strlcpy(client_p
->host
, host
,
363 sizeof(client_p
->host
));
367 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
369 return (attach_iline(client_p
, aconf
));
371 else if(aconf
->status
& CONF_KILL
)
373 if(ConfigFileEntry
.kline_with_reason
)
376 form_str(ERR_YOUREBANNEDCREEP
),
377 me
.name
, client_p
->name
, aconf
->passwd
);
379 add_reject(client_p
, aconf
->user
, aconf
->host
);
380 return (BANNED_CLIENT
);
383 return NOT_AUTHORISED
;
390 * Returns 1 if successful 0 if not
392 * This checks if the user has exceed the limits for their class
393 * unless of course they are exempt..
397 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
399 rb_patricia_node_t
*pnode
;
401 /* If the limits are 0 don't do anything.. */
402 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
405 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
408 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
410 s_assert(pnode
!= NULL
);
414 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
415 && !IsConfExemptLimits(aconf
))
417 /* This should only happen if the limits are set to 0 */
418 if((unsigned long) pnode
->data
== 0)
420 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
431 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
433 rb_patricia_node_t
*pnode
;
435 /* If the limits are 0 don't do anything.. */
436 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
439 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
444 if(((unsigned long) pnode
->data
) == 0)
446 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
454 * inputs - client pointer
457 * side effects - do actual attach
460 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
462 struct Client
*target_p
;
465 int global_count
= 0;
469 if(IsConfExemptLimits(aconf
))
470 return (attach_conf(client_p
, aconf
));
472 if(*client_p
->username
== '~')
476 /* find_hostname() returns the head of the list to search */
477 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
479 target_p
= ptr
->data
;
481 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
484 if(MyConnect(target_p
))
491 if(*target_p
->username
== '~')
494 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
497 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
498 return (TOO_MANY_LOCAL
);
499 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
500 return (TOO_MANY_GLOBAL
);
501 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
502 return (TOO_MANY_IDENT
);
506 return (attach_conf(client_p
, aconf
));
512 * inputs - pointer to client to detach
513 * output - 0 for success, -1 for failure
514 * side effects - Disassociate configuration from the client.
515 * Also removes a class from the list if marked for deleting.
518 detach_conf(struct Client
*client_p
)
520 struct ConfItem
*aconf
;
522 aconf
= client_p
->localClient
->att_conf
;
528 remove_ip_limit(client_p
, aconf
);
530 if(ConfCurrUsers(aconf
) > 0)
531 --ConfCurrUsers(aconf
);
533 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
535 free_class(ClassPtr(aconf
));
536 ClassPtr(aconf
) = NULL
;
542 if(!aconf
->clients
&& IsIllegal(aconf
))
545 client_p
->localClient
->att_conf
= NULL
;
555 * inputs - client pointer
558 * side effects - Associate a specific configuration entry to a *local*
559 * client (this is the one which used in accepting the
560 * connection). Note, that this automatically changes the
561 * attachment if there was an old one...
564 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
567 return (NOT_AUTHORISED
);
571 if(!add_ip_limit(client_p
, aconf
))
572 return (TOO_MANY_LOCAL
);
575 if((aconf
->status
& CONF_CLIENT
) &&
576 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
578 if(!IsConfExemptLimits(aconf
))
580 return (I_LINE_FULL
);
584 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
589 if(client_p
->localClient
->att_conf
!= NULL
)
590 detach_conf(client_p
);
592 client_p
->localClient
->att_conf
= aconf
;
595 ConfCurrUsers(aconf
)++;
602 * Actual REHASH service routine. Called with sig == 0 if it has been called
603 * as a result of an operator issuing this command, else assume it has been
604 * called as a result of the server receiving a HUP signal.
611 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
612 "Got signal SIGHUP, reloading ircd conf. file");
616 /* don't close listeners until we know we can go ahead with the rehash */
619 if(ServerInfo
.description
!= NULL
)
620 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
622 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
628 static struct banconf_entry
630 const char **filename
;
631 void (*func
) (FILE *);
634 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
635 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
636 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
637 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
638 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
639 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
640 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
641 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
649 char buf
[MAXPATHLEN
];
653 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
654 "Got signal SIGUSR2, reloading ban confs");
656 clear_out_address_conf_bans();
657 clear_s_newconf_bans();
659 for(i
= 0; banconfs
[i
].filename
; i
++)
662 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
664 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
666 if((file
= fopen(buf
, "r")) == NULL
)
671 ilog(L_MAIN
, "Failed reading ban file %s",
672 *banconfs
[i
].filename
);
673 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
674 "Can't open %s file bans could be missing!",
675 *banconfs
[i
].filename
);
679 (banconfs
[i
].func
)(file
);
684 check_banned_lines();
692 * side effects - Set default values here.
693 * This is called **PRIOR** to parsing the
694 * configuration file. If you want to do some validation
695 * of values later, put them in validate_conf().
703 set_default_conf(void)
705 /* ServerInfo.name is not rehashable */
706 /* ServerInfo.name = ServerInfo.name; */
707 ServerInfo
.description
= NULL
;
708 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
709 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
711 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
712 ServerInfo
.specific_ipv4_vhost
= 0;
714 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
715 ServerInfo
.specific_ipv6_vhost
= 0;
718 /* Don't reset hub, as that will break lazylinks */
719 /* ServerInfo.hub = NO; */
720 AdminInfo
.name
= NULL
;
721 AdminInfo
.email
= NULL
;
722 AdminInfo
.description
= NULL
;
724 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
725 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
726 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
728 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
729 ConfigFileEntry
.failed_oper_notice
= YES
;
730 ConfigFileEntry
.anti_nick_flood
= NO
;
731 ConfigFileEntry
.disable_fake_channels
= NO
;
732 ConfigFileEntry
.max_nick_time
= 20;
733 ConfigFileEntry
.max_nick_changes
= 5;
734 ConfigFileEntry
.max_accept
= 20;
735 ConfigFileEntry
.max_monitor
= 60;
736 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
737 ConfigFileEntry
.target_change
= YES
;
738 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
739 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
740 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
741 ConfigFileEntry
.client_exit
= YES
;
742 ConfigFileEntry
.dline_with_reason
= YES
;
743 ConfigFileEntry
.kline_with_reason
= YES
;
744 ConfigFileEntry
.kline_delay
= 0;
745 ConfigFileEntry
.warn_no_nline
= YES
;
746 ConfigFileEntry
.non_redundant_klines
= YES
;
747 ConfigFileEntry
.stats_e_disabled
= NO
;
748 ConfigFileEntry
.stats_o_oper_only
= NO
;
749 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
750 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
751 ConfigFileEntry
.stats_P_oper_only
= NO
;
752 ConfigFileEntry
.stats_c_oper_only
= NO
;
753 ConfigFileEntry
.stats_y_oper_only
= NO
;
754 ConfigFileEntry
.stats_h_oper_only
= NO
;
755 ConfigFileEntry
.map_oper_only
= YES
;
756 ConfigFileEntry
.operspy_admin_only
= NO
;
757 ConfigFileEntry
.pace_wait
= 10;
758 ConfigFileEntry
.caller_id_wait
= 60;
759 ConfigFileEntry
.pace_wait_simple
= 1;
760 ConfigFileEntry
.short_motd
= NO
;
761 ConfigFileEntry
.no_oper_flood
= NO
;
762 ConfigFileEntry
.fname_userlog
= NULL
;
763 ConfigFileEntry
.fname_fuserlog
= NULL
;
764 ConfigFileEntry
.fname_operlog
= NULL
;
765 ConfigFileEntry
.fname_foperlog
= NULL
;
766 ConfigFileEntry
.fname_serverlog
= NULL
;
767 ConfigFileEntry
.fname_klinelog
= NULL
;
768 ConfigFileEntry
.fname_operspylog
= NULL
;
769 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
770 ConfigFileEntry
.use_egd
= NO
;
771 ConfigFileEntry
.hide_spoof_ips
= YES
;
772 ConfigFileEntry
.hide_error_messages
= 1;
773 ConfigFileEntry
.dots_in_ident
= 0;
774 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
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
.throttle_count
= 4;
823 ConfigFileEntry
.throttle_duration
= 60;
825 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
835 * inputs - file descriptor pointing to config file to use
837 * side effects - Read configuration file.
840 read_conf(FILE * file
)
844 set_default_conf(); /* Set default values prior to conf parsing */
845 yyparse(); /* Load the values from the conf */
846 validate_conf(); /* Check to make sure some values are still okay. */
847 /* Some global values are also loaded here. */
848 check_class(); /* Make sure classes are valid */
854 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
855 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
857 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
858 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
860 if(ServerInfo
.network_name
== NULL
)
861 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
863 if(ServerInfo
.network_desc
== NULL
)
864 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
866 if(ServerInfo
.ssld_count
< 1)
867 ServerInfo
.ssld_count
= 1;
869 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
871 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
875 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
878 if(ServerInfo
.ssld_count
> get_ssld_count())
880 int start
= ServerInfo
.ssld_count
- get_ssld_count();
881 /* start up additional ssld if needed */
882 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
886 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
887 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
888 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
890 if(!split_users
|| !split_servers
||
891 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
893 rb_event_delete(check_splitmode_ev
);
894 check_splitmode_ev
= NULL
;
902 * inputs - pointer to struct ConfItem
904 * Side effects - links in given struct ConfItem into
905 * temporary kline link list
908 add_temp_kline(struct ConfItem
*aconf
)
910 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
912 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
913 aconf
->port
= TEMP_WEEK
;
915 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
917 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
918 aconf
->port
= TEMP_DAY
;
920 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
922 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
923 aconf
->port
= TEMP_HOUR
;
927 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
928 aconf
->port
= TEMP_MIN
;
931 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
932 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
937 * input - pointer to struct ConfItem
939 * side effects - added to tdline link list and address hash
942 add_temp_dline(struct ConfItem
*aconf
)
944 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
946 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
947 aconf
->port
= TEMP_WEEK
;
949 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
951 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
952 aconf
->port
= TEMP_DAY
;
954 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
956 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
957 aconf
->port
= TEMP_HOUR
;
961 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
962 aconf
->port
= TEMP_MIN
;
965 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
966 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, NULL
, aconf
);
971 * inputs - list pointer
974 * side effects - expire tklines and moves them between lists
977 expire_temp_kd(void *list
)
980 rb_dlink_node
*next_ptr
;
981 struct ConfItem
*aconf
;
983 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
987 if(aconf
->hold
<= rb_current_time())
989 /* Alert opers that a TKline expired - Hwy */
990 if(ConfigFileEntry
.tkline_expire_notices
)
991 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
992 "Temporary K-line for [%s@%s] expired",
993 (aconf
->user
) ? aconf
->
994 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
996 delete_one_address_conf(aconf
->host
, aconf
);
997 rb_dlinkDestroy(ptr
, list
);
1003 reorganise_temp_kd(void *list
)
1005 struct ConfItem
*aconf
;
1006 rb_dlink_node
*ptr
, *next_ptr
;
1008 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1012 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1014 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1015 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1016 aconf
->port
= TEMP_MIN
;
1018 else if(aconf
->port
> TEMP_HOUR
)
1020 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1022 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1023 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1024 aconf
->port
= TEMP_HOUR
;
1026 else if(aconf
->port
> TEMP_DAY
&&
1027 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1029 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1030 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1031 aconf
->port
= TEMP_DAY
;
1038 /* const char* get_oper_name(struct Client *client_p)
1039 * Input: A client to find the active oper{} name for.
1040 * Output: The nick!user@host{oper} of the oper.
1041 * "oper" is server name for remote opers
1042 * Side effects: None.
1045 get_oper_name(struct Client
*client_p
)
1047 /* +5 for !,@,{,} and null */
1048 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1050 if(MyOper(client_p
))
1052 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1053 client_p
->name
, client_p
->username
,
1054 client_p
->host
, client_p
->localClient
->opername
);
1058 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1059 client_p
->name
, client_p
->username
,
1060 client_p
->host
, client_p
->servptr
->name
);
1065 * get_printable_conf
1067 * inputs - struct ConfItem
1076 * Examine the struct struct ConfItem, setting the values
1077 * of name, host, pass, user to values either
1078 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1081 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1082 char **pass
, char **user
, int *port
, char **classname
)
1084 static char null
[] = "<NULL>";
1085 static char zero
[] = "default";
1087 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1088 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1089 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1090 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1091 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1092 *port
= (int) aconf
->port
;
1096 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1097 char **host
, char **reason
,
1098 char **user
, char **oper_reason
)
1100 static char null
[] = "<NULL>";
1102 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1103 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1104 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1106 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1107 *oper_reason
= NULL
;
1109 *oper_reason
= aconf
->spasswd
;
1115 * inputs - cold start YES or NO
1117 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1120 read_conf_files(int cold
)
1122 const char *filename
;
1124 conf_fbfile_in
= NULL
;
1126 filename
= get_conf_name(CONF_TYPE
);
1128 /* We need to know the initial filename for the yyerror() to report
1129 FIXME: The full path is in conffilenamebuf first time since we
1130 dont know anything else
1134 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1136 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1140 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1145 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1146 "Can't open file '%s' - aborting rehash!", filename
);
1153 clear_out_old_conf();
1156 read_conf(conf_fbfile_in
);
1157 fclose(conf_fbfile_in
);
1161 * free an alias{} entry.
1164 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1166 struct alias_entry
*aptr
= ptr
->data
;
1168 rb_free(aptr
->name
);
1169 rb_free(aptr
->target
);
1174 * clear_out_old_conf
1178 * side effects - Clear out the old configuration
1181 clear_out_old_conf(void)
1183 struct Class
*cltmp
;
1185 rb_dlink_node
*next_ptr
;
1188 * don't delete the class table, rather mark all entries
1189 * for deletion. The table is cleaned up by check_class. - avalon
1191 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1194 MaxUsers(cltmp
) = -1;
1197 clear_out_address_conf();
1200 /* clean out module paths */
1201 #ifndef STATIC_MODULES
1203 mod_add_path(MODULE_DIR
);
1204 mod_add_path(MODULE_DIR
"/autoload");
1207 /* clean out ServerInfo */
1208 rb_free(ServerInfo
.description
);
1209 ServerInfo
.description
= NULL
;
1210 rb_free(ServerInfo
.network_name
);
1211 ServerInfo
.network_name
= NULL
;
1212 rb_free(ServerInfo
.network_desc
);
1213 ServerInfo
.network_desc
= NULL
;
1215 ServerInfo
.ssld_count
= 1;
1217 /* clean out AdminInfo */
1218 rb_free(AdminInfo
.name
);
1219 AdminInfo
.name
= NULL
;
1220 rb_free(AdminInfo
.email
);
1221 AdminInfo
.email
= NULL
;
1222 rb_free(AdminInfo
.description
);
1223 AdminInfo
.description
= NULL
;
1225 /* operator{} and class{} blocks are freed above */
1226 /* clean out listeners */
1229 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1230 * and gecos{} blocks are freed above too
1233 /* clean out general */
1234 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1237 rb_dlinkDestroy(ptr
, &service_list
);
1240 /* remove any aliases... -- nenolod */
1241 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1244 destroy_blacklists();
1246 /* OK, that should be everything... */
1252 * inputs - kline, dline or resv type flag
1253 * - client pointer to report to
1254 * - user name of target
1255 * - host name of target
1256 * - reason for target
1260 * side effects - This function takes care of finding the right conf
1261 * file and adding the line to it, as well as notifying
1262 * opers and the user.
1265 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1266 char *host
, const char *reason
, const char *oper_reason
,
1267 const char *current_date
, int xtype
)
1271 const char *filename
; /* filename to use for kline */
1273 filename
= get_conf_name(type
);
1275 if(type
== KLINE_TYPE
)
1277 if(EmptyString(oper_reason
))
1279 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1280 "%s added K-Line for [%s@%s] [%s]",
1281 get_oper_name(source_p
), user
,
1283 ilog(L_KLINE
, "K %s 0 %s %s %s",
1284 get_oper_name(source_p
), user
, host
, reason
);
1288 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1289 "%s added K-Line for [%s@%s] [%s|%s]",
1290 get_oper_name(source_p
), user
,
1291 host
, reason
, oper_reason
);
1292 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1293 get_oper_name(source_p
), user
, host
,
1294 reason
, oper_reason
);
1297 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1300 else if(type
== DLINE_TYPE
)
1302 if(EmptyString(oper_reason
))
1304 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1305 "%s added D-Line for [%s] [%s]",
1306 get_oper_name(source_p
), host
, reason
);
1307 ilog(L_KLINE
, "D %s 0 %s %s",
1308 get_oper_name(source_p
), host
, reason
);
1312 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1313 "%s added D-Line for [%s] [%s|%s]",
1314 get_oper_name(source_p
), host
,
1315 reason
, oper_reason
);
1316 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1317 get_oper_name(source_p
), host
,
1318 reason
, oper_reason
);
1321 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1324 else if(type
== RESV_TYPE
)
1326 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1327 "%s added RESV for [%s] [%s]",
1328 get_oper_name(source_p
), host
, reason
);
1329 ilog(L_KLINE
, "R %s 0 %s %s",
1330 get_oper_name(source_p
), host
, reason
);
1332 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1336 if((out
= fopen(filename
, "a")) == NULL
)
1338 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1339 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1343 if(oper_reason
== NULL
)
1346 if(type
== KLINE_TYPE
)
1348 rb_snprintf(buffer
, sizeof(buffer
),
1349 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1350 user
, host
, reason
, oper_reason
, current_date
,
1351 get_oper_name(source_p
), (long int)rb_current_time());
1353 else if(type
== DLINE_TYPE
)
1355 rb_snprintf(buffer
, sizeof(buffer
),
1356 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1357 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1359 else if(type
== RESV_TYPE
)
1361 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1362 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1365 if(fputs(buffer
, out
) == -1)
1367 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1368 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1375 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1376 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1383 * inputs - type of conf file to return name of file for
1384 * output - pointer to filename for type of conf
1385 * side effects - none
1388 get_conf_name(KlineType type
)
1390 if(type
== CONF_TYPE
)
1392 return (ConfigFileEntry
.configfile
);
1394 else if(type
== DLINE_TYPE
)
1396 return (ConfigFileEntry
.dlinefile
);
1398 else if(type
== RESV_TYPE
)
1400 return (ConfigFileEntry
.resvfile
);
1403 return ConfigFileEntry
.klinefile
;
1407 * conf_add_class_to_conf
1408 * inputs - pointer to config item
1410 * side effects - Add a class pointer to a conf
1414 conf_add_class_to_conf(struct ConfItem
*aconf
)
1416 if(aconf
->className
== NULL
)
1418 aconf
->className
= rb_strdup("default");
1419 ClassPtr(aconf
) = default_class
;
1423 ClassPtr(aconf
) = find_class(aconf
->className
);
1425 if(ClassPtr(aconf
) == default_class
)
1427 if(aconf
->status
== CONF_CLIENT
)
1429 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1430 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1431 aconf
->className
, aconf
->user
, aconf
->host
);
1434 rb_free(aconf
->className
);
1435 aconf
->className
= rb_strdup("default");
1439 if(ConfMaxUsers(aconf
) < 0)
1441 ClassPtr(aconf
) = default_class
;
1442 rb_free(aconf
->className
);
1443 aconf
->className
= rb_strdup("default");
1450 * inputs - pointer to config item
1452 * side effects - Add a d/D line
1455 conf_add_d_conf(struct ConfItem
*aconf
)
1457 if(aconf
->host
== NULL
)
1462 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1463 * need this anyway, so I will disable it for now... -A1kmm
1466 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1468 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1473 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
1478 strip_tabs(char *dest
, const char *src
, size_t len
)
1482 if(dest
== NULL
|| src
== NULL
)
1485 rb_strlcpy(dest
, src
, len
);
1499 * inputs - message from parser
1501 * side effects - message to opers and log file entry is made
1504 yyerror(const char *msg
)
1506 char newlinebuf
[BUFSIZE
];
1508 strip_tabs(newlinebuf
, linebuf
, strlen(linebuf
));
1510 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1511 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1513 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1517 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1521 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1524 return (strlen(lbuf
));
1528 conf_yy_fatal_error(const char *msg
)