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"
31 #include "s_newconf.h"
40 #include "irc_string.h"
41 #include "sprintf_irc.h"
56 #include "blacklist.h"
58 struct config_server_hide ConfigServerHide
;
60 extern int yyparse(); /* defined in y.tab.c */
61 extern char linebuf
[];
64 #define INADDR_NONE ((unsigned int) 0xffffffff)
67 static BlockHeap
*confitem_heap
= NULL
;
69 dlink_list temp_klines
[LAST_TEMP_TYPE
];
70 dlink_list temp_dlines
[LAST_TEMP_TYPE
];
71 dlink_list service_list
;
73 /* internally defined functions */
74 static void set_default_conf(void);
75 static void validate_conf(void);
76 static void read_conf(FILE *);
77 static void clear_out_old_conf(void);
79 static void expire_temp_kd(void *list
);
80 static void reorganise_temp_kd(void *list
);
85 static int verify_access(struct Client
*client_p
, const char *username
);
86 static int attach_iline(struct Client
*, struct ConfItem
*);
91 confitem_heap
= BlockHeapCreate(sizeof(struct ConfItem
), CONFITEM_HEAP_SIZE
);
93 eventAddIsh("expire_temp_klines", expire_temp_kd
, &temp_klines
[TEMP_MIN
], 60);
94 eventAddIsh("expire_temp_dlines", expire_temp_kd
, &temp_dlines
[TEMP_MIN
], 60);
96 eventAddIsh("expire_temp_klines_hour", reorganise_temp_kd
,
97 &temp_klines
[TEMP_HOUR
], 3600);
98 eventAddIsh("expire_temp_dlines_hour", reorganise_temp_kd
,
99 &temp_dlines
[TEMP_HOUR
], 3600);
100 eventAddIsh("expire_temp_klines_day", reorganise_temp_kd
,
101 &temp_klines
[TEMP_DAY
], 86400);
102 eventAddIsh("expire_temp_dlines_day", reorganise_temp_kd
,
103 &temp_dlines
[TEMP_DAY
], 86400);
104 eventAddIsh("expire_temp_klines_week", reorganise_temp_kd
,
105 &temp_klines
[TEMP_WEEK
], 604800);
106 eventAddIsh("expire_temp_dlines_week", reorganise_temp_kd
,
107 &temp_dlines
[TEMP_WEEK
], 604800);
114 * output - pointer to new conf entry
115 * side effects - none
120 struct ConfItem
*aconf
;
122 aconf
= BlockHeapAlloc(confitem_heap
);
123 aconf
->status
= CONF_ILLEGAL
;
130 * inputs - pointer to conf to free
132 * side effects - crucial password fields are zeroed, conf is freed
135 free_conf(struct ConfItem
*aconf
)
137 s_assert(aconf
!= NULL
);
143 memset(aconf
->passwd
, 0, strlen(aconf
->passwd
));
145 memset(aconf
->spasswd
, 0, strlen(aconf
->spasswd
));
147 MyFree(aconf
->passwd
);
148 MyFree(aconf
->spasswd
);
150 MyFree(aconf
->className
);
154 BlockHeapFree(confitem_heap
, aconf
);
160 * inputs - pointer to client
161 * output - 0 = Success
162 * NOT_AUTHORISED (-1) = Access denied (no I line match)
163 * SOCKET_ERROR (-2) = Bad socket.
164 * I_LINE_FULL (-3) = I-line is full
165 * TOO_MANY (-4) = Too many connections from hostname
166 * BANNED_CLIENT (-5) = K-lined
167 * side effects - Ordinary client access check.
168 * Look for conf lines which have the same
169 * status as the flags passed.
172 check_client(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
176 if((i
= verify_access(source_p
, username
)))
178 ilog(L_FUSER
, "Access denied: %s[%s]",
179 source_p
->name
, source_p
->sockhost
);
185 exit_client(client_p
, source_p
, &me
, "Socket Error");
189 /* Note that these notices are sent to opers on other
190 * servers also, so even if local opers are allowed to
191 * see the IP, we still cannot send it.
193 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
194 "Too many local connections for %s!%s%s@%s",
195 source_p
->name
, IsGotId(source_p
) ? "" : "~",
197 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
199 ilog(L_FUSER
, "Too many local connections from %s!%s%s@%s",
200 source_p
->name
, IsGotId(source_p
) ? "" : "~",
201 source_p
->username
, source_p
->sockhost
);
203 ServerStats
->is_ref
++;
204 exit_client(client_p
, source_p
, &me
, "Too many host connections (local)");
207 case TOO_MANY_GLOBAL
:
208 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
209 "Too many global connections for %s!%s%s@%s",
210 source_p
->name
, IsGotId(source_p
) ? "" : "~",
212 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
213 ilog(L_FUSER
, "Too many global connections from %s!%s%s@%s",
214 source_p
->name
, IsGotId(source_p
) ? "" : "~",
215 source_p
->username
, source_p
->sockhost
);
217 ServerStats
->is_ref
++;
218 exit_client(client_p
, source_p
, &me
, "Too many host connections (global)");
222 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
223 "Too many user connections for %s!%s%s@%s",
224 source_p
->name
, IsGotId(source_p
) ? "" : "~",
226 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: source_p
->host
);
227 ilog(L_FUSER
, "Too many user connections from %s!%s%s@%s",
228 source_p
->name
, IsGotId(source_p
) ? "" : "~",
229 source_p
->username
, source_p
->sockhost
);
231 ServerStats
->is_ref
++;
232 exit_client(client_p
, source_p
, &me
, "Too many user connections (global)");
236 sendto_realops_snomask(SNO_FULL
, L_NETWIDE
,
237 "I-line is full for %s!%s%s@%s (%s).",
238 source_p
->name
, IsGotId(source_p
) ? "" : "~",
239 source_p
->username
, source_p
->host
,
240 show_ip(NULL
, source_p
) && !IsIPSpoof(source_p
) ? source_p
->sockhost
: "255.255.255.255");
242 ilog(L_FUSER
, "Too many connections from %s!%s%s@%s.",
243 source_p
->name
, IsGotId(source_p
) ? "" : "~",
244 source_p
->username
, source_p
->sockhost
);
246 ServerStats
->is_ref
++;
247 exit_client(client_p
, source_p
, &me
,
248 "No more connections allowed in your connection class");
255 if(source_p
->localClient
->ip
.ss_family
== AF_INET6
)
256 port
= ntohs(((struct sockaddr_in6
*)&source_p
->localClient
->listener
->addr
)->sin6_port
);
259 port
= ntohs(((struct sockaddr_in
*)&source_p
->localClient
->listener
->addr
)->sin_port
);
261 ServerStats
->is_ref
++;
262 /* jdc - lists server name & port connections are on */
263 /* a purely cosmetical change */
264 /* why ipaddr, and not just source_p->sockhost? --fl */
266 static char ipaddr
[HOSTIPLEN
];
267 inetntop_sock(&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
269 sendto_realops_snomask(SNO_UNAUTH
, L_ALL
,
270 "Unauthorised client connection from "
271 "%s!%s%s@%s [%s] on [%s/%u].",
272 source_p
->name
, IsGotId(source_p
) ? "" : "~",
273 source_p
->username
, source_p
->host
,
275 source_p
->localClient
->listener
->name
, port
);
278 "Unauthorised client connection from %s!%s%s@%s on [%s/%u].",
279 source_p
->name
, IsGotId(source_p
) ? "" : "~",
280 source_p
->username
, source_p
->sockhost
,
281 source_p
->localClient
->listener
->name
, port
);
282 add_reject(client_p
, NULL
, NULL
);
283 exit_client(client_p
, source_p
, &me
,
284 "You are not authorised to use this server");
288 exit_client(client_p
, client_p
, &me
, "*** Banned ");
289 ServerStats
->is_ref
++;
302 * inputs - pointer to client to verify
303 * - pointer to proposed username
304 * output - 0 if success -'ve if not
305 * side effect - find the first (best) I line to attach.
308 verify_access(struct Client
*client_p
, const char *username
)
310 struct ConfItem
*aconf
;
311 char non_ident
[USERLEN
+ 1];
313 if(IsGotId(client_p
))
315 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
316 client_p
->username
, client_p
->username
,
317 (struct sockaddr
*) &client_p
->localClient
->ip
,
318 client_p
->localClient
->ip
.ss_family
);
322 strlcpy(non_ident
, "~", sizeof(non_ident
));
323 strlcat(non_ident
, username
, sizeof(non_ident
));
324 aconf
= find_address_conf(client_p
->host
, client_p
->sockhost
,
325 non_ident
, client_p
->username
,
326 (struct sockaddr
*) &client_p
->localClient
->ip
,
327 client_p
->localClient
->ip
.ss_family
);
331 return NOT_AUTHORISED
;
333 if(aconf
->status
& CONF_CLIENT
)
335 if(aconf
->flags
& CONF_FLAGS_REDIR
)
337 sendto_one_numeric(client_p
, RPL_REDIR
, form_str(RPL_REDIR
),
338 aconf
->name
? aconf
->name
: "", aconf
->port
);
339 return (NOT_AUTHORISED
);
342 /* Thanks for spoof idea amm */
343 if(IsConfDoSpoofIp(aconf
))
347 /* show_ip() depends on this --fl */
348 SetIPSpoof(client_p
);
350 if(IsConfSpoofNotice(aconf
))
352 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
353 "%s spoofing: %s as %s",
355 show_ip(NULL
, client_p
) ? client_p
->host
: aconf
->name
,
359 /* user@host spoof */
360 if((p
= strchr(aconf
->name
, '@')) != NULL
)
365 strlcpy(client_p
->username
, aconf
->name
,
366 sizeof(client_p
->username
));
367 strlcpy(client_p
->host
, host
,
368 sizeof(client_p
->host
));
372 strlcpy(client_p
->host
, aconf
->name
, sizeof(client_p
->host
));
374 return (attach_iline(client_p
, aconf
));
376 else if(aconf
->status
& CONF_KILL
)
378 if(ConfigFileEntry
.kline_with_reason
)
381 form_str(ERR_YOUREBANNEDCREEP
),
382 me
.name
, client_p
->name
, aconf
->passwd
);
384 add_reject(client_p
, aconf
->user
, aconf
->host
);
385 return (BANNED_CLIENT
);
387 else if(aconf
->status
& CONF_GLINE
)
389 sendto_one_notice(client_p
, ":*** G-lined");
391 if(ConfigFileEntry
.kline_with_reason
)
393 form_str(ERR_YOUREBANNEDCREEP
),
394 me
.name
, client_p
->name
, aconf
->passwd
);
396 add_reject(client_p
, aconf
->user
, aconf
->host
);
397 return (BANNED_CLIENT
);
400 return NOT_AUTHORISED
;
407 * Returns 1 if successful 0 if not
409 * This checks if the user has exceed the limits for their class
410 * unless of course they are exempt..
414 add_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
416 patricia_node_t
*pnode
;
418 /* If the limits are 0 don't do anything.. */
419 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
422 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
425 pnode
= make_and_lookup_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
, ConfCidrBitlen(aconf
));
427 s_assert(pnode
!= NULL
);
431 if(((long) pnode
->data
) >= ConfCidrAmount(aconf
)
432 && !IsConfExemptLimits(aconf
))
434 /* This should only happen if the limits are set to 0 */
435 if((unsigned long) pnode
->data
== 0)
437 patricia_remove(ConfIpLimits(aconf
), pnode
);
448 remove_ip_limit(struct Client
*client_p
, struct ConfItem
*aconf
)
450 patricia_node_t
*pnode
;
452 /* If the limits are 0 don't do anything.. */
453 if(ConfCidrAmount(aconf
) == 0 || ConfCidrBitlen(aconf
) == 0)
456 pnode
= match_ip(ConfIpLimits(aconf
), (struct sockaddr
*)&client_p
->localClient
->ip
);
461 if(((unsigned long) pnode
->data
) == 0)
463 patricia_remove(ConfIpLimits(aconf
), pnode
);
471 * inputs - client pointer
474 * side effects - do actual attach
477 attach_iline(struct Client
*client_p
, struct ConfItem
*aconf
)
479 struct Client
*target_p
;
482 int global_count
= 0;
486 if(IsConfExemptLimits(aconf
))
487 return (attach_conf(client_p
, aconf
));
489 if(*client_p
->username
== '~')
493 /* find_hostname() returns the head of the list to search */
494 DLINK_FOREACH(ptr
, find_hostname(client_p
->host
))
496 target_p
= ptr
->data
;
498 if(irccmp(client_p
->host
, target_p
->orighost
) != 0)
501 if(MyConnect(target_p
))
508 if(*target_p
->username
== '~')
511 else if(irccmp(target_p
->username
, client_p
->username
) == 0)
514 if(ConfMaxLocal(aconf
) && local_count
>= ConfMaxLocal(aconf
))
515 return (TOO_MANY_LOCAL
);
516 else if(ConfMaxGlobal(aconf
) && global_count
>= ConfMaxGlobal(aconf
))
517 return (TOO_MANY_GLOBAL
);
518 else if(ConfMaxIdent(aconf
) && ident_count
>= ConfMaxIdent(aconf
))
519 return (TOO_MANY_IDENT
);
523 return (attach_conf(client_p
, aconf
));
529 * inputs - pointer to client to detach
530 * output - 0 for success, -1 for failure
531 * side effects - Disassociate configuration from the client.
532 * Also removes a class from the list if marked for deleting.
535 detach_conf(struct Client
*client_p
)
537 struct ConfItem
*aconf
;
539 aconf
= client_p
->localClient
->att_conf
;
545 remove_ip_limit(client_p
, aconf
);
547 if(ConfCurrUsers(aconf
) > 0)
548 --ConfCurrUsers(aconf
);
550 if(ConfMaxUsers(aconf
) == -1 && ConfCurrUsers(aconf
) == 0)
552 free_class(ClassPtr(aconf
));
553 ClassPtr(aconf
) = NULL
;
559 if(!aconf
->clients
&& IsIllegal(aconf
))
562 client_p
->localClient
->att_conf
= NULL
;
572 * inputs - client pointer
575 * side effects - Associate a specific configuration entry to a *local*
576 * client (this is the one which used in accepting the
577 * connection). Note, that this automatically changes the
578 * attachment if there was an old one...
581 attach_conf(struct Client
*client_p
, struct ConfItem
*aconf
)
584 return (NOT_AUTHORISED
);
588 if(!add_ip_limit(client_p
, aconf
))
589 return (TOO_MANY_LOCAL
);
592 if((aconf
->status
& CONF_CLIENT
) &&
593 ConfCurrUsers(aconf
) >= ConfMaxUsers(aconf
) && ConfMaxUsers(aconf
) > 0)
595 if(!IsConfExemptLimits(aconf
))
597 return (I_LINE_FULL
);
601 sendto_one_notice(client_p
, ":*** I: line is full, but you have an >I: line!");
602 SetExemptLimits(client_p
);
607 if(client_p
->localClient
->att_conf
!= NULL
)
608 detach_conf(client_p
);
610 client_p
->localClient
->att_conf
= aconf
;
613 ConfCurrUsers(aconf
)++;
620 * Actual REHASH service routine. Called with sig == 0 if it has been called
621 * as a result of an operator issuing this command, else assume it has been
622 * called as a result of the server receiving a HUP signal.
629 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
630 "Got signal SIGHUP, reloading ircd conf. file");
634 /* don't close listeners until we know we can go ahead with the rehash */
637 if(ServerInfo
.description
!= NULL
)
638 strlcpy(me
.info
, ServerInfo
.description
, sizeof(me
.info
));
640 strlcpy(me
.info
, "unknown", sizeof(me
.info
));
646 static struct banconf_entry
648 const char **filename
;
649 void (*func
) (FILE *);
652 { &ConfigFileEntry
.klinefile
, parse_k_file
, 0 },
653 { &ConfigFileEntry
.klinefile
, parse_k_file
, 1 },
654 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 0 },
655 { &ConfigFileEntry
.dlinefile
, parse_d_file
, 1 },
656 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 0 },
657 { &ConfigFileEntry
.xlinefile
, parse_x_file
, 1 },
658 { &ConfigFileEntry
.resvfile
, parse_resv_file
,0 },
659 { &ConfigFileEntry
.resvfile
, parse_resv_file
,1 },
667 char buf
[MAXPATHLEN
];
671 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
672 "Got signal SIGUSR2, reloading ban confs");
674 clear_out_address_conf_bans();
675 clear_s_newconf_bans();
677 for(i
= 0; banconfs
[i
].filename
; i
++)
680 snprintf(buf
, sizeof(buf
), "%s.perm", *banconfs
[i
].filename
);
682 snprintf(buf
, sizeof(buf
), "%s", *banconfs
[i
].filename
);
684 if((file
= fopen(buf
, "r")) == NULL
)
689 ilog(L_MAIN
, "Failed reading ban file %s",
690 *banconfs
[i
].filename
);
691 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
692 "Can't open %s file bans could be missing!",
693 *banconfs
[i
].filename
);
697 (banconfs
[i
].func
)(file
);
702 check_banned_lines();
710 * side effects - Set default values here.
711 * This is called **PRIOR** to parsing the
712 * configuration file. If you want to do some validation
713 * of values later, put them in validate_conf().
721 set_default_conf(void)
723 /* ServerInfo.name is not rehashable */
724 /* ServerInfo.name = ServerInfo.name; */
725 ServerInfo
.description
= NULL
;
726 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
727 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
729 memset(&ServerInfo
.ip
, 0, sizeof(ServerInfo
.ip
));
730 ServerInfo
.specific_ipv4_vhost
= 0;
732 memset(&ServerInfo
.ip6
, 0, sizeof(ServerInfo
.ip6
));
733 ServerInfo
.specific_ipv6_vhost
= 0;
736 /* Don't reset hub, as that will break lazylinks */
737 /* ServerInfo.hub = NO; */
738 AdminInfo
.name
= NULL
;
739 AdminInfo
.email
= NULL
;
740 AdminInfo
.description
= NULL
;
742 DupString(ConfigFileEntry
.default_operstring
, "is an IRC operator");
743 DupString(ConfigFileEntry
.default_adminstring
, "is a Server Administrator");
744 DupString(ConfigFileEntry
.servicestring
, "is a Network Service");
746 ConfigFileEntry
.default_umodes
= UMODE_INVISIBLE
;
747 ConfigFileEntry
.failed_oper_notice
= YES
;
748 ConfigFileEntry
.anti_nick_flood
= NO
;
749 ConfigFileEntry
.disable_fake_channels
= NO
;
750 ConfigFileEntry
.max_nick_time
= 20;
751 ConfigFileEntry
.max_nick_changes
= 5;
752 ConfigFileEntry
.max_accept
= 20;
753 ConfigFileEntry
.max_monitor
= 60;
754 ConfigFileEntry
.nick_delay
= 900; /* 15 minutes */
755 ConfigFileEntry
.target_change
= YES
;
756 ConfigFileEntry
.anti_spam_exit_message_time
= 0;
757 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
758 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
759 ConfigFileEntry
.client_exit
= YES
;
760 ConfigFileEntry
.dline_with_reason
= YES
;
761 ConfigFileEntry
.kline_with_reason
= YES
;
762 ConfigFileEntry
.kline_delay
= 0;
763 ConfigFileEntry
.warn_no_nline
= YES
;
764 ConfigFileEntry
.non_redundant_klines
= YES
;
765 ConfigFileEntry
.stats_e_disabled
= NO
;
766 ConfigFileEntry
.stats_o_oper_only
= NO
;
767 ConfigFileEntry
.stats_k_oper_only
= 1; /* masked */
768 ConfigFileEntry
.stats_i_oper_only
= 1; /* masked */
769 ConfigFileEntry
.stats_P_oper_only
= NO
;
770 ConfigFileEntry
.stats_c_oper_only
= NO
;
771 ConfigFileEntry
.stats_y_oper_only
= NO
;
772 ConfigFileEntry
.stats_h_oper_only
= NO
;
773 ConfigFileEntry
.map_oper_only
= YES
;
774 ConfigFileEntry
.operspy_admin_only
= NO
;
775 ConfigFileEntry
.pace_wait
= 10;
776 ConfigFileEntry
.caller_id_wait
= 60;
777 ConfigFileEntry
.pace_wait_simple
= 1;
778 ConfigFileEntry
.short_motd
= NO
;
779 ConfigFileEntry
.no_oper_flood
= NO
;
780 ConfigFileEntry
.fname_userlog
= NULL
;
781 ConfigFileEntry
.fname_fuserlog
= NULL
;
782 ConfigFileEntry
.fname_operlog
= NULL
;
783 ConfigFileEntry
.fname_foperlog
= NULL
;
784 ConfigFileEntry
.fname_serverlog
= NULL
;
785 ConfigFileEntry
.fname_glinelog
= NULL
;
786 ConfigFileEntry
.fname_klinelog
= NULL
;
787 ConfigFileEntry
.fname_operspylog
= NULL
;
788 ConfigFileEntry
.fname_ioerrorlog
= NULL
;
789 ConfigFileEntry
.glines
= NO
;
790 ConfigFileEntry
.use_egd
= NO
;
791 ConfigFileEntry
.gline_time
= 12 * 3600;
792 ConfigFileEntry
.gline_min_cidr
= 16;
793 ConfigFileEntry
.gline_min_cidr6
= 48;
794 ConfigFileEntry
.hide_spoof_ips
= YES
;
795 ConfigFileEntry
.hide_error_messages
= 1;
796 ConfigFileEntry
.idletime
= 0;
797 ConfigFileEntry
.dots_in_ident
= 0;
798 ConfigFileEntry
.max_targets
= MAX_TARGETS_DEFAULT
;
799 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
800 ConfigFileEntry
.egdpool_path
= NULL
;
801 ConfigFileEntry
.use_whois_actually
= YES
;
802 ConfigFileEntry
.burst_away
= NO
;
803 ConfigFileEntry
.collision_fnc
= YES
;
804 ConfigFileEntry
.global_snotices
= YES
;
805 ConfigFileEntry
.operspy_dont_care_user_info
= NO
;
808 ConfigFileEntry
.compression_level
= 4;
811 ConfigFileEntry
.oper_umodes
= UMODE_LOCOPS
| UMODE_SERVNOTICE
|
812 UMODE_OPERWALL
| UMODE_WALLOP
;
813 ConfigFileEntry
.oper_only_umodes
= UMODE_SERVNOTICE
;
814 ConfigFileEntry
.oper_snomask
= SNO_GENERAL
;
816 ConfigChannel
.use_except
= YES
;
817 ConfigChannel
.use_invex
= YES
;
818 ConfigChannel
.use_knock
= YES
;
819 ConfigChannel
.use_forward
= YES
;
820 ConfigChannel
.knock_delay
= 300;
821 ConfigChannel
.knock_delay_channel
= 60;
822 ConfigChannel
.max_chans_per_user
= 15;
823 ConfigChannel
.max_bans
= 25;
824 ConfigChannel
.max_bans_large
= 500;
825 ConfigChannel
.burst_topicwho
= NO
;
826 ConfigChannel
.kick_on_split_riding
= NO
;
828 ConfigChannel
.default_split_user_count
= 15000;
829 ConfigChannel
.default_split_server_count
= 10;
830 ConfigChannel
.no_join_on_split
= NO
;
831 ConfigChannel
.no_create_on_split
= YES
;
833 ConfigServerHide
.flatten_links
= 0;
834 ConfigServerHide
.links_delay
= 300;
835 ConfigServerHide
.hidden
= 0;
836 ConfigServerHide
.disable_hidden
= 0;
838 ConfigFileEntry
.min_nonwildcard
= 4;
839 ConfigFileEntry
.min_nonwildcard_simple
= 3;
840 ConfigFileEntry
.default_floodcount
= 8;
841 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_DEFAULT
;
842 ConfigFileEntry
.tkline_expire_notices
= 0;
844 ConfigFileEntry
.reject_after_count
= 5;
845 ConfigFileEntry
.reject_ban_time
= 300;
846 ConfigFileEntry
.reject_duration
= 120;
847 ConfigFileEntry
.max_unknown_ip
= 2;
849 ServerInfo
.max_clients
= comm_get_maxconnections() - MAX_BUFFER
;
859 * inputs - file descriptor pointing to config file to use
861 * side effects - Read configuration file.
864 read_conf(FILE * file
)
868 set_default_conf(); /* Set default values prior to conf parsing */
869 yyparse(); /* Load the values from the conf */
870 validate_conf(); /* Check to make sure some values are still okay. */
871 /* Some global values are also loaded here. */
872 check_class(); /* Make sure classes are valid */
878 if(ConfigFileEntry
.ts_warn_delta
< TS_WARN_DELTA_MIN
)
879 ConfigFileEntry
.ts_warn_delta
= TS_WARN_DELTA_DEFAULT
;
881 if(ConfigFileEntry
.ts_max_delta
< TS_MAX_DELTA_MIN
)
882 ConfigFileEntry
.ts_max_delta
= TS_MAX_DELTA_DEFAULT
;
884 if(ConfigFileEntry
.servlink_path
== NULL
)
885 DupString(ConfigFileEntry
.servlink_path
, SLPATH
);
887 if(ServerInfo
.network_name
== NULL
)
888 DupString(ServerInfo
.network_name
, NETWORK_NAME_DEFAULT
);
890 if(ServerInfo
.network_desc
== NULL
)
891 DupString(ServerInfo
.network_desc
, NETWORK_DESC_DEFAULT
);
893 if((ConfigFileEntry
.client_flood
< CLIENT_FLOOD_MIN
) ||
894 (ConfigFileEntry
.client_flood
> CLIENT_FLOOD_MAX
))
895 ConfigFileEntry
.client_flood
= CLIENT_FLOOD_MAX
;
897 GlobalSetOptions
.idletime
= (ConfigFileEntry
.idletime
* 60);
899 if(!split_users
|| !split_servers
||
900 (!ConfigChannel
.no_create_on_split
&& !ConfigChannel
.no_join_on_split
))
902 eventDelete(check_splitmode
, NULL
);
909 * lookup_confhost - start DNS lookups of all hostnames in the conf
910 * line and convert an IP addresses in a.b.c.d number for to IP#s.
915 * conf_connect_allowed
917 * inputs - pointer to inaddr
918 * - int type ipv4 or ipv6
919 * output - ban info or NULL
920 * side effects - none
923 conf_connect_allowed(struct sockaddr
*addr
, int aftype
)
925 struct ConfItem
*aconf
= find_dline(addr
, aftype
);
927 /* DLINE exempt also gets you out of static limits/pacing... */
928 if(aconf
&& (aconf
->status
& CONF_EXEMPTDLINE
))
939 * inputs - pointer to struct ConfItem
941 * Side effects - links in given struct ConfItem into
942 * temporary kline link list
945 add_temp_kline(struct ConfItem
*aconf
)
947 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
949 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_WEEK
]);
950 aconf
->port
= TEMP_WEEK
;
952 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
954 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_DAY
]);
955 aconf
->port
= TEMP_DAY
;
957 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
959 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_HOUR
]);
960 aconf
->port
= TEMP_HOUR
;
964 dlinkAddAlloc(aconf
, &temp_klines
[TEMP_MIN
]);
965 aconf
->port
= TEMP_MIN
;
968 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
969 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
974 * input - pointer to struct ConfItem
976 * side effects - added to tdline link list and address hash
979 add_temp_dline(struct ConfItem
*aconf
)
981 if(aconf
->hold
>= CurrentTime
+ (10080 * 60))
983 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_WEEK
]);
984 aconf
->port
= TEMP_WEEK
;
986 else if(aconf
->hold
>= CurrentTime
+ (1440 * 60))
988 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_DAY
]);
989 aconf
->port
= TEMP_DAY
;
991 else if(aconf
->hold
>= CurrentTime
+ (60 * 60))
993 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_HOUR
]);
994 aconf
->port
= TEMP_HOUR
;
998 dlinkAddAlloc(aconf
, &temp_dlines
[TEMP_MIN
]);
999 aconf
->port
= TEMP_MIN
;
1002 aconf
->flags
|= CONF_FLAGS_TEMPORARY
;
1003 add_conf_by_address(aconf
->host
, CONF_DLINE
, aconf
->user
, aconf
);
1008 * inputs - list pointer
1011 * side effects - expire tklines and moves them between lists
1014 expire_temp_kd(void *list
)
1017 dlink_node
*next_ptr
;
1018 struct ConfItem
*aconf
;
1020 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1024 if(aconf
->hold
<= CurrentTime
)
1026 /* Alert opers that a TKline expired - Hwy */
1027 if(ConfigFileEntry
.tkline_expire_notices
)
1028 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1029 "Temporary K-line for [%s@%s] expired",
1030 (aconf
->user
) ? aconf
->
1031 user
: "*", (aconf
->host
) ? aconf
->host
: "*");
1033 delete_one_address_conf(aconf
->host
, aconf
);
1034 dlinkDestroy(ptr
, list
);
1040 reorganise_temp_kd(void *list
)
1042 struct ConfItem
*aconf
;
1043 dlink_node
*ptr
, *next_ptr
;
1045 DLINK_FOREACH_SAFE(ptr
, next_ptr
, ((dlink_list
*) list
)->head
)
1049 if(aconf
->hold
< (CurrentTime
+ (60 * 60)))
1051 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1052 &temp_klines
[TEMP_MIN
] : &temp_dlines
[TEMP_MIN
]);
1053 aconf
->port
= TEMP_MIN
;
1055 else if(aconf
->port
> TEMP_HOUR
)
1057 if(aconf
->hold
< (CurrentTime
+ (1440 * 60)))
1059 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1060 &temp_klines
[TEMP_HOUR
] : &temp_dlines
[TEMP_HOUR
]);
1061 aconf
->port
= TEMP_HOUR
;
1063 else if(aconf
->port
> TEMP_DAY
&&
1064 (aconf
->hold
< (CurrentTime
+ (10080 * 60))))
1066 dlinkMoveNode(ptr
, list
, (aconf
->status
== CONF_KILL
) ?
1067 &temp_klines
[TEMP_DAY
] : &temp_dlines
[TEMP_DAY
]);
1068 aconf
->port
= TEMP_DAY
;
1075 /* const char* get_oper_name(struct Client *client_p)
1076 * Input: A client to find the active oper{} name for.
1077 * Output: The nick!user@host{oper} of the oper.
1078 * "oper" is server name for remote opers
1079 * Side effects: None.
1082 get_oper_name(struct Client
*client_p
)
1084 /* +5 for !,@,{,} and null */
1085 static char buffer
[NICKLEN
+ USERLEN
+ HOSTLEN
+ HOSTLEN
+ 5];
1087 if(MyOper(client_p
))
1089 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1090 client_p
->name
, client_p
->username
,
1091 client_p
->host
, client_p
->localClient
->opername
);
1095 ircsnprintf(buffer
, sizeof(buffer
), "%s!%s@%s{%s}",
1096 client_p
->name
, client_p
->username
,
1097 client_p
->host
, client_p
->servptr
->name
);
1102 * get_printable_conf
1104 * inputs - struct ConfItem
1113 * Examine the struct struct ConfItem, setting the values
1114 * of name, host, pass, user to values either
1115 * in aconf, or "<NULL>" port is set to aconf->port in all cases.
1118 get_printable_conf(struct ConfItem
*aconf
, char **name
, char **host
,
1119 char **pass
, char **user
, int *port
, char **classname
)
1121 static char null
[] = "<NULL>";
1122 static char zero
[] = "default";
1124 *name
= EmptyString(aconf
->name
) ? null
: aconf
->name
;
1125 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1126 *pass
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1127 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1128 *classname
= EmptyString(aconf
->className
) ? zero
: aconf
->className
;
1129 *port
= (int) aconf
->port
;
1133 get_printable_kline(struct Client
*source_p
, struct ConfItem
*aconf
,
1134 char **host
, char **reason
,
1135 char **user
, char **oper_reason
)
1137 static char null
[] = "<NULL>";
1139 *host
= EmptyString(aconf
->host
) ? null
: aconf
->host
;
1140 *reason
= EmptyString(aconf
->passwd
) ? null
: aconf
->passwd
;
1141 *user
= EmptyString(aconf
->user
) ? null
: aconf
->user
;
1143 if(EmptyString(aconf
->spasswd
) || !IsOper(source_p
))
1144 *oper_reason
= NULL
;
1146 *oper_reason
= aconf
->spasswd
;
1152 * inputs - cold start YES or NO
1154 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1157 read_conf_files(int cold
)
1159 const char *filename
;
1161 conf_fbfile_in
= NULL
;
1163 filename
= get_conf_name(CONF_TYPE
);
1165 /* We need to know the initial filename for the yyerror() to report
1166 FIXME: The full path is in conffilenamebuf first time since we
1167 dont know anything else
1171 strlcpy(conffilebuf
, filename
, sizeof(conffilebuf
));
1173 if((conf_fbfile_in
= fopen(filename
, "r")) == NULL
)
1177 ilog(L_MAIN
, "Failed in reading configuration file %s", filename
);
1182 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1183 "Can't open file '%s' - aborting rehash!", filename
);
1190 clear_out_old_conf();
1193 read_conf(conf_fbfile_in
);
1194 fclose(conf_fbfile_in
);
1198 * free an alias{} entry.
1201 free_alias_cb(struct DictionaryElement
*ptr
, void *unused
)
1203 struct alias_entry
*aptr
= ptr
->data
;
1206 MyFree(aptr
->target
);
1211 * clear_out_old_conf
1215 * side effects - Clear out the old configuration
1218 clear_out_old_conf(void)
1220 struct Class
*cltmp
;
1222 dlink_node
*next_ptr
;
1225 * don't delete the class table, rather mark all entries
1226 * for deletion. The table is cleaned up by check_class. - avalon
1228 DLINK_FOREACH(ptr
, class_list
.head
)
1231 MaxUsers(cltmp
) = -1;
1234 clear_out_address_conf();
1237 /* clean out module paths */
1238 #ifndef STATIC_MODULES
1240 mod_add_path(MODULE_DIR
);
1241 mod_add_path(MODULE_DIR
"/autoload");
1244 /* clean out ServerInfo */
1245 MyFree(ServerInfo
.description
);
1246 ServerInfo
.description
= NULL
;
1247 MyFree(ServerInfo
.network_name
);
1248 ServerInfo
.network_name
= NULL
;
1249 MyFree(ServerInfo
.network_desc
);
1250 ServerInfo
.network_desc
= NULL
;
1252 /* clean out AdminInfo */
1253 MyFree(AdminInfo
.name
);
1254 AdminInfo
.name
= NULL
;
1255 MyFree(AdminInfo
.email
);
1256 AdminInfo
.email
= NULL
;
1257 MyFree(AdminInfo
.description
);
1258 AdminInfo
.description
= NULL
;
1260 /* operator{} and class{} blocks are freed above */
1261 /* clean out listeners */
1264 /* auth{}, quarantine{}, shared{}, connect{}, kill{}, deny{}, exempt{}
1265 * and gecos{} blocks are freed above too
1268 /* clean out general */
1269 MyFree(ConfigFileEntry
.servlink_path
);
1270 ConfigFileEntry
.servlink_path
= NULL
;
1272 DLINK_FOREACH_SAFE(ptr
, next_ptr
, service_list
.head
)
1275 dlinkDestroy(ptr
, &service_list
);
1278 /* remove any aliases... -- nenolod */
1279 irc_dictionary_destroy(alias_dict
, free_alias_cb
, NULL
);
1282 destroy_blacklists();
1284 /* OK, that should be everything... */
1290 * inputs - kline, dline or resv type flag
1291 * - client pointer to report to
1292 * - user name of target
1293 * - host name of target
1294 * - reason for target
1298 * side effects - This function takes care of finding the right conf
1299 * file and adding the line to it, as well as notifying
1300 * opers and the user.
1303 write_confitem(KlineType type
, struct Client
*source_p
, char *user
,
1304 char *host
, const char *reason
, const char *oper_reason
,
1305 const char *current_date
, int xtype
)
1309 const char *filename
; /* filename to use for kline */
1311 filename
= get_conf_name(type
);
1313 if(type
== KLINE_TYPE
)
1315 if(EmptyString(oper_reason
))
1317 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1318 "%s added K-Line for [%s@%s] [%s]",
1319 get_oper_name(source_p
), user
,
1321 ilog(L_KLINE
, "K %s 0 %s %s %s",
1322 get_oper_name(source_p
), user
, host
, reason
);
1326 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1327 "%s added K-Line for [%s@%s] [%s|%s]",
1328 get_oper_name(source_p
), user
,
1329 host
, reason
, oper_reason
);
1330 ilog(L_KLINE
, "K %s 0 %s %s %s|%s",
1331 get_oper_name(source_p
), user
, host
,
1332 reason
, oper_reason
);
1335 sendto_one_notice(source_p
, ":Added K-Line [%s@%s]",
1338 else if(type
== DLINE_TYPE
)
1340 if(EmptyString(oper_reason
))
1342 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1343 "%s added D-Line for [%s] [%s]",
1344 get_oper_name(source_p
), host
, reason
);
1345 ilog(L_KLINE
, "D %s 0 %s %s",
1346 get_oper_name(source_p
), host
, reason
);
1350 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1351 "%s added D-Line for [%s] [%s|%s]",
1352 get_oper_name(source_p
), host
,
1353 reason
, oper_reason
);
1354 ilog(L_KLINE
, "D %s 0 %s %s|%s",
1355 get_oper_name(source_p
), host
,
1356 reason
, oper_reason
);
1359 sendto_one_notice(source_p
, ":Added D-Line [%s] to %s", host
, filename
);
1362 else if(type
== RESV_TYPE
)
1364 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1365 "%s added RESV for [%s] [%s]",
1366 get_oper_name(source_p
), host
, reason
);
1367 ilog(L_KLINE
, "R %s 0 %s %s",
1368 get_oper_name(source_p
), host
, reason
);
1370 sendto_one_notice(source_p
, ":Added RESV for [%s] [%s]",
1374 if((out
= fopen(filename
, "a")) == NULL
)
1376 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem opening %s ", filename
);
1377 sendto_one_notice(source_p
, ":*** Problem opening file, added temporarily only");
1381 if(oper_reason
== NULL
)
1384 if(type
== KLINE_TYPE
)
1386 ircsnprintf(buffer
, sizeof(buffer
),
1387 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n",
1388 user
, host
, reason
, oper_reason
, current_date
,
1389 get_oper_name(source_p
), CurrentTime
);
1391 else if(type
== DLINE_TYPE
)
1393 ircsnprintf(buffer
, sizeof(buffer
),
1394 "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host
,
1395 reason
, oper_reason
, current_date
, get_oper_name(source_p
), CurrentTime
);
1397 else if(type
== RESV_TYPE
)
1399 ircsnprintf(buffer
, sizeof(buffer
), "\"%s\",\"%s\",\"%s\",%ld\n",
1400 host
, reason
, get_oper_name(source_p
), CurrentTime
);
1403 if(fputs(buffer
, out
) == -1)
1405 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1406 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1413 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "*** Problem writing to %s", filename
);
1414 sendto_one_notice(source_p
, ":*** Problem writing to file, added temporarily only");
1421 * inputs - type of conf file to return name of file for
1422 * output - pointer to filename for type of conf
1423 * side effects - none
1426 get_conf_name(KlineType type
)
1428 if(type
== CONF_TYPE
)
1430 return (ConfigFileEntry
.configfile
);
1432 else if(type
== DLINE_TYPE
)
1434 return (ConfigFileEntry
.dlinefile
);
1436 else if(type
== RESV_TYPE
)
1438 return (ConfigFileEntry
.resvfile
);
1441 return ConfigFileEntry
.klinefile
;
1445 * conf_add_class_to_conf
1446 * inputs - pointer to config item
1448 * side effects - Add a class pointer to a conf
1452 conf_add_class_to_conf(struct ConfItem
*aconf
)
1454 if(aconf
->className
== NULL
)
1456 DupString(aconf
->className
, "default");
1457 ClassPtr(aconf
) = default_class
;
1461 ClassPtr(aconf
) = find_class(aconf
->className
);
1463 if(ClassPtr(aconf
) == default_class
)
1465 if(aconf
->status
== CONF_CLIENT
)
1467 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1468 "Warning -- Using default class for missing class \"%s\" in auth{} for %s@%s",
1469 aconf
->className
, aconf
->user
, aconf
->host
);
1472 MyFree(aconf
->className
);
1473 DupString(aconf
->className
, "default");
1477 if(ConfMaxUsers(aconf
) < 0)
1479 ClassPtr(aconf
) = default_class
;
1480 MyFree(aconf
->className
);
1481 DupString(aconf
->className
, "default");
1488 * inputs - pointer to config item
1490 * side effects - Add a d/D line
1493 conf_add_d_conf(struct ConfItem
*aconf
)
1495 if(aconf
->host
== NULL
)
1500 /* XXX - Should 'd' ever be in the old conf? For new conf we don't
1501 * need this anyway, so I will disable it for now... -A1kmm
1504 if(parse_netmask(aconf
->host
, NULL
, NULL
) == HM_HOST
)
1506 ilog(L_MAIN
, "Invalid Dline %s ignored", aconf
->host
);
1511 add_conf_by_address(aconf
->host
, CONF_DLINE
, NULL
, aconf
);
1519 * inputs - message from parser
1521 * side effects - message to opers and log file entry is made
1524 yyerror(const char *msg
)
1526 char newlinebuf
[BUFSIZE
];
1528 strip_tabs(newlinebuf
, (const unsigned char *) linebuf
, strlen(linebuf
));
1530 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "\"%s\", line %d: %s at '%s'",
1531 conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1533 ilog(L_MAIN
, "\"%s\", line %d: %s at '%s'", conffilebuf
, lineno
+ 1, msg
, newlinebuf
);
1537 conf_fgets(char *lbuf
, int max_size
, FILE * fb
)
1541 if((buff
= fgets(lbuf
, max_size
, fb
)) == NULL
)
1544 return (strlen(lbuf
));
1548 conf_yy_fatal_error(const char *msg
)