blob: 0d2adf14a3cd7c282e2df909e3d0748efe605678 [file] [log] [blame]
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05001#pragma once
2
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -05003#include "config.h"
Ratan Guptaaeaf9412019-02-11 04:41:52 -06004#include <xyz/openbmc_project/Object/Enable/server.hpp>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05005#include <xyz/openbmc_project/User/Ldap/Create/server.hpp>
Ratan Guptae1f4db62019-04-11 18:57:42 +05306#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -05007#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 Goruganti997f5e02018-08-30 03:05:11 -050013#include <string>
Ratan Gupta21e88cb2019-04-12 17:15:52 +053014#include <filesystem>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050015
16namespace phosphor
17{
18namespace ldap
19{
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050020
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050021using namespace phosphor::logging;
22using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Ratan Guptaaeaf9412019-02-11 04:41:52 -060023using ConfigIface = sdbusplus::xyz::openbmc_project::User::Ldap::server::Config;
24using EnableIface = sdbusplus::xyz::openbmc_project::Object::server::Enable;
Ratan Gupta25b9c902019-04-12 13:08:48 +053025using Ifaces = sdbusplus::server::object::object<ConfigIface, EnableIface>;
Ratan Guptaaeaf9412019-02-11 04:41:52 -060026using CreateIface = sdbusplus::server::object::object<
27 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
Ratan Gupta21e88cb2019-04-12 17:15:52 +053028namespace fs = std::filesystem;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050029class ConfigMgr;
Ratan Gupta3a1c2742019-03-20 06:49:42 +053030class MockConfigMgr;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050031
32/** @class Config
33 * @brief Configuration for LDAP.
34 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Config
35 * API, in order to provide LDAP configuration.
36 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -060037class Config : public Ifaces
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050038{
39 public:
40 Config() = delete;
41 ~Config() = default;
42 Config(const Config&) = delete;
43 Config& operator=(const Config&) = delete;
44 Config(Config&&) = default;
45 Config& operator=(Config&&) = default;
46
47 /** @brief Constructor to put object onto bus at a D-Bus path.
48 * @param[in] bus - Bus to attach to.
49 * @param[in] path - The D-Bus object path to attach at.
50 * @param[in] filePath - LDAP configuration file.
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060051 * @param[in] caCertFile - LDAP's CA certificate file.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050052 * @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.
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060056 * @param[in] lDAPBindDNPassword - credentials with which to bind.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050057 * @param[in] lDAPSearchScope - the search scope.
58 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
Ratan Guptaaeaf9412019-02-11 04:41:52 -060059 * or openLDAP.
60 * @param[in] lDAPServiceEnabled - Specifies whether the service would be
61 * enabled or not.
62 * @param[in] groupNameAttribute - Specifies attribute name that contains
63 * the name of the Group in the LDAP server.
64 * @param[in] userNameAttribute - Specifies attribute name that contains
65 * the username in the LDAP server.
66 *
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050067 * @param[in] parent - parent of config object.
68 */
69
70 Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -060071 const char* caCertFile, bool secureLDAP, std::string lDAPServerURI,
72 std::string lDAPBindDN, std::string lDAPBaseDN,
73 std::string&& lDAPBindDNPassword,
Ratan Guptaaeaf9412019-02-11 04:41:52 -060074 ConfigIface::SearchScope lDAPSearchScope, ConfigIface::Type lDAPType,
75 bool lDAPServiceEnabled, std::string groupNameAttribute,
76 std::string userNameAttribute, ConfigMgr& parent);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050077
Ratan Gupta21e88cb2019-04-12 17:15:52 +053078 /** @brief Constructor to put object onto bus at a D-Bus path.
79 * @param[in] bus - Bus to attach to.
80 * @param[in] path - The D-Bus object path to attach at.
81 * @param[in] filePath - LDAP configuration file.
82 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
83 * or openLDAP.
84 * @param[in] parent - parent of config object.
85 */
86 Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
87 const char* caCertFile, ConfigIface::Type lDAPType,
88 ConfigMgr& parent);
89
Ratan Guptaaeaf9412019-02-11 04:41:52 -060090 using ConfigIface::groupNameAttribute;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050091 using ConfigIface::lDAPBaseDN;
92 using ConfigIface::lDAPBindDN;
Ratan Gupta3a1c2742019-03-20 06:49:42 +053093 using ConfigIface::lDAPBindDNPassword;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050094 using ConfigIface::lDAPSearchScope;
95 using ConfigIface::lDAPServerURI;
96 using ConfigIface::lDAPType;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050097 using ConfigIface::setPropertyByName;
Ratan Guptaaeaf9412019-02-11 04:41:52 -060098 using ConfigIface::userNameAttribute;
99 using EnableIface::enabled;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500100
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500101 /** @brief Update the Server URI property.
102 * @param[in] value - lDAPServerURI value to be updated.
103 * @returns value of changed lDAPServerURI.
104 */
105 std::string lDAPServerURI(std::string value) override;
106
107 /** @brief Update the BindDN property.
108 * @param[in] value - lDAPBindDN value to be updated.
109 * @returns value of changed lDAPBindDN.
110 */
111 std::string lDAPBindDN(std::string value) override;
112
113 /** @brief Update the BaseDN property.
114 * @param[in] value - lDAPBaseDN value to be updated.
115 * @returns value of changed lDAPBaseDN.
116 */
117 std::string lDAPBaseDN(std::string value) override;
118
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500119 /** @brief Update the Search scope property.
120 * @param[in] value - lDAPSearchScope value to be updated.
121 * @returns value of changed lDAPSearchScope.
122 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600123 ConfigIface::SearchScope
124 lDAPSearchScope(ConfigIface::SearchScope value) override;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500125
126 /** @brief Update the LDAP Type property.
127 * @param[in] value - lDAPType value to be updated.
128 * @returns value of changed lDAPType.
129 */
Ratan Guptaaeaf9412019-02-11 04:41:52 -0600130 ConfigIface::Type lDAPType(ConfigIface::Type value) override;
131
132 /** @brief Update the ldapServiceEnabled property.
133 * @param[in] value - ldapServiceEnabled value to be updated.
134 * @returns value of changed ldapServiceEnabled.
135 */
136 bool enabled(bool value) override;
137
138 /** @brief Update the userNameAttribute property.
139 * @param[in] value - userNameAttribute value to be updated.
140 * @returns value of changed userNameAttribute.
141 */
142 std::string userNameAttribute(std::string value) override;
143
144 /** @brief Update the groupNameAttribute property.
145 * @param[in] value - groupNameAttribute value to be updated.
146 * @returns value of changed groupNameAttribute.
147 */
148 std::string groupNameAttribute(std::string value) override;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500149
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530150 /** @brief Update the BindDNPasword property.
151 * @param[in] value - lDAPBindDNPassword value to be updated.
152 * @returns value of changed lDAPBindDNPassword.
153 */
154 std::string lDAPBindDNPassword(std::string value) override;
155
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530156 /** @brief Function required by Cereal to perform deserialization.
157 * @tparam Archive - Cereal archive type (binary in our case).
158 * @param[in] archive - reference to Cereal archive.
159 * @param[in] version - Class version that enables handling
160 * a serialized data across code levels
161 */
162 template <class Archive>
163 void load(Archive& archive, const std::uint32_t version);
164
165 /** @brief Function required by Cereal to perform serialization.
166 * @tparam Archive - Cereal archive type (binary in our case).
167 * @param[in] archive - reference to Cereal archive.
168 * @param[in] version - Class version that enables handling
169 * a serialized data across code levels
170 */
171 template <class Archive>
172 void save(Archive& archive, const std::uint32_t version) const;
173
174 /** @brief Serialize and persist this object at the persist
175 * location.
176 */
177 void serialize();
178
179 /** @brief Deserialize LDAP config data from the persistent location
180 * into this object
181 * @return bool - true if the deserialization was successful, false
182 * otherwise.
183 */
184 bool deserialize();
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600185
Ratan Guptac5481d12019-04-12 18:31:05 +0530186 /** @brief enable or disable the service with the given value
187 * @param[in] value - enable/disble
188 * @returns value of changed status
189 */
190 bool enableService(bool value);
191
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500192 private:
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530193 bool secureLDAP;
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530194 std::string lDAPBindPassword{};
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600195 std::string tlsCacertFile{};
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530196 std::string configFilePath{};
197 std::string objectPath{};
198 std::filesystem::path configPersistPath{};
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500199
200 /** @brief Persistent sdbusplus D-Bus bus connection. */
201 sdbusplus::bus::bus& bus;
202
203 /** @brief Create a new LDAP config file.
204 */
205 virtual void writeConfig();
206
207 /** @brief reference to config manager object */
208 ConfigMgr& parent;
Ratan Gupta3a1c2742019-03-20 06:49:42 +0530209
210 friend class MockConfigMgr;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500211};
212
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500213} // namespace ldap
214} // namespace phosphor