xref: /openbmc/phosphor-user-manager/phosphor-ldap-config/ldap_mapper_entry.cpp (revision cf53a9466cc3aaf07d0a766d0af99e2c134183c5)
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 <phosphor-logging/elog-errors.hpp>
9 #include <phosphor-logging/elog.hpp>
10 #include <phosphor-logging/log.hpp>
11 #include <xyz/openbmc_project/Common/error.hpp>
12 #include <xyz/openbmc_project/User/Common/error.hpp>
13 
14 #include <filesystem>
15 
16 namespace phosphor
17 {
18 namespace ldap
19 {
20 
21 using namespace phosphor::logging;
22 using InvalidArgument =
23     sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
24 using Argument = xyz::openbmc_project::Common::InvalidArgument;
25 
26 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path,
27                                  const char* filePath,
28                                  const std::string& groupName,
29                                  const std::string& privilege, Config& parent) :
30     Interfaces(bus, path, true),
31     id(std::stol(std::filesystem::path(path).filename())), manager(parent),
32     persistPath(filePath)
33 {
34     Interfaces::privilege(privilege, true);
35     Interfaces::groupName(groupName, true);
36     Interfaces::emit_object_added();
37 }
38 
39 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path,
40                                  const char* filePath, Config& parent) :
41     Interfaces(bus, path, true),
42     id(std::stol(std::filesystem::path(path).filename())), manager(parent),
43     persistPath(filePath)
44 {}
45 
46 void LDAPMapperEntry::delete_(void)
47 {
48     manager.deletePrivilegeMapper(id);
49 }
50 
51 std::string LDAPMapperEntry::groupName(std::string value)
52 {
53     if (value == Interfaces::groupName())
54     {
55         return value;
56     }
57 
58     manager.checkPrivilegeMapper(value);
59     auto val = Interfaces::groupName(value);
60     serialize(*this, persistPath);
61     return val;
62 }
63 
64 std::string LDAPMapperEntry::privilege(std::string value)
65 {
66     if (value == Interfaces::privilege())
67     {
68         return value;
69     }
70 
71     manager.checkPrivilegeLevel(value);
72     auto val = Interfaces::privilege(value);
73     serialize(*this, persistPath);
74     return val;
75 }
76 
77 } // namespace ldap
78 } // namespace phosphor
79