]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sqloper.cpp
Allow the maximum length of a chanfilter message to be configured.
[user/henk/code/inspircd.git] / src / modules / m_sqloper.cpp
index b59225ee806a744f15bb256e84ad5984faa60851..d4baae7d224d975205a8176ee787555f12876556 100644 (file)
 #include "modules/sql.h"
 #include "modules/hash.h"
 
-class OpMeQuery : public SQLQuery
+class OperQuery : public SQL::Query
 {
  public:
        const std::string uid, username, password;
-       OpMeQuery(Module* me, const std::string& u, const std::string& un, const std::string& pw)
-               : SQLQuery(me), uid(u), username(un), password(pw)
+       OperQuery(Module* me, const std::string& u, const std::string& un, const std::string& pw)
+               : SQL::Query(me)
+               , uid(u)
+               , username(un)
+               , password(pw)
        {
        }
 
-       void OnResult(SQLResult& res) CXX11_OVERRIDE
+       void OnResult(SQL::Result& res) CXX11_OVERRIDE
        {
                ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "result for %s", uid.c_str());
                User* user = ServerInstance->FindNick(uid);
@@ -38,7 +41,7 @@ class OpMeQuery : public SQLQuery
                        return;
 
                // multiple rows may exist
-               SQLEntries row;
+               SQL::Row row;
                while (res.GetRow(row))
                {
                        if (OperUser(user, row[0], row[1]))
@@ -49,9 +52,9 @@ class OpMeQuery : public SQLQuery
                fallback();
        }
 
-       void OnError(SQLerror& error) CXX11_OVERRIDE
+       void OnError(SQL::Error& error) CXX11_OVERRIDE
        {
-               ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "query failed (%s)", error.Str());
+               ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "query failed (%s)", error.ToString());
                fallback();
        }
 
@@ -61,7 +64,7 @@ class OpMeQuery : public SQLQuery
                if (!user)
                        return;
 
-               Command* oper_command = ServerInstance->Parser->GetHandler("OPER");
+               Command* oper_command = ServerInstance->Parser.GetHandler("OPER");
 
                if (oper_command)
                {
@@ -78,8 +81,8 @@ class OpMeQuery : public SQLQuery
 
        bool OperUser(User* user, const std::string &pattern, const std::string &type)
        {
-               OperIndex::iterator iter = ServerInstance->Config->oper_blocks.find(" " + type);
-               if (iter == ServerInstance->Config->oper_blocks.end())
+               ServerConfig::OperIndex::const_iterator iter = ServerInstance->Config->OperTypes.find(type);
+               if (iter == ServerInstance->Config->OperTypes.end())
                {
                        ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "bad type '%s' in returned row for oper %s", type.c_str(), username.c_str());
                        return false;
@@ -88,7 +91,7 @@ class OpMeQuery : public SQLQuery
 
                std::string hostname(user->ident);
 
-               hostname.append("@").append(user->host);
+               hostname.append("@").append(user->GetRealHost());
 
                if (InspIRCd::MatchMask(pattern, hostname, user->GetIPString()))
                {
@@ -106,20 +109,12 @@ class ModuleSQLOper : public Module
 {
        std::string query;
        std::string hashtype;
-       dynamic_reference<SQLProvider> SQL;
+       dynamic_reference<SQL::Provider> SQL;
 
 public:
        ModuleSQLOper() : SQL(this, "SQL") {}
 
-       void init() CXX11_OVERRIDE
-       {
-               OnRehash(NULL);
-
-               Implementation eventlist[] = { I_OnRehash, I_OnPreCommand };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-       }
-
-       void OnRehash(User* user) CXX11_OVERRIDE
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ConfigTag* tag = ServerInstance->Config->ConfValue("sqloper");
 
@@ -130,7 +125,7 @@ public:
                        SQL.SetProvider("SQL/" + dbid);
 
                hashtype = tag->getString("hash");
-               query = tag->getString("query", "SELECT hostname as host, type FROM ircd_opers WHERE username='$username' AND password='$password'");
+               query = tag->getString("query", "SELECT hostname as host, type FROM ircd_opers WHERE username='$username' AND password='$password' AND active=1;");
        }
 
        ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE
@@ -152,12 +147,12 @@ public:
        {
                HashProvider* hash = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + hashtype);
 
-               ParamM userinfo;
-               SQL->PopulateUserInfo(user, userinfo);
+               SQL::ParamMap userinfo;
+               SQL::PopulateUserInfo(user, userinfo);
                userinfo["username"] = username;
-               userinfo["password"] = hash ? hash->hexsum(password) : password;
+               userinfo["password"] = hash ? hash->Generate(password) : password;
 
-               SQL->submit(new OpMeQuery(this, user->uuid, username, password), query, userinfo);
+               SQL->Submit(new OperQuery(this, user->uuid, username, password), query, userinfo);
        }
 
        Version GetVersion() CXX11_OVERRIDE