* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd is copyright (C) 2002-2004 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- * <omster@gmail.com>
- *
- * Written by Craig Edwards, Craig McLure, and others.
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
* This program is free but copyrighted software; see
* the file COPYING for details.
*
*/
#include <string>
-
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "m_sqlutils.h"
/* $ModDesc: Allow/Deny connections based upon an arbitary SQL table */
+/* $ModDep: m_sqlv2.h m_sqlutils.h */
class ModuleSQLAuth : public Module
{
InspIRCd* Srv;
Module* SQLutils;
+ Module* SQLprovider;
std::string usertable;
std::string userfield;
ModuleSQLAuth(InspIRCd* Me)
: Module::Module(Me), Srv(Me)
{
- SQLutils = Srv->FindFeature("SQLutils");
-
- if(SQLutils)
- {
- ServerInstance->Log(DEBUG, "Successfully got SQLutils pointer");
- }
- else
- {
- ServerInstance->Log(DEFAULT, "ERROR: This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
- throw ModuleException("This module requires a module offering the 'SQLutils' feature (usually m_sqlutils.so). Please load it and try again.");
- }
-
- OnRehash("");
+ ServerInstance->UseInterface("SQLutils");
+ ServerInstance->UseInterface("SQL");
+
+ SQLutils = ServerInstance->FindModule("m_sqlutils.so");
+ if (!SQLutils)
+ throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqlauth.so.");
+
+ OnRehash(NULL,"");
+ }
+
+ virtual ~ModuleSQLAuth()
+ {
+ ServerInstance->DoneWithInterface("SQL");
+ ServerInstance->DoneWithInterface("SQLutils");
}
void Implements(char* List)
List[I_OnUserDisconnect] = List[I_OnCheckReady] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = 1;
}
- virtual void OnRehash(const std::string ¶meter)
+ virtual void OnRehash(userrec* user, const std::string ¶meter)
{
ConfigReader Conf(Srv);
}
}
- virtual void OnUserRegister(userrec* user)
+ virtual int OnUserRegister(userrec* user)
{
if ((allowpattern != "") && (Srv->MatchText(user->nick,allowpattern)))
- return;
+ {
+ user->Extend("sqlauthed");
+ return 0;
+ }
if (!CheckCredentials(user))
{
userrec::QuitUser(Srv,user,killreason);
+ return 1;
}
+ return 0;
}
bool CheckCredentials(userrec* user)
else
{
ServerInstance->Log(DEBUG, "Got query with unknown ID, this probably means the user quit while the query was in progress");
+ return NULL;
+ }
+
+ if (!user->GetExt("sqlauthed"))
+ {
+ userrec::QuitUser(Srv,user,killreason);
}
-
return SQLSUCCESS;
}
virtual bool OnCheckReady(userrec* user)
{
- if(user->GetExt("sqlauth_failed"))
- {
- userrec::QuitUser(Srv,user,killreason);
- return false;
- }
-
return user->GetExt("sqlauthed");
}
- virtual ~ModuleSQLAuth()
- {
- }
-
virtual Version GetVersion()
{
- return Version(1,0,1,0,VF_VENDOR,API_VERSION);
+ return Version(1,1,1,0,VF_VENDOR,API_VERSION);
}
};