blob: ad2c52a79ebe54d138e8ad34a2ce79c3f5b6dde1 [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"
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -05004#include <xyz/openbmc_project/Object/Delete/server.hpp>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05005#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
6#include <xyz/openbmc_project/User/Ldap/Create/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>
14
15namespace phosphor
16{
17namespace ldap
18{
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -060019static constexpr auto defaultNslcdFile = "nslcd.conf.default";
20static constexpr auto nsSwitchFile = "nsswitch.conf";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050021
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050022using namespace phosphor::logging;
23using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050024namespace ldap_base = sdbusplus::xyz::openbmc_project::User::Ldap::server;
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -050025using ConfigIface = sdbusplus::server::object::object<
26 ldap_base::Config, sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050027using CreateIface = sdbusplus::server::object::object<ldap_base::Create>;
28
29class 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 */
36class 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 Goruganti3b4d06a2018-11-08 03:13:38 -060050 * @param[in] caCertFile - LDAP's CA certificate file.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050051 * @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 Gorugantidb60f582018-11-08 03:14:48 -060055 * @param[in] lDAPBindDNPassword - credentials with which to bind.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050056 * @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 Goruganti3b4d06a2018-11-08 03:13:38 -060063 const char* caCertFile, bool secureLDAP, std::string lDAPServerURI,
64 std::string lDAPBindDN, std::string lDAPBaseDN,
65 std::string&& lDAPBindDNPassword,
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050066 ldap_base::Config::SearchScope lDAPSearchScope,
67 ldap_base::Config::Type lDAPType, ConfigMgr& parent);
68
69 using ConfigIface::lDAPBaseDN;
70 using ConfigIface::lDAPBindDN;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050071 using ConfigIface::lDAPSearchScope;
72 using ConfigIface::lDAPServerURI;
73 using ConfigIface::lDAPType;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050074 using ConfigIface::setPropertyByName;
75
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050076 /** @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 Goruganti997f5e02018-08-30 03:05:11 -050094 /** @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 Goruganti24194bd2018-09-18 09:55:09 -0500107 /** @brief Delete this D-bus object.
108 */
109 void delete_() override;
110
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600111 bool secureLDAP;
112
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500113 private:
114 std::string configFilePath{};
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600115 std::string tlsCacertFile{};
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600116 std::string lDAPBindDNPassword{};
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500117
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 */
134class 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 Goruganti3b4d06a2018-11-08 03:13:38 -0600148 * @param[in] caCertFile - LDAP's CA certificate file.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500149 */
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600150 ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
151 const char* caCertFile) :
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600152 CreateIface(bus, path, true),
153 configFilePath(filePath), bus(bus)
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500154 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500155 try
156 {
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600157 restore(configFilePath.c_str());
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500158 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 Goruganti997f5e02018-08-30 03:05:11 -0500166 }
167
168 /** @brief concrete implementation of the pure virtual funtion
169 xyz.openbmc_project.User.Ldap.Create.createConfig.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500170 * @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 Gorugantidb60f582018-11-08 03:14:48 -0600174 * @param[in] lDAPBindDNPassword - credentials with which to bind.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500175 * @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 Gorugantidb60f582018-11-08 03:14:48 -0600180 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
181 std::string lDAPBaseDN,
182 std::string lDAPBindDNPassword,
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500183 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 Gorugantidccee2b2018-09-25 08:51:06 -0500191 /** @brief stops given service
192 * @param[in] service - Service to be stopped.
193 */
194 virtual void stopService(const std::string& service);
195
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -0500196 /** @brief delete the config D-Bus object.
197 */
198 void deleteObject();
199
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600200 protected:
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600201 std::string configFilePath{};
Nagaraju Goruganti3b4d06a2018-11-08 03:13:38 -0600202 std::string tlsCacertFile{};
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600203
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500204 /** @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 Gorugantif1940d92018-09-18 05:05:50 -0500209
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 Goruganti997f5e02018-08-30 03:05:11 -0500214};
215} // namespace ldap
216} // namespace phosphor