From 11e360cb1552b860a4195762957ceb982cc843c6 Mon Sep 17 00:00:00 2001 From: psychon Date: Mon, 10 Aug 2009 19:17:33 +0000 Subject: [PATCH] Fix unloading of /bin/rm'd modules The old code first tried to dlopen() the module again to find out if it's a global or a user module. This could have lots of weird effects. Now we just unload the user module and if that fails retry with the global module (if the user got the appropriate privileges). This removes and fixes the #warning added in the last commit. P.S.: Oh and this is less LOCs now! git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1597 726aef4b-f618-498e-8847-2d620e286838 --- ClientCommand.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/ClientCommand.cpp b/ClientCommand.cpp index cfc64834..8ff3ff45 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -676,32 +676,19 @@ void CClient::UserCommand(CString& sLine) { return; } #ifdef _MODULES - CModInfo ModInfo; - CString sRetMsg; -#warning If a module is removed while it is loaded, one can no longer unload it? - if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sMod, sRetMsg)) { - PutStatus("Unable to find modinfo for [" + sMod + "]"); - return; - } - - bool bGlobal = ModInfo.IsGlobal(); - - if (bGlobal && !m_pUser->IsAdmin()) { - PutStatus("Unable to unload global module [" + sMod + "] Access Denied."); - return; - } - if (sMod.empty()) { PutStatus("Usage: UnloadMod "); return; } CString sModRet; + bool b; - if (bGlobal) { - CZNC::Get().GetModules().UnloadModule(sMod, sModRet); - } else { - m_pUser->GetModules().UnloadModule(sMod, sModRet); + // First, try to unload the user module + b = m_pUser->GetModules().UnloadModule(sMod, sModRet); + if (!b && m_pUser->IsAdmin()) { + // If that failed and the user is an admin, try to unload a global module + b = CZNC::Get().GetModules().UnloadModule(sMod, sModRet); } PutStatus(sModRet);