]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlauth.cpp
Extra checks to not set the ssl marker twice on re-handshake (nonfatal but wasteful)
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlauth.cpp
index e1c0929c4e30543e838ba739bf5a1d0797253bc3..36b9b861176fa6e98ce0d44959225a5a2f110d67 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2004 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -72,12 +72,18 @@ class ModuleSQLAuth : public Module
                return (SQLModule);
        }
 
-       ModuleSQLAuth()
+       ModuleSQLAuth(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
+               Srv = Me;
                ReadConfig();
        }
 
+       void Implements(char* List)
+       {
+               List[I_OnRehash] = List[I_OnUserRegister] = 1;
+       }
+
        virtual void OnRehash(std::string parameter)
        {
                ReadConfig();
@@ -121,14 +127,19 @@ class ModuleSQLAuth : public Module
                password = temp;
 
                // Create a request containing the SQL query and send it to m_sql.so
-               SQLRequest* query = new SQLRequest(SQL_RESULT,dbid,"SELECT * FROM "+usertable+" WHERE "+userfield+"='"+username+"' AND "+passfield+"="+encryption+"('"+password+"')");
+               std::string querystr("SELECT * FROM "+usertable+" WHERE "+userfield+"='"+username+"' AND "+passfield+"="+encryption+"('"+password+"')");
+               
+               Srv->Log(DEBUG, "m_sqlauth.so: Query: " + querystr);
+               
+               SQLRequest* query = new SQLRequest(SQL_RESULT,dbid,querystr);
                Request queryrequest((char*)query, this, SQLModule);
                SQLResult* result = (SQLResult*)queryrequest.Send();
 
                // Did we get "OK" as a result?
                if (result->GetType() == SQL_OK)
                {
-
+                       log(DEBUG, "m_sqlauth.so: Query OK");
+                       
                        // if we did, this means we may now request a row... there should be only one row for each user, so,
                        // we don't need to loop to fetch multiple rows.
                        SQLRequest* rowrequest = new SQLRequest(SQL_ROW,dbid,"");
@@ -138,44 +149,52 @@ class ModuleSQLAuth : public Module
                        // did we get a row? If we did, we can now do something with the fields
                        if (rowresult->GetType() == SQL_ROW)
                        {
+                               log(DEBUG, "m_sqlauth.so: Got row...user '%s'", rowresult->GetField(userfield).c_str());
+                               
                                if (rowresult->GetField(userfield) == username)
                                {
+                                       log(DEBUG, "m_sqlauth.so: Got correct user...");
                                        // because the query directly asked for the password hash, we do not need to check it -
                                        // if it didnt match it wont be returned in the first place from the SELECT.
                                        // This just checks we didnt get an empty row by accident.
                                        found = true;
                                }
-                               delete rowresult;
                        }
                        else
                        {
+                               log(DEBUG, "m_sqlauth.so: Couldn't find row");
                                // we didn't have a row.
                                found = false;
                        }
+                       
                        delete rowrequest;
-                       delete result;
+                       delete rowresult;
                }
                else
                {
+                       log(DEBUG, "m_sqlauth.so: Query failed");
                        // the query was bad
                        found = false;
                }
+               
                query->SetQueryType(SQL_DONE);
                query->SetConnID(dbid);
                Request donerequest((char*)query, this, SQLModule);
                donerequest.Send();
+               
                delete query;
+               delete result;
+               
                return found;
        }
 
        virtual ~ModuleSQLAuth()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR);
+               return Version(1,0,0,2,VF_VENDOR);
        }
        
 };
@@ -191,9 +210,9 @@ class ModuleSQLAuthFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSQLAuth;
+               return new ModuleSQLAuth(Me);
        }
        
 };