blob: 71865035c5cd1ed10a771185261989a38698608e [file] [log] [blame]
Ratan Guptae1f4db62019-04-11 18:57:42 +05301#pragma once
2
Ratan Gupta37fb3fe2019-04-13 12:54:18 +05303#include "ldap_config.hpp"
Ratan Guptae1f4db62019-04-11 18:57:42 +05304
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";
Ratan Gupta27d4c012019-04-12 13:03:35 +053021static auto openLDAPDbusObjectPath =
22 std::string(LDAP_CONFIG_ROOT) + "/openldap";
23static auto ADDbusObjectPath =
24 std::string(LDAP_CONFIG_ROOT) + "/active_directory";
Ratan Guptae1f4db62019-04-11 18:57:42 +053025
26using namespace phosphor::logging;
27using namespace sdbusplus::xyz::openbmc_project::Common::Error;
28using CreateIface = sdbusplus::server::object::object<
29 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
30
31// class Config;
32/** @class ConfigMgr
33 * @brief Creates LDAP server configuration.
34 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create
35 * APIs, in order to create LDAP configuration.
36 */
37class ConfigMgr : public CreateIface
38{
39 public:
40 ConfigMgr() = delete;
41 ~ConfigMgr() = default;
42 ConfigMgr(const ConfigMgr&) = delete;
43 ConfigMgr& operator=(const ConfigMgr&) = delete;
44 ConfigMgr(ConfigMgr&&) = delete;
45 ConfigMgr& operator=(ConfigMgr&&) = delete;
46
47 /** @brief ConfigMgr to put object onto bus at a dbus path.
48 * @param[in] bus - Bus to attach to.
49 * @param[in] path - Path to attach at.
50 * @param[in] filePath - LDAP configuration file.
51 * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property.
52 * @param[in] caCertFile - LDAP's CA certificate file.
53 */
54 ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
Ratan Gupta22f13f12019-04-29 15:36:40 +053055 const char* dbusPersistentPath, const char* caCertFile,
56 const char* certFile) :
Ratan Guptae1f4db62019-04-11 18:57:42 +053057 CreateIface(bus, path, true),
58 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
Ratan Gupta22f13f12019-04-29 15:36:40 +053059 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus)
Ratan Guptae1f4db62019-04-11 18:57:42 +053060 {
Ratan Guptae1f4db62019-04-11 18:57:42 +053061 }
62
63 /** @brief concrete implementation of the pure virtual funtion
64 xyz.openbmc_project.User.Ldap.Create.createConfig.
65 * @param[in] lDAPServerURI - LDAP URI of the server.
66 * @param[in] lDAPBindDN - distinguished name with which bind to bind
67 to the directory server for lookups.
68 * @param[in] lDAPBaseDN - distinguished name to use as search base.
69 * @param[in] lDAPBindDNPassword - credentials with which to bind.
70 * @param[in] lDAPSearchScope - the search scope.
71 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
72 or openLDAP.
73 * @param[in] groupNameAttribute - Specifies attribute name that contains
74 * the name of the Group in the LDAP server.
75 * @param[in] usernameAttribute - Specifies attribute name that contains
76 * the username in the LDAP server.
77 * @returns the object path of the D-Bus object created.
78 */
79 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
80 std::string lDAPBaseDN,
81 std::string lDAPBindDNPassword,
82 CreateIface::SearchScope lDAPSearchScope,
83 CreateIface::Type lDAPType,
84 std::string groupNameAttribute,
85 std::string userNameAttribute) override;
86
87 /** @brief restarts given service
88 * @param[in] service - Service to be restarted.
89 */
90 virtual void restartService(const std::string& service);
91
92 /** @brief stops given service
93 * @param[in] service - Service to be stopped.
94 */
95 virtual void stopService(const std::string& service);
96
97 /** @brief start or stop the service depending on the given value
98 * @param[in] service - Service to be start/stop.
99 * @param[in] value - true to start the service otherwise stop.
100 */
101 virtual void startOrStopService(const std::string& service, bool value);
102
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530103 /** @brief Populate existing config into D-Bus properties
Ratan Guptae1f4db62019-04-11 18:57:42 +0530104 */
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530105 virtual void restore();
Ratan Guptac5481d12019-04-12 18:31:05 +0530106 /** @brief enable/disable the ldap service
107 * @param[in] config - config which needs to be enabled/disabled
108 * @param[in] value - boolean value to start/stop
109 */
110 bool enableService(Config& config, bool value);
Ratan Gupta27d4c012019-04-12 13:03:35 +0530111
Ratan Guptae1f4db62019-04-11 18:57:42 +0530112 /* ldap service enabled property would be saved under
113 * this path.
114 */
115 std::string dbusPersistentPath;
116
117 protected:
118 std::string configFilePath{};
119 std::string tlsCacertFile{};
Ratan Gupta22f13f12019-04-29 15:36:40 +0530120 std::string tlsCertFile{};
Ratan Guptae1f4db62019-04-11 18:57:42 +0530121
122 /** @brief Persistent sdbusplus D-Bus bus connection. */
123 sdbusplus::bus::bus& bus;
124
Ratan Gupta27d4c012019-04-12 13:03:35 +0530125 /* Below two config objects are default, which will always be there */
Ratan Guptae1f4db62019-04-11 18:57:42 +0530126
Ratan Gupta27d4c012019-04-12 13:03:35 +0530127 /* if need arises then we can have below map for additional account
128 * providers we need to create sub class of Config which will implement the
129 * delete interface as the default objects will not implement the delete
130 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
131
132 /** @brief Pointer to a openLDAP Config D-Bus object */
133 std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
134 /** @brief Pointer to a AD Config D-Bus object */
135 std::unique_ptr<Config> ADConfigPtr = nullptr;
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530136
137 /* Create the default active directory and the openldap config
138 * objects. */
139 virtual void createDefaultObjects();
Ratan Guptae1f4db62019-04-11 18:57:42 +0530140};
141} // namespace ldap
142} // namespace phosphor