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/Create/server.hpp> |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 7 | #include <xyz/openbmc_project/User/Ldap/Config/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 | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 20 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 21 | using namespace phosphor::logging; |
| 22 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 23 | using ConfigIface = sdbusplus::xyz::openbmc_project::User::Ldap::server::Config; |
| 24 | using EnableIface = sdbusplus::xyz::openbmc_project::Object::server::Enable; |
| 25 | using DeleteIface = sdbusplus::xyz::openbmc_project::Object::server::Delete; |
| 26 | using Ifaces = |
| 27 | sdbusplus::server::object::object<ConfigIface, EnableIface, DeleteIface>; |
| 28 | using CreateIface = sdbusplus::server::object::object< |
| 29 | sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 30 | |
| 31 | class ConfigMgr; |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 32 | class MockConfigMgr; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 33 | |
| 34 | /** @class Config |
| 35 | * @brief Configuration for LDAP. |
| 36 | * @details concrete implementation of xyz.openbmc_project.User.Ldap.Config |
| 37 | * API, in order to provide LDAP configuration. |
| 38 | */ |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 39 | class Config : public Ifaces |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | Config() = delete; |
| 43 | ~Config() = default; |
| 44 | Config(const Config&) = delete; |
| 45 | Config& operator=(const Config&) = delete; |
| 46 | Config(Config&&) = default; |
| 47 | Config& operator=(Config&&) = default; |
| 48 | |
| 49 | /** @brief Constructor to put object onto bus at a D-Bus path. |
| 50 | * @param[in] bus - Bus to attach to. |
| 51 | * @param[in] path - The D-Bus object path to attach at. |
| 52 | * @param[in] filePath - LDAP configuration file. |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 53 | * @param[in] caCertFile - LDAP's CA certificate file. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 54 | * @param[in] secureLDAP - Specifies whether to use SSL or not. |
| 55 | * @param[in] lDAPServerURI - LDAP URI of the server. |
| 56 | * @param[in] lDAPBindDN - distinguished name with which to bind. |
| 57 | * @param[in] lDAPBaseDN - distinguished name to use as search base. |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 58 | * @param[in] lDAPBindDNPassword - credentials with which to bind. |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 59 | * @param[in] lDAPSearchScope - the search scope. |
| 60 | * @param[in] lDAPType - Specifies the LDAP server type which can be AD |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 61 | * or openLDAP. |
| 62 | * @param[in] lDAPServiceEnabled - Specifies whether the service would be |
| 63 | * enabled or not. |
| 64 | * @param[in] groupNameAttribute - Specifies attribute name that contains |
| 65 | * the name of the Group in the LDAP server. |
| 66 | * @param[in] userNameAttribute - Specifies attribute name that contains |
| 67 | * the username in the LDAP server. |
| 68 | * |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 69 | * @param[in] parent - parent of config object. |
| 70 | */ |
| 71 | |
| 72 | Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath, |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 73 | const char* caCertFile, bool secureLDAP, std::string lDAPServerURI, |
| 74 | std::string lDAPBindDN, std::string lDAPBaseDN, |
| 75 | std::string&& lDAPBindDNPassword, |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 76 | ConfigIface::SearchScope lDAPSearchScope, ConfigIface::Type lDAPType, |
| 77 | bool lDAPServiceEnabled, std::string groupNameAttribute, |
| 78 | std::string userNameAttribute, ConfigMgr& parent); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 79 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 80 | using ConfigIface::groupNameAttribute; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 81 | using ConfigIface::lDAPBaseDN; |
| 82 | using ConfigIface::lDAPBindDN; |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 83 | using ConfigIface::lDAPBindDNPassword; |
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 | |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 140 | /** @brief Update the BindDNPasword property. |
| 141 | * @param[in] value - lDAPBindDNPassword value to be updated. |
| 142 | * @returns value of changed lDAPBindDNPassword. |
| 143 | */ |
| 144 | std::string lDAPBindDNPassword(std::string value) override; |
| 145 | |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 146 | /** @brief Delete this D-bus object. |
| 147 | */ |
| 148 | void delete_() override; |
| 149 | |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 150 | bool secureLDAP; |
| 151 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 152 | private: |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 153 | std::string lDAPBindPassword{}; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 154 | std::string configFilePath{}; |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 155 | std::string tlsCacertFile{}; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 156 | |
| 157 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 158 | sdbusplus::bus::bus& bus; |
| 159 | |
| 160 | /** @brief Create a new LDAP config file. |
| 161 | */ |
| 162 | virtual void writeConfig(); |
| 163 | |
| 164 | /** @brief reference to config manager object */ |
| 165 | ConfigMgr& parent; |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 166 | |
| 167 | friend class MockConfigMgr; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 170 | } // namespace ldap |
| 171 | } // namespace phosphor |