diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-28 22:25:43 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-28 22:25:43 +0000 |
commit | 83454575bcdc969e73fb9026dc3533dfb22c27a2 (patch) | |
tree | bc9550713de94aec291b83e4bfb33f32a3519268 /src | |
parent | 5e1d239f3d94bd1afd3ce64c2f47a64305f1e1f0 (diff) |
Fix compilation of some extras modules
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11776 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/extra/m_ldapauth.cpp | 32 | ||||
-rw-r--r-- | src/modules/m_sqlauth.cpp (renamed from src/modules/extra/m_sqlauth.cpp) | 29 | ||||
-rw-r--r-- | src/modules/m_sqllog.cpp (renamed from src/modules/extra/m_sqllog.cpp) | 1 | ||||
-rw-r--r-- | src/modules/m_sqloper.cpp (renamed from src/modules/extra/m_sqloper.cpp) | 53 | ||||
-rw-r--r-- | src/modules/m_sqlutils.cpp (renamed from src/modules/extra/m_sqlutils.cpp) | 42 | ||||
-rw-r--r-- | src/modules/m_sqlutils.h (renamed from src/modules/extra/m_sqlutils.h) | 0 | ||||
-rw-r--r-- | src/modules/m_sqlv2.h (renamed from src/modules/extra/m_sqlv2.h) | 0 |
7 files changed, 66 insertions, 91 deletions
diff --git a/src/modules/extra/m_ldapauth.cpp b/src/modules/extra/m_ldapauth.cpp index 6fa5abfe7..013bdd110 100644 --- a/src/modules/extra/m_ldapauth.cpp +++ b/src/modules/extra/m_ldapauth.cpp @@ -33,6 +33,7 @@ class ModuleLDAPAuth : public Module { + LocalIntExt ldapAuthed; std::string base; std::string attribute; std::string ldapserver; @@ -46,21 +47,21 @@ class ModuleLDAPAuth : public Module LDAP *conn; public: - ModuleLDAPAuth() - { + ModuleLDAPAuth() : ldapAuthed("ldapauth", this) + { 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); OnRehash(NULL); } - virtual ~ModuleLDAPAuth() + ~ModuleLDAPAuth() { if (conn) ldap_unbind_ext(conn, NULL, NULL); } - virtual void OnRehash(User* user) + void OnRehash(User* user) { ConfigReader Conf; @@ -110,11 +111,11 @@ public: return true; } - virtual ModResult OnUserRegister(User* user) + ModResult OnUserRegister(User* user) { if ((!allowpattern.empty()) && (InspIRCd::Match(user->nick,allowpattern))) { - user->Extend("ldapauthed"); + ldapAuthed.set(user,1); return MOD_RES_PASSTHRU; } @@ -188,7 +189,6 @@ public: { 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()); - user->Extend("ldapauth_failed"); return false; } 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) { ldap_msgfree(msg); - user->Extend("ldapauthed"); + ldapAuthed.set(user,1); return true; } else @@ -204,24 +204,16 @@ public: 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)); ldap_msgfree(msg); - user->Extend("ldapauth_failed"); return false; } } - - virtual void OnUserDisconnect(User* user) - { - user->Shrink("ldapauthed"); - user->Shrink("ldapauth_failed"); - } - - virtual ModResult OnCheckReady(User* user) + ModResult OnCheckReady(User* user) { - return user->GetExt("ldapauthed") ? MOD_RES_PASSTHRU : MOD_RES_DENY; + return ldapAuthed.get(user) ? MOD_RES_PASSTHRU : MOD_RES_DENY; } - virtual Version GetVersion() + Version GetVersion() { return Version("Allow/Deny connections based upon answer from LDAP server", VF_VENDOR, API_VERSION); } diff --git a/src/modules/extra/m_sqlauth.cpp b/src/modules/m_sqlauth.cpp index d7c0675bb..256bf346a 100644 --- a/src/modules/extra/m_sqlauth.cpp +++ b/src/modules/m_sqlauth.cpp @@ -21,6 +21,7 @@ class ModuleSQLAuth : public Module { + LocalIntExt sqlAuthed; Module* SQLutils; Module* SQLprovider; @@ -32,8 +33,8 @@ class ModuleSQLAuth : public Module bool verbose; public: - ModuleSQLAuth() - { + ModuleSQLAuth() : sqlAuthed("sqlauth", this) + { ServerInstance->Modules->UseInterface("SQLutils"); ServerInstance->Modules->UseInterface("SQL"); @@ -57,7 +58,7 @@ public: } - virtual void OnRehash(User* user) + void OnRehash(User* user) { ConfigReader Conf; @@ -68,11 +69,11 @@ public: 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))) { - user->Extend("sqlauthed"); + sqlAuthed.set(user, 1); return MOD_RES_PASSTHRU; } @@ -160,19 +161,17 @@ public: if(res->Rows()) { /* We got a row in the result, this is enough really */ - user->Extend("sqlauthed"); + sqlAuthed.set(user, 1); } else if (verbose) { /* 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()); - user->Extend("sqlauth_failed"); } } 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()); - user->Extend("sqlauth_failed"); } } else @@ -180,7 +179,7 @@ public: return NULL; } - if (!user->GetExt("sqlauthed")) + if (!sqlAuthed.get(user)) { ServerInstance->Users->QuitUser(user, killreason); } @@ -189,18 +188,12 @@ public: return NULL; } - virtual void OnUserDisconnect(User* user) - { - user->Shrink("sqlauthed"); - user->Shrink("sqlauth_failed"); - } - - virtual ModResult OnCheckReady(User* user) + ModResult OnCheckReady(User* user) { - return user->GetExt("sqlauthed") ? MOD_RES_PASSTHRU : MOD_RES_DENY; + return sqlAuthed.get(user) ? MOD_RES_PASSTHRU : MOD_RES_DENY; } - virtual Version GetVersion() + Version GetVersion() { return Version("Allow/Deny connections based upon an arbitary SQL table", VF_VENDOR, API_VERSION); } diff --git a/src/modules/extra/m_sqllog.cpp b/src/modules/m_sqllog.cpp index 4713f24a9..73f53f8c0 100644 --- a/src/modules/extra/m_sqllog.cpp +++ b/src/modules/m_sqllog.cpp @@ -43,7 +43,6 @@ public: QueryInfo(const std::string &n, const std::string &s, const std::string &h, unsigned long i, int cat) { - ServerInstance = Instance; qs = FIND_SOURCE; nick = n; source = s; diff --git a/src/modules/extra/m_sqloper.cpp b/src/modules/m_sqloper.cpp index 47aa8d1fd..5f0df4c10 100644 --- a/src/modules/extra/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -15,7 +15,6 @@ #include "m_sqlv2.h" #include "m_sqlutils.h" #include "m_hash.h" -#include "commands/cmd_oper.h" /* $ModDesc: Allows storage of oper credentials in an SQL table */ /* $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 { + LocalStringExt saved_user; + LocalStringExt saved_pass; Module* SQLutils; std::string databaseid; irc::string hashtype; @@ -32,8 +33,8 @@ class ModuleSQLOper : public Module parameterlist names; public: - ModuleSQLOper() - { + ModuleSQLOper() : saved_user("sqloper_user", this), saved_pass("sqloper_pass", this) + { ServerInstance->Modules->UseInterface("SQLutils"); ServerInstance->Modules->UseInterface("SQL"); ServerInstance->Modules->UseInterface("HashRequest"); @@ -68,8 +69,8 @@ public: if (!SQLutils) 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 }; - ServerInstance->Modules->Attach(eventlist, this, 3); + Implementation eventlist[] = { I_OnRehash, I_OnPreCommand, I_OnLoadModule }; + ServerInstance->Modules->Attach(eventlist, this, 4); } bool OneOfMatches(const char* host, const char* ip, const char* hostlist) @@ -170,8 +171,8 @@ public: */ AssociateUser(this, SQLutils, req.id, user).Send(); - user->Extend("oper_user", strdup(username.c_str())); - user->Extend("oper_pass", strdup(password.c_str())); + saved_user.set(user, username); + saved_pass.set(user, password); return true; } @@ -187,7 +188,7 @@ public: } } - virtual const char* OnRequest(Request* request) + const char* OnRequest(Request* request) { if (strcmp(SQLRESID, request->GetId()) == 0) { @@ -196,14 +197,10 @@ public: User* user = GetAssocUser(this, SQLutils, res->id).S().user; 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) { + 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->Rows()) @@ -226,15 +223,15 @@ public: if (OperUser(user, row["hostname"].d, row["type"].d)) { /* If/when one of the rows matches, stop checking and return */ + saved_user.unset(user); + saved_pass.unset(user); return SQLSUCCESS; } if (tried_user && tried_pass) { - LoginFail(user, tried_user, tried_pass); - free(tried_user); - free(tried_pass); - user->Shrink("oper_user"); - user->Shrink("oper_pass"); + LoginFail(user, *tried_user, *tried_pass); + saved_user.unset(user); + saved_pass.unset(user); } } } @@ -246,11 +243,9 @@ public: */ if (tried_user && tried_pass) { - LoginFail(user, tried_user, tried_pass); - free(tried_user); - free(tried_pass); - user->Shrink("oper_user"); - user->Shrink("oper_pass"); + LoginFail(user, *tried_user, *tried_pass); + saved_user.unset(user); + saved_pass.unset(user); } } } @@ -262,11 +257,9 @@ public: */ if (tried_user && tried_pass) { - LoginFail(user, tried_user, tried_pass); - free(tried_user); - free(tried_pass); - user->Shrink("oper_user"); - user->Shrink("oper_pass"); + LoginFail(user, *tried_user, *tried_pass); + saved_user.unset(user); + saved_pass.unset(user); } } @@ -322,7 +315,7 @@ public: return false; } - virtual Version GetVersion() + Version GetVersion() { return Version("Allows storage of oper credentials in an SQL table", VF_VENDOR, API_VERSION); } diff --git a/src/modules/extra/m_sqlutils.cpp b/src/modules/m_sqlutils.cpp index 6d40ee22c..a80e1262b 100644 --- a/src/modules/extra/m_sqlutils.cpp +++ b/src/modules/m_sqlutils.cpp @@ -28,22 +28,23 @@ class ModuleSQLutils : public Module private: IdUserMap iduser; IdChanMap idchan; + SimpleExtItem<AssocIdList> idExt; public: - ModuleSQLutils() - { + ModuleSQLutils() : idExt("sqlutils_list", this) + { ServerInstance->Modules->PublishInterface("SQLutils", this); Implementation eventlist[] = { I_OnChannelDelete, I_OnUnloadModule, I_OnRequest, I_OnUserDisconnect }; ServerInstance->Modules->Attach(eventlist, this, 4); } - virtual ~ModuleSQLutils() + ~ModuleSQLutils() { ServerInstance->Modules->UnpublishInterface("SQLutils", this); } - virtual const char* OnRequest(Request* request) + const char* OnRequest(Request* request) { if(strcmp(SQLUTILAU, request->GetId()) == 0) { @@ -98,15 +99,15 @@ public: 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. * 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. */ - 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++) { @@ -129,20 +130,19 @@ public: } } - user->Shrink("sqlutils_queryids"); - delete il; + idExt.unset(user); } } 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. */ il = new AssocIdList; - obj->Extend("sqlutils_queryids", il); + idExt.set(obj, il); } /* Now either way we have a valid list in il, attached. */ @@ -151,9 +151,9 @@ public: 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) */ il->remove(id); @@ -161,8 +161,7 @@ public: if(il->empty()) { /* If we just emptied it.. */ - delete il; - obj->Shrink("sqlutils_queryids"); + idExt.unset(obj); } } } @@ -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. * 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. */ - 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++) { @@ -215,12 +214,11 @@ public: } } - chan->Shrink("sqlutils_queryids"); - delete il; + idExt.unset(chan); } } - 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); } diff --git a/src/modules/extra/m_sqlutils.h b/src/modules/m_sqlutils.h index ce43be8cc..ce43be8cc 100644 --- a/src/modules/extra/m_sqlutils.h +++ b/src/modules/m_sqlutils.h diff --git a/src/modules/extra/m_sqlv2.h b/src/modules/m_sqlv2.h index a9297bd80..a9297bd80 100644 --- a/src/modules/extra/m_sqlv2.h +++ b/src/modules/m_sqlv2.h |