summaryrefslogtreecommitdiffstats
path: root/phosphor-ldap-config
diff options
context:
space:
mode:
Diffstat (limited to 'phosphor-ldap-config')
-rw-r--r--phosphor-ldap-config/Makefile.am3
-rw-r--r--phosphor-ldap-config/ldap_configuration.cpp14
-rw-r--r--phosphor-ldap-config/ldap_configuration.hpp11
-rw-r--r--phosphor-ldap-config/ldap_serialize.cpp88
-rw-r--r--phosphor-ldap-config/ldap_serialize.hpp29
-rw-r--r--phosphor-ldap-config/main.cpp2
6 files changed, 141 insertions, 6 deletions
diff --git a/phosphor-ldap-config/Makefile.am b/phosphor-ldap-config/Makefile.am
index 907c365..501e577 100644
--- a/phosphor-ldap-config/Makefile.am
+++ b/phosphor-ldap-config/Makefile.am
@@ -5,7 +5,8 @@ noinst_HEADERS = ldap_configuration.hpp utils.hpp
phosphor_ldap_conf_SOURCES = \
main.cpp \
utils.cpp \
- ldap_configuration.cpp
+ ldap_configuration.cpp \
+ ldap_serialize.cpp
phosphor_ldap_conf_LDFLAGS = $(SDBUSPLUS_LIBS) \
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
diff --git a/phosphor-ldap-config/ldap_configuration.cpp b/phosphor-ldap-config/ldap_configuration.cpp
index 413998a..4f2f85c 100644
--- a/phosphor-ldap-config/ldap_configuration.cpp
+++ b/phosphor-ldap-config/ldap_configuration.cpp
@@ -1,6 +1,7 @@
#include "ldap_configuration.hpp"
+#include "ldap_serialize.hpp"
#include "utils.hpp"
-#include <experimental/filesystem>
+#include <filesystem>
#include <fstream>
#include <sstream>
@@ -15,7 +16,7 @@ constexpr auto LDAPSscheme = "ldaps";
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-namespace fs = std::experimental::filesystem;
+namespace fs = std::filesystem;
using Argument = xyz::openbmc_project::Common::InvalidArgument;
using Line = std::string;
@@ -386,6 +387,8 @@ bool Config::enabled(bool value)
return value;
}
isEnable = EnableIface::enabled(value);
+ // save the enabled property.
+ serialize(*this, parent.dbusPersistentPath);
parent.startOrStopService(nslcdService, value);
}
catch (const InternalFailure& e)
@@ -691,6 +694,13 @@ void ConfigMgr::restore(const char* filePath)
std::move(configValues["bindpw"]), lDAPSearchScope,
lDAPType, std::move(configValues["map_passwd_uid"]),
std::move(configValues["map_passwd_gidNumber"]));
+
+ // Get the enabled property value from the persistent location
+ if (!deserialize(dbusPersistentPath, *configPtr))
+ {
+ log<level::INFO>(
+ "Deserialization Failed, continue with service disable");
+ }
}
catch (const InvalidArgument& e)
{
diff --git a/phosphor-ldap-config/ldap_configuration.hpp b/phosphor-ldap-config/ldap_configuration.hpp
index 0d69f08..976aac6 100644
--- a/phosphor-ldap-config/ldap_configuration.hpp
+++ b/phosphor-ldap-config/ldap_configuration.hpp
@@ -178,12 +178,14 @@ class ConfigMgr : public CreateIface
* @param[in] bus - Bus to attach to.
* @param[in] path - Path to attach at.
* @param[in] filePath - LDAP configuration file.
+ * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property.
* @param[in] caCertFile - LDAP's CA certificate file.
*/
ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
- const char* caCertFile) :
+ const char* dbusPersistentPath, const char* caCertFile) :
CreateIface(bus, path, true),
- configFilePath(filePath), bus(bus)
+ dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
+ bus(bus)
{
try
{
@@ -242,6 +244,11 @@ class ConfigMgr : public CreateIface
*/
void deleteObject();
+ /* ldap service enabled property would be saved under
+ * this path.
+ */
+ std::string dbusPersistentPath;
+
protected:
std::string configFilePath{};
std::string tlsCacertFile{};
diff --git a/phosphor-ldap-config/ldap_serialize.cpp b/phosphor-ldap-config/ldap_serialize.cpp
new file mode 100644
index 0000000..510686c
--- /dev/null
+++ b/phosphor-ldap-config/ldap_serialize.cpp
@@ -0,0 +1,88 @@
+#include <cereal/types/string.hpp>
+#include <cereal/types/vector.hpp>
+#include <cereal/archives/binary.hpp>
+#include <fstream>
+
+#include "ldap_serialize.hpp"
+#include "ldap_configuration.hpp"
+#include <phosphor-logging/log.hpp>
+#include "config.h"
+
+// Register class version
+// From cereal documentation;
+// "This macro should be placed at global scope"
+CEREAL_CLASS_VERSION(phosphor::ldap::Config, CLASS_VERSION);
+
+namespace phosphor
+{
+namespace ldap
+{
+
+using namespace phosphor::logging;
+
+/** @brief Function required by Cereal to perform serialization.
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ * @param[in] config - const reference to ldap config.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
+ */
+template <class Archive>
+void save(Archive& archive, const Config& config, const std::uint32_t version)
+{
+ archive(config.enabled());
+}
+
+/** @brief Function required by Cereal to perform deserialization.
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ * @param[in] config - reference of ldap config object.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
+ */
+template <class Archive>
+void load(Archive& archive, Config& config, const std::uint32_t version)
+{
+ bool enabled = false;
+ archive(enabled);
+ config.enabled(enabled);
+}
+
+fs::path serialize(const Config& config, const fs::path& path)
+{
+ fs::create_directories(path.parent_path());
+
+ std::ofstream os(path.string(), std::ios::binary);
+ cereal::BinaryOutputArchive oarchive(os);
+ oarchive(config);
+ return path;
+}
+
+bool deserialize(const fs::path& path, Config& config)
+{
+ try
+ {
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
+ cereal::BinaryInputArchive iarchive(is);
+ iarchive(config);
+ return true;
+ }
+ return false;
+ }
+ catch (cereal::Exception& e)
+ {
+ log<level::ERR>(e.what());
+ std::error_code ec;
+ fs::remove(path, ec);
+ return false;
+ }
+ catch (const fs::filesystem_error& e)
+ {
+ return false;
+ }
+}
+
+} // namespace ldap
+} // namespace phosphor
diff --git a/phosphor-ldap-config/ldap_serialize.hpp b/phosphor-ldap-config/ldap_serialize.hpp
new file mode 100644
index 0000000..b784baf
--- /dev/null
+++ b/phosphor-ldap-config/ldap_serialize.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <filesystem>
+#include "ldap_configuration.hpp"
+
+namespace phosphor
+{
+namespace ldap
+{
+
+namespace fs = std::filesystem;
+
+/** @brief Serialize and persist LDAP service status property.
+ * @param[in] config - const reference to LDAP config object.
+ * @param[in] path - path of persistent location where D-Bus property would be
+ * saved.
+ * @return fs::path - pathname of persisted LDAP Config file.
+ */
+fs::path serialize(const Config& config, const fs::path& path);
+
+/** @brief Deserialize LDAP service status into a D-Bus object
+ * @param[in] path - pathname of persisted LDAP Config file.
+ * @param[in] config - reference of the object which needs to be deserialized.
+ * @return bool - true if the deserialization was successful, false otherwise.
+ */
+bool deserialize(const fs::path& path, Config& config);
+
+} // namespace ldap
+} // namespace phosphor
diff --git a/phosphor-ldap-config/main.cpp b/phosphor-ldap-config/main.cpp
index 3ecc0ca..2e3bf66 100644
--- a/phosphor-ldap-config/main.cpp
+++ b/phosphor-ldap-config/main.cpp
@@ -26,7 +26,7 @@ int main(int argc, char* argv[])
sdbusplus::server::manager::manager objManager(bus, LDAP_CONFIG_ROOT);
phosphor::ldap::ConfigMgr mgr(bus, LDAP_CONFIG_ROOT, LDAP_CONFIG_FILE,
- TLS_CACERT_FILE);
+ LDAP_CONF_PERSIST_PATH, TLS_CACERT_FILE);
bus.request_name(LDAP_CONFIG_BUSNAME);
OpenPOWER on IntegriCloud