]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Fix sending DNSBL error snotices when a user isn't DNSBLed.
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index a1e4d1af70ef06adf485f86be36f9c5218a199bf..b9ff085c3ebdc488894e4db053b3ef64cddceb98 100644 (file)
@@ -42,14 +42,18 @@ static const char base32[] = "0123456789abcdefghijklmnopqrstuv";
 class CloakUser : public ModeHandler
 {
  public:
+       bool active;
        LocalStringExt ext;
        std::string debounce_uid;
        time_t debounce_ts;
        int debounce_count;
 
        CloakUser(Module* source)
-               : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER),
-               ext("cloaked_host", ExtensionItem::EXT_USER, source), debounce_ts(0), debounce_count(0)
+               : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER)
+               , active(false)
+               , ext("cloaked_host", ExtensionItem::EXT_USER, source)
+               , debounce_ts(0)
+               , debounce_count(0)
        {
        }
 
@@ -63,6 +67,8 @@ class CloakUser : public ModeHandler
                 */
                if (!user)
                {
+                       // Remote setters broadcast mode before host while local setters do the opposite, so this takes that into account
+                       active = IS_LOCAL(source) ? adding : !adding;
                        dest->SetMode(this, adding);
                        return MODEACTION_ALLOW;
                }
@@ -131,7 +137,7 @@ class CommandCloak : public Command
                syntax = "<host>";
        }
 
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
 };
 
 class ModuleCloaking : public Module
@@ -146,7 +152,11 @@ class ModuleCloaking : public Module
        unsigned int domainparts;
        dynamic_reference<HashProvider> Hash;
 
-       ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
+       ModuleCloaking()
+               : cu(this)
+               , mode(MODE_OPAQUE)
+               , ck(this)
+               , Hash(this, "hash/md5")
        {
        }
 
@@ -213,7 +223,7 @@ class ModuleCloaking : public Module
                size_t hop1, hop2, hop3;
                size_t len1, len2;
                std::string rv;
-               if (ip.sa.sa_family == AF_INET6)
+               if (ip.family() == AF_INET6)
                {
                        bindata = std::string((const char*)ip.in6.sin6_addr.s6_addr, 16);
                        hop1 = 8;
@@ -257,7 +267,7 @@ class ModuleCloaking : public Module
                }
                else
                {
-                       if (ip.sa.sa_family == AF_INET6)
+                       if (ip.family() == AF_INET6)
                        {
                                rv.append(InspIRCd::Format(".%02x%02x.%02x%02x%s",
                                        ip.in6.sin6_addr.s6_addr[2], ip.in6.sin6_addr.s6_addr[3],
@@ -300,11 +310,18 @@ class ModuleCloaking : public Module
        // mode change, we will call SetMode back to true AFTER the host change is done.
        void OnChangeHost(User* u, const std::string& host) CXX11_OVERRIDE
        {
-               if (u->IsModeSet(cu))
+               if (u->IsModeSet(cu) && !cu.active)
                {
                        u->SetMode(cu, false);
-                       u->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
+
+                       if (!IS_LOCAL(u))
+                               return;
+                       Modes::ChangeList modechangelist;
+                       modechangelist.push_remove(&cu);
+                       ClientProtocol::Events::Mode modeevent(ServerInstance->FakeClient, NULL, u, modechangelist);
+                       static_cast<LocalUser*>(u)->Send(modeevent);
                }
+               cu.active = false;
        }
 
        Version GetVersion() CXX11_OVERRIDE
@@ -339,12 +356,12 @@ class ModuleCloaking : public Module
                suffix = tag->getString("suffix", ".IP");
 
                std::string modestr = tag->getString("mode");
-               if (modestr == "half")
+               if (stdalgo::string::equalsci(modestr, "half"))
                {
                        mode = MODE_HALF_CLOAK;
-                       domainparts = tag->getInt("domainparts", 3, 1, 10);
+                       domainparts = tag->getUInt("domainparts", 3, 1, 10);
                }
-               else if (modestr == "full")
+               else if (stdalgo::string::equalsci(modestr, "full"))
                        mode = MODE_OPAQUE;
                else
                        throw ModuleException("Bad value for <cloak:mode>; must be half or full");
@@ -384,11 +401,15 @@ class ModuleCloaking : public Module
                if (cloak)
                        return;
 
+               // TODO: decide how we are going to cloak AF_UNIX hostnames.
+               if (dest->client_sa.family() != AF_INET && dest->client_sa.family() != AF_INET6)
+                       return;
+
                cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->GetRealHost()));
        }
 };
 
-CmdResult CommandCloak::Handle(const std::vector<std::string> &parameters, User *user)
+CmdResult CommandCloak::Handle(User* user, const Params& parameters)
 {
        ModuleCloaking* mod = (ModuleCloaking*)(Module*)creator;
        irc::sockets::sockaddrs sa;