Fix compilation of some extras modules

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11776 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2009-09-28 22:25:43 +00:00
parent 5e1d239f3d
commit 83454575bc
7 changed files with 66 additions and 91 deletions

View File

@ -33,6 +33,7 @@
class ModuleLDAPAuth : public Module class ModuleLDAPAuth : public Module
{ {
LocalIntExt ldapAuthed;
std::string base; std::string base;
std::string attribute; std::string attribute;
std::string ldapserver; std::string ldapserver;
@ -46,21 +47,21 @@ class ModuleLDAPAuth : public Module
LDAP *conn; LDAP *conn;
public: public:
ModuleLDAPAuth() ModuleLDAPAuth() : ldapAuthed("ldapauth", this)
{ {
conn = NULL; conn = NULL;
Implementation eventlist[] = { I_OnUserDisconnect, I_OnCheckReady, I_OnRehash, I_OnUserRegister }; Implementation eventlist[] = { I_OnCheckReady, I_OnRehash, I_OnUserRegister };
ServerInstance->Modules->Attach(eventlist, this, 4); ServerInstance->Modules->Attach(eventlist, this, 4);
OnRehash(NULL); OnRehash(NULL);
} }
virtual ~ModuleLDAPAuth() ~ModuleLDAPAuth()
{ {
if (conn) if (conn)
ldap_unbind_ext(conn, NULL, NULL); ldap_unbind_ext(conn, NULL, NULL);
} }
virtual void OnRehash(User* user) void OnRehash(User* user)
{ {
ConfigReader Conf; ConfigReader Conf;
@ -110,11 +111,11 @@ public:
return true; return true;
} }
virtual ModResult OnUserRegister(User* user) ModResult OnUserRegister(User* user)
{ {
if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern))) if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern)))
{ {
user->Extend("ldapauthed"); ldapAuthed.set(user,1);
return MOD_RES_PASSTHRU; return MOD_RES_PASSTHRU;
} }
@ -188,7 +189,6 @@ public:
{ {
if (verbose) if (verbose)
ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (No password provided)", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (No password provided)", user->nick.c_str(), user->ident.c_str(), user->host.c_str());
user->Extend("ldapauth_failed");
return false; return false;
} }
cred.bv_val = (char*)user->password.data(); cred.bv_val = (char*)user->password.data();
@ -196,7 +196,7 @@ public:
if ((res = ldap_sasl_bind_s(conn, ldap_get_dn(conn, entry), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) == LDAP_SUCCESS) if ((res = ldap_sasl_bind_s(conn, ldap_get_dn(conn, entry), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL)) == LDAP_SUCCESS)
{ {
ldap_msgfree(msg); ldap_msgfree(msg);
user->Extend("ldapauthed"); ldapAuthed.set(user,1);
return true; return true;
} }
else else
@ -204,24 +204,16 @@ public:
if (verbose) if (verbose)
ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (%s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res)); ServerInstance->SNO->WriteToSnoMask('c', "Forbidden connection from %s!%s@%s (%s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), ldap_err2string(res));
ldap_msgfree(msg); ldap_msgfree(msg);
user->Extend("ldapauth_failed");
return false; return false;
} }
} }
ModResult OnCheckReady(User* user)
virtual void OnUserDisconnect(User* user)
{ {
user->Shrink("ldapauthed"); return ldapAuthed.get(user) ? MOD_RES_PASSTHRU : MOD_RES_DENY;
user->Shrink("ldapauth_failed");
} }
virtual ModResult OnCheckReady(User* user) Version GetVersion()
{
return user->GetExt("ldapauthed") ? MOD_RES_PASSTHRU : MOD_RES_DENY;
}
virtual Version GetVersion()
{ {
return Version("Allow/Deny connections based upon answer from LDAP server", VF_VENDOR, API_VERSION); return Version("Allow/Deny connections based upon answer from LDAP server", VF_VENDOR, API_VERSION);
} }

View File

@ -21,6 +21,7 @@
class ModuleSQLAuth : public Module class ModuleSQLAuth : public Module
{ {
LocalIntExt sqlAuthed;
Module* SQLutils; Module* SQLutils;
Module* SQLprovider; Module* SQLprovider;
@ -32,7 +33,7 @@ class ModuleSQLAuth : public Module
bool verbose; bool verbose;
public: public:
ModuleSQLAuth() ModuleSQLAuth() : sqlAuthed("sqlauth", this)
{ {
ServerInstance->Modules->UseInterface("SQLutils"); ServerInstance->Modules->UseInterface("SQLutils");
ServerInstance->Modules->UseInterface("SQL"); ServerInstance->Modules->UseInterface("SQL");
@ -57,7 +58,7 @@ public:
} }
virtual void OnRehash(User* user) void OnRehash(User* user)
{ {
ConfigReader Conf; ConfigReader Conf;
@ -68,11 +69,11 @@ public:
verbose = Conf.ReadFlag("sqlauth", "verbose", 0); /* Set to true if failed connects should be reported to operators */ verbose = Conf.ReadFlag("sqlauth", "verbose", 0); /* Set to true if failed connects should be reported to operators */
} }
virtual ModResult OnUserRegister(User* user) ModResult OnUserRegister(User* user)
{ {
if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern))) if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern)))
{ {
user->Extend("sqlauthed"); sqlAuthed.set(user, 1);
return MOD_RES_PASSTHRU; return MOD_RES_PASSTHRU;
} }
@ -160,19 +161,17 @@ public:
if(res->Rows()) if(res->Rows())
{ {
/* We got a row in the result, this is enough really */ /* We got a row in the result, this is enough really */
user->Extend("sqlauthed"); sqlAuthed.set(user, 1);
} }
else if (verbose) else if (verbose)
{ {
/* No rows in result, this means there was no record matching the user */ /* No rows in result, this means there was no record matching the user */
ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick.c_str(), user->ident.c_str(), user->host.c_str()); ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick.c_str(), user->ident.c_str(), user->host.c_str());
user->Extend("sqlauth_failed");
} }
} }
else if (verbose) else if (verbose)
{ {
ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), res->error.Str()); ServerInstance->SNO->WriteGlobalSno('a', "Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), res->error.Str());
user->Extend("sqlauth_failed");
} }
} }
else else
@ -180,7 +179,7 @@ public:
return NULL; return NULL;
} }
if (!user->GetExt("sqlauthed")) if (!sqlAuthed.get(user))
{ {
ServerInstance->Users->QuitUser(user, killreason); ServerInstance->Users->QuitUser(user, killreason);
} }
@ -189,18 +188,12 @@ public:
return NULL; return NULL;
} }
virtual void OnUserDisconnect(User* user) ModResult OnCheckReady(User* user)
{ {
user->Shrink("sqlauthed"); return sqlAuthed.get(user) ? MOD_RES_PASSTHRU : MOD_RES_DENY;
user->Shrink("sqlauth_failed");
} }
virtual ModResult OnCheckReady(User* user) Version GetVersion()
{
return user->GetExt("sqlauthed") ? MOD_RES_PASSTHRU : MOD_RES_DENY;
}
virtual Version GetVersion()
{ {
return Version("Allow/Deny connections based upon an arbitary SQL table", VF_VENDOR, API_VERSION); return Version("Allow/Deny connections based upon an arbitary SQL table", VF_VENDOR, API_VERSION);
} }

View File

@ -43,7 +43,6 @@ public:
QueryInfo(const std::string &n, const std::string &s, const std::string &h, unsigned long i, int cat) QueryInfo(const std::string &n, const std::string &s, const std::string &h, unsigned long i, int cat)
{ {
ServerInstance = Instance;
qs = FIND_SOURCE; qs = FIND_SOURCE;
nick = n; nick = n;
source = s; source = s;

View File

@ -15,7 +15,6 @@
#include "m_sqlv2.h" #include "m_sqlv2.h"
#include "m_sqlutils.h" #include "m_sqlutils.h"
#include "m_hash.h" #include "m_hash.h"
#include "commands/cmd_oper.h"
/* $ModDesc: Allows storage of oper credentials in an SQL table */ /* $ModDesc: Allows storage of oper credentials in an SQL table */
/* $ModDep: m_sqlv2.h m_sqlutils.h m_hash.h */ /* $ModDep: m_sqlv2.h m_sqlutils.h m_hash.h */
@ -24,6 +23,8 @@ typedef std::map<irc::string, Module*> hashymodules;
class ModuleSQLOper : public Module class ModuleSQLOper : public Module
{ {
LocalStringExt saved_user;
LocalStringExt saved_pass;
Module* SQLutils; Module* SQLutils;
std::string databaseid; std::string databaseid;
irc::string hashtype; irc::string hashtype;
@ -32,7 +33,7 @@ class ModuleSQLOper : public Module
parameterlist names; parameterlist names;
public: public:
ModuleSQLOper() ModuleSQLOper() : saved_user("sqloper_user", this), saved_pass("sqloper_pass", this)
{ {
ServerInstance->Modules->UseInterface("SQLutils"); ServerInstance->Modules->UseInterface("SQLutils");
ServerInstance->Modules->UseInterface("SQL"); ServerInstance->Modules->UseInterface("SQL");
@ -68,8 +69,8 @@ public:
if (!SQLutils) if (!SQLutils)
throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so."); throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so.");
Implementation eventlist[] = { I_OnRequest, I_OnRehash, I_OnPreCommand, I_OnLoadModule }; Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_OnLoadModule };
ServerInstance->Modules->Attach(eventlist, this, 3); ServerInstance->Modules->Attach(eventlist, this, 4);
} }
bool OneOfMatches(const char* host, const char* ip, const char* hostlist) bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
@ -170,8 +171,8 @@ public:
*/ */
AssociateUser(this, SQLutils, req.id, user).Send(); AssociateUser(this, SQLutils, req.id, user).Send();
user->Extend("oper_user", strdup(username.c_str())); saved_user.set(user, username);
user->Extend("oper_pass", strdup(password.c_str())); saved_pass.set(user, password);
return true; return true;
} }
@ -187,7 +188,7 @@ public:
} }
} }
virtual const char* OnRequest(Request* request) const char* OnRequest(Request* request)
{ {
if (strcmp(SQLRESID, request->GetId()) == 0) if (strcmp(SQLRESID, request->GetId()) == 0)
{ {
@ -196,14 +197,10 @@ public:
User* user = GetAssocUser(this, SQLutils, res->id).S().user; User* user = GetAssocUser(this, SQLutils, res->id).S().user;
UnAssociate(this, SQLutils, res->id).S(); UnAssociate(this, SQLutils, res->id).S();
char* tried_user = NULL;
char* tried_pass = NULL;
user->GetExt("oper_user", tried_user);
user->GetExt("oper_pass", tried_pass);
if (user) if (user)
{ {
std::string* tried_user = saved_user.get(user);
std::string* tried_pass = saved_pass.get(user);
if (res->error.Id() == SQL_NO_ERROR) if (res->error.Id() == SQL_NO_ERROR)
{ {
if (res->Rows()) if (res->Rows())
@ -226,15 +223,15 @@ public:
if (OperUser(user, row["hostname"].d, row["type"].d)) if (OperUser(user, row["hostname"].d, row["type"].d))
{ {
/* If/when one of the rows matches, stop checking and return */ /* If/when one of the rows matches, stop checking and return */
saved_user.unset(user);
saved_pass.unset(user);
return SQLSUCCESS; return SQLSUCCESS;
} }
if (tried_user && tried_pass) if (tried_user && tried_pass)
{ {
LoginFail(user, tried_user, tried_pass); LoginFail(user, *tried_user, *tried_pass);
free(tried_user); saved_user.unset(user);
free(tried_pass); saved_pass.unset(user);
user->Shrink("oper_user");
user->Shrink("oper_pass");
} }
} }
} }
@ -246,11 +243,9 @@ public:
*/ */
if (tried_user && tried_pass) if (tried_user && tried_pass)
{ {
LoginFail(user, tried_user, tried_pass); LoginFail(user, *tried_user, *tried_pass);
free(tried_user); saved_user.unset(user);
free(tried_pass); saved_pass.unset(user);
user->Shrink("oper_user");
user->Shrink("oper_pass");
} }
} }
} }
@ -262,11 +257,9 @@ public:
*/ */
if (tried_user && tried_pass) if (tried_user && tried_pass)
{ {
LoginFail(user, tried_user, tried_pass); LoginFail(user, *tried_user, *tried_pass);
free(tried_user); saved_user.unset(user);
free(tried_pass); saved_pass.unset(user);
user->Shrink("oper_user");
user->Shrink("oper_pass");
} }
} }
@ -322,7 +315,7 @@ public:
return false; return false;
} }
virtual Version GetVersion() Version GetVersion()
{ {
return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR, API_VERSION); return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR, API_VERSION);
} }

View File

@ -28,22 +28,23 @@ class ModuleSQLutils : public Module
private: private:
IdUserMap iduser; IdUserMap iduser;
IdChanMap idchan; IdChanMap idchan;
SimpleExtItem<AssocIdList> idExt;
public: public:
ModuleSQLutils() ModuleSQLutils() : idExt("sqlutils_list", this)
{ {
ServerInstance->Modules->PublishInterface("SQLutils", this); ServerInstance->Modules->PublishInterface("SQLutils", this);
Implementation eventlist[] = { I_OnChannelDelete, I_OnUnloadModule, I_OnRequest, I_OnUserDisconnect }; Implementation eventlist[] = { I_OnChannelDelete, I_OnUnloadModule, I_OnRequest, I_OnUserDisconnect };
ServerInstance->Modules->Attach(eventlist, this, 4); ServerInstance->Modules->Attach(eventlist, this, 4);
} }
virtual ~ModuleSQLutils() ~ModuleSQLutils()
{ {
ServerInstance->Modules->UnpublishInterface("SQLutils", this); ServerInstance->Modules->UnpublishInterface("SQLutils", this);
} }
virtual const char* OnRequest(Request* request) const char* OnRequest(Request* request)
{ {
if(strcmp(SQLUTILAU, request->GetId()) == 0) if(strcmp(SQLUTILAU, request->GetId()) == 0)
{ {
@ -98,15 +99,15 @@ public:
return SQLUTILSUCCESS; return SQLUTILSUCCESS;
} }
virtual void OnUserDisconnect(User* user) void OnUserDisconnect(User* user)
{ {
/* A user is disconnecting, first we need to check if they have a list of queries associated with them. /* A user is disconnecting, first we need to check if they have a list of queries associated with them.
* Then, if they do, we need to erase each of them from our IdUserMap (iduser) so when the module that * Then, if they do, we need to erase each of them from our IdUserMap (iduser) so when the module that
* associated them asks to look them up then it gets a NULL result and knows to discard the query. * associated them asks to look them up then it gets a NULL result and knows to discard the query.
*/ */
AssocIdList* il; AssocIdList* il = idExt.get(user);
if(user->GetExt("sqlutils_queryids", il)) if(il)
{ {
for(AssocIdList::iterator listiter = il->begin(); listiter != il->end(); listiter++) for(AssocIdList::iterator listiter = il->begin(); listiter != il->end(); listiter++)
{ {
@ -129,20 +130,19 @@ public:
} }
} }
user->Shrink("sqlutils_queryids"); idExt.unset(user);
delete il;
} }
} }
void AttachList(Extensible* obj, unsigned long id) void AttachList(Extensible* obj, unsigned long id)
{ {
AssocIdList* il; AssocIdList* il = idExt.get(obj);
if(!obj->GetExt("sqlutils_queryids", il)) if (!il)
{ {
/* Doesn't already exist, create a new list and attach it. */ /* Doesn't already exist, create a new list and attach it. */
il = new AssocIdList; il = new AssocIdList;
obj->Extend("sqlutils_queryids", il); idExt.set(obj, il);
} }
/* Now either way we have a valid list in il, attached. */ /* Now either way we have a valid list in il, attached. */
@ -151,9 +151,9 @@ public:
void RemoveFromList(Extensible* obj, unsigned long id) void RemoveFromList(Extensible* obj, unsigned long id)
{ {
AssocIdList* il; AssocIdList* il = idExt.get(obj);
if(obj->GetExt("sqlutils_queryids", il)) if (il)
{ {
/* Only do anything if the list exists... (which it ought to) */ /* Only do anything if the list exists... (which it ought to) */
il->remove(id); il->remove(id);
@ -161,8 +161,7 @@ public:
if(il->empty()) if(il->empty())
{ {
/* If we just emptied it.. */ /* If we just emptied it.. */
delete il; idExt.unset(obj);
obj->Shrink("sqlutils_queryids");
} }
} }
} }
@ -185,15 +184,15 @@ public:
} }
} }
virtual void OnChannelDelete(Channel* chan) void OnChannelDelete(Channel* chan)
{ {
/* A channel is being destroyed, first we need to check if it has a list of queries associated with it. /* A channel is being destroyed, first we need to check if it has a list of queries associated with it.
* Then, if it does, we need to erase each of them from our IdChanMap (idchan) so when the module that * Then, if it does, we need to erase each of them from our IdChanMap (idchan) so when the module that
* associated them asks to look them up then it gets a NULL result and knows to discard the query. * associated them asks to look them up then it gets a NULL result and knows to discard the query.
*/ */
AssocIdList* il; AssocIdList* il = idExt.get(chan);
if(chan->GetExt("sqlutils_queryids", il)) if (il)
{ {
for(AssocIdList::iterator listiter = il->begin(); listiter != il->end(); listiter++) for(AssocIdList::iterator listiter = il->begin(); listiter != il->end(); listiter++)
{ {
@ -215,12 +214,11 @@ public:
} }
} }
chan->Shrink("sqlutils_queryids"); idExt.unset(chan);
delete il;
} }
} }
virtual Version GetVersion() Version GetVersion()
{ {
return Version("Provides some utilities to SQL client modules, such as mapping queries to users and channels", VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION); return Version("Provides some utilities to SQL client modules, such as mapping queries to users and channels", VF_VENDOR | VF_SERVICEPROVIDER, API_VERSION);
} }