blob: a22984f7a3bec955453f3d168e29222ed21b4a65 [file] [log] [blame]
Tom Joseph536ea322018-09-14 10:02:20 +05301#include "config.h"
Patrick Williams9638afb2021-02-22 17:16:24 -06002
Tom Joseph536ea322018-09-14 10:02:20 +05303#include "ldap_mapper_entry.hpp"
Patrick Williams9638afb2021-02-22 17:16:24 -06004
Tom Joseph536ea322018-09-14 10:02:20 +05305#include "ldap_mapper_mgr.hpp"
Tom Joseph0b14c472018-09-30 01:42:59 +05306#include "ldap_mapper_serialize.hpp"
Tom Joseph536ea322018-09-14 10:02:20 +05307
Patrick Williams9638afb2021-02-22 17:16:24 -06008#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
Tom Joseph536ea322018-09-14 10:02:20 +053016namespace phosphor
17{
18namespace user
19{
20
21using namespace phosphor::logging;
22using InvalidArgument =
23 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
24using Argument = xyz::openbmc_project::Common::InvalidArgument;
25
Patrick Williams9638afb2021-02-22 17:16:24 -060026LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path,
27 const char* filePath,
28 const std::string& groupName,
29 const std::string& privilege,
30 LDAPMapperMgr& parent) :
Tom Joseph536ea322018-09-14 10:02:20 +053031 Ifaces(bus, path, true),
Gunnar Mills703131f2020-10-28 14:26:33 -050032 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
33 persistPath(filePath)
Tom Joseph536ea322018-09-14 10:02:20 +053034{
35 Ifaces::privilege(privilege, true);
36 Ifaces::groupName(groupName, true);
37 Ifaces::emit_object_added();
38}
39
Patrick Williams9638afb2021-02-22 17:16:24 -060040LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path,
41 const char* filePath, LDAPMapperMgr& parent) :
Tom Joseph0b14c472018-09-30 01:42:59 +053042 Ifaces(bus, path, true),
Gunnar Mills703131f2020-10-28 14:26:33 -050043 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
44 persistPath(filePath)
Patrick Williams9638afb2021-02-22 17:16:24 -060045{}
Tom Joseph0b14c472018-09-30 01:42:59 +053046
Tom Joseph536ea322018-09-14 10:02:20 +053047void LDAPMapperEntry::delete_(void)
48{
49 manager.deletePrivilegeMapper(id);
50}
51
52std::string LDAPMapperEntry::groupName(std::string value)
53{
54 if (value == Ifaces::groupName())
55 {
56 return value;
57 }
58
59 manager.checkPrivilegeMapper(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053060 auto val = Ifaces::groupName(value);
Tom Josephf5bd8912018-11-19 09:49:21 +053061 serialize(*this, id, persistPath);
Tom Joseph0b14c472018-09-30 01:42:59 +053062 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053063}
64
65std::string LDAPMapperEntry::privilege(std::string value)
66{
67 if (value == Ifaces::privilege())
68 {
69 return value;
70 }
71
72 manager.checkPrivilegeLevel(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053073 auto val = Ifaces::privilege(value);
Tom Josephf5bd8912018-11-19 09:49:21 +053074 serialize(*this, id, persistPath);
Tom Joseph0b14c472018-09-30 01:42:59 +053075 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053076}
77
78} // namespace user
79} // namespace phosphor