blob: 24c12a975d93665f9877a0f7590b02df007b1694 [file] [log] [blame]
Ratan Guptae1f4db62019-04-11 18:57:42 +05301#pragma once
2
3#include "ldap_configuration.hpp"
4
5#include "config.h"
6#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
7#include <xyz/openbmc_project/User/Ldap/Create/server.hpp>
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 <string>
14namespace phosphor
15{
16namespace ldap
17{
18
19static constexpr auto defaultNslcdFile = "nslcd.conf.default";
20static constexpr auto nsSwitchFile = "nsswitch.conf";
21
22using namespace phosphor::logging;
23using namespace sdbusplus::xyz::openbmc_project::Common::Error;
24using CreateIface = sdbusplus::server::object::object<
25 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
26
27// class Config;
28/** @class ConfigMgr
29 * @brief Creates LDAP server configuration.
30 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create
31 * APIs, in order to create LDAP configuration.
32 */
33class ConfigMgr : public CreateIface
34{
35 public:
36 ConfigMgr() = delete;
37 ~ConfigMgr() = default;
38 ConfigMgr(const ConfigMgr&) = delete;
39 ConfigMgr& operator=(const ConfigMgr&) = delete;
40 ConfigMgr(ConfigMgr&&) = delete;
41 ConfigMgr& operator=(ConfigMgr&&) = delete;
42
43 /** @brief ConfigMgr to put object onto bus at a dbus path.
44 * @param[in] bus - Bus to attach to.
45 * @param[in] path - Path to attach at.
46 * @param[in] filePath - LDAP configuration file.
47 * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property.
48 * @param[in] caCertFile - LDAP's CA certificate file.
49 */
50 ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
51 const char* dbusPersistentPath, const char* caCertFile) :
52 CreateIface(bus, path, true),
53 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
54 bus(bus)
55 {
56 try
57 {
58 restore(configFilePath.c_str());
59 emit_object_added();
60 }
61 catch (const std::exception& e)
62 {
63 configPtr.reset(nullptr);
64 log<level::ERR>(e.what());
65 elog<InternalFailure>();
66 }
67 }
68
69 /** @brief concrete implementation of the pure virtual funtion
70 xyz.openbmc_project.User.Ldap.Create.createConfig.
71 * @param[in] lDAPServerURI - LDAP URI of the server.
72 * @param[in] lDAPBindDN - distinguished name with which bind to bind
73 to the directory server for lookups.
74 * @param[in] lDAPBaseDN - distinguished name to use as search base.
75 * @param[in] lDAPBindDNPassword - credentials with which to bind.
76 * @param[in] lDAPSearchScope - the search scope.
77 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
78 or openLDAP.
79 * @param[in] groupNameAttribute - Specifies attribute name that contains
80 * the name of the Group in the LDAP server.
81 * @param[in] usernameAttribute - Specifies attribute name that contains
82 * the username in the LDAP server.
83 * @returns the object path of the D-Bus object created.
84 */
85 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
86 std::string lDAPBaseDN,
87 std::string lDAPBindDNPassword,
88 CreateIface::SearchScope lDAPSearchScope,
89 CreateIface::Type lDAPType,
90 std::string groupNameAttribute,
91 std::string userNameAttribute) override;
92
93 /** @brief restarts given service
94 * @param[in] service - Service to be restarted.
95 */
96 virtual void restartService(const std::string& service);
97
98 /** @brief stops given service
99 * @param[in] service - Service to be stopped.
100 */
101 virtual void stopService(const std::string& service);
102
103 /** @brief start or stop the service depending on the given value
104 * @param[in] service - Service to be start/stop.
105 * @param[in] value - true to start the service otherwise stop.
106 */
107 virtual void startOrStopService(const std::string& service, bool value);
108
109 /** @brief delete the config D-Bus object.
110 */
111 void deleteObject();
112
113 /* ldap service enabled property would be saved under
114 * this path.
115 */
116 std::string dbusPersistentPath;
117
118 protected:
119 std::string configFilePath{};
120 std::string tlsCacertFile{};
121
122 /** @brief Persistent sdbusplus D-Bus bus connection. */
123 sdbusplus::bus::bus& bus;
124
125 /** @brief Pointer to a Config D-Bus object */
126 std::unique_ptr<Config> configPtr = nullptr;
127
128 /** @brief Populate existing config into D-Bus properties
129 * @param[in] filePath - LDAP config file path
130 */
131 virtual void restore(const char* filePath);
132};
133} // namespace ldap
134} // namespace phosphor