diff options
author | Nagaraju Goruganti <ngorugan@in.ibm.com> | 2018-09-25 08:51:06 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-10-04 15:14:12 -0400 |
commit | dccee2b7ff47757afb6a0606707b6436bb0f4c7b (patch) | |
tree | 2cb672dba7e5f6b0978415d08f27c6216f023f7b /phosphor-ldap-config | |
parent | 24194bd9672083de9eb4a33ff8e8369b46f823bf (diff) | |
download | phosphor-user-manager-dccee2b7ff47757afb6a0606707b6436bb0f4c7b.tar.gz phosphor-user-manager-dccee2b7ff47757afb6a0606707b6436bb0f4c7b.zip |
phosphor-ldap-conf: switch between config files while enabling/disabling LDAP
While creating LDAP configuration take a backup of existing config files
and restore them when LDAP configuration is disabled.
Change-Id: Id37138107311a56c5066bc66137a2d55e1e23099
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
Diffstat (limited to 'phosphor-ldap-config')
-rw-r--r-- | phosphor-ldap-config/ldap_configuration.cpp | 51 | ||||
-rw-r--r-- | phosphor-ldap-config/ldap_configuration.hpp | 5 |
2 files changed, 56 insertions, 0 deletions
diff --git a/phosphor-ldap-config/ldap_configuration.cpp b/phosphor-ldap-config/ldap_configuration.cpp index 3a4ed2e..222793e 100644 --- a/phosphor-ldap-config/ldap_configuration.cpp +++ b/phosphor-ldap-config/ldap_configuration.cpp @@ -8,6 +8,7 @@ namespace phosphor namespace ldap { constexpr auto nslcdService = "nslcd.service"; +constexpr auto nscdService = "nscd.service"; using namespace phosphor::logging; using namespace sdbusplus::xyz::openbmc_project::Common::Error; @@ -43,6 +44,24 @@ Config::Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath, void Config::delete_() { parent.deleteObject(); + try + { + fs::copy_file(defaultNslcdFile, LDAP_CONFIG_FILE, + fs::copy_options::overwrite_existing); + fs::copy_file(nsSwitchFile, LDAPNsSwitchFile, + fs::copy_options::overwrite_existing); + fs::copy_file(linuxNsSwitchFile, nsSwitchFile, + fs::copy_options::overwrite_existing); + } + catch (const std::exception& e) + { + log<level::ERR>("Failed to rename Config Files while deleting Object", + entry("ERR=%s", e.what())); + elog<InternalFailure>(); + } + + parent.restartService(nscdService); + parent.stopService(nslcdService); } void Config::writeConfig() @@ -325,6 +344,23 @@ void ConfigMgr::restartService(const std::string& service) } } +void ConfigMgr::stopService(const std::string& service) +{ + try + { + auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, + SYSTEMD_INTERFACE, "StopUnit"); + method.append(service.c_str(), "replace"); + bus.call_noreply(method); + } + catch (const sdbusplus::exception::SdBusError& ex) + { + log<level::ERR>("Failed to stop nslcd service", + entry("ERR=%s", ex.what())); + elog<InternalFailure>(); + } +} + void ConfigMgr::deleteObject() { configPtr.reset(nullptr); @@ -340,6 +376,19 @@ std::string // TODO Validate parameters passed-in. // With current implementation we support only one LDAP server. deleteObject(); + try + { + fs::copy_file(nsSwitchFile, linuxNsSwitchFile, + fs::copy_options::overwrite_existing); + fs::copy_file(LDAPNsSwitchFile, nsSwitchFile, + fs::copy_options::overwrite_existing); + } + catch (const std::exception& e) + { + log<level::ERR>("Failed to rename Config Files while creating Object", + entry("ERR=%s", e.what())); + elog<InternalFailure>(); + } auto objPath = std::string(LDAP_CONFIG_DBUS_OBJ_PATH); configPtr = std::make_unique<Config>( @@ -348,6 +397,8 @@ std::string static_cast<ldap_base::Config::SearchScope>(lDAPSearchScope), static_cast<ldap_base::Config::Type>(lDAPType), *this); + restartService(nslcdService); + restartService(nscdService); return objPath; } diff --git a/phosphor-ldap-config/ldap_configuration.hpp b/phosphor-ldap-config/ldap_configuration.hpp index 58e9930..6601bd2 100644 --- a/phosphor-ldap-config/ldap_configuration.hpp +++ b/phosphor-ldap-config/ldap_configuration.hpp @@ -196,6 +196,11 @@ class ConfigMgr : public CreateIface */ virtual void restartService(const std::string& service); + /** @brief stops given service + * @param[in] service - Service to be stopped. + */ + virtual void stopService(const std::string& service); + /** @brief delete the config D-Bus object. */ void deleteObject(); |