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
;
902 * lookup_confhost - start DNS lookups of all hostnames in the conf
903 * line and convert an IP addresses in a.b.c.d number for to IP#s.
908 * conf_connect_allowed
910 * inputs - pointer to inaddr
911 * - int type ipv4 or ipv6
912 * output - ban info or NULL
913 * side effects - none
916 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
918 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
920 /* DLINE exempt also gets you out of static limits/pacing... */
921 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
932 * inputs - pointer to struct ConfItem
934 * Side effects - links in given struct ConfItem into
935 * temporary kline link list
938 add_temp_kline(struct ConfItem
*aconf
)
940 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
942 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
943 aconf
->port
= TEMP_WEEK
;
945 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
947 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
948 aconf
->port
= TEMP_DAY
;
950 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
952 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
953 aconf
->port
= TEMP_HOUR
;
957 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
958 aconf
->port
= TEMP_MIN
;
961 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
962 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
967 * input - pointer to struct ConfItem
969 * side effects - added to tdline link list and address hash
972 add_temp_dline(struct ConfItem
*aconf
)
974 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
976 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
977 aconf
->port
= TEMP_WEEK
;
979 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
981 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
982 aconf
->port
= TEMP_DAY
;
984 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
986 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
987 aconf
->port
= TEMP_HOUR
;
991 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
992 aconf
->port
= TEMP_MIN
;
995 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
996 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
1001 * inputs - list pointer
1004 * side effects - expire tklines and moves them between lists
1007 expire_temp_kd(void *list
)
1010 rb_dlink_node
*next_ptr
;
1011 struct ConfItem
*aconf
;
1013 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1017 if(aconf
->hold
<= rb_current_time())
1019 /* Alert opers that a TKline expired - Hwy */
1020 if(ConfigFileEntry
.tkline_expire_notices
)
1021 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1022 "Temporary K-line for [%s@%s] expired",
1023 (aconf
->user
) ? aconf
->
1024 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1026 delete_one_address_conf(aconf
->host
, aconf
);
1027 rb_dlinkDestroy(ptr
, list
);
1033 reorganise_temp_kd(void *list
)
1035 struct ConfItem
*aconf
;
1036 rb_dlink_node
*ptr
, *next_ptr
;
1038 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1042 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1044 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1045 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1046 aconf
->port
= TEMP_MIN
;
1048 else if(aconf
->port
> TEMP_HOUR
)
1050 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1052 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1053 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1054 aconf
->port
= TEMP_HOUR
;
1056 else if(aconf
->port
> TEMP_DAY
&&
1057 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1059 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1060 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1061 aconf
->port
= TEMP_DAY
;
1068 /* const char* get_oper_name(struct Client *client_p)
1069 * Input: A client to find the active oper{} name for.
1070 * Output: The nick!user@host{oper} of the oper.
1071 * "oper" is server name for remote opers
1072 * Side effects: None.
1075 get_oper_name(struct Client
*client_p
)
1077 /* +5 for !,@,{,} and null */
1078 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1080 if(MyOper(client_p
))
1082 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1083 client_p
->name
, client_p
->username
,
1084 client_p
->host
, client_p
->localClient
->opername
);
1088 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1089 client_p
->name
, client_p
->username
,
1090 client_p
->host
, client_p
->servptr
->name
);
1095 * get_printable_conf
1097 * inputs - struct ConfItem
1106 * Examine the struct struct ConfItem, setting the values
1107 * of name, host, pass, user to values either
1108 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1111 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1112 char **pass
, char **user
, int *port
, char **classname
)
1114 static char null
[] = "<NULL>";
1115 static char zero
[] = "default";
1117 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1118 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1119 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1120 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1121 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1122 *port
= (int) aconf
->port
;
1126 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1127 char **host
, char **reason
,
1128 char **user
, char **oper_reason
)
1130 static char null
[] = "<NULL>";
1132 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1133 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1134 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1136 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1137 *oper_reason
= NULL
;
1139 *oper_reason
= aconf
->spasswd
;
1145 * inputs - cold start YES or NO
1147 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1150 read_conf_files(int cold
)
1152 const char *filename
;
1154 conf_fbfile_in
= NULL
;
1156 filename
= get_conf_name(CONF_TYPE
);
1158 /* We need to know the initial filename for the yyerror() to report
1159 FIXME: The full path is in conffilenamebuf first time since we
1160 dont know anything else
1164 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1166 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1170 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1175 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1176 "Can't open file '%s' - aborting rehash!", filename
);
1183 clear_out_old_conf();
1186 read_conf(conf_fbfile_in
);
1187 fclose(conf_fbfile_in
);
1191 * free an alias{} entry.
1194 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1196 struct alias_entry
*aptr
= ptr
->data
;
1198 rb_free(aptr
->name
);
1199 rb_free(aptr
->target
);
1204 * clear_out_old_conf
1208 * side effects - Clear out the old configuration
1211 clear_out_old_conf(void)
1213 struct Class
*cltmp
;
1215 rb_dlink_node
*next_ptr
;
1218 * don't delete the class table, rather mark all entries
1219 * for deletion. The table is cleaned up by check_class. - avalon
1221 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1224 MaxUsers(cltmp
) = -1;
1227 clear_out_address_conf();
1230 /* clean out module paths */
1231 #ifndef STATIC_MODULES
1233 mod_add_path(MODULE_DIR
);
1234 mod_add_path(MODULE_DIR
"/autoload");
1237 /* clean out ServerInfo */
1238 rb_free(ServerInfo
.description
);
1239 ServerInfo
.description
= NULL
;
1240 rb_free(ServerInfo
.network_name
);
1241 ServerInfo
.network_name
= NULL
;
1242 rb_free(ServerInfo
.network_desc
);
1243 ServerInfo
.network_desc
= NULL
;
1245 ServerInfo
.ssld_count
= 1;
1247 /* clean out AdminInfo */
1248 rb_free(AdminInfo
.name
);
1249 AdminInfo
.name
= NULL
;
1250 rb_free(AdminInfo
.email
);
1251 AdminInfo
.email
= NULL
;
1252 rb_free(AdminInfo
.description
);
1253 AdminInfo
.description
= NULL
;
1255 /* operator{} and class{} blocks are freed above */
1256 /* clean out listeners */
1259 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1260 * and gecos{} blocks are freed above too
1263 /* clean out general */
1264 rb_free(ConfigFileEntry
.servlink_path
);
1265 ConfigFileEntry
.servlink_path
= NULL
;
1267 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1270 rb_dlinkDestroy(ptr
, &service_list
);
1273 /* remove any aliases... -- nenolod */
1274 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1277 destroy_blacklists();
1279 /* OK, that should be everything... */
1285 * inputs - kline, dline or resv type flag
1286 * - client pointer to report to
1287 * - user name of target
1288 * - host name of target
1289 * - reason for target
1293 * side effects - This function takes care of finding the right conf
1294 * file and adding the line to it, as well as notifying
1295 * opers and the user.
1298 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1299 char *host
, const char *reason
, const char *oper_reason
,
1300 const char *current_date
, int xtype
)
1304 const char *filename
; /* filename to use for kline */
1306 filename
= get_conf_name(type
);
1308 if(type
== KLINE_TYPE
)
1310 if(EmptyString(oper_reason
))
1312 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1313 "%s added K-Line for [%s@%s] [%s]",
1314 get_oper_name(source_p
), user
,
1316 ilog(L_KLINE
, "K %s 0 %s %s %s",
1317 get_oper_name(source_p
), user
, host
, reason
);
1321 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1322 "%s added K-Line for [%s@%s] [%s|%s]",
1323 get_oper_name(source_p
), user
,
1324 host
, reason
, oper_reason
);
1325 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1326 get_oper_name(source_p
), user
, host
,
1327 reason
, oper_reason
);
1330 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1333 else if(type
== DLINE_TYPE
)
1335 if(EmptyString(oper_reason
))
1337 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1338 "%s added D-Line for [%s] [%s]",
1339 get_oper_name(source_p
), host
, reason
);
1340 ilog(L_KLINE
, "D %s 0 %s %s",
1341 get_oper_name(source_p
), host
, reason
);
1345 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1346 "%s added D-Line for [%s] [%s|%s]",
1347 get_oper_name(source_p
), host
,
1348 reason
, oper_reason
);
1349 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1350 get_oper_name(source_p
), host
,
1351 reason
, oper_reason
);
1354 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1357 else if(type
== RESV_TYPE
)
1359 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1360 "%s added RESV for [%s] [%s]",
1361 get_oper_name(source_p
), host
, reason
);
1362 ilog(L_KLINE
, "R %s 0 %s %s",
1363 get_oper_name(source_p
), host
, reason
);
1365 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1369 if((out
= fopen(filename
, "a")) == NULL
)
1371 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1372 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1376 if(oper_reason
== NULL
)
1379 if(type
== KLINE_TYPE
)
1381 rb_snprintf(buffer
, sizeof(buffer
),
1382 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1383 user
, host
, reason
, oper_reason
, current_date
,
1384 get_oper_name(source_p
), (long int)rb_current_time());
1386 else if(type
== DLINE_TYPE
)
1388 rb_snprintf(buffer
, sizeof(buffer
),
1389 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1390 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1392 else if(type
== RESV_TYPE
)
1394 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1395 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1398 if(fputs(buffer
, out
) == -1)
1400 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1401 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1408 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1409 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1416 * inputs - type of conf file to return name of file for
1417 * output - pointer to filename for type of conf
1418 * side effects - none
1421 get_conf_name(KlineType type
)
1423 if(type
== CONF_TYPE
)
1425 return (ConfigFileEntry
.configfile
);
1427 else if(type
== DLINE_TYPE
)
1429 return (ConfigFileEntry
.dlinefile
);
1431 else if(type
== RESV_TYPE
)
1433 return (ConfigFileEntry
.resvfile
);
1436 return ConfigFileEntry
.klinefile
;
1440 * conf_add_class_to_conf
1441 * inputs - pointer to config item
1443 * side effects - Add a class pointer to a conf
1447 conf_add_class_to_conf(struct ConfItem
*aconf
)
1449 if(aconf
->className
== NULL
)
1451 aconf
->className
= rb_strdup("default");
1452 ClassPtr(aconf
) = default_class
;
1456 ClassPtr(aconf
) = find_class(aconf
->className
);
1458 if(ClassPtr(aconf
) == default_class
)
1460 if(aconf
->status
== CONF_CLIENT
)
1462 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1463 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1464 aconf
->className
, aconf
->user
, aconf
->host
);
1467 rb_free(aconf
->className
);
1468 aconf
->className
= rb_strdup("default");
1472 if(ConfMaxUsers(aconf
) < 0)
1474 ClassPtr(aconf
) = default_class
;
1475 rb_free(aconf
->className
);
1476 aconf
->className
= rb_strdup("default");
1483 * inputs - pointer to config item
1485 * side effects - Add a d/D line
1488 conf_add_d_conf(struct ConfItem
*aconf
)
1490 if(aconf
->host
== NULL
)
1495 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1496 * need this anyway, so I will disable it for now... -A1kmm
1499 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1501 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1506 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1511 strip_tabs(char *dest
, const char *src
, size_t len
)
1515 if(dest
== NULL
|| src
== NULL
)
1518 rb_strlcpy(dest
, src
, len
);
1532 * inputs - message from parser
1534 * side effects - message to opers and log file entry is made
1537 yyerror(const char *msg
)
1539 char newlinebuf
[BUFSIZE
];
1541 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1543 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1544 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1546 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1550 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1554 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1557 return (strlen(lbuf
));
1561 conf_yy_fatal_error(const char *msg
)