1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 03:53:12 +02:00

- Rewrote check_pings and the whole way banning people are handled. Do loop.do_banch

to provoke a bans check. This possibly fixes #00001702, #0000137 and other
  funny bugs.
This commit is contained in:
stskeeps
2002-05-10 15:50:54 +00:00
parent e1f991f196
commit 1ccd58d2a2
13 changed files with 179 additions and 200 deletions
+3
View File
@@ -1286,3 +1286,6 @@ seen. gmtime warning still there
- Fixed a bug with \r\n being mistakenly parsed wrong. Thanks to John_z
- Fixed a config parser bug that would cause a crash under certain conditions. Reported by
roskecr (#0000173)
- Rewrote check_pings and the whole way banning people are handled. Do loop.do_bancheck = 1
to provoke a bans check. This possibly fixes #00001702, #0000137 and other
funny bugs.
+1 -1
View File
@@ -45,7 +45,7 @@ extern struct stats *ircstp;
extern int bootopt;
extern time_t TSoffset;
/* Prototype added to force errors -- Barubary */
extern TS check_pings(TS now, int check_kills);
extern TS check_pings(TS now);
extern TS TS2ts(char *s);
extern time_t timeofday;
/* newconf */
-1
View File
@@ -56,7 +56,6 @@ char *my_itoa(int i);
/* s_kline.c */
int find_tkline_match(aClient *cptr, int xx);
extern EVENT(tkl_check_expire);
int tkl_sweep(void);
/* s_serv.c */
void load_tunefile(void);
+1 -1
View File
@@ -589,8 +589,8 @@ struct MotdItem {
struct aloopStruct {
unsigned do_garbage_collect : 1;
unsigned do_tkl_sweep : 1;
unsigned ircd_booted : 1;
unsigned do_bancheck : 1;
};
typedef struct Whowas {
+154 -155
View File
@@ -171,7 +171,6 @@ TS nextconnect = 1; /* time for next try_connections call */
TS nextping = 1; /* same as above for check_pings() */
TS nextdnscheck = 0; /* next time to poll dns to force timeouts */
TS nextexpire = 1; /* next expire run on the dns cache */
TS nextkillcheck = 1; /* next time to check for nickserv kills */
TS lastlucheck = 0;
#ifdef UNREAL_DEBUG
@@ -363,11 +362,6 @@ char *areason;
EVENT(loop_event)
{
if (loop.do_tkl_sweep)
{
tkl_sweep();
loop.do_tkl_sweep = 0;
}
if (loop.do_garbage_collect == 1)
{
garbage_collect(NULL);
@@ -483,13 +477,17 @@ static TS try_connections(TS currenttime)
AKILL/RAKILL/KLINE/UNKLINE/REHASH. Very significant CPU usage decrease.
-- Barubary */
extern TS check_pings(TS currenttime, int check_kills)
extern TS check_pings(TS currenttime)
{
aClient *cptr;
aClient *cptr = NULL;
ConfigItem_ban *bconf = NULL;
int ping = 0, killflag = 0, i = 0;
TS oldest = 0;
static char banbuf[1024];
char killflag = 0;
int i = 0;
char banbuf[1024];
TS ping;
TS oldest = 0;
for (i = 0; i <= LastSlot; i++)
{
@@ -506,165 +504,164 @@ extern TS check_pings(TS currenttime, int check_kills)
(void)exit_client(cptr, cptr, &me, "Dead socket");
continue;
}
bconf = NULL;
if (check_kills)
{
if (IsPerson(cptr))
{
bconf =
Find_ban(make_user_host(cptr->
user ? cptr->user->username : cptr->
username,
cptr->user ? cptr->user->realhost : cptr->
sockhost), CONF_BAN_USER);
if (bconf)
killflag = 1;
else
killflag = 0;
}
}
else
killflag = 0;
if (check_kills && !killflag && IsPerson(cptr))
{
if ((bconf =
Find_ban(inetntoa((char *)&cptr->ip), CONF_BAN_IP)))
{
killflag = 1;
}
if (bconf)
killflag = 1;
killflag = 0;
/*
* Check if user is banned
*/
if (loop.do_bancheck)
{
if (find_tkline_match(cptr, 0) < 0)
{
/* Client exited */
continue;
}
if (!IsAnOper(cptr)
&& (bconf =
Find_ban(cptr->info, CONF_BAN_REALNAME)))
if (!killflag && IsPerson(cptr))
{
killflag = 1;
}
}
if (killflag)
{
if (IsPerson(cptr))
{
sendto_realops
("Kill line active for %s (%s)",
get_client_name(cptr, FALSE),
bconf ?
bconf->
reason ? bconf->reason : "no reason" :
"no reason");
if (bconf && bconf->reason)
/*
* If it's a user, we check for CONF_BAN_USER
*/
bconf =
Find_ban(make_user_host(cptr->
user ? cptr->user->username : cptr->
username,
cptr->user ? cptr->user->realhost : cptr->
sockhost), CONF_BAN_USER);
if (bconf)
killflag++;
if (!killflag && !IsAnOper(cptr) &&
(bconf = Find_ban(cptr->info, CONF_BAN_REALNAME)))
{
ircsprintf(banbuf,
"User has been banned (%s)",
bconf->reason);
(void)exit_client(cptr, cptr, &me,
banbuf);
killflag++;
}
}
/* If no cookie, we search for Z:lines*/
if (!killflag)
if ((bconf =
Find_ban(Inet_ia2p(&cptr->ip), CONF_BAN_IP)))
killflag++;
if (killflag)
{
if (IsPerson(cptr))
sendto_realops("Ban active for %s (%s)",
get_client_name(cptr, FALSE),
bconf->reason ? bconf->reason : "no reason");
if (IsServer(cptr))
sendto_realops("Ban active for server %s (%s)",
get_client_name(cptr, FALSE),
bconf->reason ? bconf->reason : "no reason");
if (bconf->reason)
{
if (IsPerson(cptr))
snprintf(banbuf, sizeof banbuf - 1, "User has been banned (%s)",
bconf->reason);
snprintf(banbuf, sizeof banbuf - 1, "Banned (%s)",
bconf->reason);
(void)exit_client(cptr, cptr, &me, banbuf);
}
else
{
(void)exit_client(cptr, cptr, &me,
"User has been banned");
{
if (IsPerson(cptr))
(void)exit_client(cptr, cptr, &me, "User has been banned");
else
(void)exit_client(cptr, cptr, &me, "Banned");
}
}
else
{
exit_client(cptr, cptr, &me, "Banned");
}
continue;
}
/* If we go here, its a ping timeout */
ping =
IsRegistered(cptr) ? (cptr->class ? cptr->
class->pingfreq : CONNECTTIMEOUT) : CONNECTTIMEOUT;
Debug((DEBUG_DEBUG, "c(%s)=%d p %d k %d a %d", cptr->name,
cptr->status, ping, killflag,
currenttime - cptr->lasttime));
if (ping < (currenttime - cptr->lasttime))
{
if (((cptr->flags & FLAGS_PINGSENT)
&& ((currenttime - cptr->lasttime) >= (2 * ping)))
|| ((!IsRegistered(cptr)
&& (currenttime - cptr->since) >= ping)))
{
if (!IsRegistered(cptr) &&
(DoingDNS(cptr) || DoingAuth(cptr)
))
/* We go into ping phase */
ping =
IsRegistered(cptr) ? (cptr->class ? cptr->
class->pingfreq : CONNECTTIMEOUT) : CONNECTTIMEOUT;
Debug((DEBUG_DEBUG, "c(%s)=%d p %d k %d a %d", cptr->name,
cptr->status, ping, killflag,
currenttime - cptr->lasttime));
if (ping < (currenttime - cptr->lasttime))
{
if (cptr->authfd >= 0)
if (((cptr->flags & FLAGS_PINGSENT)
&& ((currenttime - cptr->lasttime) >= (2 * ping)))
|| ((!IsRegistered(cptr)
&& (currenttime - cptr->since) >= ping)))
{
CLOSE_SOCK(cptr->authfd);
--OpenFiles;
cptr->authfd = -1;
cptr->count = 0;
*cptr->buffer = '\0';
/* One of these days you could use a 300 char terminal ..*/
if (!IsRegistered(cptr) &&
(DoingDNS(cptr) || DoingAuth(cptr)
))
{
if (cptr->authfd >= 0)
{
CLOSE_SOCK(cptr->authfd);
--OpenFiles;
cptr->authfd = -1;
cptr->count = 0;
*cptr->buffer = '\0';
}
if (SHOWCONNECTINFO) {
if (DoingDNS(cptr))
sendto_one(cptr,
REPORT_FAIL_DNS);
else if (DoingAuth(cptr))
sendto_one(cptr,
REPORT_FAIL_ID);
}
Debug((DEBUG_NOTICE,
"DNS/AUTH timeout %s",
get_client_name(cptr, TRUE)));
del_queries((char *)cptr);
ClearAuth(cptr);
ClearDNS(cptr);
SetAccess(cptr);
cptr->firsttime = currenttime;
cptr->lasttime = currenttime;
continue;
}
if (IsServer(cptr) || IsConnecting(cptr) ||
IsHandshake(cptr))
{
sendto_realops
("No response from %s, closing link",
get_client_name(cptr, FALSE));
sendto_serv_butone(&me,
":%s GLOBOPS :No response from %s, closing link",
me.name, get_client_name(cptr,
FALSE));
}
exit_client(cptr, cptr, &me, "Ping timeout");
continue;
}
if (SHOWCONNECTINFO) {
if (DoingDNS(cptr))
sendto_one(cptr,
REPORT_FAIL_DNS);
else if (DoingAuth(cptr))
sendto_one(cptr,
REPORT_FAIL_ID);
else if (IsRegistered(cptr) &&
((cptr->flags & FLAGS_PINGSENT) == 0))
{
/*
* if we havent PINGed the connection and we havent
* heard from it in a while, PING it to make sure
* it is still alive.
*/
cptr->flags |= FLAGS_PINGSENT;
/* not nice but does the job */
cptr->lasttime = currenttime - ping;
sendto_one(cptr, "%s :%s",
IsToken(cptr) ? TOK_PING : MSG_PING,
me.name);
}
Debug((DEBUG_NOTICE,
"DNS/AUTH timeout %s",
get_client_name(cptr, TRUE)));
del_queries((char *)cptr);
ClearAuth(cptr);
ClearDNS(cptr);
SetAccess(cptr);
cptr->firsttime = currenttime;
cptr->lasttime = currenttime;
continue;
}
if (IsServer(cptr) || IsConnecting(cptr) ||
IsHandshake(cptr))
{
sendto_realops
("No response from %s, closing link",
get_client_name(cptr, FALSE));
sendto_serv_butone(&me,
":%s GLOBOPS :No response from %s, closing link",
me.name, get_client_name(cptr,
FALSE));
}
exit_client(cptr, cptr, &me, "Ping timeout");
continue;
}
else if (IsRegistered(cptr) &&
((cptr->flags & FLAGS_PINGSENT) == 0))
{
}
/*
* if we havent PINGed the connection and we havent
* heard from it in a while, PING it to make sure
* it is still alive.
* Check UNKNOWN connections - if they have been in this state
* for > 100s, close them.
*/
cptr->flags |= FLAGS_PINGSENT;
/* not nice but does the job */
cptr->lasttime = currenttime - ping;
sendto_one(cptr, "%s :%s",
IsToken(cptr) ? TOK_PING : MSG_PING,
me.name);
if (IsUnknown(cptr))
if (cptr->firsttime ? ((TStime() - cptr->firsttime) >
100) : 0)
(void)exit_client(cptr, cptr, &me,
"Connection Timed Out");
}
}
/*
* Check UNKNOWN connections - if they have been in this state
* for > 100s, close them.
*/
if (IsUnknown(cptr))
if (cptr->firsttime ? ((TStime() - cptr->firsttime) >
100) : 0)
(void)exit_client(cptr, cptr, &me,
"Connection Timed Out");
}
/* EXPLANATION
* on a server with a large volume of clients, at any given point
* there may be a client which needs to be pinged the next second,
@@ -679,7 +676,8 @@ extern TS check_pings(TS currenttime, int check_kills)
* - lucas
*
*/
if (loop.do_bancheck)
loop.do_bancheck = 0;
oldest = currenttime + 9;
Debug((DEBUG_NOTICE, "Next check_ping() call at: %s, %d %d %d",
myctime(oldest), ping, oldest, currenttime));
@@ -1202,8 +1200,6 @@ int InitwIRCD(int argc, char *argv[])
#ifndef NO_FDLIST
check_fdlists(TStime());
#endif
nextkillcheck = TStime() + (TS)1;
#ifdef _WIN32
return 1;
@@ -1221,6 +1217,9 @@ void SocketLoop(void *dummy)
while (1)
#else
/* Forever drunk .. forever drunk ..
* (Sorry Alphaville.)
*/
for (;;)
#endif
{
@@ -1329,11 +1328,11 @@ void SocketLoop(void *dummy)
** ping times) --msa
*/
#ifdef NO_FDLIST
if (timeofday >= nextping)
if ((timeofday >= nextping) || (loop.do_bancheck))
#else
if (timeofday >= nextping && !lifesux)
if ((timeofday >= nextping && !lifesux) || (loop.do_bancheck))
#endif
nextping = check_pings(timeofday, 0);
nextping = check_pings(timeofday);
if (dorehash)
{
(void)rehash(&me, &me, 1);
+1 -2
View File
@@ -211,7 +211,6 @@ DLLFUNC int m_akill(aClient *cptr, aClient *sptr, int parc, char *parv[])
sendto_serv_butone(cptr, ":%s AKILL %s %s",
IsServer(cptr) ? parv[0] : me.name, hostmask, usermask);
check_pings(TStime(), 1);
loop.do_bancheck = 1;
return 0;
}
+1 -1
View File
@@ -246,6 +246,6 @@ DLLFUNC int m_kline(aClient *cptr, aClient *sptr, int parc, char *parv[])
bconf->reason = parv[2] ? strdup(parv[2]) : NULL;
bconf->flag.type2 = CONF_BAN_TYPE_TEMPORARY;
AddListItem(bconf, conf_ban);
check_pings(TStime(), 1);
loop.do_bancheck = 1;
return 0;
}
+1 -1
View File
@@ -213,6 +213,6 @@ DLLFUNC int m_rakill(aClient *cptr, aClient *sptr, int parc, char *parv[])
sendto_serv_butone(cptr, ":%s RAKILL %s %s",
IsServer(cptr) ? parv[0] : me.name, hostmask, usermask);
check_pings(TStime(), 1);
loop.do_bancheck = 1;
return 0;
}
+3 -1
View File
@@ -180,6 +180,8 @@ DLLFUNC int m_unkline(aClient *cptr, aClient *sptr, int parc, char *parv[])
return 0;
}
/* This wasn't here before -- Barubary */
check_pings(TStime(), 1);
/* check_pings crap */
/* No, and it shouldn't have been, dork. It crashes the IRCd randomly. -Stskeeps */
loop.do_bancheck = 1;
return 0;
}
+2 -11
View File
@@ -260,22 +260,13 @@ DLLFUNC int m_zline(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
goto propo_label;
}
if (!match(mask, inetntoa((char *)&cptr->ip)))
{
sendto_realops("Tried to zap cptr, from %s",
parv[0]);
MyFree(bconf);
}
else
{
AddListItem(bconf, conf_ban);
}
AddListItem(bconf, conf_ban);
propo_label:
if (propo == 1) /* propo is if a ulined server is propagating a z-line
this should go after the above check */
sendto_serv_butone(cptr, ":%s ZLINE %s :%s", parv[0], parv[1],
reason ? reason : "");
check_pings(TStime(), 1);
loop.do_bancheck = 1;
return 0;
}
+2 -1
View File
@@ -3695,7 +3695,8 @@ int rehash(aClient *cptr, aClient *sptr, int sig)
listen_cleanup();
close_listeners();
run_configuration();
check_pings(TStime(), 1);
loop.do_bancheck = 1;
/* Check pings is done AFTERWARDS return anyhow, fuckheads. */
sendto_realops("Completed rehash");
return 0;
}
+10 -25
View File
@@ -227,8 +227,8 @@ EVENT(tkl_check_expire)
/*
returns -1 if no tkline found
returns >= 0 if client exits
returns <0 if client exists (banned)
returns 1 if it is excepted
*/
int find_tkline_match(aClient *cptr, int xx)
@@ -265,14 +265,14 @@ int find_tkline_match(aClient *cptr, int xx)
}
if (points != 1)
return -1;
return 1;
strcpy(host, make_user_host(cname, chost));
strcpy(host2, make_user_host(cname, cip));
for (excepts = conf_except; excepts; excepts = (ConfigItem_except *)excepts->next) {
if (excepts->flag.type != CONF_EXCEPT_TKL || excepts->type != lp->type)
continue;
if (!match(excepts->mask, host) || !match(excepts->mask, host2))
return -1;
return 1;
}
if ((lp->type & TKL_KILL) && (xx != 2))
@@ -317,14 +317,14 @@ int find_tkline_match(aClient *cptr, int xx)
if (lp->type & (TKL_SHUN))
{
if (IsShunned(cptr))
return -1;
return 1;
if (IsAdmin(cptr))
return -1;
return 1;
SetShunned(cptr);
return -1;
return 2;
}
return -1;
return 3;
}
int find_tkline_match_zap(aClient *cptr)
@@ -372,22 +372,6 @@ int find_tkline_match_zap(aClient *cptr)
}
int tkl_sweep(void)
{
/* just sweeps local for people that should be killed */
aClient *acptr;
long i;
tkl_check_expire(NULL);
for (i = 0; i <= (MAXCONNECTIONS - 1); i++)
{
if ((acptr = local[i]))
find_tkline_match(acptr, 0);
}
return 1;
}
void tkl_stats(aClient *cptr)
{
aTKline *tk;
@@ -597,7 +581,8 @@ int m_tkl(aClient *cptr, aClient *sptr, int parc, char *parv[])
(LOG_TKL, "Permanent %s added for %s@%s on %s GMT (from %s: %s)",
txt, parv[3], parv[4], gmt, parv[5], parv[8]);
}
loop.do_tkl_sweep = 1;
loop.do_bancheck = 1;
/* Makes check_pings be run ^^ */
if (type & TKL_GLOBAL)
{
sendto_serv_butone(cptr,
BIN
View File
Binary file not shown.