Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 1 | #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 Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Common/error.hpp> |
| 12 | #include <xyz/openbmc_project/User/Common/error.hpp> |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 13 | |
| 14 | #include <filesystem> |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 15 | |
| 16 | namespace phosphor |
| 17 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 18 | namespace ldap |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 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 | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 26 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path, |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 27 | const char* filePath, |
| 28 | const std::string& groupName, |
| 29 | const std::string& privilege, Config& parent) : |
Patrick Williams | 224559b | 2022-04-05 16:10:39 -0500 | [diff] [blame] | 30 | Interfaces(bus, path, Interfaces::action::defer_emit), |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 31 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 32 | persistPath(filePath) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 33 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 34 | Interfaces::privilege(privilege, true); |
| 35 | Interfaces::groupName(groupName, true); |
| 36 | Interfaces::emit_object_added(); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 37 | } |
| 38 | |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 39 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus_t& bus, const char* path, |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 40 | const char* filePath, Config& parent) : |
Patrick Williams | 224559b | 2022-04-05 16:10:39 -0500 | [diff] [blame] | 41 | Interfaces(bus, path, Interfaces::action::defer_emit), |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 42 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 43 | persistPath(filePath) |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 44 | {} |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 45 | |
| 46 | void LDAPMapperEntry::delete_(void) |
| 47 | { |
| 48 | manager.deletePrivilegeMapper(id); |
| 49 | } |
| 50 | |
| 51 | std::string LDAPMapperEntry::groupName(std::string value) |
| 52 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 53 | if (value == Interfaces::groupName()) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 54 | { |
| 55 | return value; |
| 56 | } |
| 57 | |
| 58 | manager.checkPrivilegeMapper(value); |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 59 | auto val = Interfaces::groupName(value); |
| 60 | serialize(*this, persistPath); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 61 | return val; |
| 62 | } |
| 63 | |
| 64 | std::string LDAPMapperEntry::privilege(std::string value) |
| 65 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 66 | if (value == Interfaces::privilege()) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 67 | { |
| 68 | return value; |
| 69 | } |
| 70 | |
| 71 | manager.checkPrivilegeLevel(value); |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 72 | auto val = Interfaces::privilege(value); |
| 73 | serialize(*this, persistPath); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 74 | return val; |
| 75 | } |
| 76 | |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 77 | } // namespace ldap |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 78 | } // namespace phosphor |