diff options
-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; } |