blob: 0dfb56d6fa1d91eebf093e9799c0b1e3a76cf3c9 [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";
21static constexpr auto LDAPNsSwitchFile = "nsswitch_ldap.conf";
22static constexpr auto linuxNsSwitchFile = "nsswitch_linux.conf";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050023
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050024using namespace phosphor::logging;
25using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050026namespace ldap_base = sdbusplus::xyz::openbmc_project::User::Ldap::server;
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -050027using ConfigIface = sdbusplus::server::object::object<
28 ldap_base::Config, sdbusplus::xyz::openbmc_project::Object::server::Delete>;
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050029using CreateIface = sdbusplus::server::object::object<ldap_base::Create>;
30
31class 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 */
38class 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.
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
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,
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060065 std::string lDAPBaseDN, 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 Gorugantidb60f582018-11-08 03:14:48 -0600115 std::string lDAPBindDNPassword{};
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500116
117 /** @brief Persistent sdbusplus D-Bus bus connection. */
118 sdbusplus::bus::bus& bus;
119
120 /** @brief Create a new LDAP config file.
121 */
122 virtual void writeConfig();
123
124 /** @brief reference to config manager object */
125 ConfigMgr& parent;
126};
127
128/** @class ConfigMgr
129 * @brief Creates LDAP server configuration.
130 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create
131 * APIs, in order to create LDAP configuration.
132 */
133class ConfigMgr : public CreateIface
134{
135 public:
136 ConfigMgr() = delete;
137 ~ConfigMgr() = default;
138 ConfigMgr(const ConfigMgr&) = delete;
139 ConfigMgr& operator=(const ConfigMgr&) = delete;
140 ConfigMgr(ConfigMgr&&) = delete;
141 ConfigMgr& operator=(ConfigMgr&&) = delete;
142
143 /** @brief ConfigMgr to put object onto bus at a dbus path.
144 * @param[in] bus - Bus to attach to.
145 * @param[in] path - Path to attach at.
146 * @param[in] filePath - LDAP configuration file.
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600147 * @param[in] caCertfile - LDAP's CA certificate file.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500148 */
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600149 ConfigMgr(sdbusplus::bus::bus& bus, const char* path,
150 const char* filePath) :
151 CreateIface(bus, path, true),
152 configFilePath(filePath), bus(bus)
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500153 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500154 try
155 {
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600156 restore(configFilePath.c_str());
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500157 emit_object_added();
158 }
159 catch (const std::exception& e)
160 {
161 configPtr.reset(nullptr);
162 log<level::ERR>(e.what());
163 elog<InternalFailure>();
164 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500165 }
166
167 /** @brief concrete implementation of the pure virtual funtion
168 xyz.openbmc_project.User.Ldap.Create.createConfig.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500169 * @param[in] lDAPServerURI - LDAP URI of the server.
170 * @param[in] lDAPBindDN - distinguished name with which bind to bind
171 to the directory server for lookups.
172 * @param[in] lDAPBaseDN - distinguished name to use as search base.
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600173 * @param[in] lDAPBindDNPassword - credentials with which to bind.
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500174 * @param[in] lDAPSearchScope - the search scope.
175 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
176 or openLDAP.
177 * @returns the object path of the D-Bus object created.
178 */
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600179 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
180 std::string lDAPBaseDN,
181 std::string lDAPBindDNPassword,
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500182 ldap_base::Create::SearchScope lDAPSearchScope,
183 ldap_base::Create::Type lDAPType) override;
184
185 /** @brief restarts given service
186 * @param[in] service - Service to be restarted.
187 */
188 virtual void restartService(const std::string& service);
189
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -0500190 /** @brief stops given service
191 * @param[in] service - Service to be stopped.
192 */
193 virtual void stopService(const std::string& service);
194
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -0500195 /** @brief delete the config D-Bus object.
196 */
197 void deleteObject();
198
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600199 protected:
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600200 std::string configFilePath{};
Nagaraju Gorugantid514e5d2018-11-08 03:07:25 -0600201 std::string tlsCacertfile{};
202
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500203 /** @brief Persistent sdbusplus D-Bus bus connection. */
204 sdbusplus::bus::bus& bus;
205
206 /** @brief Pointer to a Config D-Bus object */
207 std::unique_ptr<Config> configPtr = nullptr;
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500208
209 /** @brief Populate existing config into D-Bus properties
210 * @param[in] filePath - LDAP config file path
211 */
212 virtual void restore(const char* filePath);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500213};
214} // namespace ldap
215} // namespace phosphor