blob: 84109424c344c4ca7ba4452acb5a98facb1cce88 [file] [log] [blame]
Tom Joseph536ea322018-09-14 10:02:20 +05301#include <experimental/filesystem>
2#include <xyz/openbmc_project/Common/error.hpp>
3#include <xyz/openbmc_project/User/Common/error.hpp>
4#include <phosphor-logging/log.hpp>
5#include <phosphor-logging/elog.hpp>
6#include <phosphor-logging/elog-errors.hpp>
7#include "config.h"
8#include "ldap_mapper_entry.hpp"
9#include "ldap_mapper_mgr.hpp"
Tom Joseph0b14c472018-09-30 01:42:59 +053010#include "ldap_mapper_serialize.hpp"
Tom Joseph536ea322018-09-14 10:02:20 +053011
12namespace phosphor
13{
14namespace user
15{
16
17using namespace phosphor::logging;
18using InvalidArgument =
19 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
20using Argument = xyz::openbmc_project::Common::InvalidArgument;
21
22LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
Tom Josephf5bd8912018-11-19 09:49:21 +053023 const char *filePath,
Tom Joseph536ea322018-09-14 10:02:20 +053024 const std::string &groupName,
25 const std::string &privilege,
26 LDAPMapperMgr &parent) :
27 Ifaces(bus, path, true),
28 id(std::stol(std::experimental::filesystem::path(path).filename())),
Tom Josephf5bd8912018-11-19 09:49:21 +053029 manager(parent), persistPath(filePath)
Tom Joseph536ea322018-09-14 10:02:20 +053030{
31 Ifaces::privilege(privilege, true);
32 Ifaces::groupName(groupName, true);
33 Ifaces::emit_object_added();
34}
35
Tom Joseph0b14c472018-09-30 01:42:59 +053036LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
Tom Josephf5bd8912018-11-19 09:49:21 +053037 const char *filePath, LDAPMapperMgr &parent) :
Tom Joseph0b14c472018-09-30 01:42:59 +053038 Ifaces(bus, path, true),
39 id(std::stol(std::experimental::filesystem::path(path).filename())),
Tom Josephf5bd8912018-11-19 09:49:21 +053040 manager(parent), persistPath(filePath)
Tom Joseph0b14c472018-09-30 01:42:59 +053041{
42}
43
Tom Joseph536ea322018-09-14 10:02:20 +053044void LDAPMapperEntry::delete_(void)
45{
46 manager.deletePrivilegeMapper(id);
47}
48
49std::string LDAPMapperEntry::groupName(std::string value)
50{
51 if (value == Ifaces::groupName())
52 {
53 return value;
54 }
55
56 manager.checkPrivilegeMapper(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053057 auto val = Ifaces::groupName(value);
Tom Josephf5bd8912018-11-19 09:49:21 +053058 serialize(*this, id, persistPath);
Tom Joseph0b14c472018-09-30 01:42:59 +053059 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053060}
61
62std::string LDAPMapperEntry::privilege(std::string value)
63{
64 if (value == Ifaces::privilege())
65 {
66 return value;
67 }
68
69 manager.checkPrivilegeLevel(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053070 auto val = Ifaces::privilege(value);
Tom Josephf5bd8912018-11-19 09:49:21 +053071 serialize(*this, id, persistPath);
Tom Joseph0b14c472018-09-30 01:42:59 +053072 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053073}
74
75} // namespace user
76} // namespace phosphor