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"
49 #include "privilege.h"
52 struct config_server_hide ConfigServerHide
;
54 extern int yyparse(void); /* defined in y.tab.c */
55 extern char linebuf
[];
58 #define INADDR_NONE ((unsigned int) 0xffffffff)
61 static rb_bh
*confitem_heap
= NULL
;
63 rb_dlink_list temp_klines
[LAST_TEMP_TYPE
];
64 rb_dlink_list temp_dlines
[LAST_TEMP_TYPE
];
65 rb_dlink_list service_list
;
67 /* internally defined functions */
68 static void set_default_conf(void);
69 static void validate_conf(void);
70 static void read_conf(FILE *);
71 static void clear_out_old_conf(void);
73 static void expire_temp_kd(void *list
);
74 static void reorganise_temp_kd(void *list
);
79 static int verify_access(struct Client
*client_p
, const char *username
);
80 static int attach_iline(struct Client
*, struct ConfItem
*);
85 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
, "confitem_heap");
87 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
88 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
90 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
91 &temp_klines
[TEMP_HOUR
], 3600);
92 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
93 &temp_dlines
[TEMP_HOUR
], 3600);
94 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
95 &temp_klines
[TEMP_DAY
], 86400);
96 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
97 &temp_dlines
[TEMP_DAY
], 86400);
98 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
99 &temp_klines
[TEMP_WEEK
], 604800);
100 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
101 &temp_dlines
[TEMP_WEEK
], 604800);
108 * output - pointer to new conf entry
109 * side effects - none
114 struct ConfItem
*aconf
;
116 aconf
= rb_bh_alloc(confitem_heap
);
117 aconf
->status
= CONF_ILLEGAL
;
124 * inputs - pointer to conf to free
126 * side effects - crucial password fields are zeroed, conf is freed
129 free_conf(struct ConfItem
*aconf
)
131 s_assert(aconf
!= NULL
);
137 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
139 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
141 rb_free(aconf
->passwd
);
142 rb_free(aconf
->spasswd
);
143 rb_free(aconf
->name
);
144 rb_free(aconf
->className
);
145 rb_free(aconf
->user
);
146 rb_free(aconf
->host
);
148 rb_bh_free(confitem_heap
, aconf
);
154 * inputs - pointer to client
155 * output - 0 = Success
156 * NOT_AUTHORISED (-1) = Access denied (no I line match)
157 * SOCKET_ERROR (-2) = Bad socket.
158 * I_LINE_FULL (-3) = I-line is full
159 * TOO_MANY (-4) = Too many connections from hostname
160 * BANNED_CLIENT (-5) = K-lined
161 * side effects - Ordinary client access check.
162 * Look for conf lines which have the same
163 * status as the flags passed.
166 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
170 if((i
= verify_access(source_p
, username
)))
172 ilog(L_FUSER
, "Access denied: %s[%s]",
173 source_p
->name
, source_p
->sockhost
);
179 exit_client(client_p
, source_p
, &me
, "Socket Error");
183 /* Note that these notices are sent to opers on other
184 * servers also, so even if local opers are allowed to
185 * see the IP, we still cannot send it.
187 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
188 "Too many local connections for %s!%s%s@%s",
189 source_p
->name
, IsGotId(source_p
) ? "" : "~",
191 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
193 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
194 source_p
->name
, IsGotId(source_p
) ? "" : "~",
195 source_p
->username
, source_p
->sockhost
);
197 ServerStats
.is_ref
++;
198 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
201 case TOO_MANY_GLOBAL
:
202 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
203 "Too many global connections for %s!%s%s@%s",
204 source_p
->name
, IsGotId(source_p
) ? "" : "~",
206 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
207 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
208 source_p
->name
, IsGotId(source_p
) ? "" : "~",
209 source_p
->username
, source_p
->sockhost
);
211 ServerStats
.is_ref
++;
212 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
216 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
217 "Too many user connections for %s!%s%s@%s",
218 source_p
->name
, IsGotId(source_p
) ? "" : "~",
220 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
221 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
222 source_p
->name
, IsGotId(source_p
) ? "" : "~",
223 source_p
->username
, source_p
->sockhost
);
225 ServerStats
.is_ref
++;
226 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
230 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
231 "I-line is full for %s!%s%s@%s (%s).",
232 source_p
->name
, IsGotId(source_p
) ? "" : "~",
233 source_p
->username
, source_p
->host
,
234 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
236 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
237 source_p
->name
, IsGotId(source_p
) ? "" : "~",
238 source_p
->username
, source_p
->sockhost
);
240 ServerStats
.is_ref
++;
241 exit_client(client_p
, source_p
, &me
,
242 "No more connections allowed in your connection class");
249 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
250 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
253 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
255 ServerStats
.is_ref
++;
256 /* jdc - lists server name & port connections are on */
257 /* a purely cosmetical change */
258 /* why ipaddr, and not just source_p->sockhost? --fl */
260 static char ipaddr
[HOSTIPLEN
];
261 rb_inet_ntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
263 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
264 "Unauthorised client connection from "
265 "%s!%s%s@%s [%s] on [%s/%u].",
266 source_p
->name
, IsGotId(source_p
) ? "" : "~",
267 source_p
->username
, source_p
->host
,
269 source_p
->localClient
->listener
->name
, port
);
272 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
273 source_p
->name
, IsGotId(source_p
) ? "" : "~",
274 source_p
->username
, source_p
->sockhost
,
275 source_p
->localClient
->listener
->name
, port
);
276 add_reject(client_p
, NULL
, NULL
);
277 exit_client(client_p
, source_p
, &me
,
278 "You are not authorised to use this server");
282 exit_client(client_p
, client_p
, &me
, "*** Banned ");
283 ServerStats
.is_ref
++;
296 * inputs - pointer to client to verify
297 * - pointer to proposed username
298 * output - 0 if success -'ve if not
299 * side effect - find the first (best) I line to attach.
302 verify_access(struct Client
*client_p
, const char *username
)
304 struct ConfItem
*aconf
;
305 char non_ident
[USERLEN
+ 1];
307 if(IsGotId(client_p
))
309 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
310 client_p
->username
, client_p
->username
,
311 (struct sockaddr
*) &client_p
->localClient
->ip
,
312 client_p
->localClient
->ip
.ss_family
,
313 client_p
->localClient
->auth_user
);
317 rb_strlcpy(non_ident
, "~", sizeof(non_ident
));
318 rb_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
,
323 client_p
->localClient
->auth_user
);
327 return NOT_AUTHORISED
;
329 if(aconf
->status
& CONF_CLIENT
)
331 if(aconf
->flags
& CONF_FLAGS_REDIR
)
333 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
334 aconf
->name
? aconf
->name
: "", aconf
->port
);
335 return (NOT_AUTHORISED
);
338 /* Thanks for spoof idea amm */
339 if(IsConfDoSpoofIp(aconf
))
343 /* show_ip() depends on this --fl */
344 SetIPSpoof(client_p
);
346 if(IsConfSpoofNotice(aconf
))
348 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
349 "%s spoofing: %s as %s",
351 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
355 /* user@host spoof */
356 if((p
= strchr(aconf
->name
, '@')) != NULL
)
361 rb_strlcpy(client_p
->username
, aconf
->name
,
362 sizeof(client_p
->username
));
363 rb_strlcpy(client_p
->host
, host
,
364 sizeof(client_p
->host
));
368 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
370 return (attach_iline(client_p
, aconf
));
372 else if(aconf
->status
& CONF_KILL
)
374 if(ConfigFileEntry
.kline_with_reason
)
377 form_str(ERR_YOUREBANNEDCREEP
),
378 me
.name
, client_p
->name
, aconf
->passwd
);
380 add_reject(client_p
, aconf
->user
, aconf
->host
);
381 return (BANNED_CLIENT
);
384 return NOT_AUTHORISED
;
391 * Returns 1 if successful 0 if not
393 * This checks if the user has exceed the limits for their class
394 * unless of course they are exempt..
398 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
400 rb_patricia_node_t
*pnode
;
403 /* If the limits are 0 don't do anything.. */
404 if(ConfCidrAmount(aconf
) == 0
405 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
408 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
410 if(GET_SS_FAMILY(&client_p
->localClient
->ip
) == AF_INET
)
411 bitlen
= ConfCidrIpv4Bitlen(aconf
);
413 bitlen
= ConfCidrIpv6Bitlen(aconf
);
416 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, bitlen
);
418 s_assert(pnode
!= NULL
);
422 if(((intptr_t)pnode
->data
) >= ConfCidrAmount(aconf
) && !IsConfExemptLimits(aconf
))
424 /* This should only happen if the limits are set to 0 */
425 if((intptr_t)pnode
->data
== 0)
427 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
432 pnode
->data
= (void *)(((intptr_t)pnode
->data
) + 1);
438 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
440 rb_patricia_node_t
*pnode
;
442 /* If the limits are 0 don't do anything.. */
443 if(ConfCidrAmount(aconf
) == 0
444 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
447 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
451 pnode
->data
= (void *)(((intptr_t)pnode
->data
) - 1);
452 if(((intptr_t)pnode
->data
) == 0)
454 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
462 * inputs - client pointer
465 * side effects - do actual attach
468 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
470 struct Client
*target_p
;
473 int global_count
= 0;
477 if(IsConfExemptLimits(aconf
))
478 return (attach_conf(client_p
, aconf
));
480 if(*client_p
->username
== '~')
484 /* find_hostname() returns the head of the list to search */
485 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
487 target_p
= ptr
->data
;
489 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
492 if(MyConnect(target_p
))
499 if(*target_p
->username
== '~')
502 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
505 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
506 return (TOO_MANY_LOCAL
);
507 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
508 return (TOO_MANY_GLOBAL
);
509 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
510 return (TOO_MANY_IDENT
);
514 return (attach_conf(client_p
, aconf
));
520 * inputs - pointer to client to detach
521 * output - 0 for success, -1 for failure
522 * side effects - Disassociate configuration from the client.
523 * Also removes a class from the list if marked for deleting.
526 detach_conf(struct Client
*client_p
)
528 struct ConfItem
*aconf
;
530 aconf
= client_p
->localClient
->att_conf
;
536 remove_ip_limit(client_p
, aconf
);
538 if(ConfCurrUsers(aconf
) > 0)
539 --ConfCurrUsers(aconf
);
541 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
543 free_class(ClassPtr(aconf
));
544 ClassPtr(aconf
) = NULL
;
550 if(!aconf
->clients
&& IsIllegal(aconf
))
553 client_p
->localClient
->att_conf
= NULL
;
563 * inputs - client pointer
566 * side effects - Associate a specific configuration entry to a *local*
567 * client (this is the one which used in accepting the
568 * connection). Note, that this automatically changes the
569 * attachment if there was an old one...
572 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
575 return (NOT_AUTHORISED
);
579 if(!add_ip_limit(client_p
, aconf
))
580 return (TOO_MANY_LOCAL
);
583 if((aconf
->status
& CONF_CLIENT
) &&
584 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
586 if(!IsConfExemptLimits(aconf
))
588 return (I_LINE_FULL
);
592 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
597 if(client_p
->localClient
->att_conf
!= NULL
)
598 detach_conf(client_p
);
600 client_p
->localClient
->att_conf
= aconf
;
603 ConfCurrUsers(aconf
)++;
610 * Actual REHASH service routine. Called with sig == 0 if it has been called
611 * as a result of an operator issuing this command, else assume it has been
612 * called as a result of the server receiving a HUP signal.
619 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
620 "Got signal SIGHUP, reloading ircd conf. file");
624 /* don't close listeners until we know we can go ahead with the rehash */
627 if(ServerInfo
.description
!= NULL
)
628 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
630 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
636 static struct banconf_entry
638 const char **filename
;
639 void (*func
) (FILE *);
642 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
643 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
644 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
645 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
646 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
647 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
648 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
649 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
657 char buf
[MAXPATHLEN
];
661 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
662 "Got signal SIGUSR2, reloading ban confs");
664 clear_out_address_conf_bans();
665 clear_s_newconf_bans();
667 for(i
= 0; banconfs
[i
].filename
; i
++)
670 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
672 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
674 if((file
= fopen(buf
, "r")) == NULL
)
679 ilog(L_MAIN
, "Failed reading ban file %s",
680 *banconfs
[i
].filename
);
681 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
682 "Can't open %s file bans could be missing!",
683 *banconfs
[i
].filename
);
687 (banconfs
[i
].func
)(file
);
692 check_banned_lines();
700 * side effects - Set default values here.
701 * This is called **PRIOR** to parsing the
702 * configuration file. If you want to do some validation
703 * of values later, put them in validate_conf().
711 set_default_conf(void)
713 /* ServerInfo.name is not rehashable */
714 /* ServerInfo.name = ServerInfo.name; */
715 ServerInfo
.description
= NULL
;
716 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
717 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
719 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
720 ServerInfo
.specific_ipv4_vhost
= 0;
722 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
723 ServerInfo
.specific_ipv6_vhost
= 0;
726 /* Don't reset hub, as that will break lazylinks */
727 /* ServerInfo.hub = NO; */
728 AdminInfo
.name
= NULL
;
729 AdminInfo
.email
= NULL
;
730 AdminInfo
.description
= NULL
;
732 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
733 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
734 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
736 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
737 ConfigFileEntry
.failed_oper_notice
= YES
;
738 ConfigFileEntry
.anti_nick_flood
= NO
;
739 ConfigFileEntry
.disable_fake_channels
= NO
;
740 ConfigFileEntry
.max_nick_time
= 20;
741 ConfigFileEntry
.max_nick_changes
= 5;
742 ConfigFileEntry
.max_accept
= 20;
743 ConfigFileEntry
.max_monitor
= 60;
744 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
745 ConfigFileEntry
.target_change
= YES
;
746 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
747 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
748 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
749 ConfigFileEntry
.client_exit
= YES
;
750 ConfigFileEntry
.dline_with_reason
= YES
;
751 ConfigFileEntry
.kline_with_reason
= YES
;
752 ConfigFileEntry
.kline_delay
= 0;
753 ConfigFileEntry
.warn_no_nline
= YES
;
754 ConfigFileEntry
.non_redundant_klines
= YES
;
755 ConfigFileEntry
.stats_e_disabled
= NO
;
756 ConfigFileEntry
.stats_o_oper_only
= NO
;
757 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
758 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
759 ConfigFileEntry
.stats_P_oper_only
= NO
;
760 ConfigFileEntry
.stats_c_oper_only
= NO
;
761 ConfigFileEntry
.stats_y_oper_only
= NO
;
762 ConfigFileEntry
.stats_h_oper_only
= NO
;
763 ConfigFileEntry
.map_oper_only
= YES
;
764 ConfigFileEntry
.operspy_admin_only
= NO
;
765 ConfigFileEntry
.pace_wait
= 10;
766 ConfigFileEntry
.caller_id_wait
= 60;
767 ConfigFileEntry
.pace_wait_simple
= 1;
768 ConfigFileEntry
.short_motd
= NO
;
769 ConfigFileEntry
.no_oper_flood
= NO
;
770 ConfigFileEntry
.fname_userlog
= NULL
;
771 ConfigFileEntry
.fname_fuserlog
= NULL
;
772 ConfigFileEntry
.fname_operlog
= NULL
;
773 ConfigFileEntry
.fname_foperlog
= NULL
;
774 ConfigFileEntry
.fname_serverlog
= NULL
;
775 ConfigFileEntry
.fname_klinelog
= NULL
;
776 ConfigFileEntry
.fname_operspylog
= NULL
;
777 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
778 ConfigFileEntry
.use_egd
= NO
;
779 ConfigFileEntry
.hide_spoof_ips
= YES
;
780 ConfigFileEntry
.hide_error_messages
= 1;
781 ConfigFileEntry
.dots_in_ident
= 0;
782 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
783 ConfigFileEntry
.egdpool_path
= NULL
;
784 ConfigFileEntry
.use_whois_actually
= YES
;
785 ConfigFileEntry
.burst_away
= NO
;
786 ConfigFileEntry
.collision_fnc
= YES
;
787 ConfigFileEntry
.global_snotices
= YES
;
788 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
791 ConfigFileEntry
.compression_level
= 4;
794 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
795 UMODE_OPERWALL
| UMODE_WALLOP
;
796 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
797 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
799 ConfigChannel
.use_except
= YES
;
800 ConfigChannel
.use_invex
= YES
;
801 ConfigChannel
.use_knock
= YES
;
802 ConfigChannel
.use_forward
= YES
;
803 ConfigChannel
.knock_delay
= 300;
804 ConfigChannel
.knock_delay_channel
= 60;
805 ConfigChannel
.max_chans_per_user
= 15;
806 ConfigChannel
.max_bans
= 25;
807 ConfigChannel
.max_bans_large
= 500;
808 ConfigChannel
.burst_topicwho
= NO
;
809 ConfigChannel
.kick_on_split_riding
= NO
;
811 ConfigChannel
.default_split_user_count
= 15000;
812 ConfigChannel
.default_split_server_count
= 10;
813 ConfigChannel
.no_join_on_split
= NO
;
814 ConfigChannel
.no_create_on_split
= YES
;
816 ConfigServerHide
.flatten_links
= 0;
817 ConfigServerHide
.links_delay
= 300;
818 ConfigServerHide
.hidden
= 0;
819 ConfigServerHide
.disable_hidden
= 0;
821 ConfigFileEntry
.min_nonwildcard
= 4;
822 ConfigFileEntry
.min_nonwildcard_simple
= 3;
823 ConfigFileEntry
.default_floodcount
= 8;
824 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
825 ConfigFileEntry
.tkline_expire_notices
= 0;
827 ConfigFileEntry
.reject_after_count
= 5;
828 ConfigFileEntry
.reject_ban_time
= 300;
829 ConfigFileEntry
.reject_duration
= 120;
830 ConfigFileEntry
.throttle_count
= 4;
831 ConfigFileEntry
.throttle_duration
= 60;
833 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
843 * inputs - file descriptor pointing to config file to use
845 * side effects - Read configuration file.
848 read_conf(FILE * file
)
852 set_default_conf(); /* Set default values prior to conf parsing */
853 yyparse(); /* Load the values from the conf */
854 validate_conf(); /* Check to make sure some values are still okay. */
855 /* Some global values are also loaded here. */
856 check_class(); /* Make sure classes are valid */
857 privilegeset_delete_all_illegal();
863 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
864 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
866 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
867 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
869 if(ServerInfo
.network_name
== NULL
)
870 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
872 if(ServerInfo
.network_desc
== NULL
)
873 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
875 if(ServerInfo
.ssld_count
< 1)
876 ServerInfo
.ssld_count
= 1;
878 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
880 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
884 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
887 if(ServerInfo
.ssld_count
> get_ssld_count())
889 int start
= ServerInfo
.ssld_count
- get_ssld_count();
890 /* start up additional ssld if needed */
891 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
895 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
896 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
897 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
899 if(!split_users
|| !split_servers
||
900 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
902 rb_event_delete(check_splitmode_ev
);
903 check_splitmode_ev
= NULL
;
911 * inputs - pointer to struct ConfItem
913 * Side effects - links in given struct ConfItem into
914 * temporary kline link list
917 add_temp_kline(struct ConfItem
*aconf
)
919 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
921 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
922 aconf
->port
= TEMP_WEEK
;
924 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
926 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
927 aconf
->port
= TEMP_DAY
;
929 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
931 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
932 aconf
->port
= TEMP_HOUR
;
936 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
937 aconf
->port
= TEMP_MIN
;
940 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
941 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
946 * input - pointer to struct ConfItem
948 * side effects - added to tdline link list and address hash
951 add_temp_dline(struct ConfItem
*aconf
)
953 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
955 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
956 aconf
->port
= TEMP_WEEK
;
958 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
960 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
961 aconf
->port
= TEMP_DAY
;
963 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
965 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
966 aconf
->port
= TEMP_HOUR
;
970 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
971 aconf
->port
= TEMP_MIN
;
974 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
975 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, NULL
, aconf
);
980 * inputs - list pointer
983 * side effects - expire tklines and moves them between lists
986 expire_temp_kd(void *list
)
989 rb_dlink_node
*next_ptr
;
990 struct ConfItem
*aconf
;
992 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
996 if(aconf
->hold
<= rb_current_time())
998 /* Alert opers that a TKline expired - Hwy */
999 if(ConfigFileEntry
.tkline_expire_notices
)
1000 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1001 "Temporary K-line for [%s@%s] expired",
1002 (aconf
->user
) ? aconf
->
1003 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1005 delete_one_address_conf(aconf
->host
, aconf
);
1006 rb_dlinkDestroy(ptr
, list
);
1012 reorganise_temp_kd(void *list
)
1014 struct ConfItem
*aconf
;
1015 rb_dlink_node
*ptr
, *next_ptr
;
1017 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1021 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1023 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1024 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1025 aconf
->port
= TEMP_MIN
;
1027 else if(aconf
->port
> TEMP_HOUR
)
1029 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1031 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1032 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1033 aconf
->port
= TEMP_HOUR
;
1035 else if(aconf
->port
> TEMP_DAY
&&
1036 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1038 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1039 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1040 aconf
->port
= TEMP_DAY
;
1047 /* const char* get_oper_name(struct Client *client_p)
1048 * Input: A client to find the active oper{} name for.
1049 * Output: The nick!user@host{oper} of the oper.
1050 * "oper" is server name for remote opers
1051 * Side effects: None.
1054 get_oper_name(struct Client
*client_p
)
1056 /* +5 for !,@,{,} and null */
1057 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1059 if(MyOper(client_p
))
1061 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1062 client_p
->name
, client_p
->username
,
1063 client_p
->host
, client_p
->localClient
->opername
);
1067 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1068 client_p
->name
, client_p
->username
,
1069 client_p
->host
, client_p
->servptr
->name
);
1074 * get_printable_conf
1076 * inputs - struct ConfItem
1085 * Examine the struct struct ConfItem, setting the values
1086 * of name, host, pass, user to values either
1087 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1090 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1091 char **pass
, char **user
, int *port
, char **classname
)
1093 static char null
[] = "<NULL>";
1094 static char zero
[] = "default";
1096 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1097 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1098 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1099 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1100 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1101 *port
= (int) aconf
->port
;
1105 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1106 char **host
, char **reason
,
1107 char **user
, char **oper_reason
)
1109 static char null
[] = "<NULL>";
1111 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1112 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1113 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1115 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1116 *oper_reason
= NULL
;
1118 *oper_reason
= aconf
->spasswd
;
1124 * inputs - cold start YES or NO
1126 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1129 read_conf_files(int cold
)
1131 const char *filename
;
1133 conf_fbfile_in
= NULL
;
1135 filename
= get_conf_name(CONF_TYPE
);
1137 /* We need to know the initial filename for the yyerror() to report
1138 FIXME: The full path is in conffilenamebuf first time since we
1139 dont know anything else
1143 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1145 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1149 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1154 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1155 "Can't open file '%s' - aborting rehash!", filename
);
1162 clear_out_old_conf();
1165 read_conf(conf_fbfile_in
);
1166 fclose(conf_fbfile_in
);
1170 * free an alias{} entry.
1173 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1175 struct alias_entry
*aptr
= ptr
->data
;
1177 rb_free(aptr
->name
);
1178 rb_free(aptr
->target
);
1183 * clear_out_old_conf
1187 * side effects - Clear out the old configuration
1190 clear_out_old_conf(void)
1192 struct Class
*cltmp
;
1194 rb_dlink_node
*next_ptr
;
1197 * don't delete the class table, rather mark all entries
1198 * for deletion. The table is cleaned up by check_class. - avalon
1200 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1203 MaxUsers(cltmp
) = -1;
1206 clear_out_address_conf();
1209 /* clean out module paths */
1210 #ifndef STATIC_MODULES
1212 mod_add_path(MODULE_DIR
);
1213 mod_add_path(MODULE_DIR
"/autoload");
1216 /* clean out ServerInfo */
1217 rb_free(ServerInfo
.description
);
1218 ServerInfo
.description
= NULL
;
1219 rb_free(ServerInfo
.network_name
);
1220 ServerInfo
.network_name
= NULL
;
1221 rb_free(ServerInfo
.network_desc
);
1222 ServerInfo
.network_desc
= NULL
;
1224 ServerInfo
.ssld_count
= 1;
1226 /* clean out AdminInfo */
1227 rb_free(AdminInfo
.name
);
1228 AdminInfo
.name
= NULL
;
1229 rb_free(AdminInfo
.email
);
1230 AdminInfo
.email
= NULL
;
1231 rb_free(AdminInfo
.description
);
1232 AdminInfo
.description
= NULL
;
1234 /* operator{} and class{} blocks are freed above */
1235 /* clean out listeners */
1238 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1239 * and gecos{} blocks are freed above too
1242 /* clean out general */
1243 rb_free(ConfigFileEntry
.kline_reason
);
1244 ConfigFileEntry
.kline_reason
= NULL
;
1246 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1249 rb_dlinkDestroy(ptr
, &service_list
);
1252 /* remove any aliases... -- nenolod */
1253 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1256 destroy_blacklists();
1258 privilegeset_mark_all_illegal();
1260 /* OK, that should be everything... */
1266 * inputs - kline, dline or resv type flag
1267 * - client pointer to report to
1268 * - user name of target
1269 * - host name of target
1270 * - reason for target
1274 * side effects - This function takes care of finding the right conf
1275 * file and adding the line to it, as well as notifying
1276 * opers and the user.
1279 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1280 char *host
, const char *reason
, const char *oper_reason
,
1281 const char *current_date
, int xtype
)
1285 const char *filename
; /* filename to use for kline */
1287 filename
= get_conf_name(type
);
1289 if(type
== KLINE_TYPE
)
1291 if(EmptyString(oper_reason
))
1293 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1294 "%s added K-Line for [%s@%s] [%s]",
1295 get_oper_name(source_p
), user
,
1297 ilog(L_KLINE
, "K %s 0 %s %s %s",
1298 get_oper_name(source_p
), user
, host
, reason
);
1302 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1303 "%s added K-Line for [%s@%s] [%s|%s]",
1304 get_oper_name(source_p
), user
,
1305 host
, reason
, oper_reason
);
1306 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1307 get_oper_name(source_p
), user
, host
,
1308 reason
, oper_reason
);
1311 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1314 else if(type
== DLINE_TYPE
)
1316 if(EmptyString(oper_reason
))
1318 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1319 "%s added D-Line for [%s] [%s]",
1320 get_oper_name(source_p
), host
, reason
);
1321 ilog(L_KLINE
, "D %s 0 %s %s",
1322 get_oper_name(source_p
), host
, reason
);
1326 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1327 "%s added D-Line for [%s] [%s|%s]",
1328 get_oper_name(source_p
), host
,
1329 reason
, oper_reason
);
1330 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1331 get_oper_name(source_p
), host
,
1332 reason
, oper_reason
);
1335 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1338 else if(type
== RESV_TYPE
)
1340 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1341 "%s added RESV for [%s] [%s]",
1342 get_oper_name(source_p
), host
, reason
);
1343 ilog(L_KLINE
, "R %s 0 %s %s",
1344 get_oper_name(source_p
), host
, reason
);
1346 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1350 if((out
= fopen(filename
, "a")) == NULL
)
1352 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1353 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1357 if(oper_reason
== NULL
)
1360 if(type
== KLINE_TYPE
)
1362 rb_snprintf(buffer
, sizeof(buffer
),
1363 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1364 user
, host
, reason
, oper_reason
, current_date
,
1365 get_oper_name(source_p
), (long int)rb_current_time());
1367 else if(type
== DLINE_TYPE
)
1369 rb_snprintf(buffer
, sizeof(buffer
),
1370 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1371 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1373 else if(type
== RESV_TYPE
)
1375 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1376 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1379 if(fputs(buffer
, out
) == -1)
1381 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1382 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1389 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1390 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1397 * inputs - type of conf file to return name of file for
1398 * output - pointer to filename for type of conf
1399 * side effects - none
1402 get_conf_name(KlineType type
)
1404 if(type
== CONF_TYPE
)
1406 return (ConfigFileEntry
.configfile
);
1408 else if(type
== DLINE_TYPE
)
1410 return (ConfigFileEntry
.dlinefile
);
1412 else if(type
== RESV_TYPE
)
1414 return (ConfigFileEntry
.resvfile
);
1417 return ConfigFileEntry
.klinefile
;
1421 * conf_add_class_to_conf
1422 * inputs - pointer to config item
1424 * side effects - Add a class pointer to a conf
1428 conf_add_class_to_conf(struct ConfItem
*aconf
)
1430 if(aconf
->className
== NULL
)
1432 aconf
->className
= rb_strdup("default");
1433 ClassPtr(aconf
) = default_class
;
1437 ClassPtr(aconf
) = find_class(aconf
->className
);
1439 if(ClassPtr(aconf
) == default_class
)
1441 if(aconf
->status
== CONF_CLIENT
)
1443 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1444 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1445 aconf
->className
, aconf
->user
, aconf
->host
);
1448 rb_free(aconf
->className
);
1449 aconf
->className
= rb_strdup("default");
1453 if(ConfMaxUsers(aconf
) < 0)
1455 ClassPtr(aconf
) = default_class
;
1456 rb_free(aconf
->className
);
1457 aconf
->className
= rb_strdup("default");
1464 * inputs - pointer to config item
1466 * side effects - Add a d/D line
1469 conf_add_d_conf(struct ConfItem
*aconf
)
1471 if(aconf
->host
== NULL
)
1476 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1477 * need this anyway, so I will disable it for now... -A1kmm
1480 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1482 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1487 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
1492 strip_tabs(char *dest
, const char *src
, size_t len
)
1496 if(dest
== NULL
|| src
== NULL
)
1499 rb_strlcpy(dest
, src
, len
);
1513 * inputs - message from parser
1515 * side effects - message to opers and log file entry is made
1518 yyerror(const char *msg
)
1520 char newlinebuf
[BUFSIZE
];
1522 strip_tabs(newlinebuf
, linebuf
, strlen(linebuf
));
1524 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1525 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1527 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1531 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1535 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1538 return (strlen(lbuf
));
1542 conf_yy_fatal_error(const char *msg
)