Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 1 | #include <experimental/filesystem> |
| 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" |
| 8 | #include "ldap_mapper_entry.hpp" |
| 9 | #include "ldap_mapper_mgr.hpp" |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 10 | #include "ldap_mapper_serialize.hpp" |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace user |
| 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, |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 23 | const char *filePath, |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 24 | const std::string &groupName, |
| 25 | const std::string &privilege, |
| 26 | LDAPMapperMgr &parent) : |
| 27 | Ifaces(bus, path, true), |
| 28 | id(std::stol(std::experimental::filesystem::path(path).filename())), |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 29 | manager(parent), persistPath(filePath) |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 30 | { |
| 31 | Ifaces::privilege(privilege, true); |
| 32 | Ifaces::groupName(groupName, true); |
| 33 | Ifaces::emit_object_added(); |
| 34 | } |
| 35 | |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 36 | LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path, |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 37 | const char *filePath, LDAPMapperMgr &parent) : |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 38 | Ifaces(bus, path, true), |
| 39 | id(std::stol(std::experimental::filesystem::path(path).filename())), |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 40 | manager(parent), persistPath(filePath) |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 44 | void LDAPMapperEntry::delete_(void) |
| 45 | { |
| 46 | manager.deletePrivilegeMapper(id); |
| 47 | } |
| 48 | |
| 49 | std::string LDAPMapperEntry::groupName(std::string value) |
| 50 | { |
| 51 | if (value == Ifaces::groupName()) |
| 52 | { |
| 53 | return value; |
| 54 | } |
| 55 | |
| 56 | manager.checkPrivilegeMapper(value); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 57 | auto val = Ifaces::groupName(value); |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 58 | serialize(*this, id, persistPath); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 59 | return val; |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | std::string LDAPMapperEntry::privilege(std::string value) |
| 63 | { |
| 64 | if (value == Ifaces::privilege()) |
| 65 | { |
| 66 | return value; |
| 67 | } |
| 68 | |
| 69 | manager.checkPrivilegeLevel(value); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 70 | auto val = Ifaces::privilege(value); |
Tom Joseph | f5bd891 | 2018-11-19 09:49:21 +0530 | [diff] [blame] | 71 | serialize(*this, id, persistPath); |
Tom Joseph | 0b14c47 | 2018-09-30 01:42:59 +0530 | [diff] [blame] | 72 | return val; |
Tom Joseph | 536ea32 | 2018-09-14 10:02:20 +0530 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } // namespace user |
| 76 | } // namespace phosphor |