blob: 09b0e0fe1bf1b582b9bbea856d64d166d8e4c1ee [file] [log] [blame]
Ratan Gupta7b04c352019-04-12 21:46:29 +05301#include <filesystem>
Ratan Guptafd761da2019-04-12 21:48:57 +05302#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"
Ratan Gupta7b04c352019-04-12 21:46:29 +05308#include "ldap_config.hpp"
Ratan Guptafd761da2019-04-12 21:48:57 +05309#include "ldap_mapper_entry.hpp"
Ratan Guptafd761da2019-04-12 21:48:57 +053010#include "ldap_mapper_serialize.hpp"
11
12namespace phosphor
13{
Ratan Gupta7b04c352019-04-12 21:46:29 +053014namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053015{
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,
Ratan Gupta7b04c352019-04-12 21:46:29 +053025 const std::string &privilege, Config &parent) :
26 Interfaces(bus, path, true),
27 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
28 persistPath(filePath)
Ratan Guptafd761da2019-04-12 21:48:57 +053029{
Ratan Gupta7b04c352019-04-12 21:46:29 +053030 Interfaces::privilege(privilege, true);
31 Interfaces::groupName(groupName, true);
32 Interfaces::emit_object_added();
Ratan Guptafd761da2019-04-12 21:48:57 +053033}
34
35LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path,
Ratan Gupta7b04c352019-04-12 21:46:29 +053036 const char *filePath, Config &parent) :
37 Interfaces(bus, path, true),
38 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
39 persistPath(filePath)
Ratan Guptafd761da2019-04-12 21:48:57 +053040{
41}
42
43void LDAPMapperEntry::delete_(void)
44{
45 manager.deletePrivilegeMapper(id);
46}
47
48std::string LDAPMapperEntry::groupName(std::string value)
49{
Ratan Gupta7b04c352019-04-12 21:46:29 +053050 if (value == Interfaces::groupName())
Ratan Guptafd761da2019-04-12 21:48:57 +053051 {
52 return value;
53 }
54
55 manager.checkPrivilegeMapper(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053056 auto val = Interfaces::groupName(value);
57 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053058 return val;
59}
60
61std::string LDAPMapperEntry::privilege(std::string value)
62{
Ratan Gupta7b04c352019-04-12 21:46:29 +053063 if (value == Interfaces::privilege())
Ratan Guptafd761da2019-04-12 21:48:57 +053064 {
65 return value;
66 }
67
68 manager.checkPrivilegeLevel(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053069 auto val = Interfaces::privilege(value);
70 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053071 return val;
72}
73
Ratan Gupta7b04c352019-04-12 21:46:29 +053074} // namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053075} // namespace phosphor