blob: 9ba69d4868de8db4321e36c55d2a19ba8f279529 [file] [log] [blame]
Ratan Guptae1f4db62019-04-11 18:57:42 +05301#pragma once
2
Patrick Williams9638afb2021-02-22 17:16:24 -06003#include "config.h"
4
Ratan Gupta37fb3fe2019-04-13 12:54:18 +05305#include "ldap_config.hpp"
Ratan Guptae1f4db62019-04-11 18:57:42 +05306
Patrick Williams9638afb2021-02-22 17:16:24 -06007#include <phosphor-logging/elog-errors.hpp>
8#include <phosphor-logging/elog.hpp>
9#include <phosphor-logging/log.hpp>
10#include <sdbusplus/bus.hpp>
11#include <xyz/openbmc_project/Common/error.hpp>
Ratan Guptae1f4db62019-04-11 18:57:42 +053012#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
13#include <xyz/openbmc_project/User/Ldap/Create/server.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -060014
Ratan Guptae1f4db62019-04-11 18:57:42 +053015#include <string>
16namespace phosphor
17{
18namespace ldap
19{
20
21static constexpr auto defaultNslcdFile = "nslcd.conf.default";
22static constexpr auto nsSwitchFile = "nsswitch.conf";
Ratan Gupta27d4c012019-04-12 13:03:35 +053023static auto openLDAPDbusObjectPath =
24 std::string(LDAP_CONFIG_ROOT) + "/openldap";
25static auto ADDbusObjectPath =
26 std::string(LDAP_CONFIG_ROOT) + "/active_directory";
Ratan Guptae1f4db62019-04-11 18:57:42 +053027
28using namespace phosphor::logging;
29using namespace sdbusplus::xyz::openbmc_project::Common::Error;
30using CreateIface = sdbusplus::server::object::object<
31 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
32
33// class Config;
34/** @class ConfigMgr
35 * @brief Creates LDAP server configuration.
36 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create
37 * APIs, in order to create LDAP configuration.
38 */
39class ConfigMgr : public CreateIface
40{
41 public:
42 ConfigMgr() = delete;
43 ~ConfigMgr() = default;
44 ConfigMgr(const ConfigMgr&) = delete;
45 ConfigMgr& operator=(const ConfigMgr&) = delete;
46 ConfigMgr(ConfigMgr&&) = delete;
47 ConfigMgr& operator=(ConfigMgr&&) = delete;
48
49 /** @brief ConfigMgr to put object onto bus at a dbus path.
50 * @param[in] bus - Bus to attach to.
51 * @param[in] path - Path to attach at.
52 * @param[in] filePath - LDAP configuration file.
53 * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property.
54 * @param[in] caCertFile - LDAP's CA certificate file.
55 */
56 ConfigMgr(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
Ratan Gupta22f13f12019-04-29 15:36:40 +053057 const char* dbusPersistentPath, const char* caCertFile,
58 const char* certFile) :
Ratan Guptae1f4db62019-04-11 18:57:42 +053059 CreateIface(bus, path, true),
60 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
Ratan Gupta22f13f12019-04-29 15:36:40 +053061 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus)
Patrick Williams9638afb2021-02-22 17:16:24 -060062 {}
Ratan Guptae1f4db62019-04-11 18:57:42 +053063
64 /** @brief concrete implementation of the pure virtual funtion
65 xyz.openbmc_project.User.Ldap.Create.createConfig.
Patrick Williamse6500a42021-05-01 05:58:23 -050066 * @param[in] ldapServerURI - LDAP URI of the server.
67 * @param[in] ldapBindDN - distinguished name with which bind to bind
Ratan Guptae1f4db62019-04-11 18:57:42 +053068 to the directory server for lookups.
Patrick Williamse6500a42021-05-01 05:58:23 -050069 * @param[in] ldapBaseDN - distinguished name to use as search base.
70 * @param[in] ldapBindDNPassword - credentials with which to bind.
71 * @param[in] ldapSearchScope - the search scope.
72 * @param[in] ldapType - Specifies the LDAP server type which can be AD
Ratan Guptae1f4db62019-04-11 18:57:42 +053073 or openLDAP.
74 * @param[in] groupNameAttribute - Specifies attribute name that contains
75 * the name of the Group in the LDAP server.
76 * @param[in] usernameAttribute - Specifies attribute name that contains
77 * the username in the LDAP server.
78 * @returns the object path of the D-Bus object created.
79 */
Patrick Williamse6500a42021-05-01 05:58:23 -050080 std::string createConfig(std::string ldapServerURI, std::string ldapBindDN,
81 std::string ldapBaseDN,
82 std::string ldapBindDNPassword,
83 CreateIface::SearchScope ldapSearchScope,
84 CreateIface::Type ldapType,
Ratan Guptae1f4db62019-04-11 18:57:42 +053085 std::string groupNameAttribute,
86 std::string userNameAttribute) override;
87
88 /** @brief restarts given service
89 * @param[in] service - Service to be restarted.
90 */
91 virtual void restartService(const std::string& service);
92
93 /** @brief stops given service
94 * @param[in] service - Service to be stopped.
95 */
96 virtual void stopService(const std::string& service);
97
98 /** @brief start or stop the service depending on the given value
99 * @param[in] service - Service to be start/stop.
100 * @param[in] value - true to start the service otherwise stop.
101 */
102 virtual void startOrStopService(const std::string& service, bool value);
103
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530104 /** @brief Populate existing config into D-Bus properties
Ratan Guptae1f4db62019-04-11 18:57:42 +0530105 */
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530106 virtual void restore();
Ratan Guptac5481d12019-04-12 18:31:05 +0530107 /** @brief enable/disable the ldap service
108 * @param[in] config - config which needs to be enabled/disabled
109 * @param[in] value - boolean value to start/stop
110 */
111 bool enableService(Config& config, bool value);
Ratan Gupta27d4c012019-04-12 13:03:35 +0530112
Ratan Guptae1f4db62019-04-11 18:57:42 +0530113 /* 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{};
Ratan Gupta22f13f12019-04-29 15:36:40 +0530121 std::string tlsCertFile{};
Ratan Guptae1f4db62019-04-11 18:57:42 +0530122
123 /** @brief Persistent sdbusplus D-Bus bus connection. */
124 sdbusplus::bus::bus& bus;
125
Ratan Gupta27d4c012019-04-12 13:03:35 +0530126 /* Below two config objects are default, which will always be there */
Ratan Guptae1f4db62019-04-11 18:57:42 +0530127
Ratan Gupta27d4c012019-04-12 13:03:35 +0530128 /* if need arises then we can have below map for additional account
129 * providers we need to create sub class of Config which will implement the
130 * delete interface as the default objects will not implement the delete
131 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
132
133 /** @brief Pointer to a openLDAP Config D-Bus object */
134 std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
135 /** @brief Pointer to a AD Config D-Bus object */
136 std::unique_ptr<Config> ADConfigPtr = nullptr;
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530137
138 /* Create the default active directory and the openldap config
139 * objects. */
140 virtual void createDefaultObjects();
Ratan Guptae1f4db62019-04-11 18:57:42 +0530141};
142} // namespace ldap
143} // namespace phosphor