1 #include <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_config.hpp" 9 #include "ldap_mapper_entry.hpp" 10 #include "ldap_mapper_serialize.hpp" 11 12 namespace phosphor 13 { 14 namespace ldap 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, 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) 29 { 30 Interfaces::privilege(privilege, true); 31 Interfaces::groupName(groupName, true); 32 Interfaces::emit_object_added(); 33 } 34 35 LDAPMapperEntry::LDAPMapperEntry(sdbusplus::bus::bus &bus, const char *path, 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) 40 { 41 } 42 43 void LDAPMapperEntry::delete_(void) 44 { 45 manager.deletePrivilegeMapper(id); 46 } 47 48 std::string LDAPMapperEntry::groupName(std::string value) 49 { 50 if (value == Interfaces::groupName()) 51 { 52 return value; 53 } 54 55 manager.checkPrivilegeMapper(value); 56 auto val = Interfaces::groupName(value); 57 serialize(*this, persistPath); 58 return val; 59 } 60 61 std::string LDAPMapperEntry::privilege(std::string value) 62 { 63 if (value == Interfaces::privilege()) 64 { 65 return value; 66 } 67 68 manager.checkPrivilegeLevel(value); 69 auto val = Interfaces::privilege(value); 70 serialize(*this, persistPath); 71 return val; 72 } 73 74 } // namespace ldap 75 } // namespace phosphor 76