]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sqlauth.cpp
Send HALFOP= line in CAPAB CAPABILITIES for 1201 compat (anope relies on this)
[user/henk/code/inspircd.git] / src / modules / m_sqlauth.cpp
index df2dd019065978ae99f2532088e824d2db80a3db..d87c66de980210773340e6395ba30a0ed8a1c98c 100644 (file)
@@ -29,8 +29,10 @@ class AuthQuery : public SQLQuery
        const std::string uid;
        LocalIntExt& pendingExt;
        bool verbose;
-       AuthQuery(Module* me, const std::string& db, const std::string& q, const std::string& u, LocalIntExt& e, bool v)
-               : SQLQuery(me, db, q), uid(u), pendingExt(e), verbose(v) {}
+       AuthQuery(Module* me, const std::string& u, LocalIntExt& e, bool v)
+               : SQLQuery(me), uid(u), pendingExt(e), verbose(v)
+       {
+       }
        
        void OnResult(SQLResult& res)
        {
@@ -68,7 +70,6 @@ class ModuleSQLAuth : public Module
        std::string freeformquery;
        std::string killreason;
        std::string allowpattern;
-       std::string databaseid;
        bool verbose;
 
  public:
@@ -86,13 +87,16 @@ class ModuleSQLAuth : public Module
 
        void OnRehash(User* user)
        {
-               ConfigReader Conf;
-
-               databaseid      = Conf.ReadValue("sqlauth", "dbid", 0);                 /* Database ID, given to the SQL service provider */
-               freeformquery   = Conf.ReadValue("sqlauth", "query", 0);        /* Field name where username can be found */
-               killreason      = Conf.ReadValue("sqlauth", "killreason", 0);   /* Reason to give when access is denied to a user (put your reg details here) */
-               allowpattern    = Conf.ReadValue("sqlauth", "allowpattern",0 ); /* Allow nicks matching this pattern without requiring auth */
-               verbose         = Conf.ReadFlag("sqlauth", "verbose", 0);               /* Set to true if failed connects should be reported to operators */
+               ConfigTag* conf = ServerInstance->Config->ConfValue("sqlauth");
+               std::string dbid = conf->getString("dbid");
+               if (dbid.empty())
+                       SQL.SetProvider("SQL");
+               else
+                       SQL.SetProvider("SQL/" + dbid);
+               freeformquery = conf->getString("query");
+               killreason = conf->getString("killreason");
+               allowpattern = conf->getString("allowpattern");
+               verbose = conf->getBool("verbose");
        }
 
        ModResult OnUserRegister(LocalUser* user)
@@ -108,18 +112,19 @@ class ModuleSQLAuth : public Module
                if (pendingExt.get(user))
                        return MOD_RES_PASSTHRU;
 
+               if (!SQL)
+               {
+                       ServerInstance->SNO->WriteGlobalSno('a', "Forbiding connection from %s!%s@%s (SQL database not present)",
+                               user->nick.c_str(), user->ident.c_str(), user->host.c_str());
+                       ServerInstance->Users->QuitUser(user, killreason);
+                       return MOD_RES_PASSTHRU;
+               }
+
                pendingExt.set(user, AUTH_STATE_BUSY);
 
-               std::string thisquery = freeformquery;
                ParamM userinfo;
-               userinfo["nick"] = user->nick;
+               SQL->PopulateUserInfo(user, userinfo);
                userinfo["pass"] = user->password;
-               userinfo["host"] = user->host;
-               userinfo["ip"] = user->GetIPString();
-               userinfo["gecos"] = user->fullname;
-               userinfo["ident"] = user->ident;
-               userinfo["server"] = user->server;
-               userinfo["uuid"] = user->uuid;
 
                HashProvider* md5 = ServerInstance->Modules->FindDataService<HashProvider>("hash/md5");
                if (md5)
@@ -127,9 +132,9 @@ class ModuleSQLAuth : public Module
 
                HashProvider* sha256 = ServerInstance->Modules->FindDataService<HashProvider>("hash/sha256");
                if (sha256)
-                       userinfo["$sha256pass"] = sha256->hexsum(user->password);
+                       userinfo["sha256pass"] = sha256->hexsum(user->password);
 
-               SQL->submit(new AuthQuery(this, databaseid, SQL->FormatQuery(freeformquery, userinfo), user->uuid, pendingExt, verbose));
+               SQL->submit(new AuthQuery(this, user->uuid, pendingExt, verbose), freeformquery, userinfo);
 
                return MOD_RES_PASSTHRU;
        }