Create role mapping under ldap config object

Each ldap config object should be have its own
mapping object.

This is to align with the redfish.
https://redfish.dmtf.org/schemas/AccountService.v1_4_0.json

As per redfish, Each config will have it's own
"RemoteRoleMapping".

Mapping object should be persisted and restores
when the phosphor-ldap-conf restarts.

TestedBy:
          Unit Tested.
          Creation of privilege mapping.
          Persist the priv-mapping.
          Restores the priv-mapping.

Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
Change-Id: I5ab4aeffae61f9cc57c1338f94784d0fe5607cd3
diff --git a/phosphor-ldap-config/ldap_mapper_serialize.cpp b/phosphor-ldap-config/ldap_mapper_serialize.cpp
index 3ef809e..7fe2398 100644
--- a/phosphor-ldap-config/ldap_mapper_serialize.cpp
+++ b/phosphor-ldap-config/ldap_mapper_serialize.cpp
@@ -8,11 +8,11 @@
 // Register class version
 // From cereal documentation;
 // "This macro should be placed at global scope"
-CEREAL_CLASS_VERSION(phosphor::user::LDAPMapperEntry, CLASS_VERSION);
+CEREAL_CLASS_VERSION(phosphor::ldap::LDAPMapperEntry, CLASS_VERSION);
 
 namespace phosphor
 {
-namespace user
+namespace ldap
 {
 
 using namespace phosphor::logging;
@@ -54,10 +54,10 @@
         privilege(privilege, true);
 }
 
-fs::path serialize(const LDAPMapperEntry& entry, Id id, const fs::path& dir)
+fs::path serialize(const LDAPMapperEntry& entry, const fs::path& path)
 {
-    auto path = dir / std::to_string(id);
-    std::ofstream os(path.c_str(), std::ios::binary);
+    fs::create_directories(path.parent_path());
+    std::ofstream os(path.c_str(), std::ios::binary | std::ios::out);
     cereal::BinaryOutputArchive oarchive(os);
     oarchive(entry);
     return path;
@@ -90,5 +90,5 @@
     }
 }
 
-} // namespace user
+} // namespace ldap
 } // namespace phosphor