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