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"
50 #include "blacklist.h"
51 #include "privilege.h"
55 struct config_server_hide ConfigServerHide
;
57 extern int yyparse(void); /* defined in y.tab.c */
58 extern char linebuf
[];
61 #define INADDR_NONE ((unsigned int) 0xffffffff)
64 static rb_bh
*confitem_heap
= NULL
;
66 rb_dlink_list temp_klines
[LAST_TEMP_TYPE
];
67 rb_dlink_list temp_dlines
[LAST_TEMP_TYPE
];
68 rb_dlink_list service_list
;
70 /* internally defined functions */
71 static void set_default_conf(void);
72 static void validate_conf(void);
73 static void read_conf(FILE *);
74 static void clear_out_old_conf(void);
76 static void expire_temp_kd(void *list
);
77 static void reorganise_temp_kd(void *list
);
82 static int verify_access(struct Client
*client_p
, const char *username
);
83 static int attach_iline(struct Client
*, struct ConfItem
*);
88 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
, "confitem_heap");
90 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
91 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
93 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
94 &temp_klines
[TEMP_HOUR
], 3600);
95 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
96 &temp_dlines
[TEMP_HOUR
], 3600);
97 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
98 &temp_klines
[TEMP_DAY
], 86400);
99 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
100 &temp_dlines
[TEMP_DAY
], 86400);
101 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
102 &temp_klines
[TEMP_WEEK
], 604800);
103 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
104 &temp_dlines
[TEMP_WEEK
], 604800);
111 * output - pointer to new conf entry
112 * side effects - none
117 struct ConfItem
*aconf
;
119 aconf
= rb_bh_alloc(confitem_heap
);
120 aconf
->status
= CONF_ILLEGAL
;
127 * inputs - pointer to conf to free
129 * side effects - crucial password fields are zeroed, conf is freed
132 free_conf(struct ConfItem
*aconf
)
134 s_assert(aconf
!= NULL
);
140 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
142 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
144 rb_free(aconf
->passwd
);
145 rb_free(aconf
->spasswd
);
146 rb_free(aconf
->name
);
147 rb_free(aconf
->className
);
148 rb_free(aconf
->user
);
149 rb_free(aconf
->host
);
151 rb_bh_free(confitem_heap
, aconf
);
157 * inputs - pointer to client
158 * output - 0 = Success
159 * NOT_AUTHORISED (-1) = Access denied (no I line match)
160 * SOCKET_ERROR (-2) = Bad socket.
161 * I_LINE_FULL (-3) = I-line is full
162 * TOO_MANY (-4) = Too many connections from hostname
163 * BANNED_CLIENT (-5) = K-lined
164 * side effects - Ordinary client access check.
165 * Look for conf lines which have the same
166 * status as the flags passed.
169 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
173 if((i
= verify_access(source_p
, username
)))
175 ilog(L_FUSER
, "Access denied: %s[%s]",
176 source_p
->name
, source_p
->sockhost
);
182 exit_client(client_p
, source_p
, &me
, "Socket Error");
186 /* Note that these notices are sent to opers on other
187 * servers also, so even if local opers are allowed to
188 * see the IP, we still cannot send it.
190 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
191 "Too many local connections for %s!%s%s@%s",
192 source_p
->name
, IsGotId(source_p
) ? "" : "~",
194 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
196 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
197 source_p
->name
, IsGotId(source_p
) ? "" : "~",
198 source_p
->username
, source_p
->sockhost
);
200 ServerStats
.is_ref
++;
201 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
204 case TOO_MANY_GLOBAL
:
205 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
206 "Too many global connections for %s!%s%s@%s",
207 source_p
->name
, IsGotId(source_p
) ? "" : "~",
209 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
210 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
211 source_p
->name
, IsGotId(source_p
) ? "" : "~",
212 source_p
->username
, source_p
->sockhost
);
214 ServerStats
.is_ref
++;
215 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
219 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
220 "Too many user connections for %s!%s%s@%s",
221 source_p
->name
, IsGotId(source_p
) ? "" : "~",
223 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
224 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
225 source_p
->name
, IsGotId(source_p
) ? "" : "~",
226 source_p
->username
, source_p
->sockhost
);
228 ServerStats
.is_ref
++;
229 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
233 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
234 "I-line is full for %s!%s%s@%s (%s).",
235 source_p
->name
, IsGotId(source_p
) ? "" : "~",
236 source_p
->username
, source_p
->host
,
237 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
239 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
240 source_p
->name
, IsGotId(source_p
) ? "" : "~",
241 source_p
->username
, source_p
->sockhost
);
243 ServerStats
.is_ref
++;
244 exit_client(client_p
, source_p
, &me
,
245 "No more connections allowed in your connection class");
252 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
253 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
256 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
258 ServerStats
.is_ref
++;
259 /* jdc - lists server name & port connections are on */
260 /* a purely cosmetical change */
261 /* why ipaddr, and not just source_p->sockhost? --fl */
263 static char ipaddr
[HOSTIPLEN
];
264 rb_inet_ntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
266 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
267 "Unauthorised client connection from "
268 "%s!%s%s@%s [%s] on [%s/%u].",
269 source_p
->name
, IsGotId(source_p
) ? "" : "~",
270 source_p
->username
, source_p
->host
,
272 source_p
->localClient
->listener
->name
, port
);
275 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
276 source_p
->name
, IsGotId(source_p
) ? "" : "~",
277 source_p
->username
, source_p
->sockhost
,
278 source_p
->localClient
->listener
->name
, port
);
279 add_reject(client_p
, NULL
, NULL
);
280 exit_client(client_p
, source_p
, &me
,
281 "You are not authorised to use this server");
285 exit_client(client_p
, client_p
, &me
, "*** Banned ");
286 ServerStats
.is_ref
++;
299 * inputs - pointer to client to verify
300 * - pointer to proposed username
301 * output - 0 if success -'ve if not
302 * side effect - find the first (best) I line to attach.
305 verify_access(struct Client
*client_p
, const char *username
)
307 struct ConfItem
*aconf
;
308 char non_ident
[USERLEN
+ 1];
310 if(IsGotId(client_p
))
312 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
313 client_p
->username
, client_p
->username
,
314 (struct sockaddr
*) &client_p
->localClient
->ip
,
315 client_p
->localClient
->ip
.ss_family
,
316 client_p
->localClient
->auth_user
);
320 rb_strlcpy(non_ident
, "~", sizeof(non_ident
));
321 rb_strlcat(non_ident
, username
, sizeof(non_ident
));
322 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
323 non_ident
, client_p
->username
,
324 (struct sockaddr
*) &client_p
->localClient
->ip
,
325 client_p
->localClient
->ip
.ss_family
,
326 client_p
->localClient
->auth_user
);
330 return NOT_AUTHORISED
;
332 if(aconf
->status
& CONF_CLIENT
)
334 if(aconf
->flags
& CONF_FLAGS_REDIR
)
336 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
337 aconf
->name
? aconf
->name
: "", aconf
->port
);
338 return (NOT_AUTHORISED
);
341 /* Thanks for spoof idea amm */
342 if(IsConfDoSpoofIp(aconf
))
346 /* show_ip() depends on this --fl */
347 SetIPSpoof(client_p
);
349 if(IsConfSpoofNotice(aconf
))
351 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
352 "%s spoofing: %s as %s",
354 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
358 /* user@host spoof */
359 if((p
= strchr(aconf
->name
, '@')) != NULL
)
364 rb_strlcpy(client_p
->username
, aconf
->name
,
365 sizeof(client_p
->username
));
366 rb_strlcpy(client_p
->host
, host
,
367 sizeof(client_p
->host
));
371 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
373 return (attach_iline(client_p
, aconf
));
375 else if(aconf
->status
& CONF_KILL
)
377 if(ConfigFileEntry
.kline_with_reason
)
380 form_str(ERR_YOUREBANNEDCREEP
),
381 me
.name
, client_p
->name
, aconf
->passwd
);
383 add_reject(client_p
, aconf
->user
, aconf
->host
);
384 return (BANNED_CLIENT
);
387 return NOT_AUTHORISED
;
394 * Returns 1 if successful 0 if not
396 * This checks if the user has exceed the limits for their class
397 * unless of course they are exempt..
401 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
403 rb_patricia_node_t
*pnode
;
406 /* If the limits are 0 don't do anything.. */
407 if(ConfCidrAmount(aconf
) == 0
408 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
411 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
413 if(GET_SS_FAMILY(&client_p
->localClient
->ip
) == AF_INET
)
414 bitlen
= ConfCidrIpv4Bitlen(aconf
);
416 bitlen
= ConfCidrIpv6Bitlen(aconf
);
419 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, bitlen
);
421 s_assert(pnode
!= NULL
);
425 if(((intptr_t)pnode
->data
) >= ConfCidrAmount(aconf
) && !IsConfExemptLimits(aconf
))
427 /* This should only happen if the limits are set to 0 */
428 if((intptr_t)pnode
->data
== 0)
430 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
435 pnode
->data
= (void *)(((intptr_t)pnode
->data
) + 1);
441 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
443 rb_patricia_node_t
*pnode
;
445 /* If the limits are 0 don't do anything.. */
446 if(ConfCidrAmount(aconf
) == 0
447 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
450 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
454 pnode
->data
= (void *)(((intptr_t)pnode
->data
) - 1);
455 if(((intptr_t)pnode
->data
) == 0)
457 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
465 * inputs - client pointer
468 * side effects - do actual attach
471 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
473 struct Client
*target_p
;
476 int global_count
= 0;
480 if(IsConfExemptLimits(aconf
))
481 return (attach_conf(client_p
, aconf
));
483 if(*client_p
->username
== '~')
487 /* find_hostname() returns the head of the list to search */
488 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
490 target_p
= ptr
->data
;
492 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
495 if(MyConnect(target_p
))
502 if(*target_p
->username
== '~')
505 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
508 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
509 return (TOO_MANY_LOCAL
);
510 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
511 return (TOO_MANY_GLOBAL
);
512 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
513 return (TOO_MANY_IDENT
);
517 return (attach_conf(client_p
, aconf
));
523 * inputs - pointer to client to detach
524 * output - 0 for success, -1 for failure
525 * side effects - Disassociate configuration from the client.
526 * Also removes a class from the list if marked for deleting.
529 detach_conf(struct Client
*client_p
)
531 struct ConfItem
*aconf
;
533 aconf
= client_p
->localClient
->att_conf
;
539 remove_ip_limit(client_p
, aconf
);
541 if(ConfCurrUsers(aconf
) > 0)
542 --ConfCurrUsers(aconf
);
544 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
546 free_class(ClassPtr(aconf
));
547 ClassPtr(aconf
) = NULL
;
553 if(!aconf
->clients
&& IsIllegal(aconf
))
556 client_p
->localClient
->att_conf
= NULL
;
566 * inputs - client pointer
569 * side effects - Associate a specific configuration entry to a *local*
570 * client (this is the one which used in accepting the
571 * connection). Note, that this automatically changes the
572 * attachment if there was an old one...
575 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
578 return (NOT_AUTHORISED
);
582 if(!add_ip_limit(client_p
, aconf
))
583 return (TOO_MANY_LOCAL
);
586 if((aconf
->status
& CONF_CLIENT
) &&
587 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
589 if(!IsConfExemptLimits(aconf
))
591 return (I_LINE_FULL
);
595 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
600 if(client_p
->localClient
->att_conf
!= NULL
)
601 detach_conf(client_p
);
603 client_p
->localClient
->att_conf
= aconf
;
606 ConfCurrUsers(aconf
)++;
613 * Actual REHASH service routine. Called with sig == 0 if it has been called
614 * as a result of an operator issuing this command, else assume it has been
615 * called as a result of the server receiving a HUP signal.
622 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
623 "Got signal SIGHUP, reloading ircd conf. file");
627 /* don't close listeners until we know we can go ahead with the rehash */
630 if(ServerInfo
.description
!= NULL
)
631 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
633 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
650 * side effects - Set default values here.
651 * This is called **PRIOR** to parsing the
652 * configuration file. If you want to do some validation
653 * of values later, put them in validate_conf().
661 set_default_conf(void)
663 /* ServerInfo.name is not rehashable */
664 /* ServerInfo.name = ServerInfo.name; */
665 ServerInfo
.description
= NULL
;
666 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
667 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
669 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
670 ServerInfo
.specific_ipv4_vhost
= 0;
672 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
673 ServerInfo
.specific_ipv6_vhost
= 0;
676 /* Don't reset hub, as that will break lazylinks */
677 /* ServerInfo.hub = NO; */
678 AdminInfo
.name
= NULL
;
679 AdminInfo
.email
= NULL
;
680 AdminInfo
.description
= NULL
;
682 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
683 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
684 ConfigFileEntry
.default_operhost
= rb_strdup("");
685 ConfigFileEntry
.static_quit
= rb_strdup("");
686 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
688 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
689 ConfigFileEntry
.failed_oper_notice
= YES
;
690 ConfigFileEntry
.anti_nick_flood
= NO
;
691 ConfigFileEntry
.disable_fake_channels
= NO
;
692 ConfigFileEntry
.max_nick_time
= 20;
693 ConfigFileEntry
.max_nick_changes
= 5;
694 ConfigFileEntry
.max_accept
= 20;
695 ConfigFileEntry
.max_monitor
= 60;
696 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
697 ConfigFileEntry
.target_change
= YES
;
698 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
699 ConfigFileEntry
.use_part_messages
= YES
;
700 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
701 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
702 ConfigFileEntry
.client_exit
= YES
;
703 ConfigFileEntry
.dline_with_reason
= YES
;
704 ConfigFileEntry
.kline_with_reason
= YES
;
705 ConfigFileEntry
.kline_delay
= 0;
706 ConfigFileEntry
.warn_no_nline
= YES
;
707 ConfigFileEntry
.non_redundant_klines
= YES
;
708 ConfigFileEntry
.stats_e_disabled
= NO
;
709 ConfigFileEntry
.stats_o_oper_only
= NO
;
710 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
711 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
712 ConfigFileEntry
.stats_P_oper_only
= NO
;
713 ConfigFileEntry
.stats_c_oper_only
= NO
;
714 ConfigFileEntry
.stats_y_oper_only
= NO
;
715 ConfigFileEntry
.stats_h_oper_only
= NO
;
716 ConfigFileEntry
.map_oper_only
= YES
;
717 ConfigFileEntry
.operspy_admin_only
= NO
;
718 ConfigFileEntry
.pace_wait
= 10;
719 ConfigFileEntry
.caller_id_wait
= 60;
720 ConfigFileEntry
.pace_wait_simple
= 1;
721 ConfigFileEntry
.short_motd
= NO
;
722 ConfigFileEntry
.no_oper_flood
= NO
;
723 ConfigFileEntry
.true_no_oper_flood
= NO
;
724 ConfigFileEntry
.fname_userlog
= NULL
;
725 ConfigFileEntry
.fname_fuserlog
= NULL
;
726 ConfigFileEntry
.fname_operlog
= NULL
;
727 ConfigFileEntry
.fname_foperlog
= NULL
;
728 ConfigFileEntry
.fname_serverlog
= NULL
;
729 ConfigFileEntry
.fname_klinelog
= NULL
;
730 ConfigFileEntry
.fname_operspylog
= NULL
;
731 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
732 ConfigFileEntry
.use_egd
= NO
;
733 ConfigFileEntry
.hide_spoof_ips
= YES
;
734 ConfigFileEntry
.hide_error_messages
= 1;
735 ConfigFileEntry
.dots_in_ident
= 0;
736 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
737 ConfigFileEntry
.egdpool_path
= NULL
;
738 ConfigFileEntry
.use_whois_actually
= YES
;
739 ConfigFileEntry
.burst_away
= NO
;
740 ConfigFileEntry
.collision_fnc
= YES
;
741 ConfigFileEntry
.global_snotices
= YES
;
742 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
743 ConfigFileEntry
.secret_channels_in_whois
= NO
;
746 ConfigFileEntry
.compression_level
= 4;
749 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
750 UMODE_OPERWALL
| UMODE_WALLOP
;
751 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
752 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
754 ConfigChannel
.autochanmodes
= rb_strdup("nt");
755 ConfigChannel
.exemptchanops
= rb_strdup("");
756 ConfigChannel
.use_halfop
= YES
;
757 ConfigChannel
.use_admin
= YES
;
758 ConfigChannel
.use_except
= YES
;
759 ConfigChannel
.use_invex
= YES
;
760 ConfigChannel
.use_knock
= YES
;
761 ConfigChannel
.use_forward
= YES
;
762 ConfigChannel
.use_local_channels
= YES
;
763 ConfigChannel
.knock_delay
= 300;
764 ConfigChannel
.knock_delay_channel
= 60;
765 ConfigChannel
.max_chans_per_user
= 15;
766 ConfigChannel
.max_bans
= 25;
767 ConfigChannel
.max_bans_large
= 500;
768 ConfigChannel
.only_ascii_channels
= NO
;
769 ConfigChannel
.cycle_host_change
= YES
;
770 ConfigChannel
.host_in_topic
= YES
;
771 ConfigChannel
.burst_topicwho
= NO
;
772 ConfigChannel
.kick_on_split_riding
= NO
;
774 ConfigChannel
.default_split_user_count
= 15000;
775 ConfigChannel
.default_split_server_count
= 10;
776 ConfigChannel
.no_join_on_split
= NO
;
777 ConfigChannel
.no_create_on_split
= YES
;
778 ConfigChannel
.resv_forcepart
= YES
;
779 ConfigChannel
.kick_no_rejoin_time
= 30;
781 ConfigChannel
.exempt_cmode_c
= NO
;
782 ConfigChannel
.exempt_cmode_C
= NO
;
783 ConfigChannel
.exempt_cmode_D
= NO
;
784 ConfigChannel
.exempt_cmode_T
= NO
;
785 ConfigChannel
.exempt_cmode_N
= NO
;
786 ConfigChannel
.exempt_cmode_G
= NO
;
787 ConfigChannel
.exempt_cmode_K
= NO
;
789 ConfigServerHide
.flatten_links
= 0;
790 ConfigServerHide
.links_delay
= 300;
791 ConfigServerHide
.hidden
= 0;
792 ConfigServerHide
.disable_hidden
= 0;
794 ConfigFileEntry
.min_nonwildcard
= 4;
795 ConfigFileEntry
.min_nonwildcard_simple
= 3;
796 ConfigFileEntry
.default_floodcount
= 8;
797 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
798 ConfigFileEntry
.tkline_expire_notices
= 0;
800 ConfigFileEntry
.reject_after_count
= 5;
801 ConfigFileEntry
.reject_ban_time
= 300;
802 ConfigFileEntry
.reject_duration
= 120;
803 ConfigFileEntry
.throttle_count
= 4;
804 ConfigFileEntry
.throttle_duration
= 60;
805 ConfigFileEntry
.expire_override_time
= 300;
807 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
810 alias_dict
= irc_dictionary_create(strcasecmp
);
820 * inputs - file descriptor pointing to config file to use
822 * side effects - Read configuration file.
825 read_conf(FILE * file
)
829 set_default_conf(); /* Set default values prior to conf parsing */
830 yyparse(); /* Load the values from the conf */
831 validate_conf(); /* Check to make sure some values are still okay. */
832 /* Some global values are also loaded here. */
833 check_class(); /* Make sure classes are valid */
834 privilegeset_delete_all_illegal();
840 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
841 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
843 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
844 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
846 if(ServerInfo
.network_name
== NULL
)
847 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
849 if(ServerInfo
.network_desc
== NULL
)
850 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
852 if(ServerInfo
.ssld_count
< 1)
853 ServerInfo
.ssld_count
= 1;
855 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
857 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
861 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
864 if(ServerInfo
.ssld_count
> get_ssld_count())
866 int start
= ServerInfo
.ssld_count
- get_ssld_count();
867 /* start up additional ssld if needed */
868 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
872 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
873 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
874 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
876 if(!split_users
|| !split_servers
||
877 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
879 rb_event_delete(check_splitmode_ev
);
880 check_splitmode_ev
= NULL
;
885 if(!valid_hostname(ConfigFileEntry
.default_operhost
))
887 conf_report_error("Warning -- invalid default_operhost specified, ignoring.");
888 ConfigFileEntry
.default_operhost
= rb_strdup("");
891 /* Parse the exemptchanops option and set the internal variables
892 * that we will use. */
895 for(ech
= ConfigChannel
.exemptchanops
; *ech
; ech
++)
899 ConfigChannel
.exempt_cmode_c
= 1;
904 ConfigChannel
.exempt_cmode_C
= 1;
909 ConfigChannel
.exempt_cmode_D
= 1;
914 ConfigChannel
.exempt_cmode_T
= 1;
919 ConfigChannel
.exempt_cmode_N
= 1;
924 ConfigChannel
.exempt_cmode_G
= 1;
928 ConfigChannel
.exempt_cmode_K
= 1;
934 * inputs - pointer to struct ConfItem
936 * Side effects - links in given struct ConfItem into
937 * temporary kline link list
940 add_temp_kline(struct ConfItem
*aconf
)
942 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
944 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
945 aconf
->port
= TEMP_WEEK
;
947 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
949 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
950 aconf
->port
= TEMP_DAY
;
952 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
954 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
955 aconf
->port
= TEMP_HOUR
;
959 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
960 aconf
->port
= TEMP_MIN
;
963 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
964 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
969 * input - pointer to struct ConfItem
971 * side effects - added to tdline link list and address hash
974 add_temp_dline(struct ConfItem
*aconf
)
976 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
978 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
979 aconf
->port
= TEMP_WEEK
;
981 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
983 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
984 aconf
->port
= TEMP_DAY
;
986 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
988 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
989 aconf
->port
= TEMP_HOUR
;
993 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
994 aconf
->port
= TEMP_MIN
;
997 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
998 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, NULL
, aconf
);
1003 * inputs - list pointer
1006 * side effects - expire tklines and moves them between lists
1009 expire_temp_kd(void *list
)
1012 rb_dlink_node
*next_ptr
;
1013 struct ConfItem
*aconf
;
1015 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1019 if(aconf
->hold
<= rb_current_time())
1021 /* Alert opers that a TKline expired - Hwy */
1022 if(ConfigFileEntry
.tkline_expire_notices
)
1023 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1024 "Temporary K-line for [%s@%s] expired",
1025 (aconf
->user
) ? aconf
->
1026 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1028 delete_one_address_conf(aconf
->host
, aconf
);
1029 rb_dlinkDestroy(ptr
, list
);
1035 reorganise_temp_kd(void *list
)
1037 struct ConfItem
*aconf
;
1038 rb_dlink_node
*ptr
, *next_ptr
;
1040 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1044 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1046 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1047 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1048 aconf
->port
= TEMP_MIN
;
1050 else if(aconf
->port
> TEMP_HOUR
)
1052 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1054 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1055 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1056 aconf
->port
= TEMP_HOUR
;
1058 else if(aconf
->port
> TEMP_DAY
&&
1059 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1061 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1062 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1063 aconf
->port
= TEMP_DAY
;
1070 /* const char* get_oper_name(struct Client *client_p)
1071 * Input: A client to find the active oper{} name for.
1072 * Output: The nick!user@host{oper} of the oper.
1073 * "oper" is server name for remote opers
1074 * Side effects: None.
1077 get_oper_name(struct Client
*client_p
)
1079 /* +5 for !,@,{,} and null */
1080 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1082 if(MyOper(client_p
))
1084 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1085 client_p
->name
, client_p
->username
,
1086 client_p
->host
, client_p
->localClient
->opername
);
1090 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1091 client_p
->name
, client_p
->username
,
1092 client_p
->host
, client_p
->servptr
->name
);
1097 * get_printable_conf
1099 * inputs - struct ConfItem
1108 * Examine the struct struct ConfItem, setting the values
1109 * of name, host, pass, user to values either
1110 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1113 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1114 char **pass
, char **user
, int *port
, char **classname
)
1116 static char null
[] = "<NULL>";
1117 static char zero
[] = "default";
1119 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1120 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1121 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1122 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1123 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1124 *port
= (int) aconf
->port
;
1128 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1129 char **host
, char **reason
,
1130 char **user
, char **oper_reason
)
1132 static char null
[] = "<NULL>";
1134 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1135 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1136 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1138 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1139 *oper_reason
= NULL
;
1141 *oper_reason
= aconf
->spasswd
;
1147 * inputs - cold start YES or NO
1149 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1152 read_conf_files(int cold
)
1154 const char *filename
;
1156 conf_fbfile_in
= NULL
;
1158 filename
= ConfigFileEntry
.configfile
;
1160 /* We need to know the initial filename for the yyerror() to report
1161 FIXME: The full path is in conffilenamebuf first time since we
1162 dont know anything else
1166 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1168 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1172 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1177 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1178 "Can't open file '%s' - aborting rehash!", filename
);
1185 clear_out_old_conf();
1188 read_conf(conf_fbfile_in
);
1189 fclose(conf_fbfile_in
);
1193 * free an alias{} entry.
1196 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1198 struct alias_entry
*aptr
= ptr
->data
;
1200 rb_free(aptr
->name
);
1201 rb_free(aptr
->target
);
1206 * clear_out_old_conf
1210 * side effects - Clear out the old configuration
1213 clear_out_old_conf(void)
1215 struct Class
*cltmp
;
1217 rb_dlink_node
*next_ptr
;
1220 * don't delete the class table, rather mark all entries
1221 * for deletion. The table is cleaned up by check_class. - avalon
1223 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1226 MaxUsers(cltmp
) = -1;
1229 clear_out_address_conf();
1232 /* clean out module paths */
1233 #ifndef STATIC_MODULES
1235 mod_add_path(MODULE_DIR
);
1236 mod_add_path(MODULE_DIR
"/autoload");
1239 /* clean out ServerInfo */
1240 rb_free(ServerInfo
.description
);
1241 ServerInfo
.description
= NULL
;
1242 rb_free(ServerInfo
.network_name
);
1243 ServerInfo
.network_name
= NULL
;
1244 rb_free(ServerInfo
.network_desc
);
1245 ServerInfo
.network_desc
= NULL
;
1247 ServerInfo
.ssld_count
= 1;
1249 /* clean out AdminInfo */
1250 rb_free(AdminInfo
.name
);
1251 AdminInfo
.name
= NULL
;
1252 rb_free(AdminInfo
.email
);
1253 AdminInfo
.email
= NULL
;
1254 rb_free(AdminInfo
.description
);
1255 AdminInfo
.description
= NULL
;
1257 /* operator{} and class{} blocks are freed above */
1258 /* clean out listeners */
1261 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1262 * and gecos{} blocks are freed above too
1265 /* clean out general */
1266 rb_free(ConfigFileEntry
.kline_reason
);
1267 ConfigFileEntry
.kline_reason
= NULL
;
1269 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1272 rb_dlinkDestroy(ptr
, &service_list
);
1275 /* remove any aliases... -- nenolod */
1276 if (alias_dict
!= NULL
)
1278 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1282 destroy_blacklists();
1284 privilegeset_mark_all_illegal();
1286 /* OK, that should be everything... */
1291 * conf_add_class_to_conf
1292 * inputs - pointer to config item
1294 * side effects - Add a class pointer to a conf
1298 conf_add_class_to_conf(struct ConfItem
*aconf
)
1300 if(aconf
->className
== NULL
)
1302 aconf
->className
= rb_strdup("default");
1303 ClassPtr(aconf
) = default_class
;
1307 ClassPtr(aconf
) = find_class(aconf
->className
);
1309 if(ClassPtr(aconf
) == default_class
)
1311 if(aconf
->status
== CONF_CLIENT
)
1314 "Using default class for missing class \"%s\" in auth{} for %s@%s",
1315 aconf
->className
, aconf
->user
, aconf
->host
);
1318 rb_free(aconf
->className
);
1319 aconf
->className
= rb_strdup("default");
1323 if(ConfMaxUsers(aconf
) < 0)
1325 ClassPtr(aconf
) = default_class
;
1326 rb_free(aconf
->className
);
1327 aconf
->className
= rb_strdup("default");
1334 * inputs - pointer to config item
1336 * side effects - Add a d/D line
1339 conf_add_d_conf(struct ConfItem
*aconf
)
1341 if(aconf
->host
== NULL
)
1346 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1347 * need this anyway, so I will disable it for now... -A1kmm
1350 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1352 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1357 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
1362 strip_tabs(char *dest
, const char *src
, size_t len
)
1366 if(dest
== NULL
|| src
== NULL
)
1369 rb_strlcpy(dest
, src
, len
);
1383 * inputs - message from parser
1385 * side effects - message to opers and log file entry is made
1388 yyerror(const char *msg
)
1390 char newlinebuf
[BUFSIZE
];
1392 strip_tabs(newlinebuf
, linebuf
, strlen(linebuf
));
1394 ierror("\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1395 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1396 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1401 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1405 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1408 return (strlen(lbuf
));
1412 conf_yy_fatal_error(const char *msg
)