]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cloaking.cpp
Add server ports to ServerInstance->ports, enable SSL on them using OnHookIO
[user/henk/code/inspircd.git] / src / modules / m_cloaking.cpp
index 2a348ba8b57e4c028625a4b738b4b33c21a03353..ddea8737cd54bb65d74a5c0f4f4a96a3c42c77e4 100644 (file)
@@ -63,8 +63,8 @@ class CloakUser : public ModeHandler
                        return host.substr(splitdot);
        }
 
-       CloakUser(InspIRCd* Instance, Module* source, Module* Hash) 
-               : ModeHandler(Instance, source, 'x', 0, 0, false, MODETYPE_USER, false), HashProvider(Hash),
+       CloakUser(Module* source, Module* Hash)
+               : ModeHandler(source, "cloak", 'x', PARAM_NONE, MODETYPE_USER), HashProvider(Hash),
                ext("cloaked_host", source)
        {
        }
@@ -133,7 +133,6 @@ class CloakUser : public ModeHandler
        {
                unsigned int iv[] = { key1, key2, key3, key4 };
                irc::sepstream seps(ip, '.');
-               std::string ra[4];;
                std::string octet[4];
                int i[4];
 
@@ -148,17 +147,19 @@ class CloakUser : public ModeHandler
                octet[1] = octet[0] + "." + octet[1];
 
                /* Reset the Hash module and send it our IV */
-               HashResetRequest(creator, HashProvider).Send();
-               HashKeyRequest(creator, HashProvider, iv).Send();
+
+               std::string rv;
 
                /* Send the Hash module a different hex table for each octet group's Hash sum */
                for (int k = 0; k < 4; k++)
                {
-                       HashHexRequest(creator, HashProvider, xtab[(iv[k]+i[k]) % 4]).Send();
-                       ra[k] = std::string(HashSumRequest(creator, HashProvider, octet[k]).Send()).substr(0,6);
+                       HashRequestIV hash(creator, HashProvider, iv, xtab[(iv[k]+i[k]) % 4], octet[k]);
+                       rv.append(hash.result.substr(0,6));
+                       if (k < 3)
+                               rv.append(".");
                }
                /* Stick them all together */
-               return std::string().append(ra[0]).append(".").append(ra[1]).append(".").append(ra[2]).append(".").append(ra[3]);
+               return rv;
        }
 
        std::string Cloak6(const char* ip)
@@ -169,27 +170,22 @@ class CloakUser : public ModeHandler
                int rounds = 0;
 
                /* Reset the Hash module and send it our IV */
-               HashResetRequest(creator, HashProvider).Send();
-               HashKeyRequest(creator, HashProvider, iv).Send();
 
                for (const char* input = ip; *input; input++)
                {
                        item += *input;
                        if (item.length() > 7)
                        {
-                               /* Send the Hash module a different hex table for each octet group's Hash sum */
-                               HashHexRequest(creator, HashProvider, xtab[(key1+rounds) % 4]).Send();
-                               hashies.push_back(std::string(HashSumRequest(creator, HashProvider, item).Send()).substr(0,8));
+                               HashRequestIV hash(creator, HashProvider, iv, xtab[(key1+rounds) % 4], item);
+                               hashies.push_back(hash.result.substr(0,8));
                                item.clear();
                        }
                        rounds++;
                }
                if (!item.empty())
                {
-                       /* Send the Hash module a different hex table for each octet group's Hash sum */
-                       HashHexRequest(creator, HashProvider, xtab[(key1+rounds) % 4]).Send();
-                       hashies.push_back(std::string(HashSumRequest(creator, HashProvider, item).Send()).substr(0,8));
-                       item.clear();
+                       HashRequestIV hash(creator, HashProvider, iv, xtab[(key1+rounds) % 4], item);
+                       hashies.push_back(hash.result.substr(0,8));
                }
                /* Stick them all together */
                return irc::stringjoiner(":", hashies, 0, hashies.size() - 1).GetJoined();
@@ -197,7 +193,7 @@ class CloakUser : public ModeHandler
 
        void DoRehash()
        {
-               ConfigReader Conf(ServerInstance);
+               ConfigReader Conf;
                bool lowercase;
 
                /* These are *not* using the need_positive parameter of ReadInteger -
@@ -256,15 +252,14 @@ class ModuleCloaking : public Module
        CloakUser* cu;
 
  public:
-       ModuleCloaking(InspIRCd* Me)
-               : Module(Me)
+       ModuleCloaking()
        {
                /* Attempt to locate the md5 service provider, bail if we can't find it */
                Module* HashModule = ServerInstance->Modules->Find("m_md5.so");
                if (!HashModule)
                        throw ModuleException("Can't find m_md5.so. Please load m_md5.so before m_cloaking.so.");
 
-               cu = new CloakUser(ServerInstance, this, HashModule);
+               cu = new CloakUser(this, HashModule);
 
                try
                {
@@ -305,19 +300,16 @@ class ModuleCloaking : public Module
                }
        }
 
-       ModResult OnCheckBan(User* user, Channel* chan)
+       ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask)
        {
-               char mask[MAXBUF];
+               char cmask[MAXBUF];
                std::string* cloak = cu->ext.get(user);
                /* Check if they have a cloaked host, but are not using it */
                if (cloak && *cloak != user->dhost)
                {
-                       snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
-                       for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
-                       {
-                               if (InspIRCd::Match(mask,i->data))
-                                       return MOD_RES_DENY;
-                       }
+                       snprintf(cmask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
+                       if (InspIRCd::Match(cmask,mask))
+                               return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
        }
@@ -334,7 +326,6 @@ class ModuleCloaking : public Module
 
        ~ModuleCloaking()
        {
-               ServerInstance->Modes->DelMode(cu);
                delete cu;
                ServerInstance->Modules->DoneWithInterface("HashRequest");
        }
@@ -343,7 +334,7 @@ class ModuleCloaking : public Module
        {
                // returns the version number of the module to be
                // listed in /MODULES
-               return Version("$Id$", VF_COMMON|VF_VENDOR,API_VERSION);
+               return Version("Provides masking of user hostnames", VF_COMMON|VF_VENDOR,API_VERSION);
        }
 
        void OnRehash(User* user)
@@ -375,12 +366,10 @@ class ModuleCloaking : public Module
                        if (!cu->ipalways)
                        {
                                /** Reset the Hash module, and send it our IV and hex table */
-                               HashResetRequest(this, cu->HashProvider).Send();
-                               HashKeyRequest(this, cu->HashProvider, iv).Send();
-                               HashHexRequest(this, cu->HashProvider, cu->xtab[(dest->host[0]) % 4]);
+                               HashRequestIV hash(this, cu->HashProvider, iv, cu->xtab[(dest->host[0]) % 4], dest->host);
 
                                /* Generate a cloak using specialized Hash */
-                               std::string hostcloak = cu->prefix + "-" + std::string(HashSumRequest(this, cu->HashProvider, dest->host.c_str()).Send()).substr(0,8) + a;
+                               std::string hostcloak = cu->prefix + "-" + hash.result.substr(0,8) + a;
 
                                /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes
                                 * according to the DNS RFC) then tough titty, they get cloaked as an IP.