From c140cd5abeef477456a4cea197de14259ade0f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Tue, 30 Jan 2024 17:47:35 +0100 Subject: [PATCH] libshvbroker: Detect LDAP config even with missing LDAP support --- libshvbroker/include/shv/broker/appclioptions.h | 2 -- libshvbroker/src/appclioptions.cpp | 2 -- libshvbroker/src/brokerapp.cpp | 6 ++++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libshvbroker/include/shv/broker/appclioptions.h b/libshvbroker/include/shv/broker/appclioptions.h index 4315ec3dd..340309942 100644 --- a/libshvbroker/include/shv/broker/appclioptions.h +++ b/libshvbroker/include/shv/broker/appclioptions.h @@ -38,14 +38,12 @@ class SHVBROKER_DECL_EXPORT AppCliOptions : public shv::core::utils::ConfigCLIOp CLIOPTION_GETTER_SETTER2(shv::chainpack::RpcValue, "masters.connections", m, setM, asterBrokersConnections) CLIOPTION_GETTER_SETTER2(bool, "masters.enabled", is, set, MasterBrokersEnabled) -#ifdef WITH_SHV_LDAP CLIOPTION_GETTER_SETTER2(std::string, "ldap.username", l, setL, dapUsername) CLIOPTION_GETTER_SETTER2(std::string, "ldap.password", l, setL, dapPassword) CLIOPTION_GETTER_SETTER2(std::string, "ldap.hostname", l, setL, dapHostname) CLIOPTION_GETTER_SETTER2(std::string, "ldap.searchBaseDN", l, setL, dapSearchBaseDN) CLIOPTION_GETTER_SETTER2(chainpack::RpcValue::List, "ldap.searchAttrs", l, setL, dapSearchAttrs) CLIOPTION_GETTER_SETTER2(chainpack::RpcValue::List, "ldap.groupMapping", l, setL, dapGroupMapping) -#endif CLIOPTION_GETTER_SETTER2(chainpack::RpcValue::List, "azure.groupMapping", a, setA, zureGroupMapping) }; diff --git a/libshvbroker/src/appclioptions.cpp b/libshvbroker/src/appclioptions.cpp index 1961209c6..c52602308 100644 --- a/libshvbroker/src/appclioptions.cpp +++ b/libshvbroker/src/appclioptions.cpp @@ -39,14 +39,12 @@ AppCliOptions::AppCliOptions() addOption("masters.connections").setType(cp::RpcValue::Type::Map).setComment("Can be used from config file only."); addOption("masters.enabled").setType(cp::RpcValue::Type::Bool).setNames("--mce", "--master-connections-enabled").setComment("Enable slave connections to master broker."); -#ifdef WITH_SHV_LDAP addOption("ldap.username").setType(cp::RpcValue::Type::String).setNames("--ldap-username").setComment("Set the LDAP username for the broker to use"); addOption("ldap.password").setType(cp::RpcValue::Type::String).setNames("--ldap-password").setComment("Set the LDAP password for the broker to use"); addOption("ldap.hostname").setType(cp::RpcValue::Type::String).setNames("--ldap-host").setComment("Set the LDAP server hostname"); addOption("ldap.searchBaseDN").setType(cp::RpcValue::Type::String).setNames("--ldap-search-base-dn").setComment("Set the base DN for LDAP searches (the DN where user entries live)"); addOption("ldap.searchAttrs").setType(cp::RpcValue::Type::List).setNames("--ldap-search-attrs").setComment("Set the LDAP attributes containing the login name for LDAP user entries"); addOption("ldap.groupMapping").setType(cp::RpcValue::Type::List).setComment("Set the mapping of LDAP groups to shv groups as an ordered list of pairs"); -#endif addOption("azure.groupMapping").setType(cp::RpcValue::Type::List).setComment("Set the mapping of Azure groups to shv groups as an ordered list of pairs"); } } diff --git a/libshvbroker/src/brokerapp.cpp b/libshvbroker/src/brokerapp.cpp index d1538f2a2..1af56feda 100644 --- a/libshvbroker/src/brokerapp.cpp +++ b/libshvbroker/src/brokerapp.cpp @@ -334,8 +334,8 @@ BrokerApp::BrokerApp(int &argc, char **argv, AppCliOptions *cli_opts) }); } -#ifdef WITH_SHV_LDAP if (cli_opts->ldapHostname_isset()) { +#ifdef WITH_SHV_LDAP m_ldapLib = {dlopen(LDAP_LIBNAME, RTLD_LAZY), [] (void* handle) { if (dlclose(handle)) { shvError() << "Couldn't close OpenLDAP library:" << dlerror(); @@ -393,8 +393,10 @@ BrokerApp::BrokerApp(int &argc, char **argv, AppCliOptions *cli_opts) .groupMapping = transform_cli_group_mapping(cli_opts->ldapGroupMapping()) }; new LdapAclNode(*m_ldapConfig, etc_acl_root_node); - } +#else + shvWarning() << "LDAP has been configured, but this broker wasn't compiled with LDAP support. LDAP will NOT be enabled."; #endif + } if (cli_opts->azureGroupMapping_isset()) { m_azureConfig = AzureConfig { .groupMapping = transform_cli_group_mapping(cli_opts->azureGroupMapping())