blob: 41b56eb7d1f0639a531f0cc400cd11f666607a72 [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
Patrick Williams9638afb2021-02-22 17:16:24 -06008#include <filesystem>
Ratan Guptafd761da2019-04-12 21:48:57 +05309
10namespace phosphor
11{
Ratan Gupta7b04c352019-04-12 21:46:29 +053012namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053013{
14
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050015LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
Patrick Williams9638afb2021-02-22 17:16:24 -060016 const char* filePath,
17 const std::string& groupName,
18 const std::string& privilege, Config& parent) :
Patrick Williams224559b2022-04-05 16:10:39 -050019 Interfaces(bus, path, Interfaces::action::defer_emit),
Ratan Gupta7b04c352019-04-12 21:46:29 +053020 id(std::stol(std::filesystem::path(path).filename())), manager(parent),
21 persistPath(filePath)
Ratan Guptafd761da2019-04-12 21:48:57 +053022{
Ratan Gupta7b04c352019-04-12 21:46:29 +053023 Interfaces::privilege(privilege, true);
24 Interfaces::groupName(groupName, true);
25 Interfaces::emit_object_added();
Ratan Guptafd761da2019-04-12 21:48:57 +053026}
27
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050028LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path,
Patrick Williams9638afb2021-02-22 17:16:24 -060029 const char* filePath, 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)
Patrick Williams9638afb2021-02-22 17:16:24 -060033{}
Ratan Guptafd761da2019-04-12 21:48:57 +053034
35void LDAPMapperEntry::delete_(void)
36{
37 manager.deletePrivilegeMapper(id);
38}
39
40std::string LDAPMapperEntry::groupName(std::string value)
41{
Ratan Gupta7b04c352019-04-12 21:46:29 +053042 if (value == Interfaces::groupName())
Ratan Guptafd761da2019-04-12 21:48:57 +053043 {
44 return value;
45 }
46
47 manager.checkPrivilegeMapper(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053048 auto val = Interfaces::groupName(value);
49 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053050 return val;
51}
52
53std::string LDAPMapperEntry::privilege(std::string value)
54{
Ratan Gupta7b04c352019-04-12 21:46:29 +053055 if (value == Interfaces::privilege())
Ratan Guptafd761da2019-04-12 21:48:57 +053056 {
57 return value;
58 }
59
60 manager.checkPrivilegeLevel(value);
Ratan Gupta7b04c352019-04-12 21:46:29 +053061 auto val = Interfaces::privilege(value);
62 serialize(*this, persistPath);
Ratan Guptafd761da2019-04-12 21:48:57 +053063 return val;
64}
65
Ratan Gupta7b04c352019-04-12 21:46:29 +053066} // namespace ldap
Ratan Guptafd761da2019-04-12 21:48:57 +053067} // namespace phosphor