kill_link() and Server::QuitUser() -> userrec::QuitUser() (static member) - this cant be a normal member as it causes the userrec to be deleted, and "delete this" is bad, mmm'k

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4789 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-08-08 14:38:24 +00:00
parent 6ab1d0dffb
commit 93876363f8
16 changed files with 42 additions and 60 deletions

View File

@ -1507,18 +1507,6 @@ class Server : public Extensible
*/ */
virtual void ChangeUserNick(userrec* user, const std::string &nickname); virtual void ChangeUserNick(userrec* user, const std::string &nickname);
/** Forces a user to quit with the specified reason.
* To the user, it will appear as if they typed /QUIT themselves, except for the fact that this function
* may bypass the quit prefix specified in the config file.
*
* WARNING!
*
* Once you call this function, userrec* user will immediately become INVALID. You MUST NOT write to, or
* read from this pointer after calling the QuitUser method UNDER ANY CIRCUMSTANCES! The best course of
* action after calling this method is to immediately bail from your handler.
*/
virtual void QuitUser(userrec* user, const std::string &reason);
/** Matches text against a glob pattern. /** Matches text against a glob pattern.
* Uses the ircd's internal matching function to match string against a globbing pattern, e.g. *!*@*.com * Uses the ircd's internal matching function to match string against a globbing pattern, e.g. *!*@*.com
* Returns true if the literal successfully matches the pattern, false if otherwise. * Returns true if the literal successfully matches the pattern, false if otherwise.

View File

@ -435,6 +435,10 @@ class userrec : public connection
*/ */
void CloseSocket(); void CloseSocket();
/** Disconnect a user gracefully
*/
static void QuitUser(userrec *user, const std::string &r);
/** Default destructor /** Default destructor
*/ */
virtual ~userrec(); virtual ~userrec();
@ -461,8 +465,7 @@ typedef std::map<irc::string,whowas_set*> whowas_users;
void AddOper(userrec* user); void AddOper(userrec* user);
void DeleteOper(userrec* user); void DeleteOper(userrec* user);
void kill_link(userrec *user,const char* r); //void kill_link(userrec *user,const char* r);
void kill_link_silent(userrec *user,const char* r);
void AddWhoWas(userrec* u); void AddWhoWas(userrec* u);
void MaintainWhoWas(time_t TIME); void MaintainWhoWas(time_t TIME);
void AddClient(int socket, int port, bool iscached, insp_inaddr ip4); void AddClient(int socket, int port, bool iscached, insp_inaddr ip4);

View File

@ -79,7 +79,7 @@ void cmd_kill::Handle (const char** parameters, int pcnt, userrec *user)
WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, Config->ServerName, user->dhost, user->nick, parameters[1]); WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, Config->ServerName, user->dhost, user->nick, parameters[1]);
WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]); WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]);
snprintf(killreason,MAXQUIT,"Killed (%s (%s))", user->nick, parameters[1]); snprintf(killreason,MAXQUIT,"Killed (%s (%s))", user->nick, parameters[1]);
kill_link(u, killreason); userrec::QuitUser(u, killreason);
} }
} }
else else

View File

@ -133,7 +133,7 @@ int CullList::Apply()
{ {
std::vector<CullItem>::iterator a = list.begin(); std::vector<CullItem>::iterator a = list.begin();
kill_link(a->GetUser(), a->GetReason().c_str()); userrec::QuitUser(a->GetUser(), a->GetReason().c_str());
list.erase(list.begin()); list.erase(list.begin());
} }
return n; return n;

View File

@ -414,11 +414,6 @@ void Server::ChangeUserNick(userrec* user, const std::string &nickname)
force_nickchange(user,nickname.c_str()); force_nickchange(user,nickname.c_str());
} }
void Server::QuitUser(userrec* user, const std::string &reason)
{
kill_link(user,reason.c_str());
}
bool Server::IsUlined(const std::string &server) bool Server::IsUlined(const std::string &server)
{ {
return is_uline(server.c_str()); return is_uline(server.c_str());
@ -633,7 +628,7 @@ bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &me
std::string oldnick = alive->nick; std::string oldnick = alive->nick;
std::string oldhost = alive->host; std::string oldhost = alive->host;
std::string oldident = alive->ident; std::string oldident = alive->ident;
kill_link(alive,message.c_str()); userrec::QuitUser(alive,message.c_str());
if (find(local_users.begin(),local_users.end(),alive) != local_users.end()) if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
{ {
local_users.erase(find(local_users.begin(),local_users.end(),alive)); local_users.erase(find(local_users.begin(),local_users.end(),alive));

View File

@ -144,7 +144,7 @@ class ModuleFilterPCRE : public Module
if (do_action == "kill") if (do_action == "kill")
{ {
Srv->QuitUser(user,reason); userrec::QuitUser(user,reason);
} }
return 1; return 1;
} }

View File

@ -94,7 +94,7 @@ public:
if (!CheckCredentials(user)) if (!CheckCredentials(user))
{ {
Srv->QuitUser(user,killreason); userrec::QuitUser(user,killreason);
} }
} }
@ -202,7 +202,7 @@ public:
{ {
if(user->GetExt("sqlauth_failed")) if(user->GetExt("sqlauth_failed"))
{ {
Srv->QuitUser(user,killreason); userrec::QuitUser(user,killreason);
return false; return false;
} }

View File

@ -141,7 +141,7 @@ public:
WriteOpers("*** %s had an /amsg or /ame denied", user->nick); WriteOpers("*** %s had an /amsg or /ame denied", user->nick);
if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS) if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS)
Srv->QuitUser(user, "Global message (/amsg or /ame) detected"); userrec::QuitUser(user, "Global message (/amsg or /ame) detected");
else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS) else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS)
WriteServ(user->fd, "NOTICE %s :Global message (/amsg or /ame) detected", user->nick); WriteServ(user->fd, "NOTICE %s :Global message (/amsg or /ame) detected", user->nick);

View File

@ -94,7 +94,7 @@ class ModuleWaitPong : public Module
else else
{ {
if(killonbadreply) if(killonbadreply)
Srv->QuitUser(user, "Incorrect ping reply for registration"); userrec::QuitUser(user, "Incorrect ping reply for registration");
return 1; return 1;
} }
} }

View File

@ -94,7 +94,7 @@ public:
Srv->SendOpers("*** Connection throttle deactivated"); Srv->SendOpers("*** Connection throttle deactivated");
return; return;
} }
Srv->QuitUser(user, quitmsg); userrec::QuitUser(user, quitmsg);
return; return;
} }
@ -104,7 +104,7 @@ public:
{ {
throttled = 1; throttled = 1;
Srv->SendOpers("*** Connection throttle activated"); Srv->SendOpers("*** Connection throttle activated");
Srv->QuitUser(user, quitmsg); userrec::QuitUser(user, quitmsg);
return; return;
} }
} }

View File

@ -116,7 +116,7 @@ class ModuleFilter : public Module
if (f->action == "kill") if (f->action == "kill")
{ {
Srv->QuitUser(user,f->reason); userrec::QuitUser(user,f->reason);
} }
return 1; return 1;
} }

View File

@ -325,7 +325,7 @@ class ModulePark : public Module
// and then corrupt the pointer! // and then corrupt the pointer!
pinfo.erase(j); pinfo.erase(j);
if (thisnick) if (thisnick)
Srv->QuitUser(thisnick,"PARK timeout"); userrec::QuitUser(thisnick,"PARK timeout");
go_again = true; go_again = true;
break; break;
} }

View File

@ -63,7 +63,7 @@ class cmd_saquit : public command_t
line = line + std::string(parameters[pcnt-1]); line = line + std::string(parameters[pcnt-1]);
Srv->SendOpers(std::string(user->nick)+" used SAQUIT to make "+std::string(dest->nick)+" quit with a reason of "+line); Srv->SendOpers(std::string(user->nick)+" used SAQUIT to make "+std::string(dest->nick)+" quit with a reason of "+line);
Srv->QuitUser(dest, line); userrec::QuitUser(dest, line);
} }
} }
}; };

View File

@ -330,7 +330,7 @@ class TreeServer : public classbase
userrec* a = (userrec*)*n; userrec* a = (userrec*)*n;
log(DEBUG,"Kill %s fd=%d",a->nick,a->fd); log(DEBUG,"Kill %s fd=%d",a->nick,a->fd);
if (!IS_LOCAL(a)) if (!IS_LOCAL(a))
kill_link(a,reason_s); userrec::QuitUser(a,reason_s);
} }
return time_to_die.size(); return time_to_die.size();
} }
@ -2078,7 +2078,7 @@ class TreeSocket : public InspSocket
params[1] = ":" + params[1]; params[1] = ":" + params[1];
DoOneToAllButSender(prefix,"KILL",params,sourceserv); DoOneToAllButSender(prefix,"KILL",params,sourceserv);
::Write(who->fd, ":%s KILL %s :%s (%s)", sourceserv.c_str(), who->nick, sourceserv.c_str(), reason.c_str()); ::Write(who->fd, ":%s KILL %s :%s (%s)", sourceserv.c_str(), who->nick, sourceserv.c_str(), reason.c_str());
Srv->QuitUser(who,reason); userrec::QuitUser(who,reason);
} }
return true; return true;
} }
@ -2965,11 +2965,11 @@ class TreeSocket : public InspSocket
p.push_back(prefix); p.push_back(prefix);
p.push_back("Nickname collision"); p.push_back("Nickname collision");
DoOneToMany(Srv->GetServerName(),"KILL",p); DoOneToMany(Srv->GetServerName(),"KILL",p);
Srv->QuitUser(x,"Nickname collision ("+prefix+" -> "+params[0]+")"); userrec::QuitUser(x,"Nickname collision ("+prefix+" -> "+params[0]+")");
userrec* y = Srv->FindNick(prefix); userrec* y = Srv->FindNick(prefix);
if (y) if (y)
{ {
Srv->QuitUser(y,"Nickname collision"); userrec::QuitUser(y,"Nickname collision");
} }
return DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params); return DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
} }

View File

@ -157,7 +157,7 @@ void ProcessUser(userrec* cu)
{ {
log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
kill_link(current,"Excess flood"); userrec::QuitUser(current,"Excess flood");
return; return;
} }
else else
@ -181,7 +181,7 @@ void ProcessUser(userrec* cu)
{ {
if (current->registered == REG_ALL) if (current->registered == REG_ALL)
{ {
kill_link(current,"RecvQ exceeded"); userrec::QuitUser(current,"RecvQ exceeded");
} }
else else
{ {
@ -207,7 +207,7 @@ void ProcessUser(userrec* cu)
{ {
log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
kill_link(current,"Excess flood"); userrec::QuitUser(current,"Excess flood");
return; return;
} }
@ -217,7 +217,7 @@ void ProcessUser(userrec* cu)
{ {
log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
kill_link(current,"Excess flood"); userrec::QuitUser(current,"Excess flood");
} }
else else
{ {
@ -262,7 +262,7 @@ void ProcessUser(userrec* cu)
if ((result == -1) && (errno != EAGAIN) && (errno != EINTR)) if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
{ {
log(DEBUG,"killing: %s",cu->nick); log(DEBUG,"killing: %s",cu->nick);
kill_link(cu,strerror(errno)); userrec::QuitUser(cu,strerror(errno));
return; return;
} }
} }
@ -275,7 +275,7 @@ void ProcessUser(userrec* cu)
else if (result == 0) else if (result == 0)
{ {
log(DEBUG,"InspIRCd: Exited: %s",cu->nick); log(DEBUG,"InspIRCd: Exited: %s",cu->nick);
kill_link(cu,"Client exited"); userrec::QuitUser(cu,"Client exited");
log(DEBUG,"Bailing from client exit"); log(DEBUG,"Bailing from client exit");
return; return;
} }

View File

@ -634,7 +634,7 @@ void DeleteOper(userrec* user)
} }
} }
void kill_link(userrec *user,const char* r) void userrec::QuitUser(userrec *user,const std::string &quitreason)
{ {
user_hash::iterator iter = clientlist.find(user->nick); user_hash::iterator iter = clientlist.find(user->nick);
@ -648,20 +648,19 @@ void kill_link(userrec *user,const char* r)
* if (iter == clientlist.end()) * if (iter == clientlist.end())
* return; * return;
*/ */
std::string reason = quitreason;
char reason[MAXBUF]; if (reason.length() > MAXQUIT - 1)
reason.resize(MAXQUIT - 1);
strlcpy(reason,r,MAXQUIT-1);
log(DEBUG,"kill_link: %s %d '%s'",user->nick,user->fd,reason);
if (IS_LOCAL(user)) if (IS_LOCAL(user))
Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason); Write(user->fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
if (user->registered == REG_ALL) if (user->registered == REG_ALL)
{ {
purge_empty_chans(user); purge_empty_chans(user);
FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,reason)); FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,reason));
WriteCommonExcept(user,"QUIT :%s",reason); WriteCommonExcept(user,"QUIT :%s",reason.c_str());
} }
if (IS_LOCAL(user)) if (IS_LOCAL(user))
@ -698,7 +697,7 @@ void kill_link(userrec *user,const char* r)
if (user->registered == REG_ALL) if (user->registered == REG_ALL)
{ {
if (IS_LOCAL(user)) if (IS_LOCAL(user))
WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason); WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
AddWhoWas(user); AddWhoWas(user);
} }
@ -709,10 +708,7 @@ void kill_link(userrec *user,const char* r)
{ {
fd_ref_table[user->fd] = NULL; fd_ref_table[user->fd] = NULL;
if (find(local_users.begin(),local_users.end(),user) != local_users.end()) if (find(local_users.begin(),local_users.end(),user) != local_users.end())
{
local_users.erase(find(local_users.begin(),local_users.end(),user)); local_users.erase(find(local_users.begin(),local_users.end(),user));
log(DEBUG,"Delete local user");
}
} }
clientlist.erase(iter); clientlist.erase(iter);
DELETE(user); DELETE(user);
@ -868,13 +864,13 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
if (local_users.size() > Config->SoftLimit) if (local_users.size() > Config->SoftLimit)
{ {
kill_link(_new,"No more connections allowed"); userrec::QuitUser(_new,"No more connections allowed");
return; return;
} }
if (local_users.size() >= MAXCLIENTS) if (local_users.size() >= MAXCLIENTS)
{ {
kill_link(_new,"No more connections allowed"); userrec::QuitUser(_new,"No more connections allowed");
return; return;
} }
@ -890,7 +886,7 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
*/ */
if ((unsigned)socket >= MAX_DESCRIPTORS) if ((unsigned)socket >= MAX_DESCRIPTORS)
{ {
kill_link(_new,"Server is full"); userrec::QuitUser(_new,"Server is full");
return; return;
} }
char* e = matches_exception(ipaddr); char* e = matches_exception(ipaddr);
@ -901,7 +897,7 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
{ {
char reason[MAXBUF]; char reason[MAXBUF];
snprintf(reason,MAXBUF,"Z-Lined: %s",r); snprintf(reason,MAXBUF,"Z-Lined: %s",r);
kill_link(_new,reason); userrec::QuitUser(_new,reason);
return; return;
} }
} }
@ -910,7 +906,7 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip)
{ {
if (!ServerInstance->SE->AddFd(socket,true,X_ESTAB_CLIENT)) if (!ServerInstance->SE->AddFd(socket,true,X_ESTAB_CLIENT))
{ {
kill_link(_new, "Internal error handling connection"); userrec::QuitUser(_new, "Internal error handling connection");
return; return;
} }
} }
@ -1099,14 +1095,14 @@ void force_nickchange(userrec* user,const char* newnick)
if (MOD_RESULT) if (MOD_RESULT)
{ {
ServerInstance->stats->statsCollisions++; ServerInstance->stats->statsCollisions++;
kill_link(user,"Nickname collision"); userrec::QuitUser(user,"Nickname collision");
return; return;
} }
if (matches_qline(newnick)) if (matches_qline(newnick))
{ {
ServerInstance->stats->statsCollisions++; ServerInstance->stats->statsCollisions++;
kill_link(user,"Nickname collision"); userrec::QuitUser(user,"Nickname collision");
return; return;
} }