From dccee2b7ff47757afb6a0606707b6436bb0f4c7b Mon Sep 17 00:00:00 2001 From: Nagaraju Goruganti Date: Tue, 25 Sep 2018 08:51:06 -0500 Subject: 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 --- phosphor-ldap-config/ldap_configuration.cpp | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'phosphor-ldap-config/ldap_configuration.cpp') 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("Failed to rename Config Files while deleting Object", + entry("ERR=%s", e.what())); + elog(); + } + + 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("Failed to stop nslcd service", + entry("ERR=%s", ex.what())); + elog(); + } +} + 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("Failed to rename Config Files while creating Object", + entry("ERR=%s", e.what())); + elog(); + } auto objPath = std::string(LDAP_CONFIG_DBUS_OBJ_PATH); configPtr = std::make_unique( @@ -348,6 +397,8 @@ std::string static_cast(lDAPSearchScope), static_cast(lDAPType), *this); + restartService(nslcdService); + restartService(nscdService); return objPath; } -- cgit v1.2.1