blob: 84109424c344c4ca7ba4452acb5a98facb1cce88 [file] [log] [blame]
Ratan Guptafd761da2019-04-12 21:48:57 +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"
10#include "ldap_mapper_serialize.hpp"
11
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 char *filePath,
24 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())),
29 manager(parent), persistPath(filePath)
30{
31 Ifaces::privilege(privilege, true);
32 Ifaces::groupName(groupName, true);
33 Ifaces::emit_object_added();
34}
35
36LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
37 const char *filePath, LDAPMapperMgr &parent) :
38 Ifaces(bus, path, true),
39 id(std::stol(std::experimental::filesystem::path(path).filename())),
40 manager(parent), persistPath(filePath)
41{
42}
43
44void 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);
57 auto val = Ifaces::groupName(value);
58 serialize(*this, id, persistPath);
59 return val;
60}
61
62std::string LDAPMapperEntry::privilege(std::string value)
63{
64 if (value == Ifaces::privilege())
65 {
66 return value;
67 }
68
69 manager.checkPrivilegeLevel(value);
70 auto val = Ifaces::privilege(value);
71 serialize(*this, id, persistPath);
72 return val;
73}
74
75} // namespace user
76} // namespace phosphor