From 1ccd58d2a2b838f103e065f0c002f067dc952e2d Mon Sep 17 00:00:00 2001 From: stskeeps Date: Fri, 10 May 2002 15:50:54 +0000 Subject: [PATCH] - 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. --- Changes | 3 + include/h.h | 2 +- include/proto.h | 1 - include/struct.h | 2 +- src/ircd.c | 309 ++++++++++++++++++++-------------------- src/modules/m_akill.c | 3 +- src/modules/m_kline.c | 2 +- src/modules/m_rakill.c | 2 +- src/modules/m_unkline.c | 4 +- src/modules/m_zline.c | 13 +- src/s_conf.c | 3 +- src/s_kline.c | 35 ++--- src/ssl.rnd | Bin 1024 -> 1024 bytes 13 files changed, 179 insertions(+), 200 deletions(-) diff --git a/Changes b/Changes index ac057689f..a2011da14 100644 --- a/Changes +++ b/Changes @@ -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. diff --git a/include/h.h b/include/h.h index d0a11c5c0..d34b19548 100644 --- a/include/h.h +++ b/include/h.h @@ -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 */ diff --git a/include/proto.h b/include/proto.h index f3eb176b3..d67f74828 100644 --- a/include/proto.h +++ b/include/proto.h @@ -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); diff --git a/include/struct.h b/include/struct.h index 2faefbe89..8ff98b6f1 100644 --- a/include/struct.h +++ b/include/struct.h @@ -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 { diff --git a/src/ircd.c b/src/ircd.c index 4e182c04b..be6613012 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -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); diff --git a/src/modules/m_akill.c b/src/modules/m_akill.c index b2c7f8acc..8010a283e 100644 --- a/src/modules/m_akill.c +++ b/src/modules/m_akill.c @@ -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; } diff --git a/src/modules/m_kline.c b/src/modules/m_kline.c index e84a94c27..601e1d71b 100644 --- a/src/modules/m_kline.c +++ b/src/modules/m_kline.c @@ -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; } diff --git a/src/modules/m_rakill.c b/src/modules/m_rakill.c index af8838b68..8dd8a1cd8 100644 --- a/src/modules/m_rakill.c +++ b/src/modules/m_rakill.c @@ -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; } diff --git a/src/modules/m_unkline.c b/src/modules/m_unkline.c index 101f7c989..c9b1696b4 100644 --- a/src/modules/m_unkline.c +++ b/src/modules/m_unkline.c @@ -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; } diff --git a/src/modules/m_zline.c b/src/modules/m_zline.c index 80ee183b0..e92d59c0e 100644 --- a/src/modules/m_zline.c +++ b/src/modules/m_zline.c @@ -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; } diff --git a/src/s_conf.c b/src/s_conf.c index bdcc4de0e..713171f45 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -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; } diff --git a/src/s_kline.c b/src/s_kline.c index 40df10b9d..34a57d8ee 100644 --- a/src/s_kline.c +++ b/src/s_kline.c @@ -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, diff --git a/src/ssl.rnd b/src/ssl.rnd index 292ff03b4744a337bad04574cce0b0c2c24da76d..bca937cc8912549d9d705345ea26fda69dfb0e43 100644 GIT binary patch literal 1024 zcmV+b1poV%t@f)lALV;GM}8*dn-(HR{9BV;Cl$sqVki)1_!KMo}sUzoIk z@b1`R>lN&Xv|5dIjWSy?SplMEtzD});Os#TbiJ!$=@2y3J5pDCv)ap^fcEGH8ucWr zJ_JxHLwEcZlm6`Kxmca2-7BDg|LM?`vs|EA6+wut9Cr<-Z;2wAz!pf|n?DRM_`Yx&JdCEYpqCYFbn^Qu-aj$wg`VAab0a!dIh)14^%{>Kw z#^B6)Tms{IPTv`LMcyfSVFB>+Q;%tt8M8Q0IvQ|KL=$p&oRju=({O)4Gu}AVi^%Q3+YB^d1Mq-2&U3!jkd3rvTz(_ zl0QI=*l&SRULn_53#ORblLxbO;!rW+qUF$ZX!jx4LqU{PH?R)}X&Xi-AF5JOhB-){ z_q!TQ0O@XWLL#pH`b#wXFvc?@OIIwmolG5FHpa}7Iwum&j3)1T@DzKAzu+hsyIOkC zU8F>mkD>EthgiCqF-D4ohTQml-Fgh+a|wU+B9M2mS>m1nbwTg@yeS^rKIpOI*0wnyQ2-1h<>+yrardxGmDmg59F=lv%#YIChjm^I zCz-XTr|fqbt&iE4sqIP@!{mcVi_4fiR{_?2dPwhD!FzN);;>tZ+)or9B;95$-vVEWjoJA*HSNS3!yiATG(})sJq?cN(U)wg20F+_$&L)Mdhs+IS?h>d~{_UxJu0POxjZ`B`2RY|~`Z>p{V? zZy23!#j0jHTjVjda{QCF4lpX3U0q)lU)-TqsxE)>D$D8@#T`s#k1Z`_aYiWw`gdZc|{*_f4SP})ybar=3sR1r-iLdY=hKU;e0cj>qjql+CZ&%s}r9_XvClP{M3w{ uwY{oqt3%Tt@xlR+Vdnw$E67zTZih?GwO&dqF|;wEwi-v7*Q7TgjRL3aR`G)X literal 1024 zcmV+b1poU#)4%<;MN__1H8+QaP7CKRax;w$iThd=SIfkLABqSi8b()ikvENb}K3HwSrb0B(6}TeP+zFC!jnrcJ%y96_8BFj0 zp`>9Q5h{Yb2#bL+oH#1Ip|96TLr>$2Cdptd)#82II}MFAzC^%FKmRC0ClDN+8cGbWGak3pIBWy=3W3Yke2n1Z%<-yzk=gesT~74-6TdYi>Nnf#4e+=3HNGEYLX;2x zB)W8I?hW#x(esCoiR&6u6A|$zptC{(bIjJT+o=!E63Q)?yT84~)y_+6bWZ@*)lCHC zwaf`myJaylJJeo}CB?jw+8xduTl;MgnLyxvdbls)a_|q+xGVL0D$It~@XvE5I{x1i zrNksGuqSP%D^TGHXyHcEHaUbWT0zD%QQTh_)Ca+j0hZ%!QARpz1($-rZrX zo1ASM?R}?D5cKe;Ql$55VX0KRfFsE zP)^OqGtflmP3zqHLI*4Dn-(@xUxv76+xHSoW1b+)8G^J#RZZOU>TyF}>u@89shtOE|`aG(N)ciZEM-AyAnr>!~; zf(|nH77^PLGjXV!KQe{t!@=K}J18nW6M!u*zgaSLLPeV(YNPxbRR~d!%&uOii)p`A z6v