blob: 95f381d0ff3d2ee3826912466e42fdedeea63757 [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,
23 const std::string &groupName,
24 const std::string &privilege,
25 LDAPMapperMgr &parent) :
26 Ifaces(bus, path, true),
27 id(std::stol(std::experimental::filesystem::path(path).filename())),
28 manager(parent)
29{
30 Ifaces::privilege(privilege, true);
31 Ifaces::groupName(groupName, true);
32 Ifaces::emit_object_added();
33}
34
Tom Joseph0b14c472018-09-30 01:42:59 +053035LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
36 LDAPMapperMgr &parent) :
37 Ifaces(bus, path, true),
38 id(std::stol(std::experimental::filesystem::path(path).filename())),
39 manager(parent)
40{
41}
42
Tom Joseph536ea322018-09-14 10:02:20 +053043void LDAPMapperEntry::delete_(void)
44{
45 manager.deletePrivilegeMapper(id);
46}
47
48std::string LDAPMapperEntry::groupName(std::string value)
49{
50 if (value == Ifaces::groupName())
51 {
52 return value;
53 }
54
55 manager.checkPrivilegeMapper(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053056 auto val = Ifaces::groupName(value);
57 serialize(*this, id);
58 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053059}
60
61std::string LDAPMapperEntry::privilege(std::string value)
62{
63 if (value == Ifaces::privilege())
64 {
65 return value;
66 }
67
68 manager.checkPrivilegeLevel(value);
Tom Joseph0b14c472018-09-30 01:42:59 +053069 auto val = Ifaces::privilege(value);
70 serialize(*this, id);
71 return val;
Tom Joseph536ea322018-09-14 10:02:20 +053072}
73
74} // namespace user
75} // namespace phosphor