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