Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 1 | #include <filesystem> |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 2 | #include <xyz/openbmc_project/Common/error.hpp> |
| 3 | #include <xyz/openbmc_project/User/Common/error.hpp> |
| 4 | #include <phosphor-logging/log.hpp> |
| 5 | #include <phosphor-logging/elog.hpp> |
| 6 | #include <phosphor-logging/elog-errors.hpp> |
| 7 | #include "config.h" |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 8 | #include "ldap_config.hpp" |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 9 | #include "ldap_mapper_entry.hpp" |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 10 | #include "ldap_mapper_serialize.hpp" |
| 11 | |
| 12 | namespace phosphor |
| 13 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 14 | namespace ldap |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 15 | { |
| 16 | |
| 17 | using namespace phosphor::logging; |
| 18 | using InvalidArgument = |
| 19 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 20 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
| 21 | |
| 22 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path, |
| 23 | const char *filePath, |
| 24 | const std::string &groupName, |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 25 | const std::string &privilege, Config &parent) : |
| 26 | Interfaces(bus, path, true), |
| 27 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 28 | persistPath(filePath) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 29 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 30 | Interfaces::privilege(privilege, true); |
| 31 | Interfaces::groupName(groupName, true); |
| 32 | Interfaces::emit_object_added(); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path, |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 36 | const char *filePath, Config &parent) : |
| 37 | Interfaces(bus, path, true), |
| 38 | id(std::stol(std::filesystem::path(path).filename())), manager(parent), |
| 39 | persistPath(filePath) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | void LDAPMapperEntry::delete_(void) |
| 44 | { |
| 45 | manager.deletePrivilegeMapper(id); |
| 46 | } |
| 47 | |
| 48 | std::string LDAPMapperEntry::groupName(std::string value) |
| 49 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 50 | if (value == Interfaces::groupName()) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 51 | { |
| 52 | return value; |
| 53 | } |
| 54 | |
| 55 | manager.checkPrivilegeMapper(value); |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 56 | auto val = Interfaces::groupName(value); |
| 57 | serialize(*this, persistPath); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 58 | return val; |
| 59 | } |
| 60 | |
| 61 | std::string LDAPMapperEntry::privilege(std::string value) |
| 62 | { |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 63 | if (value == Interfaces::privilege()) |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 64 | { |
| 65 | return value; |
| 66 | } |
| 67 | |
| 68 | manager.checkPrivilegeLevel(value); |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 69 | auto val = Interfaces::privilege(value); |
| 70 | serialize(*this, persistPath); |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 71 | return val; |
| 72 | } |
| 73 | |
Ratan Gupta | 7b04c35 | 2019-04-12 21:46:29 +0530 | [diff] [blame] | 74 | } // namespace ldap |
Ratan Gupta | fd761da | 2019-04-12 21:48:57 +0530 | [diff] [blame] | 75 | } // namespace phosphor |