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(); /* 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
);
315 rb_strlcpy(non_ident
, "~", sizeof(non_ident
));
316 rb_strlcat(non_ident
, username
, sizeof(non_ident
));
317 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
318 non_ident
, client_p
->username
,
319 (struct sockaddr
*) &client_p
->localClient
->ip
,
320 client_p
->localClient
->ip
.ss_family
);
324 return NOT_AUTHORISED
;
326 if(aconf
->status
& CONF_CLIENT
)
328 if(aconf
->flags
& CONF_FLAGS_REDIR
)
330 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
331 aconf
->name
? aconf
->name
: "", aconf
->port
);
332 return (NOT_AUTHORISED
);
335 /* Thanks for spoof idea amm */
336 if(IsConfDoSpoofIp(aconf
))
340 /* show_ip() depends on this --fl */
341 SetIPSpoof(client_p
);
343 if(IsConfSpoofNotice(aconf
))
345 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
346 "%s spoofing: %s as %s",
348 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
352 /* user@host spoof */
353 if((p
= strchr(aconf
->name
, '@')) != NULL
)
358 rb_strlcpy(client_p
->username
, aconf
->name
,
359 sizeof(client_p
->username
));
360 rb_strlcpy(client_p
->host
, host
,
361 sizeof(client_p
->host
));
365 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
367 return (attach_iline(client_p
, aconf
));
369 else if(aconf
->status
& CONF_KILL
)
371 if(ConfigFileEntry
.kline_with_reason
)
374 form_str(ERR_YOUREBANNEDCREEP
),
375 me
.name
, client_p
->name
, aconf
->passwd
);
377 add_reject(client_p
, aconf
->user
, aconf
->host
);
378 return (BANNED_CLIENT
);
381 return NOT_AUTHORISED
;
388 * Returns 1 if successful 0 if not
390 * This checks if the user has exceed the limits for their class
391 * unless of course they are exempt..
395 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
397 rb_patricia_node_t
*pnode
;
399 /* If the limits are 0 don't do anything.. */
400 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
403 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
406 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
408 s_assert(pnode
!= NULL
);
412 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
413 && !IsConfExemptLimits(aconf
))
415 /* This should only happen if the limits are set to 0 */
416 if((unsigned long) pnode
->data
== 0)
418 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
429 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
431 rb_patricia_node_t
*pnode
;
433 /* If the limits are 0 don't do anything.. */
434 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
437 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
442 if(((unsigned long) pnode
->data
) == 0)
444 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
452 * inputs - client pointer
455 * side effects - do actual attach
458 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
460 struct Client
*target_p
;
463 int global_count
= 0;
467 if(IsConfExemptLimits(aconf
))
468 return (attach_conf(client_p
, aconf
));
470 if(*client_p
->username
== '~')
474 /* find_hostname() returns the head of the list to search */
475 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
477 target_p
= ptr
->data
;
479 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
482 if(MyConnect(target_p
))
489 if(*target_p
->username
== '~')
492 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
495 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
496 return (TOO_MANY_LOCAL
);
497 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
498 return (TOO_MANY_GLOBAL
);
499 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
500 return (TOO_MANY_IDENT
);
504 return (attach_conf(client_p
, aconf
));
510 * inputs - pointer to client to detach
511 * output - 0 for success, -1 for failure
512 * side effects - Disassociate configuration from the client.
513 * Also removes a class from the list if marked for deleting.
516 detach_conf(struct Client
*client_p
)
518 struct ConfItem
*aconf
;
520 aconf
= client_p
->localClient
->att_conf
;
526 remove_ip_limit(client_p
, aconf
);
528 if(ConfCurrUsers(aconf
) > 0)
529 --ConfCurrUsers(aconf
);
531 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
533 free_class(ClassPtr(aconf
));
534 ClassPtr(aconf
) = NULL
;
540 if(!aconf
->clients
&& IsIllegal(aconf
))
543 client_p
->localClient
->att_conf
= NULL
;
553 * inputs - client pointer
556 * side effects - Associate a specific configuration entry to a *local*
557 * client (this is the one which used in accepting the
558 * connection). Note, that this automatically changes the
559 * attachment if there was an old one...
562 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
565 return (NOT_AUTHORISED
);
569 if(!add_ip_limit(client_p
, aconf
))
570 return (TOO_MANY_LOCAL
);
573 if((aconf
->status
& CONF_CLIENT
) &&
574 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
576 if(!IsConfExemptLimits(aconf
))
578 return (I_LINE_FULL
);
582 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
587 if(client_p
->localClient
->att_conf
!= NULL
)
588 detach_conf(client_p
);
590 client_p
->localClient
->att_conf
= aconf
;
593 ConfCurrUsers(aconf
)++;
600 * Actual REHASH service routine. Called with sig == 0 if it has been called
601 * as a result of an operator issuing this command, else assume it has been
602 * called as a result of the server receiving a HUP signal.
609 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
610 "Got signal SIGHUP, reloading ircd conf. file");
614 /* don't close listeners until we know we can go ahead with the rehash */
617 if(ServerInfo
.description
!= NULL
)
618 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
620 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
626 static struct banconf_entry
628 const char **filename
;
629 void (*func
) (FILE *);
632 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
633 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
634 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
635 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
636 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
637 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
638 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
639 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
647 char buf
[MAXPATHLEN
];
651 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
652 "Got signal SIGUSR2, reloading ban confs");
654 clear_out_address_conf_bans();
655 clear_s_newconf_bans();
657 for(i
= 0; banconfs
[i
].filename
; i
++)
660 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
662 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
664 if((file
= fopen(buf
, "r")) == NULL
)
669 ilog(L_MAIN
, "Failed reading ban file %s",
670 *banconfs
[i
].filename
);
671 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
672 "Can't open %s file bans could be missing!",
673 *banconfs
[i
].filename
);
677 (banconfs
[i
].func
)(file
);
682 check_banned_lines();
690 * side effects - Set default values here.
691 * This is called **PRIOR** to parsing the
692 * configuration file. If you want to do some validation
693 * of values later, put them in validate_conf().
701 set_default_conf(void)
703 /* ServerInfo.name is not rehashable */
704 /* ServerInfo.name = ServerInfo.name; */
705 ServerInfo
.description
= NULL
;
706 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
707 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
709 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
710 ServerInfo
.specific_ipv4_vhost
= 0;
712 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
713 ServerInfo
.specific_ipv6_vhost
= 0;
716 /* Don't reset hub, as that will break lazylinks */
717 /* ServerInfo.hub = NO; */
718 AdminInfo
.name
= NULL
;
719 AdminInfo
.email
= NULL
;
720 AdminInfo
.description
= NULL
;
722 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
723 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
724 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
726 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
727 ConfigFileEntry
.failed_oper_notice
= YES
;
728 ConfigFileEntry
.anti_nick_flood
= NO
;
729 ConfigFileEntry
.disable_fake_channels
= NO
;
730 ConfigFileEntry
.max_nick_time
= 20;
731 ConfigFileEntry
.max_nick_changes
= 5;
732 ConfigFileEntry
.max_accept
= 20;
733 ConfigFileEntry
.max_monitor
= 60;
734 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
735 ConfigFileEntry
.target_change
= YES
;
736 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
737 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
738 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
739 ConfigFileEntry
.client_exit
= YES
;
740 ConfigFileEntry
.dline_with_reason
= YES
;
741 ConfigFileEntry
.kline_with_reason
= YES
;
742 ConfigFileEntry
.kline_delay
= 0;
743 ConfigFileEntry
.warn_no_nline
= YES
;
744 ConfigFileEntry
.non_redundant_klines
= YES
;
745 ConfigFileEntry
.stats_e_disabled
= NO
;
746 ConfigFileEntry
.stats_o_oper_only
= NO
;
747 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
748 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
749 ConfigFileEntry
.stats_P_oper_only
= NO
;
750 ConfigFileEntry
.stats_c_oper_only
= NO
;
751 ConfigFileEntry
.stats_y_oper_only
= NO
;
752 ConfigFileEntry
.stats_h_oper_only
= NO
;
753 ConfigFileEntry
.map_oper_only
= YES
;
754 ConfigFileEntry
.operspy_admin_only
= NO
;
755 ConfigFileEntry
.pace_wait
= 10;
756 ConfigFileEntry
.caller_id_wait
= 60;
757 ConfigFileEntry
.pace_wait_simple
= 1;
758 ConfigFileEntry
.short_motd
= NO
;
759 ConfigFileEntry
.no_oper_flood
= NO
;
760 ConfigFileEntry
.fname_userlog
= NULL
;
761 ConfigFileEntry
.fname_fuserlog
= NULL
;
762 ConfigFileEntry
.fname_operlog
= NULL
;
763 ConfigFileEntry
.fname_foperlog
= NULL
;
764 ConfigFileEntry
.fname_serverlog
= NULL
;
765 ConfigFileEntry
.fname_klinelog
= NULL
;
766 ConfigFileEntry
.fname_operspylog
= NULL
;
767 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
768 ConfigFileEntry
.use_egd
= NO
;
769 ConfigFileEntry
.hide_spoof_ips
= YES
;
770 ConfigFileEntry
.hide_error_messages
= 1;
771 ConfigFileEntry
.dots_in_ident
= 0;
772 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
773 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
774 ConfigFileEntry
.egdpool_path
= NULL
;
775 ConfigFileEntry
.use_whois_actually
= YES
;
776 ConfigFileEntry
.burst_away
= NO
;
777 ConfigFileEntry
.collision_fnc
= YES
;
778 ConfigFileEntry
.global_snotices
= YES
;
779 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
782 ConfigFileEntry
.compression_level
= 4;
785 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
786 UMODE_OPERWALL
| UMODE_WALLOP
;
787 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
788 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
790 ConfigChannel
.use_except
= YES
;
791 ConfigChannel
.use_invex
= YES
;
792 ConfigChannel
.use_knock
= YES
;
793 ConfigChannel
.use_forward
= YES
;
794 ConfigChannel
.knock_delay
= 300;
795 ConfigChannel
.knock_delay_channel
= 60;
796 ConfigChannel
.max_chans_per_user
= 15;
797 ConfigChannel
.max_bans
= 25;
798 ConfigChannel
.max_bans_large
= 500;
799 ConfigChannel
.burst_topicwho
= NO
;
800 ConfigChannel
.kick_on_split_riding
= NO
;
802 ConfigChannel
.default_split_user_count
= 15000;
803 ConfigChannel
.default_split_server_count
= 10;
804 ConfigChannel
.no_join_on_split
= NO
;
805 ConfigChannel
.no_create_on_split
= YES
;
807 ConfigServerHide
.flatten_links
= 0;
808 ConfigServerHide
.links_delay
= 300;
809 ConfigServerHide
.hidden
= 0;
810 ConfigServerHide
.disable_hidden
= 0;
812 ConfigFileEntry
.min_nonwildcard
= 4;
813 ConfigFileEntry
.min_nonwildcard_simple
= 3;
814 ConfigFileEntry
.default_floodcount
= 8;
815 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
816 ConfigFileEntry
.tkline_expire_notices
= 0;
818 ConfigFileEntry
.reject_after_count
= 5;
819 ConfigFileEntry
.reject_ban_time
= 300;
820 ConfigFileEntry
.reject_duration
= 120;
821 ConfigFileEntry
.max_unknown_ip
= 2;
823 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
833 * inputs - file descriptor pointing to config file to use
835 * side effects - Read configuration file.
838 read_conf(FILE * file
)
842 set_default_conf(); /* Set default values prior to conf parsing */
843 yyparse(); /* Load the values from the conf */
844 validate_conf(); /* Check to make sure some values are still okay. */
845 /* Some global values are also loaded here. */
846 check_class(); /* Make sure classes are valid */
852 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
853 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
855 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
856 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
858 if(ConfigFileEntry
.servlink_path
== NULL
)
859 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
861 if(ServerInfo
.network_name
== NULL
)
862 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
864 if(ServerInfo
.network_desc
== NULL
)
865 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
867 if(ServerInfo
.ssld_count
< 1)
868 ServerInfo
.ssld_count
= 1;
870 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
872 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
876 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
879 if(ServerInfo
.ssld_count
> get_ssld_count())
881 int start
= ServerInfo
.ssld_count
- get_ssld_count();
882 /* start up additional ssld if needed */
883 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
887 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
888 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
889 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
891 if(!split_users
|| !split_servers
||
892 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
894 rb_event_delete(check_splitmode_ev
);
895 check_splitmode_ev
= NULL
;
903 * inputs - pointer to struct ConfItem
905 * Side effects - links in given struct ConfItem into
906 * temporary kline link list
909 add_temp_kline(struct ConfItem
*aconf
)
911 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
913 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
914 aconf
->port
= TEMP_WEEK
;
916 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
918 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
919 aconf
->port
= TEMP_DAY
;
921 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
923 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
924 aconf
->port
= TEMP_HOUR
;
928 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
929 aconf
->port
= TEMP_MIN
;
932 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
933 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
938 * input - pointer to struct ConfItem
940 * side effects - added to tdline link list and address hash
943 add_temp_dline(struct ConfItem
*aconf
)
945 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
947 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
948 aconf
->port
= TEMP_WEEK
;
950 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
952 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
953 aconf
->port
= TEMP_DAY
;
955 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
957 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
958 aconf
->port
= TEMP_HOUR
;
962 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
963 aconf
->port
= TEMP_MIN
;
966 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
967 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
972 * inputs - list pointer
975 * side effects - expire tklines and moves them between lists
978 expire_temp_kd(void *list
)
981 rb_dlink_node
*next_ptr
;
982 struct ConfItem
*aconf
;
984 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
988 if(aconf
->hold
<= rb_current_time())
990 /* Alert opers that a TKline expired - Hwy */
991 if(ConfigFileEntry
.tkline_expire_notices
)
992 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
993 "Temporary K-line for [%s@%s] expired",
994 (aconf
->user
) ? aconf
->
995 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
997 delete_one_address_conf(aconf
->host
, aconf
);
998 rb_dlinkDestroy(ptr
, list
);
1004 reorganise_temp_kd(void *list
)
1006 struct ConfItem
*aconf
;
1007 rb_dlink_node
*ptr
, *next_ptr
;
1009 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1013 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1015 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1016 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1017 aconf
->port
= TEMP_MIN
;
1019 else if(aconf
->port
> TEMP_HOUR
)
1021 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1023 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1024 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1025 aconf
->port
= TEMP_HOUR
;
1027 else if(aconf
->port
> TEMP_DAY
&&
1028 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1030 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1031 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1032 aconf
->port
= TEMP_DAY
;
1039 /* const char* get_oper_name(struct Client *client_p)
1040 * Input: A client to find the active oper{} name for.
1041 * Output: The nick!user@host{oper} of the oper.
1042 * "oper" is server name for remote opers
1043 * Side effects: None.
1046 get_oper_name(struct Client
*client_p
)
1048 /* +5 for !,@,{,} and null */
1049 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1051 if(MyOper(client_p
))
1053 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1054 client_p
->name
, client_p
->username
,
1055 client_p
->host
, client_p
->localClient
->opername
);
1059 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1060 client_p
->name
, client_p
->username
,
1061 client_p
->host
, client_p
->servptr
->name
);
1066 * get_printable_conf
1068 * inputs - struct ConfItem
1077 * Examine the struct struct ConfItem, setting the values
1078 * of name, host, pass, user to values either
1079 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1082 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1083 char **pass
, char **user
, int *port
, char **classname
)
1085 static char null
[] = "<NULL>";
1086 static char zero
[] = "default";
1088 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1089 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1090 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1091 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1092 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1093 *port
= (int) aconf
->port
;
1097 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1098 char **host
, char **reason
,
1099 char **user
, char **oper_reason
)
1101 static char null
[] = "<NULL>";
1103 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1104 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1105 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1107 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1108 *oper_reason
= NULL
;
1110 *oper_reason
= aconf
->spasswd
;
1116 * inputs - cold start YES or NO
1118 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1121 read_conf_files(int cold
)
1123 const char *filename
;
1125 conf_fbfile_in
= NULL
;
1127 filename
= get_conf_name(CONF_TYPE
);
1129 /* We need to know the initial filename for the yyerror() to report
1130 FIXME: The full path is in conffilenamebuf first time since we
1131 dont know anything else
1135 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1137 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1141 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1146 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1147 "Can't open file '%s' - aborting rehash!", filename
);
1154 clear_out_old_conf();
1157 read_conf(conf_fbfile_in
);
1158 fclose(conf_fbfile_in
);
1162 * free an alias{} entry.
1165 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1167 struct alias_entry
*aptr
= ptr
->data
;
1169 rb_free(aptr
->name
);
1170 rb_free(aptr
->target
);
1175 * clear_out_old_conf
1179 * side effects - Clear out the old configuration
1182 clear_out_old_conf(void)
1184 struct Class
*cltmp
;
1186 rb_dlink_node
*next_ptr
;
1189 * don't delete the class table, rather mark all entries
1190 * for deletion. The table is cleaned up by check_class. - avalon
1192 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1195 MaxUsers(cltmp
) = -1;
1198 clear_out_address_conf();
1201 /* clean out module paths */
1202 #ifndef STATIC_MODULES
1204 mod_add_path(MODULE_DIR
);
1205 mod_add_path(MODULE_DIR
"/autoload");
1208 /* clean out ServerInfo */
1209 rb_free(ServerInfo
.description
);
1210 ServerInfo
.description
= NULL
;
1211 rb_free(ServerInfo
.network_name
);
1212 ServerInfo
.network_name
= NULL
;
1213 rb_free(ServerInfo
.network_desc
);
1214 ServerInfo
.network_desc
= NULL
;
1216 ServerInfo
.ssld_count
= 1;
1218 /* clean out AdminInfo */
1219 rb_free(AdminInfo
.name
);
1220 AdminInfo
.name
= NULL
;
1221 rb_free(AdminInfo
.email
);
1222 AdminInfo
.email
= NULL
;
1223 rb_free(AdminInfo
.description
);
1224 AdminInfo
.description
= NULL
;
1226 /* operator{} and class{} blocks are freed above */
1227 /* clean out listeners */
1230 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1231 * and gecos{} blocks are freed above too
1234 /* clean out general */
1235 rb_free(ConfigFileEntry
.servlink_path
);
1236 ConfigFileEntry
.servlink_path
= NULL
;
1238 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1241 rb_dlinkDestroy(ptr
, &service_list
);
1244 /* remove any aliases... -- nenolod */
1245 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1248 destroy_blacklists();
1250 /* OK, that should be everything... */
1256 * inputs - kline, dline or resv type flag
1257 * - client pointer to report to
1258 * - user name of target
1259 * - host name of target
1260 * - reason for target
1264 * side effects - This function takes care of finding the right conf
1265 * file and adding the line to it, as well as notifying
1266 * opers and the user.
1269 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1270 char *host
, const char *reason
, const char *oper_reason
,
1271 const char *current_date
, int xtype
)
1275 const char *filename
; /* filename to use for kline */
1277 filename
= get_conf_name(type
);
1279 if(type
== KLINE_TYPE
)
1281 if(EmptyString(oper_reason
))
1283 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1284 "%s added K-Line for [%s@%s] [%s]",
1285 get_oper_name(source_p
), user
,
1287 ilog(L_KLINE
, "K %s 0 %s %s %s",
1288 get_oper_name(source_p
), user
, host
, reason
);
1292 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1293 "%s added K-Line for [%s@%s] [%s|%s]",
1294 get_oper_name(source_p
), user
,
1295 host
, reason
, oper_reason
);
1296 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1297 get_oper_name(source_p
), user
, host
,
1298 reason
, oper_reason
);
1301 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1304 else if(type
== DLINE_TYPE
)
1306 if(EmptyString(oper_reason
))
1308 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1309 "%s added D-Line for [%s] [%s]",
1310 get_oper_name(source_p
), host
, reason
);
1311 ilog(L_KLINE
, "D %s 0 %s %s",
1312 get_oper_name(source_p
), host
, reason
);
1316 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1317 "%s added D-Line for [%s] [%s|%s]",
1318 get_oper_name(source_p
), host
,
1319 reason
, oper_reason
);
1320 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1321 get_oper_name(source_p
), host
,
1322 reason
, oper_reason
);
1325 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1328 else if(type
== RESV_TYPE
)
1330 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1331 "%s added RESV for [%s] [%s]",
1332 get_oper_name(source_p
), host
, reason
);
1333 ilog(L_KLINE
, "R %s 0 %s %s",
1334 get_oper_name(source_p
), host
, reason
);
1336 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1340 if((out
= fopen(filename
, "a")) == NULL
)
1342 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1343 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1347 if(oper_reason
== NULL
)
1350 if(type
== KLINE_TYPE
)
1352 rb_snprintf(buffer
, sizeof(buffer
),
1353 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1354 user
, host
, reason
, oper_reason
, current_date
,
1355 get_oper_name(source_p
), (long int)rb_current_time());
1357 else if(type
== DLINE_TYPE
)
1359 rb_snprintf(buffer
, sizeof(buffer
),
1360 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1361 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1363 else if(type
== RESV_TYPE
)
1365 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1366 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1369 if(fputs(buffer
, out
) == -1)
1371 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1372 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1379 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1380 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1387 * inputs - type of conf file to return name of file for
1388 * output - pointer to filename for type of conf
1389 * side effects - none
1392 get_conf_name(KlineType type
)
1394 if(type
== CONF_TYPE
)
1396 return (ConfigFileEntry
.configfile
);
1398 else if(type
== DLINE_TYPE
)
1400 return (ConfigFileEntry
.dlinefile
);
1402 else if(type
== RESV_TYPE
)
1404 return (ConfigFileEntry
.resvfile
);
1407 return ConfigFileEntry
.klinefile
;
1411 * conf_add_class_to_conf
1412 * inputs - pointer to config item
1414 * side effects - Add a class pointer to a conf
1418 conf_add_class_to_conf(struct ConfItem
*aconf
)
1420 if(aconf
->className
== NULL
)
1422 aconf
->className
= rb_strdup("default");
1423 ClassPtr(aconf
) = default_class
;
1427 ClassPtr(aconf
) = find_class(aconf
->className
);
1429 if(ClassPtr(aconf
) == default_class
)
1431 if(aconf
->status
== CONF_CLIENT
)
1433 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1434 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1435 aconf
->className
, aconf
->user
, aconf
->host
);
1438 rb_free(aconf
->className
);
1439 aconf
->className
= rb_strdup("default");
1443 if(ConfMaxUsers(aconf
) < 0)
1445 ClassPtr(aconf
) = default_class
;
1446 rb_free(aconf
->className
);
1447 aconf
->className
= rb_strdup("default");
1454 * inputs - pointer to config item
1456 * side effects - Add a d/D line
1459 conf_add_d_conf(struct ConfItem
*aconf
)
1461 if(aconf
->host
== NULL
)
1466 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1467 * need this anyway, so I will disable it for now... -A1kmm
1470 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1472 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1477 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1482 strip_tabs(char *dest
, const char *src
, size_t len
)
1486 if(dest
== NULL
|| src
== NULL
)
1489 rb_strlcpy(dest
, src
, len
);
1503 * inputs - message from parser
1505 * side effects - message to opers and log file entry is made
1508 yyerror(const char *msg
)
1510 char newlinebuf
[BUFSIZE
];
1512 strip_tabs(newlinebuf
, linebuf
, strlen(linebuf
));
1514 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1515 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1517 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1521 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1525 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1528 return (strlen(lbuf
));
1532 conf_yy_fatal_error(const char *msg
)