From 0b14c471fc77cbcb93f435a46878b25f57741e0e Mon Sep 17 00:00:00 2001 From: Tom Joseph Date: Sun, 30 Sep 2018 01:42:59 +0530 Subject: ldap: Add persistence for LDAP mapper D-Bus objects Change-Id: Ib8979a7c655f74c332d80e7fb221ef03e9a3f83c Signed-off-by: Tom Joseph --- phosphor-ldap-mapper/ldap_mapper_mgr.cpp | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'phosphor-ldap-mapper/ldap_mapper_mgr.cpp') diff --git a/phosphor-ldap-mapper/ldap_mapper_mgr.cpp b/phosphor-ldap-mapper/ldap_mapper_mgr.cpp index 9fe40ad..a321331 100644 --- a/phosphor-ldap-mapper/ldap_mapper_mgr.cpp +++ b/phosphor-ldap-mapper/ldap_mapper_mgr.cpp @@ -5,6 +5,7 @@ #include #include "config.h" #include "ldap_mapper_mgr.hpp" +#include "ldap_mapper_serialize.hpp" namespace phosphor { @@ -38,6 +39,8 @@ ObjectPath LDAPMapperMgr::create(std::string groupName, std::string privilege) auto entry = std::make_unique( bus, mapperObject.c_str(), groupName, privilege, *this); + serialize(*entry, entryId); + PrivilegeMapperList.emplace(entryId, std::move(entry)); return mapperObject; @@ -45,6 +48,11 @@ ObjectPath LDAPMapperMgr::create(std::string groupName, std::string privilege) void LDAPMapperMgr::deletePrivilegeMapper(Id id) { + // Delete the persistent representation of the privilege mapper. + fs::path mapperPath(LDAP_MAPPER_PERSIST_PATH); + mapperPath /= std::to_string(id); + fs::remove(mapperPath); + PrivilegeMapperList.erase(id); } @@ -84,5 +92,34 @@ void LDAPMapperMgr::checkPrivilegeLevel(const std::string &privilege) } } +void LDAPMapperMgr::restore() +{ + namespace fs = std::experimental::filesystem; + + fs::path dir(LDAP_MAPPER_PERSIST_PATH); + if (!fs::exists(dir) || fs::is_empty(dir)) + { + return; + } + + for (auto &file : fs::directory_iterator(dir)) + { + std::string id = file.path().filename().c_str(); + size_t idNum = std::stol(id); + auto entryPath = std::string(mapperMgrRoot) + '/' + id; + auto entry = std::make_unique( + bus, entryPath.c_str(), *this); + if (deserialize(file.path(), *entry)) + { + entry->Ifaces::emit_object_added(); + PrivilegeMapperList.emplace(idNum, std::move(entry)); + if (idNum > entryId) + { + entryId = idNum; + } + } + } +} + } // namespace user } // namespace phosphor -- cgit v1.2.1