]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Merge pull request #1351 from SaberUK/master+webirc
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index 4e203d14c97a8079c06b946d5ef6196ef9a0ee37..cb3fdac1a1a565646523bfab457c2091eeaa656e 100644 (file)
@@ -49,7 +49,7 @@ class CloakUser : public ModeHandler
 
        CloakUser(Module* source)
                : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER),
-               ext("cloaked_host", source), debounce_ts(0), debounce_count(0)
+               ext("cloaked_host", ExtensionItem::EXT_USER, source), debounce_ts(0), debounce_count(0)
        {
        }
 
@@ -89,6 +89,10 @@ class CloakUser : public ModeHandler
 
                if (adding)
                {
+                       // assume this is more correct
+                       if (user->registered != REG_ALL && user->host != user->dhost)
+                               return MODEACTION_DENY;
+
                        std::string* cloak = ext.get(user);
 
                        if (!cloak)
@@ -99,7 +103,7 @@ class CloakUser : public ModeHandler
                        }
                        if (cloak)
                        {
-                               user->ChangeDisplayedHost(cloak->c_str());
+                               user->ChangeDisplayedHost(*cloak);
                                user->SetMode(this, true);
                                return MODEACTION_ALLOW;
                        }
@@ -139,22 +143,12 @@ class ModuleCloaking : public Module
        std::string prefix;
        std::string suffix;
        std::string key;
-       const char* xtab[4];
        dynamic_reference<HashProvider> Hash;
 
        ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
        {
        }
 
-       void init() CXX11_OVERRIDE
-       {
-               OnRehash(NULL);
-
-               ServerInstance->Modules->AddService(cu);
-               ServerInstance->Modules->AddService(ck);
-               ServerInstance->Modules->AddService(cu.ext);
-       }
-
        /** This function takes a domain name string and returns just the last two domain parts,
         * or the last domain part if only two are available. Failing that it just returns what it was given.
         *
@@ -201,7 +195,7 @@ class ModuleCloaking : public Module
                input.append(1, '\0'); // null does not terminate a C++ string
                input.append(item);
 
-               std::string rv = Hash->sum(input).substr(0,len);
+               std::string rv = Hash->GenerateRaw(input).substr(0,len);
                for(int i=0; i < len; i++)
                {
                        // this discards 3 bits per byte. We have an
@@ -262,19 +256,17 @@ class ModuleCloaking : public Module
                }
                else
                {
-                       char buf[50];
                        if (ip.sa.sa_family == AF_INET6)
                        {
-                               snprintf(buf, 50, ".%02x%02x.%02x%02x%s",
+                               rv.append(InspIRCd::Format(".%02x%02x.%02x%02x%s",
                                        ip.in6.sin6_addr.s6_addr[2], ip.in6.sin6_addr.s6_addr[3],
-                                       ip.in6.sin6_addr.s6_addr[0], ip.in6.sin6_addr.s6_addr[1], suffix.c_str());
+                                       ip.in6.sin6_addr.s6_addr[0], ip.in6.sin6_addr.s6_addr[1], suffix.c_str()));
                        }
                        else
                        {
                                const unsigned char* ip4 = (const unsigned char*)&ip.in4.sin_addr;
-                               snprintf(buf, 50, ".%d.%d%s", ip4[1], ip4[0], suffix.c_str());
+                               rv.append(InspIRCd::Format(".%d.%d%s", ip4[1], ip4[0], suffix.c_str()));
                        }
-                       rv.append(buf);
                }
                return rv;
        }
@@ -297,7 +289,7 @@ class ModuleCloaking : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void Prioritize()
+       void Prioritize() CXX11_OVERRIDE
        {
                /* Needs to be after m_banexception etc. */
                ServerInstance->Modules->SetPriority(this, I_OnCheckBan, PRIORITY_LAST);
@@ -310,7 +302,7 @@ class ModuleCloaking : public Module
                if (u->IsModeSet(cu))
                {
                        u->SetMode(cu, false);
-                       u->WriteServ("MODE %s -%c", u->nick.c_str(), cu.GetModeChar());
+                       u->WriteCommand("MODE", "-" + ConvToStr(cu.GetModeChar()));
                }
        }
 
@@ -331,7 +323,7 @@ class ModuleCloaking : public Module
                return Version("Provides masking of user hostnames", VF_COMMON|VF_VENDOR, testcloak);
        }
 
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("cloak");
                prefix = tag->getString("prefix");
@@ -354,11 +346,14 @@ class ModuleCloaking : public Module
        {
                std::string chost;
 
+               irc::sockets::sockaddrs hostip;
+               bool host_is_ip = irc::sockets::aptosa(host, ip.port(), hostip) && hostip == ip;
+
                switch (mode)
                {
                        case MODE_HALF_CLOAK:
                        {
-                               if (ipstr != host)
+                               if (!host_is_ip)
                                        chost = prefix + SegmentCloak(host, 1, 6) + LastTwoDomainParts(host);
                                if (chost.empty() || chost.length() > 50)
                                        chost = SegmentIP(ip, false);