Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 3 | #include "config.h" |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 4 | #include <xyz/openbmc_project/Object/Delete/server.hpp> |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 5 | #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> |
| 6 | #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Common/error.hpp> |
| 8 | #include <phosphor-logging/log.hpp> |
| 9 | #include <phosphor-logging/elog.hpp> |
| 10 | #include <phosphor-logging/elog-errors.hpp> |
| 11 | #include <sdbusplus/bus.hpp> |
| 12 | #include <sdbusplus/server/object.hpp> |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 13 | #include <string> |
| 14 | |
| 15 | namespace phosphor |
| 16 | { |
| 17 | namespace ldap |
| 18 | { |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 19 | static constexpr auto defaultNslcdFile = "nslcd.conf.default"; |
| 20 | static constexpr auto nsSwitchFile = "nsswitch.conf"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 21 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 22 | using namespace phosphor::logging; |
| 23 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 24 | namespace ldap_base = sdbusplus::xyz::openbmc_project::User::Ldap::server; |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 25 | using ConfigIface = sdbusplus::server::object::object< |
| 26 | ldap_base::Config, sdbusplus::xyz::openbmc_project::Object::server::Delete>; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 27 | using CreateIface = sdbusplus::server::object::object<ldap_base::Create>; |
| 28 | |
| 29 | class ConfigMgr; |
| 30 | |
| 31 | /** @class Config |
| 32 | * @brief Configuration for LDAP. |
| 33 | * @details concrete implementation of xyz.openbmc_project.User.Ldap.Config |
| 34 | * API, in order to provide LDAP configuration. |
| 35 | */ |
| 36 | class Config : public ConfigIface |
| 37 | { |
| 38 | public: |
| 39 | Config() = delete; |
| 40 | ~Config() = default; |
| 41 | Config(const Config&) = delete; |
| 42 | Config& operator=(const Config&) = delete; |
| 43 | Config(Config&&) = default; |
| 44 | Config& operator=(Config&&) = default; |
| 45 | |
| 46 | /** @brief Constructor to put object onto bus at a D-Bus path. |
| 47 | * @param[in] bus - Bus to attach to. |
| 48 | * @param[in] path - The D-Bus object path to attach at. |
| 49 | * @param[in] filePath - LDAP configuration file. |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 50 | * @param[in] caCertFile - LDAP's CA certificate file. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 51 | * @param[in] secureLDAP - Specifies whether to use SSL or not. |
| 52 | * @param[in] lDAPServerURI - LDAP URI of the server. |
| 53 | * @param[in] lDAPBindDN - distinguished name with which to bind. |
| 54 | * @param[in] lDAPBaseDN - distinguished name to use as search base. |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 55 | * @param[in] lDAPBindDNPassword - credentials with which to bind. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 56 | * @param[in] lDAPSearchScope - the search scope. |
| 57 | * @param[in] lDAPType - Specifies the LDAP server type which can be AD |
| 58 | or openLDAP. |
| 59 | * @param[in] parent - parent of config object. |
| 60 | */ |
| 61 | |
| 62 | Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath, |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 63 | const char* caCertFile, bool secureLDAP, std::string lDAPServerURI, |
| 64 | std::string lDAPBindDN, std::string lDAPBaseDN, |
| 65 | std::string&& lDAPBindDNPassword, |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 66 | ldap_base::Config::SearchScope lDAPSearchScope, |
| 67 | ldap_base::Config::Type lDAPType, ConfigMgr& parent); |
| 68 | |
| 69 | using ConfigIface::lDAPBaseDN; |
| 70 | using ConfigIface::lDAPBindDN; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 71 | using ConfigIface::lDAPSearchScope; |
| 72 | using ConfigIface::lDAPServerURI; |
| 73 | using ConfigIface::lDAPType; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 74 | using ConfigIface::setPropertyByName; |
| 75 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 76 | /** @brief Update the Server URI property. |
| 77 | * @param[in] value - lDAPServerURI value to be updated. |
| 78 | * @returns value of changed lDAPServerURI. |
| 79 | */ |
| 80 | std::string lDAPServerURI(std::string value) override; |
| 81 | |
| 82 | /** @brief Update the BindDN property. |
| 83 | * @param[in] value - lDAPBindDN value to be updated. |
| 84 | * @returns value of changed lDAPBindDN. |
| 85 | */ |
| 86 | std::string lDAPBindDN(std::string value) override; |
| 87 | |
| 88 | /** @brief Update the BaseDN property. |
| 89 | * @param[in] value - lDAPBaseDN value to be updated. |
| 90 | * @returns value of changed lDAPBaseDN. |
| 91 | */ |
| 92 | std::string lDAPBaseDN(std::string value) override; |
| 93 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 94 | /** @brief Update the Search scope property. |
| 95 | * @param[in] value - lDAPSearchScope value to be updated. |
| 96 | * @returns value of changed lDAPSearchScope. |
| 97 | */ |
| 98 | ldap_base::Config::SearchScope |
| 99 | lDAPSearchScope(ldap_base::Config::SearchScope value) override; |
| 100 | |
| 101 | /** @brief Update the LDAP Type property. |
| 102 | * @param[in] value - lDAPType value to be updated. |
| 103 | * @returns value of changed lDAPType. |
| 104 | */ |
| 105 | ldap_base::Config::Type lDAPType(ldap_base::Config::Type value) override; |
| 106 | |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 107 | /** @brief Delete this D-bus object. |
| 108 | */ |
| 109 | void delete_() override; |
| 110 | |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 111 | bool secureLDAP; |
| 112 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 113 | private: |
| 114 | std::string configFilePath{}; |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 115 | std::string tlsCacertFile{}; |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 116 | std::string lDAPBindDNPassword{}; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 117 | |
| 118 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 119 | sdbusplus::bus::bus& bus; |
| 120 | |
| 121 | /** @brief Create a new LDAP config file. |
| 122 | */ |
| 123 | virtual void writeConfig(); |
| 124 | |
| 125 | /** @brief reference to config manager object */ |
| 126 | ConfigMgr& parent; |
| 127 | }; |
| 128 | |
| 129 | /** @class ConfigMgr |
| 130 | * @brief Creates LDAP server configuration. |
| 131 | * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create |
| 132 | * APIs, in order to create LDAP configuration. |
| 133 | */ |
| 134 | class ConfigMgr : public CreateIface |
| 135 | { |
| 136 | public: |
| 137 | ConfigMgr() = delete; |
| 138 | ~ConfigMgr() = default; |
| 139 | ConfigMgr(const ConfigMgr&) = delete; |
| 140 | ConfigMgr& operator=(const ConfigMgr&) = delete; |
| 141 | ConfigMgr(ConfigMgr&&) = delete; |
| 142 | ConfigMgr& operator=(ConfigMgr&&) = delete; |
| 143 | |
| 144 | /** @brief ConfigMgr to put object onto bus at a dbus path. |
| 145 | * @param[in] bus - Bus to attach to. |
| 146 | * @param[in] path - Path to attach at. |
| 147 | * @param[in] filePath - LDAP configuration file. |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 148 | * @param[in] caCertFile - LDAP's CA certificate file. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 149 | */ |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 150 | ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath, |
| 151 | const char* caCertFile) : |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 152 | CreateIface(bus, path, true), |
| 153 | configFilePath(filePath), bus(bus) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 154 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 155 | try |
| 156 | { |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 157 | restore(configFilePath.c_str()); |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 158 | emit_object_added(); |
| 159 | } |
| 160 | catch (const std::exception& e) |
| 161 | { |
| 162 | configPtr.reset(nullptr); |
| 163 | log<level::ERR>(e.what()); |
| 164 | elog<InternalFailure>(); |
| 165 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /** @brief concrete implementation of the pure virtual funtion |
| 169 | xyz.openbmc_project.User.Ldap.Create.createConfig. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 170 | * @param[in] lDAPServerURI - LDAP URI of the server. |
| 171 | * @param[in] lDAPBindDN - distinguished name with which bind to bind |
| 172 | to the directory server for lookups. |
| 173 | * @param[in] lDAPBaseDN - distinguished name to use as search base. |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 174 | * @param[in] lDAPBindDNPassword - credentials with which to bind. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 175 | * @param[in] lDAPSearchScope - the search scope. |
| 176 | * @param[in] lDAPType - Specifies the LDAP server type which can be AD |
| 177 | or openLDAP. |
| 178 | * @returns the object path of the D-Bus object created. |
| 179 | */ |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 180 | std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN, |
| 181 | std::string lDAPBaseDN, |
| 182 | std::string lDAPBindDNPassword, |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 183 | ldap_base::Create::SearchScope lDAPSearchScope, |
| 184 | ldap_base::Create::Type lDAPType) override; |
| 185 | |
| 186 | /** @brief restarts given service |
| 187 | * @param[in] service - Service to be restarted. |
| 188 | */ |
| 189 | virtual void restartService(const std::string& service); |
| 190 | |
Nagaraju Goruganti | dccee2b | 2018-09-25 08:51:06 -0500 | [diff] [blame] | 191 | /** @brief stops given service |
| 192 | * @param[in] service - Service to be stopped. |
| 193 | */ |
| 194 | virtual void stopService(const std::string& service); |
| 195 | |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 196 | /** @brief delete the config D-Bus object. |
| 197 | */ |
| 198 | void deleteObject(); |
| 199 | |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 200 | protected: |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 201 | std::string configFilePath{}; |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 202 | std::string tlsCacertFile{}; |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 203 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 204 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 205 | sdbusplus::bus::bus& bus; |
| 206 | |
| 207 | /** @brief Pointer to a Config D-Bus object */ |
| 208 | std::unique_ptr<Config> configPtr = nullptr; |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 209 | |
| 210 | /** @brief Populate existing config into D-Bus properties |
| 211 | * @param[in] filePath - LDAP config file path |
| 212 | */ |
| 213 | virtual void restore(const char* filePath); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 214 | }; |
| 215 | } // namespace ldap |
| 216 | } // namespace phosphor |