diff options
author | Tom Joseph <tomjoseph@in.ibm.com> | 2018-09-30 01:42:59 +0530 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-10-04 14:27:10 -0400 |
commit | 0b14c471fc77cbcb93f435a46878b25f57741e0e (patch) | |
tree | a0048f6956d1969c2eb9f0103fd2475a7afc6ae1 /phosphor-ldap-mapper/ldap_mapper_mgr.cpp | |
parent | 536ea32ddc61bc3f5ad34eada5788797e1771832 (diff) | |
download | phosphor-user-manager-0b14c471fc77cbcb93f435a46878b25f57741e0e.tar.gz phosphor-user-manager-0b14c471fc77cbcb93f435a46878b25f57741e0e.zip |
ldap: Add persistence for LDAP mapper D-Bus objects
Change-Id: Ib8979a7c655f74c332d80e7fb221ef03e9a3f83c
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'phosphor-ldap-mapper/ldap_mapper_mgr.cpp')
-rw-r--r-- | phosphor-ldap-mapper/ldap_mapper_mgr.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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 <phosphor-logging/elog-errors.hpp> #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<phosphor::user::LDAPMapperEntry>( 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<phosphor::user::LDAPMapperEntry>( + 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 |