]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sqloper.cpp
Fix iteration of oper blocks by SSLINFO
[user/henk/code/inspircd.git] / src / modules / m_sqloper.cpp
index c4eaa6911000cc14187b490b2e2d3caa6a514e32..6421f3dd4bbcac92c0489c954c66a6ca9a3f82eb 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
@@ -27,50 +27,22 @@ class ModuleSQLOper : public Module
        LocalStringExt saved_pass;
        Module* SQLutils;
        std::string databaseid;
-       irc::string hashtype;
-       hashymodules hashers;
-       bool diduseiface;
+       std::string hashtype;
        parameterlist names;
 
 public:
        ModuleSQLOper() : saved_user("sqloper_user", this), saved_pass("sqloper_pass", this)
        {
-               ServerInstance->Modules->UseInterface("SQLutils");
-               ServerInstance->Modules->UseInterface("SQL");
-               ServerInstance->Modules->UseInterface("HashRequest");
-
                OnRehash(NULL);
 
-               diduseiface = false;
-
-               /* Find all modules which implement the interface 'HashRequest' */
-               modulelist* ml = ServerInstance->Modules->FindInterface("HashRequest");
-
-               /* Did we find any modules? */
-               if (ml)
-               {
-                       /* Yes, enumerate them all to find out the hashing algorithm name */
-                       for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
-                       {
-                               /* Make a request to it for its name, its implementing
-                                * HashRequest so we know its safe to do this
-                                */
-                               std::string name = HashNameRequest(this, *m).response;
-                               /* Build a map of them */
-                               hashers[name.c_str()] = *m;
-                               names.push_back(name);
-                       }
-                       /* UseInterface doesn't do anything if there are no providers, so we'll have to call it later if a module gets loaded later on. */
-                       diduseiface = true;
-                       ServerInstance->Modules->UseInterface("HashRequest");
-               }
-
                SQLutils = ServerInstance->Modules->Find("m_sqlutils.so");
                if (!SQLutils)
                        throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so.");
 
                Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_OnLoadModule };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               ServerInstance->Modules->Attach(eventlist, this, 3);
+               ServerInstance->Modules->AddService(saved_user);
+               ServerInstance->Modules->AddService(saved_pass);
        }
 
        bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
@@ -87,36 +59,12 @@ public:
                return false;
        }
 
-       virtual void OnLoadModule(Module* mod)
-       {
-               if (ServerInstance->Modules->ModuleHasInterface(mod, "HashRequest"))
-               {
-                       std::string sname = HashNameRequest(this, mod).response;
-                       hashers[sname.c_str()] = mod;
-                       names.push_back(sname);
-                       if (!diduseiface)
-                       {
-                               ServerInstance->Modules->UseInterface("HashRequest");
-                               diduseiface = true;
-                       }
-               }
-       }
-
-       virtual ~ModuleSQLOper()
-       {
-               ServerInstance->Modules->DoneWithInterface("SQL");
-               ServerInstance->Modules->DoneWithInterface("SQLutils");
-               if (diduseiface)
-                       ServerInstance->Modules->DoneWithInterface("HashRequest");
-       }
-
-
        virtual void OnRehash(User* user)
        {
                ConfigReader Conf;
 
                databaseid = Conf.ReadValue("sqloper", "dbid", 0); /* Database ID of a database configured for the service provider module */
-               hashtype = assign(Conf.ReadValue("sqloper", "hash", 0));
+               hashtype = Conf.ReadValue("sqloper", "hash", 0);
        }
 
        virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
@@ -138,18 +86,14 @@ public:
 
        bool LookupOper(User* user, const std::string &username, const std::string &password)
        {
-               Module* target;
-
-               target = ServerInstance->Modules->FindFeature("SQL");
-
-               if (target)
+               ServiceProvider* prov = ServerInstance->Modules->FindService(SERVICE_DATA, "SQL");
+               if (prov)
                {
-                       hashymodules::iterator x = hashers.find(hashtype);
-                       if (x == hashers.end())
-                               return false;
+                       Module* target = prov->creator;
+                       HashProvider* hash = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + hashtype);
 
                        /* Make an MD5 hash of the password for using in the query */
-                       std::string md5_pass_hash = HashRequest(this, x->second, password).hex();
+                       std::string md5_pass_hash = hash ? hash->hexsum(password) : password;
 
                        /* We generate our own sum here because some database providers (e.g. SQLite) dont have a builtin md5/sha256 function,
                         * also hashing it in the module and only passing a remote query containing a hash is more secure.
@@ -275,26 +219,21 @@ public:
 
        bool OperUser(User* user, const std::string &pattern, const std::string &type)
        {
-               ConfigReader Conf;
-
-               for (int j = 0; j < Conf.Enumerate("type"); j++)
-               {
-                       std::string tname = Conf.ReadValue("type","name",j);
-                       std::string hostname(user->ident);
+               OperIndex::iterator iter = ServerInstance->Config->oper_blocks.find(" " + type);
+               if (iter == ServerInstance->Config->oper_blocks.end())
+                       return false;
+               OperInfo* ifo = iter->second;
 
-                       hostname.append("@").append(user->host);
+               std::string hostname(user->ident);
 
-                       if ((tname == type) && OneOfMatches(hostname.c_str(), user->GetIPString(), pattern.c_str()))
-                       {
-                               /* Opertype and host match, looks like this is it. */
-                               std::string operhost = Conf.ReadValue("type", "host", j);
+               hostname.append("@").append(user->host);
 
-                               if (operhost.size())
-                                       user->ChangeDisplayedHost(operhost.c_str());
+               if (OneOfMatches(hostname.c_str(), user->GetIPString(), pattern.c_str()))
+               {
+                       /* Opertype and host match, looks like this is it. */
 
-                               user->Oper(type, tname);
-                               return true;
-                       }
+                       user->Oper(ifo);
+                       return true;
                }
 
                return false;