1 #include "config.h"
2
3 #include "ldap_mapper_entry.hpp"
4
5 #include "ldap_config.hpp"
6 #include "ldap_mapper_serialize.hpp"
7
8 #include <filesystem>
9
10 namespace phosphor
11 {
12 namespace ldap
13 {
14
LDAPMapperEntry(sdbusplus::bus_t & bus,const char * path,const char * filePath,const std::string & groupName,const std::string & privilege,Config & parent)15 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
16 const char* filePath,
17 const std::string& groupName,
18 const std::string& privilege, Config& parent) :
19 Interfaces(bus, path, Interfaces::action::defer_emit),
20 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
21 persistPath(filePath)
22 {
23 Interfaces::privilege(privilege, true);
24 Interfaces::groupName(groupName, true);
25 Interfaces::emit_object_added();
26 }
27
LDAPMapperEntry(sdbusplus::bus_t & bus,const char * path,const char * filePath,Config & parent)28 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
29 const char* filePath, Config& parent) :
30 Interfaces(bus, path, Interfaces::action::defer_emit),
31 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
32 persistPath(filePath)
33 {}
34
delete_(void)35 void LDAPMapperEntry::delete_(void)
36 {
37 manager.deletePrivilegeMapper(id);
38 }
39
groupName(std::string value)40 std::string LDAPMapperEntry::groupName(std::string value)
41 {
42 if (value == Interfaces::groupName())
43 {
44 return value;
45 }
46
47 manager.checkPrivilegeMapper(value);
48 auto val = Interfaces::groupName(value);
49 serialize(*this, persistPath);
50 return val;
51 }
52
privilege(std::string value)53 std::string LDAPMapperEntry::privilege(std::string value)
54 {
55 if (value == Interfaces::privilege())
56 {
57 return value;
58 }
59
60 manager.checkPrivilegeLevel(value);
61 auto val = Interfaces::privilege(value);
62 serialize(*this, persistPath);
63 return val;
64 }
65
66 } // namespace ldap
67 } // namespace phosphor
68