blob: 13211c89efdee413d1b32759dd2396f177b5b5fb [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 <sdbusplus/bus.hpp>
Ratan Guptae1f4db62019-04-11 18:57:42 +05308#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
9#include <xyz/openbmc_project/User/Ldap/Create/server.hpp>
Patrick Williams9638afb2021-02-22 17:16:24 -060010
Ratan Guptae1f4db62019-04-11 18:57:42 +053011#include <string>
Jiaqing Zhaoe8d664d2022-07-05 21:22:54 +080012
Ratan Guptae1f4db62019-04-11 18:57:42 +053013namespace phosphor
14{
15namespace ldap
16{
17
18static constexpr auto defaultNslcdFile = "nslcd.conf.default";
19static constexpr auto nsSwitchFile = "nsswitch.conf";
Patrick Williamsb7043042023-05-10 07:50:52 -050020static auto openLDAPDbusObjectPath = std::string(LDAP_CONFIG_ROOT) +
21 "/openldap";
22static auto adDbusObjectPath = std::string(LDAP_CONFIG_ROOT) +
23 "/active_directory";
Ratan Guptae1f4db62019-04-11 18:57:42 +053024
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050025using CreateIface = sdbusplus::server::object_t<
Ratan Guptae1f4db62019-04-11 18:57:42 +053026 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>;
27
28// class Config;
29/** @class ConfigMgr
30 * @brief Creates LDAP server configuration.
31 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create
32 * APIs, in order to create LDAP configuration.
33 */
34class ConfigMgr : public CreateIface
35{
36 public:
37 ConfigMgr() = delete;
38 ~ConfigMgr() = default;
39 ConfigMgr(const ConfigMgr&) = delete;
40 ConfigMgr& operator=(const ConfigMgr&) = delete;
41 ConfigMgr(ConfigMgr&&) = delete;
42 ConfigMgr& operator=(ConfigMgr&&) = delete;
43
44 /** @brief ConfigMgr to put object onto bus at a dbus path.
45 * @param[in] bus - Bus to attach to.
46 * @param[in] path - Path to attach at.
47 * @param[in] filePath - LDAP configuration file.
48 * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property.
49 * @param[in] caCertFile - LDAP's CA certificate file.
50 */
Patrick Williamsb3ef4e12022-07-22 19:26:55 -050051 ConfigMgr(sdbusplus::bus_t& bus, const char* path, const char* filePath,
Ratan Gupta22f13f12019-04-29 15:36:40 +053052 const char* dbusPersistentPath, const char* caCertFile,
53 const char* certFile) :
Patrick Williams224559b2022-04-05 16:10:39 -050054 CreateIface(bus, path, CreateIface::action::defer_emit),
Ratan Guptae1f4db62019-04-11 18:57:42 +053055 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
Ratan Gupta22f13f12019-04-29 15:36:40 +053056 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus)
Patrick Williams9638afb2021-02-22 17:16:24 -060057 {}
Ratan Guptae1f4db62019-04-11 18:57:42 +053058
Manojkiran Eda46e773a2024-06-17 14:45:33 +053059 /** @brief concrete implementation of the pure virtual function
Ratan Guptae1f4db62019-04-11 18:57:42 +053060 xyz.openbmc_project.User.Ldap.Create.createConfig.
Patrick Williamse6500a42021-05-01 05:58:23 -050061 * @param[in] ldapServerURI - LDAP URI of the server.
62 * @param[in] ldapBindDN - distinguished name with which bind to bind
Ratan Guptae1f4db62019-04-11 18:57:42 +053063 to the directory server for lookups.
Patrick Williamse6500a42021-05-01 05:58:23 -050064 * @param[in] ldapBaseDN - distinguished name to use as search base.
65 * @param[in] ldapBindDNPassword - credentials with which to bind.
66 * @param[in] ldapSearchScope - the search scope.
67 * @param[in] ldapType - Specifies the LDAP server type which can be AD
Ratan Guptae1f4db62019-04-11 18:57:42 +053068 or openLDAP.
69 * @param[in] groupNameAttribute - Specifies attribute name that contains
70 * the name of the Group in the LDAP server.
71 * @param[in] usernameAttribute - Specifies attribute name that contains
72 * the username in the LDAP server.
73 * @returns the object path of the D-Bus object created.
74 */
Patrick Williamse6500a42021-05-01 05:58:23 -050075 std::string createConfig(std::string ldapServerURI, std::string ldapBindDN,
76 std::string ldapBaseDN,
77 std::string ldapBindDNPassword,
78 CreateIface::SearchScope ldapSearchScope,
79 CreateIface::Type ldapType,
Ratan Guptae1f4db62019-04-11 18:57:42 +053080 std::string groupNameAttribute,
81 std::string userNameAttribute) override;
82
83 /** @brief restarts given service
84 * @param[in] service - Service to be restarted.
85 */
86 virtual void restartService(const std::string& service);
87
88 /** @brief stops given service
89 * @param[in] service - Service to be stopped.
90 */
91 virtual void stopService(const std::string& service);
92
93 /** @brief start or stop the service depending on the given value
94 * @param[in] service - Service to be start/stop.
95 * @param[in] value - true to start the service otherwise stop.
96 */
97 virtual void startOrStopService(const std::string& service, bool value);
98
Ratan Gupta21e88cb2019-04-12 17:15:52 +053099 /** @brief Populate existing config into D-Bus properties
Ratan Guptae1f4db62019-04-11 18:57:42 +0530100 */
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530101 virtual void restore();
Ratan Guptac5481d12019-04-12 18:31:05 +0530102 /** @brief enable/disable the ldap service
103 * @param[in] config - config which needs to be enabled/disabled
104 * @param[in] value - boolean value to start/stop
105 */
106 bool enableService(Config& config, bool value);
Ratan Gupta27d4c012019-04-12 13:03:35 +0530107
Ratan Guptae1f4db62019-04-11 18:57:42 +0530108 /* ldap service enabled property would be saved under
109 * this path.
110 */
111 std::string dbusPersistentPath;
112
113 protected:
114 std::string configFilePath{};
115 std::string tlsCacertFile{};
Ratan Gupta22f13f12019-04-29 15:36:40 +0530116 std::string tlsCertFile{};
Ratan Guptae1f4db62019-04-11 18:57:42 +0530117
118 /** @brief Persistent sdbusplus D-Bus bus connection. */
Patrick Williamsb3ef4e12022-07-22 19:26:55 -0500119 sdbusplus::bus_t& bus;
Ratan Guptae1f4db62019-04-11 18:57:42 +0530120
Ratan Gupta27d4c012019-04-12 13:03:35 +0530121 /* Below two config objects are default, which will always be there */
Ratan Guptae1f4db62019-04-11 18:57:42 +0530122
Ratan Gupta27d4c012019-04-12 13:03:35 +0530123 /* if need arises then we can have below map for additional account
124 * providers we need to create sub class of Config which will implement the
125 * delete interface as the default objects will not implement the delete
126 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
127
128 /** @brief Pointer to a openLDAP Config D-Bus object */
129 std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
130 /** @brief Pointer to a AD Config D-Bus object */
131 std::unique_ptr<Config> ADConfigPtr = nullptr;
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530132
133 /* Create the default active directory and the openldap config
134 * objects. */
135 virtual void createDefaultObjects();
Ratan Guptae1f4db62019-04-11 18:57:42 +0530136};
137} // namespace ldap
138} // namespace phosphor