]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sqloper.cpp
Fix infinite loop on alias expansion, found by Adam
[user/henk/code/inspircd.git] / src / modules / m_sqloper.cpp
index 5f0df4c1064984d568991ebf1fb549d9d3e2d13e..c4eaa6911000cc14187b490b2e2d3caa6a514e32 100644 (file)
@@ -55,7 +55,7 @@ public:
                                /* 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).Send();
+                               std::string name = HashNameRequest(this, *m).response;
                                /* Build a map of them */
                                hashers[name.c_str()] = *m;
                                names.push_back(name);
@@ -87,12 +87,11 @@ public:
                return false;
        }
 
-       virtual void OnLoadModule(Module* mod, const std::string& name)
+       virtual void OnLoadModule(Module* mod)
        {
                if (ServerInstance->Modules->ModuleHasInterface(mod, "HashRequest"))
                {
-                       ServerInstance->Logs->Log("m_sqloper",DEBUG, "Post-load registering hasher: %s", name.c_str());
-                       std::string sname = HashNameRequest(this, mod).Send();
+                       std::string sname = HashNameRequest(this, mod).response;
                        hashers[sname.c_str()] = mod;
                        names.push_back(sname);
                        if (!diduseiface)
@@ -149,10 +148,8 @@ public:
                        if (x == hashers.end())
                                return false;
 
-                       /* Reset hash module first back to MD5 standard state */
-                       HashResetRequest(this, x->second).Send();
                        /* Make an MD5 hash of the password for using in the query */
-                       std::string md5_pass_hash = HashSumRequest(this, x->second, password.c_str()).Send();
+                       std::string md5_pass_hash = HashRequest(this, x->second, password).hex();
 
                        /* 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.
@@ -160,26 +157,19 @@ public:
                        SQLrequest req = SQLrequest(this, target, databaseid,
                                        SQLquery("SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password='?'") % username % md5_pass_hash);
 
-                       if (req.Send())
-                       {
-                               /* When we get the query response from the service provider we will be given an ID to play with,
-                                * just an ID number which is unique to this query. We need a way of associating that ID with a User
-                                * so we insert it into a map mapping the IDs to users.
-                                * Thankfully m_sqlutils provides this, it will associate a ID with a user or channel, and if the user quits it removes the
-                                * association. This means that if the user quits during a query we will just get a failed lookup from m_sqlutils - telling
-                                * us to discard the query.
-                                */
-                               AssociateUser(this, SQLutils, req.id, user).Send();
-
-                               saved_user.set(user, username);
-                               saved_pass.set(user, password);
+                       /* When we get the query response from the service provider we will be given an ID to play with,
+                        * just an ID number which is unique to this query. We need a way of associating that ID with a User
+                        * so we insert it into a map mapping the IDs to users.
+                        * Thankfully m_sqlutils provides this, it will associate a ID with a user or channel, and if the user quits it removes the
+                        * association. This means that if the user quits during a query we will just get a failed lookup from m_sqlutils - telling
+                        * us to discard the query.
+                        */
+                       AssociateUser(this, SQLutils, req.id, user).Send();
 
-                               return true;
-                       }
-                       else
-                       {
-                               return false;
-                       }
+                       saved_user.set(user, username);
+                       saved_pass.set(user, password);
+
+                       return true;
                }
                else
                {
@@ -188,11 +178,11 @@ public:
                }
        }
 
-       const char* OnRequest(Request* request)
+       void OnRequest(Request& request)
        {
-               if (strcmp(SQLRESID, request->GetId()) == 0)
+               if (strcmp(SQLRESID, request.id) == 0)
                {
-                       SQLresult* res = static_cast<SQLresult*>(request);
+                       SQLresult* res = static_cast<SQLresult*>(&request);
 
                        User* user = GetAssocUser(this, SQLutils, res->id).S().user;
                        UnAssociate(this, SQLutils, res->id).S();
@@ -225,7 +215,6 @@ public:
                                                                /* If/when one of the rows matches, stop checking and return */
                                                                saved_user.unset(user);
                                                                saved_pass.unset(user);
-                                                               return SQLSUCCESS;
                                                        }
                                                        if (tried_user && tried_pass)
                                                        {
@@ -264,11 +253,7 @@ public:
 
                                }
                        }
-
-                       return SQLSUCCESS;
                }
-
-               return NULL;
        }
 
        void LoginFail(User* user, const std::string &username, const std::string &pass)
@@ -317,7 +302,7 @@ public:
 
        Version GetVersion()
        {
-               return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR, API_VERSION);
+               return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR);
        }
 
 };