diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-03-13 20:29:36 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-03-13 20:29:36 +0000 |
commit | 63732f37cba3d493954154c0f2440ddc88d7f207 (patch) | |
tree | 5ca2c614d648cd768a319d7a1ebbdb3918c407ed | |
parent | a45254ff4c15ca23b03bb2dbd52a6cd3b30c2662 (diff) |
Handle database not present a bit better, add missing MySQL rehash on init
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12634 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modules/extra/m_mysql.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_sqlauth.cpp | 26 | ||||
-rw-r--r-- | src/modules/m_sqloper.cpp | 20 |
3 files changed, 34 insertions, 14 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 88c98a5e7..b4d7cd7c6 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -376,6 +376,8 @@ void ModuleSQL::init() Implementation eventlist[] = { I_OnRehash, I_OnUnloadModule }; ServerInstance->Modules->Attach(eventlist, this, 2); + + OnRehash(NULL); } ModuleSQL::~ModuleSQL() diff --git a/src/modules/m_sqlauth.cpp b/src/modules/m_sqlauth.cpp index 29554b031..d87c66de9 100644 --- a/src/modules/m_sqlauth.cpp +++ b/src/modules/m_sqlauth.cpp @@ -87,14 +87,16 @@ class ModuleSQLAuth : public Module void OnRehash(User* user) { - ConfigReader Conf; - - SQL.SetProvider("SQL/" + 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 */ - SQL.lookup(); + 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) @@ -110,6 +112,14 @@ 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); ParamM userinfo; diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index 92e402811..bded0ea04 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -146,19 +146,27 @@ public: { ConfigTag* tag = ServerInstance->Config->ConfValue("sqloper"); - SQL.SetProvider("SQL/" + tag->getString("dbid")); - SQL.lookup(); + std::string dbid = tag->getString("dbid"); + if (dbid.empty()) + SQL.SetProvider("SQL"); + else + 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'"); } ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser *user, bool validated, const std::string &original_line) { - if (validated && command == "OPER" && parameters.size() == 2 && SQL) + if (validated && command == "OPER" && parameters.size() >= 2) { - LookupOper(user, parameters[0], parameters[1]); - /* Query is in progress, it will re-invoke OPER if needed */ - return MOD_RES_DENY; + if (SQL) + { + LookupOper(user, parameters[0], parameters[1]); + /* Query is in progress, it will re-invoke OPER if needed */ + return MOD_RES_DENY; + } + ServerInstance->Logs->Log("m_sqloper",DEFAULT, "SQLOPER: database not present"); } return MOD_RES_PASSTHRU; } |