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"
49 #include "blacklist.h"
50 #include "privilege.h"
53 struct config_server_hide ConfigServerHide
;
55 extern int yyparse(void); /* 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
);
79 struct Client
*remote_rehash_oper_p
;
81 static int verify_access(struct Client
*client_p
, const char *username
);
82 static int attach_iline(struct Client
*, struct ConfItem
*);
87 confitem_heap
= rb_bh_create(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
, "confitem_heap");
89 rb_event_addish("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
90 rb_event_addish("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
92 rb_event_addish("expire_temp_klines_hour", reorganise_temp_kd
,
93 &temp_klines
[TEMP_HOUR
], 3600);
94 rb_event_addish("expire_temp_dlines_hour", reorganise_temp_kd
,
95 &temp_dlines
[TEMP_HOUR
], 3600);
96 rb_event_addish("expire_temp_klines_day", reorganise_temp_kd
,
97 &temp_klines
[TEMP_DAY
], 86400);
98 rb_event_addish("expire_temp_dlines_day", reorganise_temp_kd
,
99 &temp_dlines
[TEMP_DAY
], 86400);
100 rb_event_addish("expire_temp_klines_week", reorganise_temp_kd
,
101 &temp_klines
[TEMP_WEEK
], 604800);
102 rb_event_addish("expire_temp_dlines_week", reorganise_temp_kd
,
103 &temp_dlines
[TEMP_WEEK
], 604800);
110 * output - pointer to new conf entry
111 * side effects - none
116 struct ConfItem
*aconf
;
118 aconf
= rb_bh_alloc(confitem_heap
);
119 aconf
->status
= CONF_ILLEGAL
;
126 * inputs - pointer to conf to free
128 * side effects - crucial password fields are zeroed, conf is freed
131 free_conf(struct ConfItem
*aconf
)
133 s_assert(aconf
!= NULL
);
139 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
141 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
143 rb_free(aconf
->passwd
);
144 rb_free(aconf
->spasswd
);
145 rb_free(aconf
->name
);
146 rb_free(aconf
->className
);
147 rb_free(aconf
->user
);
148 rb_free(aconf
->host
);
150 rb_bh_free(confitem_heap
, aconf
);
156 * inputs - pointer to client
157 * output - 0 = Success
158 * NOT_AUTHORISED (-1) = Access denied (no I line match)
159 * SOCKET_ERROR (-2) = Bad socket.
160 * I_LINE_FULL (-3) = I-line is full
161 * TOO_MANY (-4) = Too many connections from hostname
162 * BANNED_CLIENT (-5) = K-lined
163 * side effects - Ordinary client access check.
164 * Look for conf lines which have the same
165 * status as the flags passed.
168 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
172 if((i
= verify_access(source_p
, username
)))
174 ilog(L_FUSER
, "Access denied: %s[%s]",
175 source_p
->name
, source_p
->sockhost
);
181 exit_client(client_p
, source_p
, &me
, "Socket Error");
185 /* Note that these notices are sent to opers on other
186 * servers also, so even if local opers are allowed to
187 * see the IP, we still cannot send it.
189 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
190 "Too many local connections for %s!%s%s@%s",
191 source_p
->name
, IsGotId(source_p
) ? "" : "~",
193 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
195 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
196 source_p
->name
, IsGotId(source_p
) ? "" : "~",
197 source_p
->username
, source_p
->sockhost
);
199 ServerStats
.is_ref
++;
200 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
203 case TOO_MANY_GLOBAL
:
204 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
205 "Too many global connections for %s!%s%s@%s",
206 source_p
->name
, IsGotId(source_p
) ? "" : "~",
208 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
209 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
210 source_p
->name
, IsGotId(source_p
) ? "" : "~",
211 source_p
->username
, source_p
->sockhost
);
213 ServerStats
.is_ref
++;
214 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
218 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
219 "Too many user connections for %s!%s%s@%s",
220 source_p
->name
, IsGotId(source_p
) ? "" : "~",
222 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
223 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
224 source_p
->name
, IsGotId(source_p
) ? "" : "~",
225 source_p
->username
, source_p
->sockhost
);
227 ServerStats
.is_ref
++;
228 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
232 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
233 "I-line is full for %s!%s%s@%s (%s).",
234 source_p
->name
, IsGotId(source_p
) ? "" : "~",
235 source_p
->username
, source_p
->host
,
236 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
238 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
239 source_p
->name
, IsGotId(source_p
) ? "" : "~",
240 source_p
->username
, source_p
->sockhost
);
242 ServerStats
.is_ref
++;
243 exit_client(client_p
, source_p
, &me
,
244 "No more connections allowed in your connection class");
251 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
252 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
255 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
257 ServerStats
.is_ref
++;
258 /* jdc - lists server name & port connections are on */
259 /* a purely cosmetical change */
260 /* why ipaddr, and not just source_p->sockhost? --fl */
262 static char ipaddr
[HOSTIPLEN
];
263 rb_inet_ntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
265 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
266 "Unauthorised client connection from "
267 "%s!%s%s@%s [%s] on [%s/%u].",
268 source_p
->name
, IsGotId(source_p
) ? "" : "~",
269 source_p
->username
, source_p
->host
,
271 source_p
->localClient
->listener
->name
, port
);
274 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
275 source_p
->name
, IsGotId(source_p
) ? "" : "~",
276 source_p
->username
, source_p
->sockhost
,
277 source_p
->localClient
->listener
->name
, port
);
278 add_reject(client_p
, NULL
, NULL
);
279 exit_client(client_p
, source_p
, &me
,
280 "You are not authorised to use this server");
284 exit_client(client_p
, client_p
, &me
, "*** Banned ");
285 ServerStats
.is_ref
++;
298 * inputs - pointer to client to verify
299 * - pointer to proposed username
300 * output - 0 if success -'ve if not
301 * side effect - find the first (best) I line to attach.
304 verify_access(struct Client
*client_p
, const char *username
)
306 struct ConfItem
*aconf
;
307 char non_ident
[USERLEN
+ 1];
309 if(IsGotId(client_p
))
311 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
312 client_p
->username
, client_p
->username
,
313 (struct sockaddr
*) &client_p
->localClient
->ip
,
314 client_p
->localClient
->ip
.ss_family
,
315 client_p
->localClient
->auth_user
);
319 rb_strlcpy(non_ident
, "~", sizeof(non_ident
));
320 rb_strlcat(non_ident
, username
, sizeof(non_ident
));
321 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
322 non_ident
, client_p
->username
,
323 (struct sockaddr
*) &client_p
->localClient
->ip
,
324 client_p
->localClient
->ip
.ss_family
,
325 client_p
->localClient
->auth_user
);
329 return NOT_AUTHORISED
;
331 if(aconf
->status
& CONF_CLIENT
)
333 if(aconf
->flags
& CONF_FLAGS_REDIR
)
335 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
336 aconf
->name
? aconf
->name
: "", aconf
->port
);
337 return (NOT_AUTHORISED
);
340 /* Thanks for spoof idea amm */
341 if(IsConfDoSpoofIp(aconf
))
345 /* show_ip() depends on this --fl */
346 SetIPSpoof(client_p
);
348 if(IsConfSpoofNotice(aconf
))
350 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
351 "%s spoofing: %s as %s",
353 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
357 /* user@host spoof */
358 if((p
= strchr(aconf
->name
, '@')) != NULL
)
363 rb_strlcpy(client_p
->username
, aconf
->name
,
364 sizeof(client_p
->username
));
365 rb_strlcpy(client_p
->host
, host
,
366 sizeof(client_p
->host
));
370 rb_strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
372 return (attach_iline(client_p
, aconf
));
374 else if(aconf
->status
& CONF_KILL
)
376 if(ConfigFileEntry
.kline_with_reason
)
379 form_str(ERR_YOUREBANNEDCREEP
),
380 me
.name
, client_p
->name
, aconf
->passwd
);
382 add_reject(client_p
, aconf
->user
, aconf
->host
);
383 return (BANNED_CLIENT
);
386 return NOT_AUTHORISED
;
393 * Returns 1 if successful 0 if not
395 * This checks if the user has exceed the limits for their class
396 * unless of course they are exempt..
400 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
402 rb_patricia_node_t
*pnode
;
405 /* If the limits are 0 don't do anything.. */
406 if(ConfCidrAmount(aconf
) == 0
407 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
410 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
412 if(GET_SS_FAMILY(&client_p
->localClient
->ip
) == AF_INET
)
413 bitlen
= ConfCidrIpv4Bitlen(aconf
);
415 bitlen
= ConfCidrIpv6Bitlen(aconf
);
418 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, bitlen
);
420 s_assert(pnode
!= NULL
);
424 if(((intptr_t)pnode
->data
) >= ConfCidrAmount(aconf
) && !IsConfExemptLimits(aconf
))
426 /* This should only happen if the limits are set to 0 */
427 if((intptr_t)pnode
->data
== 0)
429 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
434 pnode
->data
= (void *)(((intptr_t)pnode
->data
) + 1);
440 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
442 rb_patricia_node_t
*pnode
;
444 /* If the limits are 0 don't do anything.. */
445 if(ConfCidrAmount(aconf
) == 0
446 || (ConfCidrIpv4Bitlen(aconf
) == 0 && ConfCidrIpv6Bitlen(aconf
) == 0))
449 pnode
= rb_match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
453 pnode
->data
= (void *)(((intptr_t)pnode
->data
) - 1);
454 if(((intptr_t)pnode
->data
) == 0)
456 rb_patricia_remove(ConfIpLimits(aconf
), pnode
);
464 * inputs - client pointer
467 * side effects - do actual attach
470 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
472 struct Client
*target_p
;
475 int global_count
= 0;
479 if(IsConfExemptLimits(aconf
))
480 return (attach_conf(client_p
, aconf
));
482 if(*client_p
->username
== '~')
486 /* find_hostname() returns the head of the list to search */
487 RB_DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
489 target_p
= ptr
->data
;
491 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
494 if(MyConnect(target_p
))
501 if(*target_p
->username
== '~')
504 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
507 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
508 return (TOO_MANY_LOCAL
);
509 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
510 return (TOO_MANY_GLOBAL
);
511 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
512 return (TOO_MANY_IDENT
);
516 return (attach_conf(client_p
, aconf
));
522 * inputs - pointer to client to detach
523 * output - 0 for success, -1 for failure
524 * side effects - Disassociate configuration from the client.
525 * Also removes a class from the list if marked for deleting.
528 detach_conf(struct Client
*client_p
)
530 struct ConfItem
*aconf
;
532 aconf
= client_p
->localClient
->att_conf
;
538 remove_ip_limit(client_p
, aconf
);
540 if(ConfCurrUsers(aconf
) > 0)
541 --ConfCurrUsers(aconf
);
543 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
545 free_class(ClassPtr(aconf
));
546 ClassPtr(aconf
) = NULL
;
552 if(!aconf
->clients
&& IsIllegal(aconf
))
555 client_p
->localClient
->att_conf
= NULL
;
565 * inputs - client pointer
568 * side effects - Associate a specific configuration entry to a *local*
569 * client (this is the one which used in accepting the
570 * connection). Note, that this automatically changes the
571 * attachment if there was an old one...
574 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
577 return (NOT_AUTHORISED
);
581 if(!add_ip_limit(client_p
, aconf
))
582 return (TOO_MANY_LOCAL
);
585 if((aconf
->status
& CONF_CLIENT
) &&
586 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
588 if(!IsConfExemptLimits(aconf
))
590 return (I_LINE_FULL
);
594 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
599 if(client_p
->localClient
->att_conf
!= NULL
)
600 detach_conf(client_p
);
602 client_p
->localClient
->att_conf
= aconf
;
605 ConfCurrUsers(aconf
)++;
612 * Actual REHASH service routine. Called with sig == 0 if it has been called
613 * as a result of an operator issuing this command, else assume it has been
614 * called as a result of the server receiving a HUP signal.
621 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
622 "Got signal SIGHUP, reloading ircd conf. file");
626 /* don't close listeners until we know we can go ahead with the rehash */
629 if(ServerInfo
.description
!= NULL
)
630 rb_strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
632 rb_strlcpy(me
.info
, "unknown", sizeof(me
.info
));
638 static struct banconf_entry
640 const char **filename
;
641 void (*func
) (FILE *);
644 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
645 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
646 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
647 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
648 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
649 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
650 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
651 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
659 char buf
[MAXPATHLEN
];
663 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
664 "Got signal SIGUSR2, reloading ban confs");
666 clear_out_address_conf_bans();
667 clear_s_newconf_bans();
669 for(i
= 0; banconfs
[i
].filename
; i
++)
672 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
674 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
676 if((file
= fopen(buf
, "r")) == NULL
)
681 ilog(L_MAIN
, "Failed reading ban file %s",
682 *banconfs
[i
].filename
);
683 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
684 "Can't open %s file bans could be missing!",
685 *banconfs
[i
].filename
);
686 if (remote_rehash_oper_p
)
687 sendto_one_notice(remote_rehash_oper_p
,
688 ":*** Notice -- Can't open %s file bans could be missing!",
689 *banconfs
[i
].filename
);
693 (banconfs
[i
].func
)(file
);
698 check_banned_lines();
706 * side effects - Set default values here.
707 * This is called **PRIOR** to parsing the
708 * configuration file. If you want to do some validation
709 * of values later, put them in validate_conf().
717 set_default_conf(void)
719 /* ServerInfo.name is not rehashable */
720 /* ServerInfo.name = ServerInfo.name; */
721 ServerInfo
.description
= NULL
;
722 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
723 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
725 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
726 ServerInfo
.specific_ipv4_vhost
= 0;
728 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
729 ServerInfo
.specific_ipv6_vhost
= 0;
732 /* Don't reset hub, as that will break lazylinks */
733 /* ServerInfo.hub = NO; */
734 AdminInfo
.name
= NULL
;
735 AdminInfo
.email
= NULL
;
736 AdminInfo
.description
= NULL
;
738 ConfigFileEntry
.default_operstring
= rb_strdup("is an IRC operator");
739 ConfigFileEntry
.default_adminstring
= rb_strdup("is a Server Administrator");
740 ConfigFileEntry
.servicestring
= rb_strdup("is a Network Service");
742 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
743 ConfigFileEntry
.failed_oper_notice
= YES
;
744 ConfigFileEntry
.anti_nick_flood
= NO
;
745 ConfigFileEntry
.disable_fake_channels
= NO
;
746 ConfigFileEntry
.max_nick_time
= 20;
747 ConfigFileEntry
.max_nick_changes
= 5;
748 ConfigFileEntry
.max_accept
= 20;
749 ConfigFileEntry
.max_monitor
= 60;
750 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
751 ConfigFileEntry
.target_change
= YES
;
752 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
753 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
754 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
755 ConfigFileEntry
.client_exit
= YES
;
756 ConfigFileEntry
.dline_with_reason
= YES
;
757 ConfigFileEntry
.kline_with_reason
= YES
;
758 ConfigFileEntry
.kline_delay
= 0;
759 ConfigFileEntry
.warn_no_nline
= YES
;
760 ConfigFileEntry
.non_redundant_klines
= YES
;
761 ConfigFileEntry
.stats_e_disabled
= NO
;
762 ConfigFileEntry
.stats_o_oper_only
= NO
;
763 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
764 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
765 ConfigFileEntry
.stats_P_oper_only
= NO
;
766 ConfigFileEntry
.stats_c_oper_only
= NO
;
767 ConfigFileEntry
.stats_y_oper_only
= NO
;
768 ConfigFileEntry
.stats_h_oper_only
= NO
;
769 ConfigFileEntry
.map_oper_only
= YES
;
770 ConfigFileEntry
.operspy_admin_only
= NO
;
771 ConfigFileEntry
.pace_wait
= 10;
772 ConfigFileEntry
.caller_id_wait
= 60;
773 ConfigFileEntry
.pace_wait_simple
= 1;
774 ConfigFileEntry
.short_motd
= NO
;
775 ConfigFileEntry
.no_oper_flood
= NO
;
776 ConfigFileEntry
.fname_userlog
= NULL
;
777 ConfigFileEntry
.fname_fuserlog
= NULL
;
778 ConfigFileEntry
.fname_operlog
= NULL
;
779 ConfigFileEntry
.fname_foperlog
= NULL
;
780 ConfigFileEntry
.fname_serverlog
= NULL
;
781 ConfigFileEntry
.fname_klinelog
= NULL
;
782 ConfigFileEntry
.fname_operspylog
= NULL
;
783 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
784 ConfigFileEntry
.use_egd
= NO
;
785 ConfigFileEntry
.hide_spoof_ips
= YES
;
786 ConfigFileEntry
.hide_error_messages
= 1;
787 ConfigFileEntry
.dots_in_ident
= 0;
788 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
789 ConfigFileEntry
.egdpool_path
= NULL
;
790 ConfigFileEntry
.use_whois_actually
= YES
;
791 ConfigFileEntry
.burst_away
= NO
;
792 ConfigFileEntry
.collision_fnc
= YES
;
793 ConfigFileEntry
.global_snotices
= YES
;
794 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
797 ConfigFileEntry
.compression_level
= 4;
800 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
801 UMODE_OPERWALL
| UMODE_WALLOP
;
802 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
803 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
805 ConfigChannel
.use_except
= YES
;
806 ConfigChannel
.use_invex
= YES
;
807 ConfigChannel
.use_knock
= YES
;
808 ConfigChannel
.use_forward
= YES
;
809 ConfigChannel
.knock_delay
= 300;
810 ConfigChannel
.knock_delay_channel
= 60;
811 ConfigChannel
.max_chans_per_user
= 15;
812 ConfigChannel
.max_bans
= 25;
813 ConfigChannel
.max_bans_large
= 500;
814 ConfigChannel
.only_ascii_channels
= NO
;
815 ConfigChannel
.burst_topicwho
= NO
;
816 ConfigChannel
.kick_on_split_riding
= NO
;
818 ConfigChannel
.default_split_user_count
= 15000;
819 ConfigChannel
.default_split_server_count
= 10;
820 ConfigChannel
.no_join_on_split
= NO
;
821 ConfigChannel
.no_create_on_split
= YES
;
823 ConfigServerHide
.flatten_links
= 0;
824 ConfigServerHide
.links_delay
= 300;
825 ConfigServerHide
.hidden
= 0;
826 ConfigServerHide
.disable_hidden
= 0;
828 ConfigFileEntry
.min_nonwildcard
= 4;
829 ConfigFileEntry
.min_nonwildcard_simple
= 3;
830 ConfigFileEntry
.default_floodcount
= 8;
831 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
832 ConfigFileEntry
.tkline_expire_notices
= 0;
834 ConfigFileEntry
.reject_after_count
= 5;
835 ConfigFileEntry
.reject_ban_time
= 300;
836 ConfigFileEntry
.reject_duration
= 120;
837 ConfigFileEntry
.throttle_count
= 4;
838 ConfigFileEntry
.throttle_duration
= 60;
840 ServerInfo
.default_max_clients
= MAXCONNECTIONS
;
850 * inputs - file descriptor pointing to config file to use
852 * side effects - Read configuration file.
855 read_conf(FILE * file
)
859 set_default_conf(); /* Set default values prior to conf parsing */
860 yyparse(); /* Load the values from the conf */
861 validate_conf(); /* Check to make sure some values are still okay. */
862 /* Some global values are also loaded here. */
863 check_class(); /* Make sure classes are valid */
864 privilegeset_delete_all_illegal();
870 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
871 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
873 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
874 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
876 if(ServerInfo
.network_name
== NULL
)
877 ServerInfo
.network_name
= rb_strdup(NETWORK_NAME_DEFAULT
);
879 if(ServerInfo
.network_desc
== NULL
)
880 ServerInfo
.network_desc
= rb_strdup(NETWORK_DESC_DEFAULT
);
882 if(ServerInfo
.ssld_count
< 1)
883 ServerInfo
.ssld_count
= 1;
885 if(!rb_setup_ssl_server(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
))
887 ilog(L_MAIN
, "WARNING: Unable to setup SSL.");
891 send_new_ssl_certs(ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
894 if(ServerInfo
.ssld_count
> get_ssld_count())
896 int start
= ServerInfo
.ssld_count
- get_ssld_count();
897 /* start up additional ssld if needed */
898 start_ssldaemon(start
, ServerInfo
.ssl_cert
, ServerInfo
.ssl_private_key
, ServerInfo
.ssl_dh_params
);
902 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
903 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
904 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
906 if(!split_users
|| !split_servers
||
907 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
909 rb_event_delete(check_splitmode_ev
);
910 check_splitmode_ev
= NULL
;
918 * inputs - pointer to struct ConfItem
920 * Side effects - links in given struct ConfItem into
921 * temporary kline link list
924 add_temp_kline(struct ConfItem
*aconf
)
926 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
928 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
929 aconf
->port
= TEMP_WEEK
;
931 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
933 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
934 aconf
->port
= TEMP_DAY
;
936 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
938 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
939 aconf
->port
= TEMP_HOUR
;
943 rb_dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
944 aconf
->port
= TEMP_MIN
;
947 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
948 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, NULL
, aconf
);
953 * input - pointer to struct ConfItem
955 * side effects - added to tdline link list and address hash
958 add_temp_dline(struct ConfItem
*aconf
)
960 if(aconf
->hold
>= rb_current_time() + (10080 * 60))
962 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
963 aconf
->port
= TEMP_WEEK
;
965 else if(aconf
->hold
>= rb_current_time() + (1440 * 60))
967 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
968 aconf
->port
= TEMP_DAY
;
970 else if(aconf
->hold
>= rb_current_time() + (60 * 60))
972 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
973 aconf
->port
= TEMP_HOUR
;
977 rb_dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
978 aconf
->port
= TEMP_MIN
;
981 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
982 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, NULL
, aconf
);
987 * inputs - list pointer
990 * side effects - expire tklines and moves them between lists
993 expire_temp_kd(void *list
)
996 rb_dlink_node
*next_ptr
;
997 struct ConfItem
*aconf
;
999 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1003 if(aconf
->hold
<= rb_current_time())
1005 /* Alert opers that a TKline expired - Hwy */
1006 if(ConfigFileEntry
.tkline_expire_notices
)
1007 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1008 "Temporary K-line for [%s@%s] expired",
1009 (aconf
->user
) ? aconf
->
1010 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1012 delete_one_address_conf(aconf
->host
, aconf
);
1013 rb_dlinkDestroy(ptr
, list
);
1019 reorganise_temp_kd(void *list
)
1021 struct ConfItem
*aconf
;
1022 rb_dlink_node
*ptr
, *next_ptr
;
1024 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((rb_dlink_list
*) list
)->head
)
1028 if(aconf
->hold
< (rb_current_time() + (60 * 60)))
1030 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1031 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1032 aconf
->port
= TEMP_MIN
;
1034 else if(aconf
->port
> TEMP_HOUR
)
1036 if(aconf
->hold
< (rb_current_time() + (1440 * 60)))
1038 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1039 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1040 aconf
->port
= TEMP_HOUR
;
1042 else if(aconf
->port
> TEMP_DAY
&&
1043 (aconf
->hold
< (rb_current_time() + (10080 * 60))))
1045 rb_dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1046 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1047 aconf
->port
= TEMP_DAY
;
1054 /* const char* get_oper_name(struct Client *client_p)
1055 * Input: A client to find the active oper{} name for.
1056 * Output: The nick!user@host{oper} of the oper.
1057 * "oper" is server name for remote opers
1058 * Side effects: None.
1061 get_oper_name(struct Client
*client_p
)
1063 /* +5 for !,@,{,} and null */
1064 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1066 if(MyOper(client_p
))
1068 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1069 client_p
->name
, client_p
->username
,
1070 client_p
->host
, client_p
->localClient
->opername
);
1074 rb_snprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1075 client_p
->name
, client_p
->username
,
1076 client_p
->host
, client_p
->servptr
->name
);
1081 * get_printable_conf
1083 * inputs - struct ConfItem
1092 * Examine the struct struct ConfItem, setting the values
1093 * of name, host, pass, user to values either
1094 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1097 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1098 char **pass
, char **user
, int *port
, char **classname
)
1100 static char null
[] = "<NULL>";
1101 static char zero
[] = "default";
1103 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1104 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1105 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1106 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1107 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1108 *port
= (int) aconf
->port
;
1112 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1113 char **host
, char **reason
,
1114 char **user
, char **oper_reason
)
1116 static char null
[] = "<NULL>";
1118 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1119 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1120 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1122 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1123 *oper_reason
= NULL
;
1125 *oper_reason
= aconf
->spasswd
;
1131 * inputs - cold start YES or NO
1133 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1136 read_conf_files(int cold
)
1138 const char *filename
;
1140 conf_fbfile_in
= NULL
;
1142 filename
= get_conf_name(CONF_TYPE
);
1144 /* We need to know the initial filename for the yyerror() to report
1145 FIXME: The full path is in conffilenamebuf first time since we
1146 dont know anything else
1150 rb_strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1152 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1156 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1161 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1162 "Can't open file '%s' - aborting rehash!", filename
);
1163 if (remote_rehash_oper_p
)
1164 sendto_one_notice(remote_rehash_oper_p
,
1165 ":*** Notice -- Can't open file '%s' - aborting rehash!", filename
);
1172 clear_out_old_conf();
1175 read_conf(conf_fbfile_in
);
1176 fclose(conf_fbfile_in
);
1180 * free an alias{} entry.
1183 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1185 struct alias_entry
*aptr
= ptr
->data
;
1187 rb_free(aptr
->name
);
1188 rb_free(aptr
->target
);
1193 * clear_out_old_conf
1197 * side effects - Clear out the old configuration
1200 clear_out_old_conf(void)
1202 struct Class
*cltmp
;
1204 rb_dlink_node
*next_ptr
;
1207 * don't delete the class table, rather mark all entries
1208 * for deletion. The table is cleaned up by check_class. - avalon
1210 RB_DLINK_FOREACH(ptr
, class_list
.head
)
1213 MaxUsers(cltmp
) = -1;
1216 clear_out_address_conf();
1219 /* clean out module paths */
1220 #ifndef STATIC_MODULES
1222 mod_add_path(MODULE_DIR
);
1223 mod_add_path(MODULE_DIR
"/autoload");
1226 /* clean out ServerInfo */
1227 rb_free(ServerInfo
.description
);
1228 ServerInfo
.description
= NULL
;
1229 rb_free(ServerInfo
.network_name
);
1230 ServerInfo
.network_name
= NULL
;
1231 rb_free(ServerInfo
.network_desc
);
1232 ServerInfo
.network_desc
= NULL
;
1234 ServerInfo
.ssld_count
= 1;
1236 /* clean out AdminInfo */
1237 rb_free(AdminInfo
.name
);
1238 AdminInfo
.name
= NULL
;
1239 rb_free(AdminInfo
.email
);
1240 AdminInfo
.email
= NULL
;
1241 rb_free(AdminInfo
.description
);
1242 AdminInfo
.description
= NULL
;
1244 /* operator{} and class{} blocks are freed above */
1245 /* clean out listeners */
1248 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1249 * and gecos{} blocks are freed above too
1252 /* clean out general */
1253 rb_free(ConfigFileEntry
.kline_reason
);
1254 ConfigFileEntry
.kline_reason
= NULL
;
1256 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1259 rb_dlinkDestroy(ptr
, &service_list
);
1262 /* remove any aliases... -- nenolod */
1263 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1266 destroy_blacklists();
1268 privilegeset_mark_all_illegal();
1270 /* OK, that should be everything... */
1276 * inputs - kline, dline or resv type flag
1277 * - client pointer to report to
1278 * - user name of target
1279 * - host name of target
1280 * - reason for target
1284 * side effects - This function takes care of finding the right conf
1285 * file and adding the line to it, as well as notifying
1286 * opers and the user.
1289 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1290 char *host
, const char *reason
, const char *oper_reason
,
1291 const char *current_date
, int xtype
)
1295 const char *filename
; /* filename to use for kline */
1297 filename
= get_conf_name(type
);
1299 if(type
== KLINE_TYPE
)
1301 if(EmptyString(oper_reason
))
1303 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1304 "%s added K-Line for [%s@%s] [%s]",
1305 get_oper_name(source_p
), user
,
1307 ilog(L_KLINE
, "K %s 0 %s %s %s",
1308 get_oper_name(source_p
), user
, host
, reason
);
1312 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1313 "%s added K-Line for [%s@%s] [%s|%s]",
1314 get_oper_name(source_p
), user
,
1315 host
, reason
, oper_reason
);
1316 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1317 get_oper_name(source_p
), user
, host
,
1318 reason
, oper_reason
);
1321 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1324 else if(type
== DLINE_TYPE
)
1326 if(EmptyString(oper_reason
))
1328 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1329 "%s added D-Line for [%s] [%s]",
1330 get_oper_name(source_p
), host
, reason
);
1331 ilog(L_KLINE
, "D %s 0 %s %s",
1332 get_oper_name(source_p
), host
, reason
);
1336 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1337 "%s added D-Line for [%s] [%s|%s]",
1338 get_oper_name(source_p
), host
,
1339 reason
, oper_reason
);
1340 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1341 get_oper_name(source_p
), host
,
1342 reason
, oper_reason
);
1345 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1348 else if(type
== RESV_TYPE
)
1350 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1351 "%s added RESV for [%s] [%s]",
1352 get_oper_name(source_p
), host
, reason
);
1353 ilog(L_KLINE
, "R %s 0 %s %s",
1354 get_oper_name(source_p
), host
, reason
);
1356 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1360 if((out
= fopen(filename
, "a")) == NULL
)
1362 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1363 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1367 if(oper_reason
== NULL
)
1370 if(type
== KLINE_TYPE
)
1372 rb_snprintf(buffer
, sizeof(buffer
),
1373 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1374 user
, host
, reason
, oper_reason
, current_date
,
1375 get_oper_name(source_p
), (long int)rb_current_time());
1377 else if(type
== DLINE_TYPE
)
1379 rb_snprintf(buffer
, sizeof(buffer
),
1380 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1381 reason
, oper_reason
, current_date
, get_oper_name(source_p
), (long int)rb_current_time());
1383 else if(type
== RESV_TYPE
)
1385 rb_snprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1386 host
, reason
, get_oper_name(source_p
), (long int)rb_current_time());
1389 if(fputs(buffer
, out
) == -1)
1391 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1392 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1399 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1400 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1407 * inputs - type of conf file to return name of file for
1408 * output - pointer to filename for type of conf
1409 * side effects - none
1412 get_conf_name(KlineType type
)
1414 if(type
== CONF_TYPE
)
1416 return (ConfigFileEntry
.configfile
);
1418 else if(type
== DLINE_TYPE
)
1420 return (ConfigFileEntry
.dlinefile
);
1422 else if(type
== RESV_TYPE
)
1424 return (ConfigFileEntry
.resvfile
);
1427 return ConfigFileEntry
.klinefile
;
1431 * conf_add_class_to_conf
1432 * inputs - pointer to config item
1434 * side effects - Add a class pointer to a conf
1438 conf_add_class_to_conf(struct ConfItem
*aconf
)
1440 if(aconf
->className
== NULL
)
1442 aconf
->className
= rb_strdup("default");
1443 ClassPtr(aconf
) = default_class
;
1447 ClassPtr(aconf
) = find_class(aconf
->className
);
1449 if(ClassPtr(aconf
) == default_class
)
1451 if(aconf
->status
== CONF_CLIENT
)
1454 "Using default class for missing class \"%s\" in auth{} for %s@%s",
1455 aconf
->className
, aconf
->user
, aconf
->host
);
1458 rb_free(aconf
->className
);
1459 aconf
->className
= rb_strdup("default");
1463 if(ConfMaxUsers(aconf
) < 0)
1465 ClassPtr(aconf
) = default_class
;
1466 rb_free(aconf
->className
);
1467 aconf
->className
= rb_strdup("default");
1474 * inputs - pointer to config item
1476 * side effects - Add a d/D line
1479 conf_add_d_conf(struct ConfItem
*aconf
)
1481 if(aconf
->host
== NULL
)
1486 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1487 * need this anyway, so I will disable it for now... -A1kmm
1490 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1492 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1497 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, NULL
, aconf
);
1502 strip_tabs(char *dest
, const char *src
, size_t len
)
1506 if(dest
== NULL
|| src
== NULL
)
1509 rb_strlcpy(dest
, src
, len
);
1523 * inputs - message from parser
1525 * side effects - message to opers and log file entry is made
1528 yyerror(const char *msg
)
1530 char newlinebuf
[BUFSIZE
];
1532 strip_tabs(newlinebuf
, linebuf
, strlen(linebuf
));
1534 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1535 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1536 if (remote_rehash_oper_p
)
1537 sendto_one_notice(remote_rehash_oper_p
, ":*** Notice -- \"%s\", line %d: %s at '%s'",
1538 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1540 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1544 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1548 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1551 return (strlen(lbuf
));
1555 conf_yy_fatal_error(const char *msg
)