summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2023-06-03 21:42:06 +0100
committerSadie Powell <sadie@witchery.services>2023-06-03 21:51:07 +0100
commit9d0a6ddc67b1e7bd0c32603b6fa90b702c13447d (patch)
tree1e4d019535c89f67e7cf54a76afabe188947c668 /modules
parent29db25dac7aff36b4f7239a9fabd57230534cf35 (diff)
parentfbf3b344740f6bd4f9337e485e35e9e8103428bc (diff)
Merge branch '2.0' into 2.1.
Diffstat (limited to 'modules')
-rw-r--r--modules/CMakeLists.txt34
-rw-r--r--modules/commands/ns_recover.cpp2
-rw-r--r--modules/commands/os_config.cpp2
-rw-r--r--modules/commands/os_mode.cpp4
-rw-r--r--modules/extra/m_ldap.cpp97
-rw-r--r--modules/extra/m_regex_pcre2.cpp2
-rw-r--r--modules/extra/m_ssl_openssl.cpp2
-rw-r--r--modules/protocol/inspircd.cpp2
-rw-r--r--modules/pseudoclients/chanserv.cpp4
9 files changed, 129 insertions, 20 deletions
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index a8b3d6cc5..311e9964b 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -3,6 +3,40 @@ if(WIN32)
add_definitions(-DMODULE_COMPILE)
endif()
+# enable extra modules if conan is used
+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../conanbuildinfo.cmake")
+ function(enable_extra NAME PACKAGE)
+ if(DEFINED "CONAN_${PACKAGE}_ROOT")
+ message("Enabling the ${NAME} module")
+ # copy the modules out of extra so it gets picked up by build_modules
+ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extra/${NAME}.cpp" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}")
+ else()
+ message("Unable to enable the ${NAME} module (missing library)")
+ endif()
+ endfunction()
+
+ function(copy_extra NAME)
+ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extra/${NAME}.cpp" DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}")
+ endfunction()
+
+ enable_extra("m_mysql" "LIBMYSQLCLIENT")
+ enable_extra("m_regex_pcre2" "PCRE2")
+ enable_extra("m_sqlite" "SQLITE3")
+ enable_extra("m_ssl_openssl" "OPENSSL")
+ # this uses Wldap so should always be available
+ copy_extra("m_ldap")
+ # these don't actually have extra dependencies, but require a module which does
+ copy_extra("m_sql_authentication")
+ copy_extra("m_sql_log")
+ copy_extra("m_sql_oper")
+ copy_extra("m_ldap_authentication")
+ copy_extra("m_ldap_oper")
+
+ # Package extra dlls
+ file(GLOB EXTRA_DLLS "${Anope_SOURCE_DIR}/extradll/bin/*.dll" "${Anope_SOURCE_DIR}/extradll/lib/*.dll")
+ install(FILES ${EXTRA_DLLS} DESTINATION ${BIN_DIR})
+endif()
+
macro(build_modules SRC)
if(NOT ${SRC} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR} AND EXISTS "${SRC}/CMakeLists.txt")
add_subdirectory("${SRC}")
diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp
index 1e6f4a9bc..776080afb 100644
--- a/modules/commands/ns_recover.cpp
+++ b/modules/commands/ns_recover.cpp
@@ -284,7 +284,7 @@ class NSRecover : public Module
if (it != ei->end())
{
for (size_t i = 0; i < it->second.Modes().length(); ++i)
- c->SetMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID());
+ c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID());
ei->erase(it);
if (ei->empty())
diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp
index 939f1b846..f94491a5c 100644
--- a/modules/commands/os_config.cpp
+++ b/modules/commands/os_config.cpp
@@ -32,7 +32,7 @@ class CommandOSConfig : public Command
return;
}
- Configuration::Block *block = Config->GetBlock(params[1]);
+ Configuration::MutableBlock *block = Config->GetMutableBlock(params[1]);
if (!block)
block = Config->GetModule(params[1]);
diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp
index afbaafb1a..541aa8fbc 100644
--- a/modules/commands/os_mode.cpp
+++ b/modules/commands/os_mode.cpp
@@ -37,7 +37,7 @@ class CommandOSMode : public Command
const Channel::ModeList chmodes = c->GetModes();
for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it)
- c->RemoveMode(c->ci->WhoSends(), it->first, it->second, false);
+ c->RemoveMode(c->WhoSends(), it->first, it->second, false);
if (!c)
{
@@ -55,7 +55,7 @@ class CommandOSMode : public Command
continue;
for (size_t i = uc->status.Modes().length(); i > 0; --i)
- c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
+ c->RemoveMode(c->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
}
source.Reply(_("All modes cleared on %s."), c->name.c_str());
diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp
index ef6c24564..aa34162d0 100644
--- a/modules/extra/m_ldap.cpp
+++ b/modules/extra/m_ldap.cpp
@@ -10,11 +10,29 @@
*/
/* RequiredLibraries: ldap_r|ldap,lber */
-/* RequiredWindowsLibraries: libldap_r|libldap,liblber */
#include "module.h"
#include "modules/ldap.h"
-#include <ldap.h>
+
+#ifdef _WIN32
+# include <Winldap.h>
+# include <WinBer.h>
+# include <wininet.h>
+# define LDAP_OPT_SUCCESS LDAP_SUCCESS
+# define LDAP_OPT_NETWORK_TIMEOUT LDAP_OPT_SEND_TIMEOUT
+# define LDAP_STR(X) const_cast<PSTR>((X).c_str())
+# define LDAP_SASL_SIMPLE static_cast<PSTR>(0)
+# define LDAP_TIME(X) reinterpret_cast<PLDAP_TIMEVAL>(&(X))
+# define ldap_first_message ldap_first_entry
+# define ldap_next_message ldap_next_entry
+# define ldap_unbind_ext(LDAP, UNUSED1, UNUSED2) ldap_unbind(LDAP)
+# pragma comment(lib, "Wldap32.lib")
+# pragma comment(lib, "Wininet.lib")
+#else
+# include <ldap.h>
+# define LDAP_STR(X) ((X).c_str())
+# define LDAP_TIME(X) (&(X))
+#endif
#if defined LDAP_API_FEATURE_X_OPENLDAP_REENTRANT && !LDAP_API_FEATURE_X_OPENLDAP_REENTRANT
# error Anope requires OpenLDAP to be built as reentrant.
@@ -70,13 +88,13 @@ class LDAPBind : public LDAPRequest
int run() override;
};
-class LDAPSearch : public LDAPRequest
+class LDAPSearchRequest : public LDAPRequest
{
Anope::string base;
Anope::string filter;
public:
- LDAPSearch(LDAPService *s, LDAPInterface *i, const Anope::string &b, const Anope::string &f)
+ LDAPSearchRequest(LDAPService *s, LDAPInterface *i, const Anope::string &b, const Anope::string &f)
: LDAPRequest(s, i)
, base(b)
, filter(f)
@@ -187,6 +205,63 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
}
private:
+#ifdef _WIN32
+ // Windows LDAP does not implement this so we need to do it.
+ int ldap_initialize(LDAP** ldap, const char* url)
+ {
+ URL_COMPONENTS urlComponents;
+ memset(&urlComponents, 0, sizeof(urlComponents));
+ urlComponents.dwStructSize = sizeof(urlComponents);
+
+ urlComponents.lpszScheme = new char[8];
+ urlComponents.dwSchemeLength = 8;
+
+ urlComponents.lpszHostName = new char[1024];
+ urlComponents.dwHostNameLength = 1024;
+
+ if (!InternetCrackUrlA(url, 0, 0, &urlComponents))
+ {
+ delete[] urlComponents.lpszScheme;
+ delete[] urlComponents.lpszHostName;
+ return LDAP_CONNECT_ERROR; // Malformed url.
+ }
+
+ unsigned long port = 389; // Default plaintext port.
+ bool secure = false; // LDAP defaults to plaintext.
+ if (urlComponents.dwSchemeLength > 0)
+ {
+ const Anope::string scheme(urlComponents.lpszScheme);
+ if (scheme.equals_ci("ldaps"))
+ {
+ port = 636; // Default encrypted port.
+ secure = true;
+ }
+ else if (!scheme.equals_ci("ldap"))
+ {
+ delete[] urlComponents.lpszScheme;
+ delete[] urlComponents.lpszHostName;
+ return LDAP_CONNECT_ERROR; // Invalid protocol.
+ }
+ }
+
+ if (urlComponents.nPort > 0)
+ {
+ port = urlComponents.nPort;
+ }
+
+ *ldap = ldap_sslinit(urlComponents.lpszHostName, port, secure);
+ delete[] urlComponents.lpszScheme;
+ delete[] urlComponents.lpszHostName;
+ if (!*ldap)
+ {
+ return LdapGetLastError(); // Something went wrong, find out what.
+ }
+
+ // We're connected to the LDAP server!
+ return LDAP_SUCCESS;
+ }
+#endif
+
void Connect()
{
int i = ldap_initialize(&this->con, this->server.c_str());
@@ -288,7 +363,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
if (i == NULL)
throw LDAPException("No interface");
- LDAPSearch *s = new LDAPSearch(this, i, base, filter);
+ LDAPSearchRequest *s = new LDAPSearchRequest(this, i, base, filter);
QueueRequest(s);
}
@@ -587,35 +662,35 @@ int LDAPBind::run()
cred.bv_val = strdup(pass.c_str());
cred.bv_len = pass.length();
- int i = ldap_sasl_bind_s(service->GetConnection(), who.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
+ int i = ldap_sasl_bind_s(service->GetConnection(), LDAP_STR(who), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
free(cred.bv_val);
return i;
}
-int LDAPSearch::run()
+int LDAPSearchRequest::run()
{
- return ldap_search_ext_s(service->GetConnection(), base.c_str(), LDAP_SCOPE_SUBTREE, filter.c_str(), NULL, 0, NULL, NULL, &tv, 0, &message);
+ return ldap_search_ext_s(service->GetConnection(), LDAP_STR(base), LDAP_SCOPE_SUBTREE, LDAP_STR(filter), NULL, 0, NULL, NULL, LDAP_TIME(tv), 0, &message);
}
int LDAPAdd::run()
{
LDAPMod **mods = LDAPService::BuildMods(attributes);
- int i = ldap_add_ext_s(service->GetConnection(), dn.c_str(), mods, NULL, NULL);
+ int i = ldap_add_ext_s(service->GetConnection(), LDAP_STR(dn), mods, NULL, NULL);
LDAPService::FreeMods(mods);
return i;
}
int LDAPDel::run()
{
- return ldap_delete_ext_s(service->GetConnection(), dn.c_str(), NULL, NULL);
+ return ldap_delete_ext_s(service->GetConnection(), LDAP_STR(dn), NULL, NULL);
}
int LDAPModify::run()
{
LDAPMod **mods = LDAPService::BuildMods(attributes);
- int i = ldap_modify_ext_s(service->GetConnection(), base.c_str(), mods, NULL, NULL);
+ int i = ldap_modify_ext_s(service->GetConnection(), LDAP_STR(base), mods, NULL, NULL);
LDAPService::FreeMods(mods);
return i;
}
diff --git a/modules/extra/m_regex_pcre2.cpp b/modules/extra/m_regex_pcre2.cpp
index 0fb008982..f741ff2ba 100644
--- a/modules/extra/m_regex_pcre2.cpp
+++ b/modules/extra/m_regex_pcre2.cpp
@@ -7,7 +7,7 @@
*/
/* RequiredLibraries: pcre2-8 */
-/* RequiredWindowsLibraries: libpcre2-8 */
+/* RequiredWindowsLibraries: pcre2-8 */
#include "module.h"
diff --git a/modules/extra/m_ssl_openssl.cpp b/modules/extra/m_ssl_openssl.cpp
index 57a5c128c..1b504c122 100644
--- a/modules/extra/m_ssl_openssl.cpp
+++ b/modules/extra/m_ssl_openssl.cpp
@@ -7,7 +7,7 @@
*/
/* RequiredLibraries: ssl,crypto */
-/* RequiredWindowsLibraries: ssleay32,libeay32 */
+/* RequiredWindowsLibraries: libssl,libcrypto */
#include "module.h"
#include "modules/ssl.h"
diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp
index 236f9e89f..b70987ea8 100644
--- a/modules/protocol/inspircd.cpp
+++ b/modules/protocol/inspircd.cpp
@@ -180,7 +180,7 @@ class InspIRCdProto : public IRCDProto
{
if (Servers::Capab.count("SVSTOPIC"))
{
- UplinkSocket::Message(c->ci->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
+ UplinkSocket::Message(c->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic;
}
else
{
diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp
index 2e54a1272..9349ee6bc 100644
--- a/modules/pseudoclients/chanserv.cpp
+++ b/modules/pseudoclients/chanserv.cpp
@@ -288,7 +288,7 @@ class ChanServCore : public Module, public ChanServService
if (c->ci)
c->SetMode(c->ci->WhoSends(), "REGISTERED", "", false);
else
- c->RemoveMode(ChanServ, "REGISTERED", "", false);
+ c->RemoveMode(c->WhoSends(), "REGISTERED", "", false);
const Anope::string &require = Config->GetModule(this)->Get<const Anope::string>("require");
if (!require.empty())
@@ -296,7 +296,7 @@ class ChanServCore : public Module, public ChanServService
if (c->ci)
c->SetModes(c->ci->WhoSends(), false, "+%s", require.c_str());
else
- c->SetModes(ChanServ, false, "-%s", require.c_str());
+ c->SetModes(c->WhoSends(), false, "-%s", require.c_str());
}
}