blob: af57e2df9372343cefb0b77844e9903e63c6cf9d [file] [log] [blame]
Patrick Williams9638afb2021-02-22 17:16:24 -06001#include "config.h"
2
3#include "ldap_mapper_entry.hpp"
4
5#include "ldap_config.hpp"
6#include "ldap_mapper_serialize.hpp"
7
8#include <phosphor-logging/elog-errors.hpp>
9#include <phosphor-logging/elog.hpp>
10#include <phosphor-logging/log.hpp>
Ratan Guptafd761da2019-04-12 21:48:57 +053011#include <xyz/openbmc_project/Common/error.hpp>
12#include <xyz/openbmc_project/User/Common/error.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -060013
14#include <filesystem>
Ratan Guptafd761da2019-04-12 21:48:57 +053015
16namespace phosphor
17{
Ratan Gupta7b04c352019-04-12 21:46:29 +053018namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053019{
20
21using namespace phosphor::logging;
22using InvalidArgument =
23 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
24using Argument = xyz::openbmc_project::Common::InvalidArgument;
25
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050026LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
Patrick Williams9638afb2021-02-22 17:16:24 -060027 const char* filePath,
28 const std::string& groupName,
29 const std::string& privilege, Config& parent) :
Patrick Williams224559b2022-04-05 16:10:39 -050030 Interfaces(bus, path, Interfaces::action::defer_emit),
Ratan Gupta7b04c352019-04-12 21:46:29 +053031 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
32 persistPath(filePath)
Ratan Guptafd761da2019-04-12 21:48:57 +053033{
Ratan Gupta7b04c352019-04-12 21:46:29 +053034 Interfaces::privilege(privilege, true);
35 Interfaces::groupName(groupName, true);
36 Interfaces::emit_object_added();
Ratan Guptafd761da2019-04-12 21:48:57 +053037}
38
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050039LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
Patrick Williams9638afb2021-02-22 17:16:24 -060040 const char* filePath, Config& parent) :
Patrick Williams224559b2022-04-05 16:10:39 -050041 Interfaces(bus, path, Interfaces::action::defer_emit),
Ratan Gupta7b04c352019-04-12 21:46:29 +053042 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
43 persistPath(filePath)
Patrick Williams9638afb2021-02-22 17:16:24 -060044{}
Ratan Guptafd761da2019-04-12 21:48:57 +053045
46void LDAPMapperEntry::delete_(void)
47{
48 manager.deletePrivilegeMapper(id);
49}
50
51std::string LDAPMapperEntry::groupName(std::string value)
52{
Ratan Gupta7b04c352019-04-12 21:46:29 +053053 if (value == Interfaces::groupName())
Ratan Guptafd761da2019-04-12 21:48:57 +053054 {
55 return value;
56 }
57
58 manager.checkPrivilegeMapper(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053059 auto val = Interfaces::groupName(value);
60 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053061 return val;
62}
63
64std::string LDAPMapperEntry::privilege(std::string value)
65{
Ratan Gupta7b04c352019-04-12 21:46:29 +053066 if (value == Interfaces::privilege())
Ratan Guptafd761da2019-04-12 21:48:57 +053067 {
68 return value;
69 }
70
71 manager.checkPrivilegeLevel(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053072 auto val = Interfaces::privilege(value);
73 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053074 return val;
75}
76
Ratan Gupta7b04c352019-04-12 21:46:29 +053077} // namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053078} // namespace phosphor