]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_pbkdf2.cpp
Allow the maximum length of a chanfilter message to be configured.
[user/henk/code/inspircd.git] / src / modules / m_pbkdf2.cpp
index b66b3f05891fa972943ed8c2823cb4f2555212e7..8b1346c845659bbd71ff0f5e082f8d3d2987f6ed 100644 (file)
@@ -81,24 +81,26 @@ class PBKDF2Provider : public HashProvider
                size_t blocks = std::ceil((double)dkl / provider->out_size);
 
                std::string output;
+               std::string tmphash;
+               std::string salt_block = salt;
                for (size_t block = 1; block <= blocks; block++)
                {
                        char salt_data[4];
                        for (size_t i = 0; i < sizeof(salt_data); i++)
                                salt_data[i] = block >> (24 - i * 8) & 0x0F;
 
-                       std::string salt_block(salt_data, 4);
-                       salt_block = salt + salt_block;
+                       salt_block.erase(salt.length());
+                       salt_block.append(salt_data, sizeof(salt_data));
 
                        std::string blockdata = provider->hmac(pass, salt_block);
                        std::string lasthash = blockdata;
                        for (size_t iter = 1; iter < itr; iter++)
                        {
-                               std::string tmphash = provider->hmac(pass, lasthash);
+                               tmphash = provider->hmac(pass, lasthash);
                                for (size_t i = 0; i < provider->out_size; i++)
                                        blockdata[i] ^= tmphash[i];
 
-                               lasthash = tmphash;
+                               lasthash.swap(tmphash);
                        }
                        output += blockdata;
                }
@@ -178,71 +180,35 @@ class ModulePBKDF2 : public Module
                stdalgo::delete_all(providers);
        }
 
-       void Prioritize() CXX11_OVERRIDE
+       void OnServiceAdd(ServiceProvider& provider) CXX11_OVERRIDE
        {
-               OnLoadModule(NULL);
-       }
-
-       void OnLoadModule(Module* mod) CXX11_OVERRIDE
-       {
-               bool newProv = false;
-               // As the module doesn't tell us what ServiceProviders it has, let's iterate all (yay ...) the ServiceProviders
-               // Good thing people don't run loading and unloading those all the time
-               for (std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.begin(); i != ServerInstance->Modules->DataProviders.end(); ++i)
-               {
-                       ServiceProvider* provider = i->second;
-
-                       // Does the service belong to the new mod?
-                       // In the case this is our first run (mod == NULL, continue anyway)
-                       if (mod && provider->creator != mod)
-                               continue;
-
-                       // Check if it's a hash provider
-                       if (provider->name.compare(0, 5, "hash/"))
-                               continue;
-
-                       HashProvider* hp = static_cast<HashProvider*>(provider);
-
-                       if (hp->IsKDF())
-                               continue;
-
-                       bool has_prov = false;
-                       for (std::vector<PBKDF2Provider*>::const_iterator j = providers.begin(); j != providers.end(); ++j)
-                       {
-                               if ((*j)->provider == hp)
-                               {
-                                       has_prov = true;
-                                       break;
-                               }
-                       }
-                       if (has_prov)
-                               continue;
+               // Check if it's a hash provider
+               if (provider.name.compare(0, 5, "hash/"))
+                       return;
 
-                       newProv = true;
+               HashProvider* hp = static_cast<HashProvider*>(&provider);
+               if (hp->IsKDF())
+                       return;
 
-                       PBKDF2Provider* prov = new PBKDF2Provider(this, hp);
-                       providers.push_back(prov);
-                       ServerInstance->Modules->AddService(*prov);
-               }
+               PBKDF2Provider* prov = new PBKDF2Provider(this, hp);
+               providers.push_back(prov);
+               ServerInstance->Modules.AddService(*prov);
 
-               if (newProv)
-                       GetConfig();
+               GetConfig();
        }
 
-       void OnUnloadModule(Module* mod) CXX11_OVERRIDE
+       void OnServiceDel(ServiceProvider& prov) CXX11_OVERRIDE
        {
-               for (std::vector<PBKDF2Provider*>::iterator i = providers.begin(); i != providers.end(); )
+               for (std::vector<PBKDF2Provider*>::iterator i = providers.begin(); i != providers.end(); ++i)
                {
                        PBKDF2Provider* item = *i;
-                       if (item->provider->creator != mod)
-                       {
-                               ++i;
+                       if (item->provider != &prov)
                                continue;
-                       }
 
                        ServerInstance->Modules->DelService(*item);
                        delete item;
-                       i = providers.erase(i);
+                       providers.erase(i);
+                       break;
                }
        }