Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
| 4 | #include <sdbusplus/server/object.hpp> |
| 5 | #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> |
| 6 | #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> |
| 7 | #include <string> |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace ldap |
| 12 | { |
| 13 | static constexpr auto defaultNslcdFile = "/etc/nslcd.conf.default"; |
| 14 | static constexpr auto nsSwitchFile = "/etc/nsswitch.conf"; |
| 15 | static constexpr auto LDAPNsSwitchFile = "/etc/nsswitch_ldap.conf"; |
| 16 | static constexpr auto linuxNsSwitchFile = "/etc/nsswitch_linux.conf"; |
| 17 | |
| 18 | namespace ldap_base = sdbusplus::xyz::openbmc_project::User::Ldap::server; |
| 19 | using ConfigIface = sdbusplus::server::object::object<ldap_base::Config>; |
| 20 | using CreateIface = sdbusplus::server::object::object<ldap_base::Create>; |
| 21 | |
| 22 | class ConfigMgr; |
| 23 | |
| 24 | /** @class Config |
| 25 | * @brief Configuration for LDAP. |
| 26 | * @details concrete implementation of xyz.openbmc_project.User.Ldap.Config |
| 27 | * API, in order to provide LDAP configuration. |
| 28 | */ |
| 29 | class Config : public ConfigIface |
| 30 | { |
| 31 | public: |
| 32 | Config() = delete; |
| 33 | ~Config() = default; |
| 34 | Config(const Config&) = delete; |
| 35 | Config& operator=(const Config&) = delete; |
| 36 | Config(Config&&) = default; |
| 37 | Config& operator=(Config&&) = default; |
| 38 | |
| 39 | /** @brief Constructor to put object onto bus at a D-Bus path. |
| 40 | * @param[in] bus - Bus to attach to. |
| 41 | * @param[in] path - The D-Bus object path to attach at. |
| 42 | * @param[in] filePath - LDAP configuration file. |
| 43 | * @param[in] secureLDAP - Specifies whether to use SSL or not. |
| 44 | * @param[in] lDAPServerURI - LDAP URI of the server. |
| 45 | * @param[in] lDAPBindDN - distinguished name with which to bind. |
| 46 | * @param[in] lDAPBaseDN - distinguished name to use as search base. |
| 47 | * @param[in] lDAPBindDNpassword - credentials with which to bind. |
| 48 | * @param[in] lDAPSearchScope - the search scope. |
| 49 | * @param[in] lDAPType - Specifies the LDAP server type which can be AD |
| 50 | or openLDAP. |
| 51 | * @param[in] parent - parent of config object. |
| 52 | */ |
| 53 | |
| 54 | Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath, |
| 55 | bool secureLDAP, std::string lDAPServerURI, std::string lDAPBindDN, |
| 56 | std::string lDAPBaseDN, std::string lDAPBindDNpassword, |
| 57 | ldap_base::Config::SearchScope lDAPSearchScope, |
| 58 | ldap_base::Config::Type lDAPType, ConfigMgr& parent); |
| 59 | |
| 60 | using ConfigIface::lDAPBaseDN; |
| 61 | using ConfigIface::lDAPBindDN; |
| 62 | using ConfigIface::lDAPBINDDNpassword; |
| 63 | using ConfigIface::lDAPSearchScope; |
| 64 | using ConfigIface::lDAPServerURI; |
| 65 | using ConfigIface::lDAPType; |
| 66 | using ConfigIface::secureLDAP; |
| 67 | using ConfigIface::setPropertyByName; |
| 68 | |
| 69 | /** @brief Update the secure LDAP property. |
| 70 | * @param[in] value - secureLDAP value to be updated. |
| 71 | * @returns value of changed secureLDAP. |
| 72 | */ |
| 73 | bool secureLDAP(bool value) override; |
| 74 | |
| 75 | /** @brief Update the Server URI property. |
| 76 | * @param[in] value - lDAPServerURI value to be updated. |
| 77 | * @returns value of changed lDAPServerURI. |
| 78 | */ |
| 79 | std::string lDAPServerURI(std::string value) override; |
| 80 | |
| 81 | /** @brief Update the BindDN property. |
| 82 | * @param[in] value - lDAPBindDN value to be updated. |
| 83 | * @returns value of changed lDAPBindDN. |
| 84 | */ |
| 85 | std::string lDAPBindDN(std::string value) override; |
| 86 | |
| 87 | /** @brief Update the BaseDN property. |
| 88 | * @param[in] value - lDAPBaseDN value to be updated. |
| 89 | * @returns value of changed lDAPBaseDN. |
| 90 | */ |
| 91 | std::string lDAPBaseDN(std::string value) override; |
| 92 | |
| 93 | /** @brief Update the BindDN password property. |
| 94 | * @param[in] value - lDAPBINDDNpassword value to be updated. |
| 95 | * @returns value of changed lDAPBINDDNpassword. |
| 96 | */ |
| 97 | std::string lDAPBINDDNpassword(std::string value) override; |
| 98 | |
| 99 | /** @brief Update the Search scope property. |
| 100 | * @param[in] value - lDAPSearchScope value to be updated. |
| 101 | * @returns value of changed lDAPSearchScope. |
| 102 | */ |
| 103 | ldap_base::Config::SearchScope |
| 104 | lDAPSearchScope(ldap_base::Config::SearchScope value) override; |
| 105 | |
| 106 | /** @brief Update the LDAP Type property. |
| 107 | * @param[in] value - lDAPType value to be updated. |
| 108 | * @returns value of changed lDAPType. |
| 109 | */ |
| 110 | ldap_base::Config::Type lDAPType(ldap_base::Config::Type value) override; |
| 111 | |
| 112 | private: |
| 113 | std::string configFilePath{}; |
| 114 | |
| 115 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 116 | sdbusplus::bus::bus& bus; |
| 117 | |
| 118 | /** @brief Create a new LDAP config file. |
| 119 | */ |
| 120 | virtual void writeConfig(); |
| 121 | |
| 122 | /** @brief reference to config manager object */ |
| 123 | ConfigMgr& parent; |
| 124 | }; |
| 125 | |
| 126 | /** @class ConfigMgr |
| 127 | * @brief Creates LDAP server configuration. |
| 128 | * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create |
| 129 | * APIs, in order to create LDAP configuration. |
| 130 | */ |
| 131 | class ConfigMgr : public CreateIface |
| 132 | { |
| 133 | public: |
| 134 | ConfigMgr() = delete; |
| 135 | ~ConfigMgr() = default; |
| 136 | ConfigMgr(const ConfigMgr&) = delete; |
| 137 | ConfigMgr& operator=(const ConfigMgr&) = delete; |
| 138 | ConfigMgr(ConfigMgr&&) = delete; |
| 139 | ConfigMgr& operator=(ConfigMgr&&) = delete; |
| 140 | |
| 141 | /** @brief ConfigMgr to put object onto bus at a dbus path. |
| 142 | * @param[in] bus - Bus to attach to. |
| 143 | * @param[in] path - Path to attach at. |
| 144 | * @param[in] filePath - LDAP configuration file. |
| 145 | */ |
| 146 | ConfigMgr(sdbusplus::bus::bus& bus, const char* path) : |
| 147 | CreateIface(bus, path), bus(bus) |
| 148 | { |
| 149 | // TODO restore config object if config file exists. |
| 150 | } |
| 151 | |
| 152 | /** @brief concrete implementation of the pure virtual funtion |
| 153 | xyz.openbmc_project.User.Ldap.Create.createConfig. |
| 154 | * @param[in] secureLDAP - Specifies whether to use SSL or not. |
| 155 | * @param[in] lDAPServerURI - LDAP URI of the server. |
| 156 | * @param[in] lDAPBindDN - distinguished name with which bind to bind |
| 157 | to the directory server for lookups. |
| 158 | * @param[in] lDAPBaseDN - distinguished name to use as search base. |
| 159 | * @param[in] lDAPBindDNpassword - credentials with which to bind. |
| 160 | * @param[in] lDAPSearchScope - the search scope. |
| 161 | * @param[in] lDAPType - Specifies the LDAP server type which can be AD |
| 162 | or openLDAP. |
| 163 | * @returns the object path of the D-Bus object created. |
| 164 | */ |
| 165 | std::string createConfig(bool secureLDAP, std::string lDAPServerURI, |
| 166 | std::string lDAPBindDN, std::string lDAPBaseDN, |
| 167 | std::string lDAPBindDNpassword, |
| 168 | ldap_base::Create::SearchScope lDAPSearchScope, |
| 169 | ldap_base::Create::Type lDAPType) override; |
| 170 | |
| 171 | /** @brief restarts given service |
| 172 | * @param[in] service - Service to be restarted. |
| 173 | */ |
| 174 | virtual void restartService(const std::string& service); |
| 175 | |
| 176 | private: |
| 177 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 178 | sdbusplus::bus::bus& bus; |
| 179 | |
| 180 | /** @brief Pointer to a Config D-Bus object */ |
| 181 | std::unique_ptr<Config> configPtr = nullptr; |
| 182 | }; |
| 183 | } // namespace ldap |
| 184 | } // namespace phosphor |