]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fix FIDENT response forging to run prior to the ENCAP strip
[user/henk/code/inspircd.git] / src / users.cpp
index c2890f9f723e1b7ffe071a277347075d7bf3913c..1392af0755af7ea1c41f122346bc445505ad9d7f 100644 (file)
@@ -236,7 +236,7 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so
 User::~User()
 {
        if (ServerInstance->Users->uuidlist->find(uuid) != ServerInstance->Users->uuidlist->end())
-               ServerInstance->Logs->Log("USERS", ERROR, "User destructor for %s called without cull", uuid.c_str());
+               ServerInstance->Logs->Log("USERS", DEFAULT, "User destructor for %s called without cull", uuid.c_str());
 }
 
 const std::string& User::MakeHost()
@@ -575,7 +575,6 @@ CullResult User::cull()
        if (client_sa.sa.sa_family != AF_UNSPEC)
                ServerInstance->Users->RemoveCloneCounts(this);
 
-       ServerInstance->Users->uuidlist->erase(uuid);
        return Extensible::cull();
 }
 
@@ -595,6 +594,8 @@ CullResult FakeUser::cull()
 {
        // Fake users don't quit, they just get culled.
        quitting = true;
+       ServerInstance->Users->clientlist->erase(nick);
+       ServerInstance->Users->uuidlist->erase(uuid);
        return User::cull();
 }
 
@@ -620,10 +621,7 @@ void User::Oper(OperInfo* info)
                        l->ChangeDisplayedHost(vhost.c_str());
                std::string opClass = oper->getConfig("class");
                if (!opClass.empty())
-               {
                        l->SetClass(opClass);
-                       l->CheckClass();
-               }
        }
 
        ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')",
@@ -808,16 +806,18 @@ void LocalUser::FullConnect()
        /* Check the password, if one is required by the user's connect class.
         * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
         */
-       if (!MyClass->pass.empty())
+       if (!MyClass->config->getString("pass").empty())
        {
-               if (ServerInstance->PassCompare(this, MyClass->pass.c_str(), password.c_str(), MyClass->hash.c_str()))
+               if (ServerInstance->PassCompare(this, MyClass->config->getString("pass"), password, MyClass->config->getString("hash")))
                {
                        ServerInstance->Users->QuitUser(this, "Invalid password");
                        return;
                }
        }
+       CheckClass();
+       CheckLines();
 
-       if (this->CheckLines())
+       if (quitting)
                return;
 
        this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network.c_str());
@@ -829,18 +829,21 @@ void LocalUser::FullConnect()
        ServerInstance->Config->Send005(this);
        this->WriteNumeric(RPL_YOURUUID, "%s %s :your unique ID", this->nick.c_str(), this->uuid.c_str());
 
-
-       this->ShowMOTD();
-
        /* Now registered */
        if (ServerInstance->Users->unregistered_count)
                ServerInstance->Users->unregistered_count--;
 
-       /* Trigger LUSERS output, give modules a chance too */
+       /* Trigger MOTD and LUSERS output, give modules a chance too */
        ModResult MOD_RESULT;
-       std::string command("LUSERS");
+       std::string command("MOTD");
        std::vector<std::string> parameters;
-       FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, "LUSERS"));
+       FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
+       if (!MOD_RESULT)
+               ServerInstance->CallCommandHandler(command, parameters, this);
+
+       MOD_RESULT = MOD_RES_PASSTHRU;
+       command = "LUSERS";
+       FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, parameters, this, true, command));
        if (!MOD_RESULT)
                ServerInstance->CallCommandHandler(command, parameters, this);
 
@@ -860,27 +863,6 @@ void LocalUser::FullConnect()
        ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
 }
 
-/** User::UpdateNick()
- * re-allocates a nick in the user_hash after they change nicknames,
- * returns a pointer to the new user as it may have moved
- */
-User* User::UpdateNickHash(const char* New)
-{
-       //user_hash::iterator newnick;
-       user_hash::iterator oldnick = ServerInstance->Users->clientlist->find(this->nick);
-
-       if (!irc::string(this->nick.c_str()).compare(New))
-               return oldnick->second;
-
-       if (oldnick == ServerInstance->Users->clientlist->end())
-               return NULL; /* doesnt exist */
-
-       User* olduser = oldnick->second;
-       ServerInstance->Users->clientlist->erase(oldnick);
-       (*(ServerInstance->Users->clientlist))[New] = olduser;
-       return olduser;
-}
-
 void User::InvalidateCache()
 {
        /* Invalidate cache */
@@ -890,13 +872,12 @@ void User::InvalidateCache()
        cached_fullrealhost.clear();
 }
 
-bool User::ForceNickChange(const char* newnick)
+bool User::ChangeNick(const std::string& newnick, bool force)
 {
        ModResult MOD_RESULT;
 
-       this->InvalidateCache();
-
-       ServerInstance->NICKForced.set(this, 1);
+       if (force)
+               ServerInstance->NICKForced.set(this, 1);
        FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (this, newnick));
        ServerInstance->NICKForced.set(this, 0);
 
@@ -906,20 +887,98 @@ bool User::ForceNickChange(const char* newnick)
                return false;
        }
 
-       std::deque<classbase*> dummy;
-       Command* nickhandler = ServerInstance->Parser->GetHandler("NICK");
-       if (nickhandler) // wtfbbq, when would this not be here
+       if (assign(newnick) == assign(nick))
        {
-               std::vector<std::string> parameters;
-               parameters.push_back(newnick);
-               ServerInstance->NICKForced.set(this, 1);
-               bool result = (ServerInstance->Parser->CallHandler("NICK", parameters, this) == CMD_SUCCESS);
-               ServerInstance->NICKForced.set(this, 0);
-               return result;
+               // case change, don't need to check Q:lines and such
+               // and, if it's identical including case, we can leave right now
+               if (newnick == nick)
+                       return true;
        }
+       else
+       {
+               /*
+                * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
+                * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
+                * Thanks Kein for finding this. -- w00t
+                *
+                * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
+                *              -- w00t
+                */
+               if (!IS_LOCAL(this))
+               {
+                       XLine* mq = ServerInstance->XLines->MatchesLine("Q",newnick);
+                       if (mq)
+                       {
+                               if (this->registered == REG_ALL)
+                               {
+                                       ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s!%s@%s: %s",
+                                               newnick.c_str(), this->nick.c_str(), this->ident.c_str(), this->host.c_str(), mq->reason.c_str());
+                               }
+                               this->WriteNumeric(432, "%s %s :Invalid nickname: %s",this->nick.c_str(), newnick.c_str(), mq->reason.c_str());
+                               return false;
+                       }
 
-       // Unreachable, we hope
-       return false;
+                       if (ServerInstance->Config->RestrictBannedUsers)
+                       {
+                               for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
+                               {
+                                       Channel *chan = *i;
+                                       if (chan->GetPrefixValue(this) < VOICE_VALUE && chan->IsBanned(this))
+                                       {
+                                               this->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", this->nick.c_str(), chan->name.c_str());
+                                               return false;
+                                       }
+                               }
+                       }
+               }
+
+               /*
+                * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
+                * then we have a potential collide. Check whether someone else is camping on the nick
+                * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
+                * camper to their UID, and allow the incoming nick change.
+                *
+                * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
+                * because the nick is already (rightfully) in use. -- w00t
+                */
+               User* InUse = ServerInstance->FindNickOnly(newnick);
+               if (InUse && (InUse != this))
+               {
+                       if (InUse->registered != REG_ALL)
+                       {
+                               /* force the camper to their UUID, and ask them to re-send a NICK. */
+                               InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
+                               InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick.c_str(), InUse->nick.c_str());
+
+                               ServerInstance->Users->clientlist->erase(InUse->nick);
+                               (*(ServerInstance->Users->clientlist))[InUse->uuid] = InUse;
+
+                               InUse->nick = InUse->uuid;
+                               InUse->InvalidateCache();
+                               InUse->registered &= ~REG_NICK;
+                       }
+                       else
+                       {
+                               /* No camping, tell the incoming user  to stop trying to change nick ;p */
+                               this->WriteNumeric(433, "%s %s :Nickname is already in use.", this->registered >= REG_NICK ? this->nick.c_str() : "*", newnick.c_str());
+                               return false;
+                       }
+               }
+       }
+
+       if (this->registered == REG_ALL)
+               this->WriteCommon("NICK %s",newnick.c_str());
+       std::string oldnick = nick;
+       nick = newnick;
+
+       InvalidateCache();
+       ServerInstance->Users->clientlist->erase(oldnick);
+       (*(ServerInstance->Users->clientlist))[newnick] = this;
+
+       if (registered == REG_ALL)
+               FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(this,oldnick));
+
+       return true;
 }
 
 int LocalUser::GetServerPort()
@@ -1544,15 +1603,20 @@ void LocalUser::SetClass(const std::string &explicit_name)
                {
                        ConnectClass* c = *i;
 
-                       if (c->type == CC_ALLOW)
-                       {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "ALLOW %s %d %s", c->host.c_str(), c->GetPort(), c->GetName().c_str());
-                       }
-                       else
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnSetConnectClass, MOD_RESULT, (this,c));
+                       if (MOD_RESULT == MOD_RES_DENY)
+                               continue;
+                       if (MOD_RESULT == MOD_RES_ALLOW)
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "DENY %s %d %s", c->GetHost().c_str(), c->GetPort(), c->GetName().c_str());
+                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Class forced by module to %s", c->GetName().c_str());
+                               found = c;
+                               break;
                        }
 
+                       if (c->type == CC_NAMED)
+                               continue;
+
                        /* check if host matches.. */
                        if (c->GetHost().length() && !InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) &&
                            !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL))
@@ -1572,16 +1636,14 @@ void LocalUser::SetClass(const std::string &explicit_name)
                        }
 
                        /* if it requires a port ... */
-                       if (c->GetPort())
+                       int port = c->config->getInt("port");
+                       if (port)
                        {
-                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", c->GetPort());
+                               ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Requires port (%d)", port);
 
                                /* and our port doesn't match, fail. */
-                               if (this->GetServerPort() != c->GetPort())
-                               {
-                                       ServerInstance->Logs->Log("CONNECTCLASS", DEBUG, "Port match failed (%d)", this->GetServerPort());
+                               if (this->GetServerPort() != port)
                                        continue;
-                               }
                        }
 
                        /* we stop at the first class that meets ALL critera. */
@@ -1626,37 +1688,6 @@ void User::PurgeEmptyChannels()
        this->UnOper();
 }
 
-void User::ShowMOTD()
-{
-       if (!ServerInstance->Config->MOTD.size())
-       {
-               this->WriteNumeric(ERR_NOMOTD, "%s :Message of the day file is missing.",this->nick.c_str());
-               return;
-       }
-       this->WriteNumeric(RPL_MOTDSTART, "%s :%s message of the day", this->nick.c_str(), ServerInstance->Config->ServerName.c_str());
-
-       for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++)
-               this->WriteNumeric(RPL_MOTD, "%s :- %s",this->nick.c_str(),i->c_str());
-
-       this->WriteNumeric(RPL_ENDOFMOTD, "%s :End of message of the day.", this->nick.c_str());
-}
-
-void User::ShowRULES()
-{
-       if (!ServerInstance->Config->RULES.size())
-       {
-               this->WriteNumeric(ERR_NORULES, "%s :RULES File is missing",this->nick.c_str());
-               return;
-       }
-
-       this->WriteNumeric(RPL_RULESTART, "%s :- %s Server Rules -",this->nick.c_str(),ServerInstance->Config->ServerName.c_str());
-
-       for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++)
-               this->WriteNumeric(RPL_RULES, "%s :- %s",this->nick.c_str(),i->c_str());
-
-       this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
-}
-
 const std::string& FakeUser::GetFullHost()
 {
        if (!ServerInstance->Config->HideWhoisServer.empty())
@@ -1673,19 +1704,18 @@ const std::string& FakeUser::GetFullRealHost()
 
 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)
        : config(tag), type(t), fakelag(true), name("unnamed"), registration_timeout(0), host(mask),
-       pingtime(0), pass(""), hash(""), softsendqmax(0), hardsendqmax(0), recvqmax(0),
-       penaltythreshold(0), commandrate(0), maxlocal(0), maxglobal(0), maxchans(0), port(0), limit(0)
+       pingtime(0), softsendqmax(0), hardsendqmax(0), recvqmax(0),
+       penaltythreshold(0), commandrate(0), maxlocal(0), maxglobal(0), maxchans(0), limit(0)
 {
 }
 
 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask, const ConnectClass& parent)
        : config(tag), type(t), fakelag(parent.fakelag), name("unnamed"),
        registration_timeout(parent.registration_timeout), host(mask), pingtime(parent.pingtime),
-       pass(parent.pass), hash(parent.hash), softsendqmax(parent.softsendqmax),
-       hardsendqmax(parent.hardsendqmax), recvqmax(parent.recvqmax),
+       softsendqmax(parent.softsendqmax), hardsendqmax(parent.hardsendqmax), recvqmax(parent.recvqmax),
        penaltythreshold(parent.penaltythreshold), commandrate(parent.commandrate),
        maxlocal(parent.maxlocal), maxglobal(parent.maxglobal), maxchans(parent.maxchans),
-       port(parent.port), limit(parent.limit)
+       limit(parent.limit)
 {
 }
 
@@ -1695,8 +1725,6 @@ void ConnectClass::Update(const ConnectClass* src)
        registration_timeout = src->registration_timeout;
        host = src->host;
        pingtime = src->pingtime;
-       pass = src->pass;
-       hash = src->hash;
        softsendqmax = src->softsendqmax;
        hardsendqmax = src->hardsendqmax;
        recvqmax = src->recvqmax;