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