Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 1 | #include "config.h" |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 2 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 3 | #include "ldap_mapper_entry.hpp" |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 4 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 5 | #include "ldap_mapper_mgr.hpp" |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 6 | #include "ldap_mapper_serialize.hpp" |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 7 | |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/elog-errors.hpp> |
| 9 | #include <phosphor-logging/elog.hpp> |
| 10 | #include <phosphor-logging/log.hpp> |
| 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | #include <xyz/openbmc_project/User/Common/error.hpp> |
| 13 | |
| 14 | #include <filesystem> |
| 15 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 16 | namespace phosphor |
| 17 | { |
| 18 | namespace user |
| 19 | { |
| 20 | |
| 21 | using namespace phosphor::logging; |
| 22 | using InvalidArgument = |
| 23 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 24 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 25 | |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 26 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path, |
| 27 | const char* filePath, |
| 28 | const std::string& groupName, |
| 29 | const std::string& privilege, |
| 30 | LDAPMapperMgr& parent) : |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 31 | Ifaces(bus, path, true), |
Gunnar Mills | 703131f | 2020-10-28 14:26:33 -0500 | [diff] [blame] | 32 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 33 | persistPath(filePath) |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 34 | { |
| 35 | Ifaces::privilege(privilege, true); |
| 36 | Ifaces::groupName(groupName, true); |
| 37 | Ifaces::emit_object_added(); |
| 38 | } |
| 39 | |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 40 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus& bus, const char* path, |
| 41 | const char* filePath, LDAPMapperMgr& parent) : |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 42 | Ifaces(bus, path, true), |
Gunnar Mills | 703131f | 2020-10-28 14:26:33 -0500 | [diff] [blame] | 43 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 44 | persistPath(filePath) |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 45 | {} |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 46 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 47 | void LDAPMapperEntry::delete_(void) |
| 48 | { |
| 49 | manager.deletePrivilegeMapper(id); |
| 50 | } |
| 51 | |
| 52 | std::string LDAPMapperEntry::groupName(std::string value) |
| 53 | { |
| 54 | if (value == Ifaces::groupName()) |
| 55 | { |
| 56 | return value; |
| 57 | } |
| 58 | |
| 59 | manager.checkPrivilegeMapper(value); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 60 | auto val = Ifaces::groupName(value); |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 61 | serialize(*this, id, persistPath); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 62 | return val; |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | std::string LDAPMapperEntry::privilege(std::string value) |
| 66 | { |
| 67 | if (value == Ifaces::privilege()) |
| 68 | { |
| 69 | return value; |
| 70 | } |
| 71 | |
| 72 | manager.checkPrivilegeLevel(value); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 73 | auto val = Ifaces::privilege(value); |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 74 | serialize(*this, id, persistPath); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 75 | return val; |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace user |
| 79 | } // namespace phosphor |