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
26 #include "ircd_defs.h"
29 #include "s_newconf.h"
38 #include "irc_string.h"
39 #include "sprintf_irc.h"
53 #include "blacklist.h"
55 struct config_server_hide ConfigServerHide
;
57 extern int yyparse(); /* defined in y.tab.c */
58 extern char linebuf
[];
61 #define INADDR_NONE ((unsigned int) 0xffffffff)
64 static BlockHeap
*confitem_heap
= NULL
;
66 dlink_list temp_klines
[LAST_TEMP_TYPE
];
67 dlink_list temp_dlines
[LAST_TEMP_TYPE
];
68 dlink_list service_list
;
70 /* internally defined functions */
71 static void set_default_conf(void);
72 static void validate_conf(void);
73 static void read_conf(FILE *);
74 static void clear_out_old_conf(void);
76 static void expire_temp_kd(void *list
);
77 static void reorganise_temp_kd(void *list
);
82 static int verify_access(struct Client
*client_p
, const char *username
);
83 static int attach_iline(struct Client
*, struct ConfItem
*);
88 confitem_heap
= BlockHeapCreate(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
);
90 eventAddIsh("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
91 eventAddIsh("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
93 eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd
,
94 &temp_klines
[TEMP_HOUR
], 3600);
95 eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd
,
96 &temp_dlines
[TEMP_HOUR
], 3600);
97 eventAddIsh("expire_temp_klines_day", reorganise_temp_kd
,
98 &temp_klines
[TEMP_DAY
], 86400);
99 eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd
,
100 &temp_dlines
[TEMP_DAY
], 86400);
101 eventAddIsh("expire_temp_klines_week", reorganise_temp_kd
,
102 &temp_klines
[TEMP_WEEK
], 604800);
103 eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd
,
104 &temp_dlines
[TEMP_WEEK
], 604800);
111 * output - pointer to new conf entry
112 * side effects - none
117 struct ConfItem
*aconf
;
119 aconf
= BlockHeapAlloc(confitem_heap
);
120 aconf
->status
= CONF_ILLEGAL
;
127 * inputs - pointer to conf to free
129 * side effects - crucial password fields are zeroed, conf is freed
132 free_conf(struct ConfItem
*aconf
)
134 s_assert(aconf
!= NULL
);
140 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
142 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
144 MyFree(aconf
->passwd
);
145 MyFree(aconf
->spasswd
);
147 MyFree(aconf
->className
);
151 BlockHeapFree(confitem_heap
, aconf
);
157 * inputs - pointer to client
158 * output - 0 = Success
159 * NOT_AUTHORISED (-1) = Access denied (no I line match)
160 * SOCKET_ERROR (-2) = Bad socket.
161 * I_LINE_FULL (-3) = I-line is full
162 * TOO_MANY (-4) = Too many connections from hostname
163 * BANNED_CLIENT (-5) = K-lined
164 * side effects - Ordinary client access check.
165 * Look for conf lines which have the same
166 * status as the flags passed.
169 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
173 ClearAccess(source_p
);
175 if((i
= verify_access(source_p
, username
)))
177 ilog(L_FUSER
, "Access denied: %s[%s]",
178 source_p
->name
, source_p
->sockhost
);
184 exit_client(client_p
, source_p
, &me
, "Socket Error");
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
) ? "" : "~",
191 source_p
->username
, source_p
->sockhost
);
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
) ? "" : "~",
205 source_p
->username
, source_p
->sockhost
);
206 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
207 source_p
->name
, IsGotId(source_p
) ? "" : "~",
208 source_p
->username
, source_p
->sockhost
);
210 ServerStats
->is_ref
++;
211 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
215 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
216 "Too many user connections for %s!%s%s@%s",
217 source_p
->name
, IsGotId(source_p
) ? "" : "~",
218 source_p
->username
, source_p
->sockhost
);
219 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
220 source_p
->name
, IsGotId(source_p
) ? "" : "~",
221 source_p
->username
, source_p
->sockhost
);
223 ServerStats
->is_ref
++;
224 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
228 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
229 "I-line is full for %s!%s%s@%s (%s).",
230 source_p
->name
, IsGotId(source_p
) ? "" : "~",
231 source_p
->username
, source_p
->host
,
234 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
235 source_p
->name
, IsGotId(source_p
) ? "" : "~",
236 source_p
->username
, source_p
->sockhost
);
238 ServerStats
->is_ref
++;
239 exit_client(client_p
, source_p
, &me
,
240 "No more connections allowed in your connection class");
247 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
248 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
251 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
253 ServerStats
->is_ref
++;
254 /* jdc - lists server name & port connections are on */
255 /* a purely cosmetical change */
256 /* why ipaddr, and not just source_p->sockhost? --fl */
258 static char ipaddr
[HOSTIPLEN
];
259 inetntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
261 sendto_realops_snomask(SNO_UNAUTH
, L_NETWIDE
,
262 "Unauthorised client connection from "
263 "%s!%s%s@%s [%s] on [%s/%u].",
264 source_p
->name
, IsGotId(source_p
) ? "" : "~",
265 source_p
->username
, source_p
->host
,
267 source_p
->localClient
->listener
->name
, port
);
270 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
271 source_p
->name
, IsGotId(source_p
) ? "" : "~",
272 source_p
->username
, source_p
->sockhost
,
273 source_p
->localClient
->listener
->name
, port
);
274 add_reject(client_p
);
275 exit_client(client_p
, source_p
, &me
,
276 "You are not authorised to use this server");
280 add_reject(client_p
);
281 exit_client(client_p
, client_p
, &me
, "*** Banned ");
282 ServerStats
->is_ref
++;
295 * inputs - pointer to client to verify
296 * - pointer to proposed username
297 * output - 0 if success -'ve if not
298 * side effect - find the first (best) I line to attach.
301 verify_access(struct Client
*client_p
, const char *username
)
303 struct ConfItem
*aconf
;
304 char non_ident
[USERLEN
+ 1];
306 if(IsGotId(client_p
))
308 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
310 (struct sockaddr
*) &client_p
->localClient
->ip
,
311 client_p
->localClient
->ip
.ss_family
);
315 strlcpy(non_ident
, "~", sizeof(non_ident
));
316 strlcat(non_ident
, username
, sizeof(non_ident
));
317 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
319 (struct sockaddr
*) &client_p
->localClient
->ip
,
320 client_p
->localClient
->ip
.ss_family
);
324 return NOT_AUTHORISED
;
326 if(aconf
->status
& CONF_CLIENT
)
328 if(aconf
->flags
& CONF_FLAGS_REDIR
)
330 sendto_one(client_p
, form_str(RPL_REDIR
),
331 me
.name
, client_p
->name
,
332 aconf
->name
? aconf
->name
: "", aconf
->port
);
333 return (NOT_AUTHORISED
);
337 if(IsConfDoIdentd(aconf
))
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_NETWIDE
,
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 strlcpy(client_p
->username
, aconf
->name
,
364 sizeof(client_p
->username
));
365 strlcpy(client_p
->host
, host
,
366 sizeof(client_p
->host
));
370 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 ":%s NOTICE %s :*** Banned %s",
380 me
.name
, client_p
->name
, aconf
->passwd
);
382 return (BANNED_CLIENT
);
385 return NOT_AUTHORISED
;
392 * Returns 1 if successful 0 if not
394 * This checks if the user has exceed the limits for their class
395 * unless of course they are exempt..
399 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
401 patricia_node_t
*pnode
;
403 /* If the limits are 0 don't do anything.. */
404 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
407 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
410 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
412 s_assert(pnode
!= NULL
);
416 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
417 && !IsConfExemptLimits(aconf
))
419 /* This should only happen if the limits are set to 0 */
420 if((unsigned long) pnode
->data
== 0)
422 patricia_remove(ConfIpLimits(aconf
), pnode
);
433 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
435 patricia_node_t
*pnode
;
437 /* If the limits are 0 don't do anything.. */
438 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
441 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
446 if(((unsigned long) pnode
->data
) == 0)
448 patricia_remove(ConfIpLimits(aconf
), pnode
);
456 * inputs - client pointer
459 * side effects - do actual attach
462 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
464 struct Client
*target_p
;
467 int global_count
= 0;
471 if(IsConfExemptLimits(aconf
))
472 return (attach_conf(client_p
, aconf
));
474 if(*client_p
->username
== '~')
478 /* find_hostname() returns the head of the list to search */
479 DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
481 target_p
= ptr
->data
;
483 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
486 if(MyConnect(target_p
))
493 if(*target_p
->username
== '~')
496 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
499 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
500 return (TOO_MANY_LOCAL
);
501 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
502 return (TOO_MANY_GLOBAL
);
503 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
504 return (TOO_MANY_IDENT
);
508 return (attach_conf(client_p
, aconf
));
514 * inputs - pointer to client to detach
515 * output - 0 for success, -1 for failure
516 * side effects - Disassociate configuration from the client.
517 * Also removes a class from the list if marked for deleting.
520 detach_conf(struct Client
*client_p
)
522 struct ConfItem
*aconf
;
524 aconf
= client_p
->localClient
->att_conf
;
530 remove_ip_limit(client_p
, aconf
);
532 if(ConfCurrUsers(aconf
) > 0)
533 --ConfCurrUsers(aconf
);
535 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
537 free_class(ClassPtr(aconf
));
538 ClassPtr(aconf
) = NULL
;
544 if(!aconf
->clients
&& IsIllegal(aconf
))
547 client_p
->localClient
->att_conf
= NULL
;
557 * inputs - client pointer
560 * side effects - Associate a specific configuration entry to a *local*
561 * client (this is the one which used in accepting the
562 * connection). Note, that this automatically changes the
563 * attachment if there was an old one...
566 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
569 return (NOT_AUTHORISED
);
573 if(!add_ip_limit(client_p
, aconf
))
574 return (TOO_MANY_LOCAL
);
577 if((aconf
->status
& CONF_CLIENT
) &&
578 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
580 if(!IsConfExemptLimits(aconf
))
582 return (I_LINE_FULL
);
586 sendto_one(client_p
, ":%s NOTICE %s :*** I: line is full, but you have an >I: line!",
587 me
.name
, client_p
->name
);
588 SetExemptLimits(client_p
);
593 if(client_p
->localClient
->att_conf
!= NULL
)
594 detach_conf(client_p
);
596 client_p
->localClient
->att_conf
= aconf
;
599 ConfCurrUsers(aconf
)++;
606 * Actual REHASH service routine. Called with sig == 0 if it has been called
607 * as a result of an operator issuing this command, else assume it has been
608 * called as a result of the server receiving a HUP signal.
615 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
616 "Got signal SIGHUP, reloading ircd conf. file");
620 /* don't close listeners until we know we can go ahead with the rehash */
623 if(ServerInfo
.description
!= NULL
)
624 strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
626 strlcpy(me
.info
, "unknown", sizeof(me
.info
));
632 static struct banconf_entry
634 const char **filename
;
635 void (*func
) (FILE *);
638 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
639 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
640 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
641 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
642 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
643 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
644 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
645 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
653 char buf
[MAXPATHLEN
];
657 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
658 "Got signal SIGUSR2, reloading ban confs");
660 clear_out_address_conf_bans();
661 clear_s_newconf_bans();
663 for(i
= 0; banconfs
[i
].filename
; i
++)
666 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
668 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
670 if((file
= fopen(buf
, "r")) == NULL
)
675 ilog(L_MAIN
, "Failed reading ban file %s",
676 *banconfs
[i
].filename
);
677 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
678 "Can't open %s file bans could be missing!",
679 *banconfs
[i
].filename
);
683 (banconfs
[i
].func
)(file
);
688 check_banned_lines();
696 * side effects - Set default values here.
697 * This is called **PRIOR** to parsing the
698 * configuration file. If you want to do some validation
699 * of values later, put them in validate_conf().
707 set_default_conf(void)
709 /* ServerInfo.name is not rehashable */
710 /* ServerInfo.name = ServerInfo.name; */
711 ServerInfo
.description
= NULL
;
712 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
713 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
715 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
716 ServerInfo
.specific_ipv4_vhost
= 0;
718 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
719 ServerInfo
.specific_ipv6_vhost
= 0;
721 ServerInfo
.use_ts6
= YES
;
723 /* Don't reset hub, as that will break lazylinks */
724 /* ServerInfo.hub = NO; */
725 AdminInfo
.name
= NULL
;
726 AdminInfo
.email
= NULL
;
727 AdminInfo
.description
= NULL
;
729 DupString(ConfigFileEntry
.default_operstring
, "is an IRC operator");
730 DupString(ConfigFileEntry
.default_adminstring
, "is a Server Administrator");
731 DupString(ConfigFileEntry
.servicestring
, "is a Network Service");
733 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
734 ConfigFileEntry
.failed_oper_notice
= YES
;
735 ConfigFileEntry
.anti_nick_flood
= NO
;
736 ConfigFileEntry
.disable_fake_channels
= NO
;
737 ConfigFileEntry
.max_nick_time
= 20;
738 ConfigFileEntry
.max_nick_changes
= 5;
739 ConfigFileEntry
.max_accept
= 20;
740 ConfigFileEntry
.max_monitor
= 60;
741 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
742 ConfigFileEntry
.target_change
= YES
;
743 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
744 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
745 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
746 ConfigFileEntry
.client_exit
= YES
;
747 ConfigFileEntry
.dline_with_reason
= YES
;
748 ConfigFileEntry
.kline_with_reason
= YES
;
749 ConfigFileEntry
.kline_delay
= 0;
750 ConfigFileEntry
.warn_no_nline
= YES
;
751 ConfigFileEntry
.non_redundant_klines
= YES
;
752 ConfigFileEntry
.stats_e_disabled
= NO
;
753 ConfigFileEntry
.stats_o_oper_only
= NO
;
754 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
755 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
756 ConfigFileEntry
.stats_P_oper_only
= NO
;
757 ConfigFileEntry
.stats_c_oper_only
= NO
;
758 ConfigFileEntry
.stats_y_oper_only
= NO
;
759 ConfigFileEntry
.stats_h_oper_only
= NO
;
760 ConfigFileEntry
.map_oper_only
= YES
;
761 ConfigFileEntry
.pace_wait
= 10;
762 ConfigFileEntry
.caller_id_wait
= 60;
763 ConfigFileEntry
.pace_wait_simple
= 1;
764 ConfigFileEntry
.short_motd
= NO
;
765 ConfigFileEntry
.no_oper_flood
= NO
;
766 ConfigFileEntry
.fname_userlog
= NULL
;
767 ConfigFileEntry
.fname_fuserlog
= NULL
;
768 ConfigFileEntry
.fname_operlog
= NULL
;
769 ConfigFileEntry
.fname_foperlog
= NULL
;
770 ConfigFileEntry
.fname_serverlog
= NULL
;
771 ConfigFileEntry
.fname_klinelog
= NULL
;
772 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
773 ConfigFileEntry
.use_egd
= NO
;
774 ConfigFileEntry
.hide_spoof_ips
= YES
;
775 ConfigFileEntry
.hide_error_messages
= 1;
776 ConfigFileEntry
.idletime
= 0;
777 ConfigFileEntry
.dots_in_ident
= 0;
778 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
779 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
780 ConfigFileEntry
.egdpool_path
= NULL
;
781 ConfigFileEntry
.use_whois_actually
= YES
;
782 ConfigFileEntry
.burst_away
= NO
;
783 ConfigFileEntry
.collision_fnc
= YES
;
784 ConfigFileEntry
.global_snotices
= YES
;
785 ConfigFileEntry
.remote_die
= NO
;
786 ConfigFileEntry
.remote_restart
= NO
;
789 ConfigFileEntry
.compression_level
= 4;
792 ConfigFileEntry
.oper_umodes
= UMODE_SERVNOTICE
|
793 UMODE_OPERWALL
| UMODE_WALLOP
;
794 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
795 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
797 ConfigChannel
.use_except
= YES
;
798 ConfigChannel
.use_invex
= YES
;
799 ConfigChannel
.use_knock
= YES
;
800 ConfigChannel
.knock_delay
= 300;
801 ConfigChannel
.knock_delay_channel
= 60;
802 ConfigChannel
.max_chans_per_user
= 15;
803 ConfigChannel
.max_chans_per_user_large
= 60;
804 ConfigChannel
.max_bans
= 25;
805 ConfigChannel
.max_bans_large
= 500;
806 ConfigChannel
.burst_topicwho
= NO
;
807 ConfigChannel
.invite_ops_only
= YES
;
808 ConfigChannel
.kick_on_split_riding
= NO
;
810 ConfigChannel
.default_split_user_count
= 15000;
811 ConfigChannel
.default_split_server_count
= 10;
812 ConfigChannel
.no_join_on_split
= NO
;
813 ConfigChannel
.no_create_on_split
= YES
;
815 ConfigServerHide
.flatten_links
= 0;
816 ConfigServerHide
.links_delay
= 300;
817 ConfigServerHide
.hidden
= 0;
818 ConfigServerHide
.disable_hidden
= 0;
820 ConfigFileEntry
.min_nonwildcard
= 4;
821 ConfigFileEntry
.min_nonwildcard_simple
= 3;
822 ConfigFileEntry
.default_floodcount
= 8;
823 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
824 ConfigFileEntry
.tkline_expire_notices
= 0;
826 ConfigFileEntry
.reject_after_count
= 5;
827 ConfigFileEntry
.reject_ban_time
= 300;
828 ConfigFileEntry
.reject_duration
= 120;
830 DupString(ConfigFileEntry
.idented_user_prefix
, "");
840 * inputs - file descriptor pointing to config file to use
842 * side effects - Read configuration file.
845 read_conf(FILE * file
)
849 set_default_conf(); /* Set default values prior to conf parsing */
850 yyparse(); /* Load the values from the conf */
851 validate_conf(); /* Check to make sure some values are still okay. */
852 /* Some global values are also loaded here. */
853 check_class(); /* Make sure classes are valid */
859 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
860 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
862 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
863 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
865 if(ConfigFileEntry
.servlink_path
== NULL
)
866 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
868 if(ServerInfo
.network_name
== NULL
)
869 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
871 if(ServerInfo
.network_desc
== NULL
)
872 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
874 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
875 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
876 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
878 GlobalSetOptions
.idletime
= (ConfigFileEntry
.idletime
* 60);
880 if(!split_users
|| !split_servers
||
881 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
883 eventDelete(check_splitmode
, NULL
);
890 * lookup_confhost - start DNS lookups of all hostnames in the conf
891 * line and convert an IP addresses in a.b.c.d number for to IP#s.
896 * conf_connect_allowed
898 * inputs - pointer to inaddr
899 * - int type ipv4 or ipv6
900 * output - ban info or NULL
901 * side effects - none
904 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
906 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
908 /* DLINE exempt also gets you out of static limits/pacing... */
909 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
920 * inputs - pointer to struct ConfItem
922 * Side effects - links in given struct ConfItem into
923 * temporary kline link list
926 add_temp_kline(struct ConfItem
*aconf
)
928 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
930 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
931 aconf
->port
= TEMP_WEEK
;
933 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
935 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
936 aconf
->port
= TEMP_DAY
;
938 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
940 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
941 aconf
->port
= TEMP_HOUR
;
945 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
946 aconf
->port
= TEMP_MIN
;
949 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
950 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
955 * input - pointer to struct ConfItem
957 * side effects - added to tdline link list and address hash
960 add_temp_dline(struct ConfItem
*aconf
)
962 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
964 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
965 aconf
->port
= TEMP_WEEK
;
967 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
969 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
970 aconf
->port
= TEMP_DAY
;
972 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
974 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
975 aconf
->port
= TEMP_HOUR
;
979 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
980 aconf
->port
= TEMP_MIN
;
983 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
984 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
989 * inputs - list pointer
992 * side effects - expire tklines and moves them between lists
995 expire_temp_kd(void *list
)
998 dlink_node
*next_ptr
;
999 struct ConfItem
*aconf
;
1001 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1005 if(aconf
->hold
<= CurrentTime
)
1007 /* Alert opers that a TKline expired - Hwy */
1008 if(ConfigFileEntry
.tkline_expire_notices
)
1009 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1010 "Temporary K-line for [%s@%s] expired",
1011 (aconf
->user
) ? aconf
->
1012 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1014 delete_one_address_conf(aconf
->host
, aconf
);
1015 dlinkDestroy(ptr
, list
);
1021 reorganise_temp_kd(void *list
)
1023 struct ConfItem
*aconf
;
1024 dlink_node
*ptr
, *next_ptr
;
1026 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1030 if(aconf
->hold
< (CurrentTime
+ (60 * 60)))
1032 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1033 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1034 aconf
->port
= TEMP_MIN
;
1036 else if(aconf
->port
> TEMP_HOUR
)
1038 if(aconf
->hold
< (CurrentTime
+ (1440 * 60)))
1040 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1041 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1042 aconf
->port
= TEMP_HOUR
;
1044 else if(aconf
->port
> TEMP_DAY
&&
1045 (aconf
->hold
< (CurrentTime
+ (10080 * 60))))
1047 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1048 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1049 aconf
->port
= TEMP_DAY
;
1056 /* const char* get_oper_name(struct Client *client_p)
1057 * Input: A client to find the active oper{} name for.
1058 * Output: The nick!user@host{oper} of the oper.
1059 * "oper" is server name for remote opers
1060 * Side effects: None.
1063 get_oper_name(struct Client
*client_p
)
1065 /* +5 for !,@,{,} and null */
1066 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1068 if(MyOper(client_p
))
1070 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1071 client_p
->name
, client_p
->username
,
1072 client_p
->host
, client_p
->localClient
->opername
);
1076 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1077 client_p
->name
, client_p
->username
,
1078 client_p
->host
, client_p
->servptr
->name
);
1083 * get_printable_conf
1085 * inputs - struct ConfItem
1094 * Examine the struct struct ConfItem, setting the values
1095 * of name, host, pass, user to values either
1096 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1099 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1100 char **pass
, char **user
, int *port
, char **classname
)
1102 static char null
[] = "<NULL>";
1103 static char zero
[] = "default";
1105 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1106 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1107 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1108 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1109 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1110 *port
= (int) aconf
->port
;
1114 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1115 char **host
, char **reason
,
1116 char **user
, char **oper_reason
)
1118 static char null
[] = "<NULL>";
1120 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1121 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1122 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1124 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1125 *oper_reason
= NULL
;
1127 *oper_reason
= aconf
->spasswd
;
1133 * inputs - cold start YES or NO
1135 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1138 read_conf_files(int cold
)
1140 const char *filename
;
1142 conf_fbfile_in
= NULL
;
1144 filename
= get_conf_name(CONF_TYPE
);
1146 /* We need to know the initial filename for the yyerror() to report
1147 FIXME: The full path is in conffilenamebuf first time since we
1148 dont know anything else
1152 strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1154 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1158 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1163 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1164 "Can't open file '%s' - aborting rehash!", filename
);
1171 clear_out_old_conf();
1174 read_conf(conf_fbfile_in
);
1175 fclose(conf_fbfile_in
);
1179 * clear_out_old_conf
1183 * side effects - Clear out the old configuration
1186 clear_out_old_conf(void)
1188 struct Class
*cltmp
;
1190 dlink_node
*next_ptr
;
1194 * don't delete the class table, rather mark all entries
1195 * for deletion. The table is cleaned up by check_class. - avalon
1197 DLINK_FOREACH(ptr
, class_list
.head
)
1200 MaxUsers(cltmp
) = -1;
1203 clear_out_address_conf();
1206 /* clean out module paths */
1207 #ifndef STATIC_MODULES
1209 mod_add_path(MODULE_DIR
);
1210 mod_add_path(MODULE_DIR
"/autoload");
1213 /* clean out ServerInfo */
1214 MyFree(ServerInfo
.description
);
1215 ServerInfo
.description
= NULL
;
1216 MyFree(ServerInfo
.network_name
);
1217 ServerInfo
.network_name
= NULL
;
1218 MyFree(ServerInfo
.network_desc
);
1219 ServerInfo
.network_desc
= NULL
;
1221 /* clean out AdminInfo */
1222 MyFree(AdminInfo
.name
);
1223 AdminInfo
.name
= NULL
;
1224 MyFree(AdminInfo
.email
);
1225 AdminInfo
.email
= NULL
;
1226 MyFree(AdminInfo
.description
);
1227 AdminInfo
.description
= NULL
;
1229 /* operator{} and class{} blocks are freed above */
1230 /* clean out listeners */
1233 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1234 * and gecos{} blocks are freed above too
1237 /* clean out general */
1238 MyFree(ConfigFileEntry
.servlink_path
);
1239 ConfigFileEntry
.servlink_path
= NULL
;
1241 DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1244 dlinkDestroy(ptr
, &service_list
);
1247 /* remove any aliases... -- nenolod */
1248 for (i
= 0; i
< MAX_MSG_HASH
; i
++)
1250 DLINK_FOREACH_SAFE(ptr
, next_ptr
, alias_hash_table
[i
].head
)
1252 struct alias_entry
*aptr
= ptr
->data
;
1255 MyFree(aptr
->target
);
1258 dlinkDestroy(ptr
, &alias_hash_table
[i
]);
1262 destroy_blacklists();
1264 /* OK, that should be everything... */
1270 * inputs - kline, dline or resv type flag
1271 * - client pointer to report to
1272 * - user name of target
1273 * - host name of target
1274 * - reason for target
1278 * side effects - This function takes care of finding the right conf
1279 * file and adding the line to it, as well as notifying
1280 * opers and the user.
1283 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1284 char *host
, const char *reason
, const char *oper_reason
,
1285 const char *current_date
, int xtype
)
1289 const char *filename
; /* filename to use for kline */
1291 filename
= get_conf_name(type
);
1294 if((out
= fopen(filename
, "a")) == NULL
)
1296 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1300 if(oper_reason
== NULL
)
1303 if(type
== KLINE_TYPE
)
1305 ircsnprintf(buffer
, sizeof(buffer
),
1306 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1307 user
, host
, reason
, oper_reason
, current_date
,
1308 get_oper_name(source_p
), CurrentTime
);
1310 else if(type
== DLINE_TYPE
)
1312 ircsnprintf(buffer
, sizeof(buffer
),
1313 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1314 reason
, oper_reason
, current_date
, get_oper_name(source_p
), CurrentTime
);
1316 else if(type
== RESV_TYPE
)
1318 ircsnprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1319 host
, reason
, get_oper_name(source_p
), CurrentTime
);
1322 if(fputs(buffer
, out
) == -1)
1324 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1331 if(type
== KLINE_TYPE
)
1333 if(EmptyString(oper_reason
))
1335 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1336 "%s added K-Line for [%s@%s] [%s]",
1337 get_oper_name(source_p
), user
,
1339 ilog(L_KLINE
, "K %s 0 %s %s %s",
1340 get_oper_name(source_p
), user
, host
, reason
);
1344 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1345 "%s added K-Line for [%s@%s] [%s|%s]",
1346 get_oper_name(source_p
), user
,
1347 host
, reason
, oper_reason
);
1348 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1349 get_oper_name(source_p
), user
, host
,
1350 reason
, oper_reason
);
1353 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1356 else if(type
== DLINE_TYPE
)
1358 if(EmptyString(oper_reason
))
1360 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1361 "%s added D-Line for [%s] [%s]",
1362 get_oper_name(source_p
), host
, reason
);
1363 ilog(L_KLINE
, "D %s 0 %s %s",
1364 get_oper_name(source_p
), host
, reason
);
1368 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
1369 "%s added D-Line for [%s] [%s|%s]",
1370 get_oper_name(source_p
), host
,
1371 reason
, oper_reason
);
1372 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1373 get_oper_name(source_p
), host
,
1374 reason
, oper_reason
);
1377 sendto_one(source_p
,
1378 ":%s NOTICE %s :Added D-Line [%s] to %s", me
.name
,
1379 source_p
->name
, host
, filename
);
1382 else if(type
== RESV_TYPE
)
1384 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1385 "%s added RESV for [%s] [%s]",
1386 get_oper_name(source_p
), host
, reason
);
1387 ilog(L_KLINE
, "R %s 0 %s %s",
1388 get_oper_name(source_p
), host
, reason
);
1390 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
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 DupString(aconf
->className
, "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 MyFree(aconf
->className
);
1449 DupString(aconf
->className
, "default");
1453 if(ConfMaxUsers(aconf
) < 0)
1455 ClassPtr(aconf
) = default_class
;
1456 MyFree(aconf
->className
);
1457 DupString(aconf
->className
, "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
, aconf
);
1495 * inputs - message from parser
1497 * side effects - message to opers and log file entry is made
1500 yyerror(const char *msg
)
1502 char newlinebuf
[BUFSIZE
];
1504 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1506 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1507 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1509 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1513 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1517 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1520 return (strlen(lbuf
));
1524 conf_yy_fatal_error(const char *msg
)