2 * ircd-ratbox: A slightly useful ircd.
3 * s_conf.c: Configuration file functions.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $
28 #include "ircd_defs.h"
30 #include "s_newconf.h"
38 #include "irc_string.h"
39 #include "sprintf_irc.h"
51 #include "blacklist.h"
53 struct config_server_hide ConfigServerHide
;
55 extern int yyparse(); /* defined in y.tab.c */
56 extern char linebuf
[];
59 #define INADDR_NONE ((unsigned int) 0xffffffff)
62 static rb_bh
*confitem_heap
= NULL
;
64 rb_dlink_list temp_klines
[LAST_TEMP_TYPE
];
65 rb_dlink_list temp_dlines
[LAST_TEMP_TYPE
];
66 rb_dlink_list service_list
;
68 /* internally defined functions */
69 static void set_default_conf(void);
70 static void validate_conf(void);
71 static void read_conf(FILE *);
72 static void clear_out_old_conf(void);
74 static void expire_temp_kd(void *list
);
75 static void reorganise_temp_kd(void *list
);
80 static int verify_access(struct Client
*client_p
, const char *username
);
81 static int attach_iline(struct Client
*, struct ConfItem
*);
86 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
);
88 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
89 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
91 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
92 &temp_klines
[TEMP_HOUR
], 3600);
93 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
94 &temp_dlines
[TEMP_HOUR
], 3600);
95 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
96 &temp_klines
[TEMP_DAY
], 86400);
97 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
98 &temp_dlines
[TEMP_DAY
], 86400);
99 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
100 &temp_klines
[TEMP_WEEK
], 604800);
101 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
102 &temp_dlines
[TEMP_WEEK
], 604800);
109 * output - pointer to new conf entry
110 * side effects - none
115 struct ConfItem
*aconf
;
117 aconf
= rb_bh_alloc(confitem_heap
);
118 aconf
->status
= CONF_ILLEGAL
;
125 * inputs - pointer to conf to free
127 * side effects - crucial password fields are zeroed, conf is freed
130 free_conf(struct ConfItem
*aconf
)
132 s_assert(aconf
!= NULL
);
138 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
140 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
142 rb_free(aconf
->passwd
);
143 rb_free(aconf
->spasswd
);
144 rb_free(aconf
->name
);
145 rb_free(aconf
->className
);
146 rb_free(aconf
->user
);
147 rb_free(aconf
->host
);
149 rb_bh_free(confitem_heap
, aconf
);
155 * inputs - pointer to client
156 * output - 0 = Success
157 * NOT_AUTHORISED (-1) = Access denied (no I line match)
158 * SOCKET_ERROR (-2) = Bad socket.
159 * I_LINE_FULL (-3) = I-line is full
160 * TOO_MANY (-4) = Too many connections from hostname
161 * BANNED_CLIENT (-5) = K-lined
162 * side effects - Ordinary client access check.
163 * Look for conf lines which have the same
164 * status as the flags passed.
167 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
171 if((i
= verify_access(source_p
, username
)))
173 ilog(L_FUSER
, "Access denied: %s[%s]",
174 source_p
->name
, source_p
->sockhost
);
180 exit_client(client_p
, source_p
, &me
, "Socket Error");
184 /* Note that these notices are sent to opers on other
185 * servers also, so even if local opers are allowed to
186 * see the IP, we still cannot send it.
188 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
189 "Too many local connections for %s!%s%s@%s",
190 source_p
->name
, IsGotId(source_p
) ? "" : "~",
192 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
194 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
195 source_p
->name
, IsGotId(source_p
) ? "" : "~",
196 source_p
->username
, source_p
->sockhost
);
198 ServerStats
.is_ref
++;
199 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
202 case TOO_MANY_GLOBAL
:
203 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
204 "Too many global connections for %s!%s%s@%s",
205 source_p
->name
, IsGotId(source_p
) ? "" : "~",
207 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
208 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
209 source_p
->name
, IsGotId(source_p
) ? "" : "~",
210 source_p
->username
, source_p
->sockhost
);
212 ServerStats
.is_ref
++;
213 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
217 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
218 "Too many user connections for %s!%s%s@%s",
219 source_p
->name
, IsGotId(source_p
) ? "" : "~",
221 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
222 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
223 source_p
->name
, IsGotId(source_p
) ? "" : "~",
224 source_p
->username
, source_p
->sockhost
);
226 ServerStats
.is_ref
++;
227 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
231 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
232 "I-line is full for %s!%s%s@%s (%s).",
233 source_p
->name
, IsGotId(source_p
) ? "" : "~",
234 source_p
->username
, source_p
->host
,
235 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
237 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
238 source_p
->name
, IsGotId(source_p
) ? "" : "~",
239 source_p
->username
, source_p
->sockhost
);
241 ServerStats
.is_ref
++;
242 exit_client(client_p
, source_p
, &me
,
243 "No more connections allowed in your connection class");
250 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
251 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
254 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
256 ServerStats
.is_ref
++;
257 /* jdc - lists server name & port connections are on */
258 /* a purely cosmetical change */
259 /* why ipaddr, and not just source_p->sockhost? --fl */
261 static char ipaddr
[HOSTIPLEN
];
262 inetntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
264 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
265 "Unauthorised client connection from "
266 "%s!%s%s@%s [%s] on [%s/%u].",
267 source_p
->name
, IsGotId(source_p
) ? "" : "~",
268 source_p
->username
, source_p
->host
,
270 source_p
->localClient
->listener
->name
, port
);
273 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
274 source_p
->name
, IsGotId(source_p
) ? "" : "~",
275 source_p
->username
, source_p
->sockhost
,
276 source_p
->localClient
->listener
->name
, port
);
277 add_reject(client_p
, NULL
, NULL
);
278 exit_client(client_p
, source_p
, &me
,
279 "You are not authorised to use this server");
283 exit_client(client_p
, client_p
, &me
, "*** Banned ");
284 ServerStats
.is_ref
++;
297 * inputs - pointer to client to verify
298 * - pointer to proposed username
299 * output - 0 if success -'ve if not
300 * side effect - find the first (best) I line to attach.
303 verify_access(struct Client
*client_p
, const char *username
)
305 struct ConfItem
*aconf
;
306 char non_ident
[USERLEN
+ 1];
308 if(IsGotId(client_p
))
310 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
311 client_p
->username
, client_p
->username
,
312 (struct sockaddr
*) &client_p
->localClient
->ip
,
313 client_p
->localClient
->ip
.ss_family
);
317 strlcpy(non_ident
, "~", sizeof(non_ident
));
318 strlcat(non_ident
, username
, sizeof(non_ident
));
319 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
320 non_ident
, client_p
->username
,
321 (struct sockaddr
*) &client_p
->localClient
->ip
,
322 client_p
->localClient
->ip
.ss_family
);
326 return NOT_AUTHORISED
;
328 if(aconf
->status
& CONF_CLIENT
)
330 if(aconf
->flags
& CONF_FLAGS_REDIR
)
332 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
333 aconf
->name
? aconf
->name
: "", aconf
->port
);
334 return (NOT_AUTHORISED
);
337 /* Thanks for spoof idea amm */
338 if(IsConfDoSpoofIp(aconf
))
342 /* show_ip() depends on this --fl */
343 SetIPSpoof(client_p
);
345 if(IsConfSpoofNotice(aconf
))
347 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
348 "%s spoofing: %s as %s",
350 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
354 /* user@host spoof */
355 if((p
= strchr(aconf
->name
, '@')) != NULL
)
360 strlcpy(client_p
->username
, aconf
->name
,
361 sizeof(client_p
->username
));
362 strlcpy(client_p
->host
, host
,
363 sizeof(client_p
->host
));
367 strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
369 return (attach_iline(client_p
, aconf
));
371 else if(aconf
->status
& CONF_KILL
)
373 if(ConfigFileEntry
.kline_with_reason
)
376 form_str(ERR_YOUREBANNEDCREEP
),
377 me
.name
, client_p
->name
, aconf
->passwd
);
379 add_reject(client_p
, aconf
->user
, aconf
->host
);
380 return (BANNED_CLIENT
);
382 else if(aconf
->status
& CONF_GLINE
)
384 sendto_one_notice(client_p
, ":*** G-lined");
386 if(ConfigFileEntry
.kline_with_reason
)
388 form_str(ERR_YOUREBANNEDCREEP
),
389 me
.name
, client_p
->name
, aconf
->passwd
);
391 add_reject(client_p
, aconf
->user
, aconf
->host
);
392 return (BANNED_CLIENT
);
395 return NOT_AUTHORISED
;
402 * Returns 1 if successful 0 if not
404 * This checks if the user has exceed the limits for their class
405 * unless of course they are exempt..
409 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
411 patricia_node_t
*pnode
;
413 /* If the limits are 0 don't do anything.. */
414 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
417 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
420 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
422 s_assert(pnode
!= NULL
);
426 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
427 && !IsConfExemptLimits(aconf
))
429 /* This should only happen if the limits are set to 0 */
430 if((unsigned long) pnode
->data
== 0)
432 patricia_remove(ConfIpLimits(aconf
), pnode
);
443 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
445 patricia_node_t
*pnode
;
447 /* If the limits are 0 don't do anything.. */
448 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
451 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
456 if(((unsigned long) pnode
->data
) == 0)
458 patricia_remove(ConfIpLimits(aconf
), pnode
);
466 * inputs - client pointer
469 * side effects - do actual attach
472 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
474 struct Client
*target_p
;
477 int global_count
= 0;
481 if(IsConfExemptLimits(aconf
))
482 return (attach_conf(client_p
, aconf
));
484 if(*client_p
->username
== '~')
488 /* find_hostname() returns the head of the list to search */
489 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
491 target_p
= ptr
->data
;
493 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
496 if(MyConnect(target_p
))
503 if(*target_p
->username
== '~')
506 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
509 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
510 return (TOO_MANY_LOCAL
);
511 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
512 return (TOO_MANY_GLOBAL
);
513 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
514 return (TOO_MANY_IDENT
);
518 return (attach_conf(client_p
, aconf
));
524 * inputs - pointer to client to detach
525 * output - 0 for success, -1 for failure
526 * side effects - Disassociate configuration from the client.
527 * Also removes a class from the list if marked for deleting.
530 detach_conf(struct Client
*client_p
)
532 struct ConfItem
*aconf
;
534 aconf
= client_p
->localClient
->att_conf
;
540 remove_ip_limit(client_p
, aconf
);
542 if(ConfCurrUsers(aconf
) > 0)
543 --ConfCurrUsers(aconf
);
545 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
547 free_class(ClassPtr(aconf
));
548 ClassPtr(aconf
) = NULL
;
554 if(!aconf
->clients
&& IsIllegal(aconf
))
557 client_p
->localClient
->att_conf
= NULL
;
567 * inputs - client pointer
570 * side effects - Associate a specific configuration entry to a *local*
571 * client (this is the one which used in accepting the
572 * connection). Note, that this automatically changes the
573 * attachment if there was an old one...
576 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
579 return (NOT_AUTHORISED
);
583 if(!add_ip_limit(client_p
, aconf
))
584 return (TOO_MANY_LOCAL
);
587 if((aconf
->status
& CONF_CLIENT
) &&
588 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
590 if(!IsConfExemptLimits(aconf
))
592 return (I_LINE_FULL
);
596 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
601 if(client_p
->localClient
->att_conf
!= NULL
)
602 detach_conf(client_p
);
604 client_p
->localClient
->att_conf
= aconf
;
607 ConfCurrUsers(aconf
)++;
614 * Actual REHASH service routine. Called with sig == 0 if it has been called
615 * as a result of an operator issuing this command, else assume it has been
616 * called as a result of the server receiving a HUP signal.
623 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
624 "Got signal SIGHUP, reloading ircd conf. file");
628 /* don't close listeners until we know we can go ahead with the rehash */
631 if(ServerInfo
.description
!= NULL
)
632 strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
634 strlcpy(me
.info
, "unknown", sizeof(me
.info
));
640 static struct banconf_entry
642 const char **filename
;
643 void (*func
) (FILE *);
646 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
647 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
648 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
649 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
650 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
651 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
652 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
653 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
661 char buf
[MAXPATHLEN
];
665 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
666 "Got signal SIGUSR2, reloading ban confs");
668 clear_out_address_conf_bans();
669 clear_s_newconf_bans();
671 for(i
= 0; banconfs
[i
].filename
; i
++)
674 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
676 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
678 if((file
= fopen(buf
, "r")) == NULL
)
683 ilog(L_MAIN
, "Failed reading ban file %s",
684 *banconfs
[i
].filename
);
685 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
686 "Can't open %s file bans could be missing!",
687 *banconfs
[i
].filename
);
691 (banconfs
[i
].func
)(file
);
696 check_banned_lines();
704 * side effects - Set default values here.
705 * This is called **PRIOR** to parsing the
706 * configuration file. If you want to do some validation
707 * of values later, put them in validate_conf().
715 set_default_conf(void)
717 /* ServerInfo.name is not rehashable */
718 /* ServerInfo.name = ServerInfo.name; */
719 ServerInfo
.description
= NULL
;
720 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
721 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
723 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
724 ServerInfo
.specific_ipv4_vhost
= 0;
726 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
727 ServerInfo
.specific_ipv6_vhost
= 0;
730 /* Don't reset hub, as that will break lazylinks */
731 /* ServerInfo.hub = NO; */
732 AdminInfo
.name
= NULL
;
733 AdminInfo
.email
= NULL
;
734 AdminInfo
.description
= NULL
;
736 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
737 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
738 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
740 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
741 ConfigFileEntry
.failed_oper_notice
= YES
;
742 ConfigFileEntry
.anti_nick_flood
= NO
;
743 ConfigFileEntry
.disable_fake_channels
= NO
;
744 ConfigFileEntry
.max_nick_time
= 20;
745 ConfigFileEntry
.max_nick_changes
= 5;
746 ConfigFileEntry
.max_accept
= 20;
747 ConfigFileEntry
.max_monitor
= 60;
748 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
749 ConfigFileEntry
.target_change
= YES
;
750 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
751 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
752 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
753 ConfigFileEntry
.client_exit
= YES
;
754 ConfigFileEntry
.dline_with_reason
= YES
;
755 ConfigFileEntry
.kline_with_reason
= YES
;
756 ConfigFileEntry
.kline_delay
= 0;
757 ConfigFileEntry
.warn_no_nline
= YES
;
758 ConfigFileEntry
.non_redundant_klines
= YES
;
759 ConfigFileEntry
.stats_e_disabled
= NO
;
760 ConfigFileEntry
.stats_o_oper_only
= NO
;
761 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
762 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
763 ConfigFileEntry
.stats_P_oper_only
= NO
;
764 ConfigFileEntry
.stats_c_oper_only
= NO
;
765 ConfigFileEntry
.stats_y_oper_only
= NO
;
766 ConfigFileEntry
.stats_h_oper_only
= NO
;
767 ConfigFileEntry
.map_oper_only
= YES
;
768 ConfigFileEntry
.operspy_admin_only
= NO
;
769 ConfigFileEntry
.pace_wait
= 10;
770 ConfigFileEntry
.caller_id_wait
= 60;
771 ConfigFileEntry
.pace_wait_simple
= 1;
772 ConfigFileEntry
.short_motd
= NO
;
773 ConfigFileEntry
.no_oper_flood
= NO
;
774 ConfigFileEntry
.fname_userlog
= NULL
;
775 ConfigFileEntry
.fname_fuserlog
= NULL
;
776 ConfigFileEntry
.fname_operlog
= NULL
;
777 ConfigFileEntry
.fname_foperlog
= NULL
;
778 ConfigFileEntry
.fname_serverlog
= NULL
;
779 ConfigFileEntry
.fname_glinelog
= NULL
;
780 ConfigFileEntry
.fname_klinelog
= NULL
;
781 ConfigFileEntry
.fname_operspylog
= NULL
;
782 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
783 ConfigFileEntry
.glines
= NO
;
784 ConfigFileEntry
.use_egd
= NO
;
785 ConfigFileEntry
.gline_time
= 12 * 3600;
786 ConfigFileEntry
.gline_min_cidr
= 16;
787 ConfigFileEntry
.gline_min_cidr6
= 48;
788 ConfigFileEntry
.hide_spoof_ips
= YES
;
789 ConfigFileEntry
.hide_error_messages
= 1;
790 ConfigFileEntry
.dots_in_ident
= 0;
791 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
792 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
793 ConfigFileEntry
.egdpool_path
= NULL
;
794 ConfigFileEntry
.use_whois_actually
= YES
;
795 ConfigFileEntry
.burst_away
= NO
;
796 ConfigFileEntry
.collision_fnc
= YES
;
797 ConfigFileEntry
.global_snotices
= YES
;
798 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
801 ConfigFileEntry
.compression_level
= 4;
804 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
805 UMODE_OPERWALL
| UMODE_WALLOP
;
806 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
807 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
809 ConfigChannel
.use_except
= YES
;
810 ConfigChannel
.use_invex
= YES
;
811 ConfigChannel
.use_knock
= YES
;
812 ConfigChannel
.use_forward
= YES
;
813 ConfigChannel
.knock_delay
= 300;
814 ConfigChannel
.knock_delay_channel
= 60;
815 ConfigChannel
.max_chans_per_user
= 15;
816 ConfigChannel
.max_bans
= 25;
817 ConfigChannel
.max_bans_large
= 500;
818 ConfigChannel
.burst_topicwho
= NO
;
819 ConfigChannel
.kick_on_split_riding
= NO
;
821 ConfigChannel
.default_split_user_count
= 15000;
822 ConfigChannel
.default_split_server_count
= 10;
823 ConfigChannel
.no_join_on_split
= NO
;
824 ConfigChannel
.no_create_on_split
= YES
;
826 ConfigServerHide
.flatten_links
= 0;
827 ConfigServerHide
.links_delay
= 300;
828 ConfigServerHide
.hidden
= 0;
829 ConfigServerHide
.disable_hidden
= 0;
831 ConfigFileEntry
.min_nonwildcard
= 4;
832 ConfigFileEntry
.min_nonwildcard_simple
= 3;
833 ConfigFileEntry
.default_floodcount
= 8;
834 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
835 ConfigFileEntry
.tkline_expire_notices
= 0;
837 ConfigFileEntry
.reject_after_count
= 5;
838 ConfigFileEntry
.reject_ban_time
= 300;
839 ConfigFileEntry
.reject_duration
= 120;
840 ConfigFileEntry
.max_unknown_ip
= 2;
842 ServerInfo
.max_clients
= rb_get_maxconnections() - MAX_BUFFER
;
852 * inputs - file descriptor pointing to config file to use
854 * side effects - Read configuration file.
857 read_conf(FILE * file
)
861 set_default_conf(); /* Set default values prior to conf parsing */
862 yyparse(); /* Load the values from the conf */
863 validate_conf(); /* Check to make sure some values are still okay. */
864 /* Some global values are also loaded here. */
865 check_class(); /* Make sure classes are valid */
871 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
872 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
874 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
875 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
877 if(ConfigFileEntry
.servlink_path
== NULL
)
878 ConfigFileEntry
.servlink_path
= rb_strdup(SLPATH
);
880 if(ServerInfo
.network_name
== NULL
)
881 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
883 if(ServerInfo
.network_desc
== NULL
)
884 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
886 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
887 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
888 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
890 if(!split_users
|| !split_servers
||
891 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
893 eventDelete(check_splitmode
, NULL
);
900 * lookup_confhost - start DNS lookups of all hostnames in the conf
901 * line and convert an IP addresses in a.b.c.d number for to IP#s.
906 * conf_connect_allowed
908 * inputs - pointer to inaddr
909 * - int type ipv4 or ipv6
910 * output - ban info or NULL
911 * side effects - none
914 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
916 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
918 /* DLINE exempt also gets you out of static limits/pacing... */
919 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
930 * inputs - pointer to struct ConfItem
932 * Side effects - links in given struct ConfItem into
933 * temporary kline link list
936 add_temp_kline(struct ConfItem
*aconf
)
938 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
940 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
941 aconf
->port
= TEMP_WEEK
;
943 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
945 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
946 aconf
->port
= TEMP_DAY
;
948 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
950 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
951 aconf
->port
= TEMP_HOUR
;
955 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
956 aconf
->port
= TEMP_MIN
;
959 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
960 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
965 * input - pointer to struct ConfItem
967 * side effects - added to tdline link list and address hash
970 add_temp_dline(struct ConfItem
*aconf
)
972 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
974 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
975 aconf
->port
= TEMP_WEEK
;
977 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
979 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
980 aconf
->port
= TEMP_DAY
;
982 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
984 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
985 aconf
->port
= TEMP_HOUR
;
989 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
990 aconf
->port
= TEMP_MIN
;
993 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
994 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
999 * inputs - list pointer
1002 * side effects - expire tklines and moves them between lists
1005 expire_temp_kd(void *list
)
1008 rb_dlink_node
*next_ptr
;
1009 struct ConfItem
*aconf
;
1011 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1015 if(aconf
->hold
<= rb_current_time())
1017 /* Alert opers that a TKline expired - Hwy */
1018 if(ConfigFileEntry
.tkline_expire_notices
)
1019 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1020 "Temporary K-line for [%s@%s] expired",
1021 (aconf
->user
) ? aconf
->
1022 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1024 delete_one_address_conf(aconf
->host
, aconf
);
1025 rb_dlinkDestroy(ptr
, list
);
1031 reorganise_temp_kd(void *list
)
1033 struct ConfItem
*aconf
;
1034 rb_dlink_node
*ptr
, *next_ptr
;
1036 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1040 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1042 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1043 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1044 aconf
->port
= TEMP_MIN
;
1046 else if(aconf
->port
> TEMP_HOUR
)
1048 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1050 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1051 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1052 aconf
->port
= TEMP_HOUR
;
1054 else if(aconf
->port
> TEMP_DAY
&&
1055 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1057 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1058 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1059 aconf
->port
= TEMP_DAY
;
1066 /* const char* get_oper_name(struct Client *client_p)
1067 * Input: A client to find the active oper{} name for.
1068 * Output: The nick!user@host{oper} of the oper.
1069 * "oper" is server name for remote opers
1070 * Side effects: None.
1073 get_oper_name(struct Client
*client_p
)
1075 /* +5 for !,@,{,} and null */
1076 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1078 if(MyOper(client_p
))
1080 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1081 client_p
->name
, client_p
->username
,
1082 client_p
->host
, client_p
->localClient
->opername
);
1086 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1087 client_p
->name
, client_p
->username
,
1088 client_p
->host
, client_p
->servptr
->name
);
1093 * get_printable_conf
1095 * inputs - struct ConfItem
1104 * Examine the struct struct ConfItem, setting the values
1105 * of name, host, pass, user to values either
1106 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1109 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1110 char **pass
, char **user
, int *port
, char **classname
)
1112 static char null
[] = "<NULL>";
1113 static char zero
[] = "default";
1115 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1116 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1117 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1118 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1119 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1120 *port
= (int) aconf
->port
;
1124 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1125 char **host
, char **reason
,
1126 char **user
, char **oper_reason
)
1128 static char null
[] = "<NULL>";
1130 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1131 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1132 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1134 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1135 *oper_reason
= NULL
;
1137 *oper_reason
= aconf
->spasswd
;
1143 * inputs - cold start YES or NO
1145 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1148 read_conf_files(int cold
)
1150 const char *filename
;
1152 conf_fbfile_in
= NULL
;
1154 filename
= get_conf_name(CONF_TYPE
);
1156 /* We need to know the initial filename for the yyerror() to report
1157 FIXME: The full path is in conffilenamebuf first time since we
1158 dont know anything else
1162 strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1164 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1168 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1173 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1174 "Can't open file '%s' - aborting rehash!", filename
);
1181 clear_out_old_conf();
1184 read_conf(conf_fbfile_in
);
1185 fclose(conf_fbfile_in
);
1189 * free an alias{} entry.
1192 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1194 struct alias_entry
*aptr
= ptr
->data
;
1196 rb_free(aptr
->name
);
1197 rb_free(aptr
->target
);
1202 * clear_out_old_conf
1206 * side effects - Clear out the old configuration
1209 clear_out_old_conf(void)
1211 struct Class
*cltmp
;
1213 rb_dlink_node
*next_ptr
;
1216 * don't delete the class table, rather mark all entries
1217 * for deletion. The table is cleaned up by check_class. - avalon
1219 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1222 MaxUsers(cltmp
) = -1;
1225 clear_out_address_conf();
1228 /* clean out module paths */
1229 #ifndef STATIC_MODULES
1231 mod_add_path(MODULE_DIR
);
1232 mod_add_path(MODULE_DIR
"/autoload");
1235 /* clean out ServerInfo */
1236 rb_free(ServerInfo
.description
);
1237 ServerInfo
.description
= NULL
;
1238 rb_free(ServerInfo
.network_name
);
1239 ServerInfo
.network_name
= NULL
;
1240 rb_free(ServerInfo
.network_desc
);
1241 ServerInfo
.network_desc
= NULL
;
1243 /* clean out AdminInfo */
1244 rb_free(AdminInfo
.name
);
1245 AdminInfo
.name
= NULL
;
1246 rb_free(AdminInfo
.email
);
1247 AdminInfo
.email
= NULL
;
1248 rb_free(AdminInfo
.description
);
1249 AdminInfo
.description
= NULL
;
1251 /* operator{} and class{} blocks are freed above */
1252 /* clean out listeners */
1255 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1256 * and gecos{} blocks are freed above too
1259 /* clean out general */
1260 rb_free(ConfigFileEntry
.servlink_path
);
1261 ConfigFileEntry
.servlink_path
= NULL
;
1263 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1266 rb_dlinkDestroy(ptr
, &service_list
);
1269 /* remove any aliases... -- nenolod */
1270 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1273 destroy_blacklists();
1275 /* OK, that should be everything... */
1281 * inputs - kline, dline or resv type flag
1282 * - client pointer to report to
1283 * - user name of target
1284 * - host name of target
1285 * - reason for target
1289 * side effects - This function takes care of finding the right conf
1290 * file and adding the line to it, as well as notifying
1291 * opers and the user.
1294 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1295 char *host
, const char *reason
, const char *oper_reason
,
1296 const char *current_date
, int xtype
)
1300 const char *filename
; /* filename to use for kline */
1302 filename
= get_conf_name(type
);
1304 if(type
== KLINE_TYPE
)
1306 if(EmptyString(oper_reason
))
1308 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1309 "%s added K-Line for [%s@%s] [%s]",
1310 get_oper_name(source_p
), user
,
1312 ilog(L_KLINE
, "K %s 0 %s %s %s",
1313 get_oper_name(source_p
), user
, host
, reason
);
1317 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1318 "%s added K-Line for [%s@%s] [%s|%s]",
1319 get_oper_name(source_p
), user
,
1320 host
, reason
, oper_reason
);
1321 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1322 get_oper_name(source_p
), user
, host
,
1323 reason
, oper_reason
);
1326 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1329 else if(type
== DLINE_TYPE
)
1331 if(EmptyString(oper_reason
))
1333 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1334 "%s added D-Line for [%s] [%s]",
1335 get_oper_name(source_p
), host
, reason
);
1336 ilog(L_KLINE
, "D %s 0 %s %s",
1337 get_oper_name(source_p
), host
, reason
);
1341 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1342 "%s added D-Line for [%s] [%s|%s]",
1343 get_oper_name(source_p
), host
,
1344 reason
, oper_reason
);
1345 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1346 get_oper_name(source_p
), host
,
1347 reason
, oper_reason
);
1350 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1353 else if(type
== RESV_TYPE
)
1355 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1356 "%s added RESV for [%s] [%s]",
1357 get_oper_name(source_p
), host
, reason
);
1358 ilog(L_KLINE
, "R %s 0 %s %s",
1359 get_oper_name(source_p
), host
, reason
);
1361 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1365 if((out
= fopen(filename
, "a")) == NULL
)
1367 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1368 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1372 if(oper_reason
== NULL
)
1375 if(type
== KLINE_TYPE
)
1377 rb_snprintf(buffer
, sizeof(buffer
),
1378 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1379 user
, host
, reason
, oper_reason
, current_date
,
1380 get_oper_name(source_p
), rb_current_time());
1382 else if(type
== DLINE_TYPE
)
1384 rb_snprintf(buffer
, sizeof(buffer
),
1385 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1386 reason
, oper_reason
, current_date
, get_oper_name(source_p
), rb_current_time());
1388 else if(type
== RESV_TYPE
)
1390 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1391 host
, reason
, get_oper_name(source_p
), rb_current_time());
1394 if(fputs(buffer
, out
) == -1)
1396 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1397 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1404 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1405 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1412 * inputs - type of conf file to return name of file for
1413 * output - pointer to filename for type of conf
1414 * side effects - none
1417 get_conf_name(KlineType type
)
1419 if(type
== CONF_TYPE
)
1421 return (ConfigFileEntry
.configfile
);
1423 else if(type
== DLINE_TYPE
)
1425 return (ConfigFileEntry
.dlinefile
);
1427 else if(type
== RESV_TYPE
)
1429 return (ConfigFileEntry
.resvfile
);
1432 return ConfigFileEntry
.klinefile
;
1436 * conf_add_class_to_conf
1437 * inputs - pointer to config item
1439 * side effects - Add a class pointer to a conf
1443 conf_add_class_to_conf(struct ConfItem
*aconf
)
1445 if(aconf
->className
== NULL
)
1447 aconf
->className
= rb_strdup("default");
1448 ClassPtr(aconf
) = default_class
;
1452 ClassPtr(aconf
) = find_class(aconf
->className
);
1454 if(ClassPtr(aconf
) == default_class
)
1456 if(aconf
->status
== CONF_CLIENT
)
1458 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1459 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1460 aconf
->className
, aconf
->user
, aconf
->host
);
1463 rb_free(aconf
->className
);
1464 aconf
->className
= rb_strdup("default");
1468 if(ConfMaxUsers(aconf
) < 0)
1470 ClassPtr(aconf
) = default_class
;
1471 rb_free(aconf
->className
);
1472 aconf
->className
= rb_strdup("default");
1479 * inputs - pointer to config item
1481 * side effects - Add a d/D line
1484 conf_add_d_conf(struct ConfItem
*aconf
)
1486 if(aconf
->host
== NULL
)
1491 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1492 * need this anyway, so I will disable it for now... -A1kmm
1495 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1497 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1502 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1510 * inputs - message from parser
1512 * side effects - message to opers and log file entry is made
1515 yyerror(const char *msg
)
1517 char newlinebuf
[BUFSIZE
];
1519 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1521 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1522 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1524 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1528 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1532 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1535 return (strlen(lbuf
));
1539 conf_yy_fatal_error(const char *msg
)