blob: 3c969a7023878693daf5c597f407f2106612dc01 [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 Williams16c2b682024-08-16 15:20:56 -040020static auto openLDAPDbusObjectPath =
21 std::string(LDAP_CONFIG_ROOT) + "/openldap";
22static auto adDbusObjectPath =
23 std::string(LDAP_CONFIG_ROOT) + "/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 Williams16c2b682024-08-16 15:20:56 -040075 std::string createConfig(
76 std::string ldapServerURI, std::string ldapBindDN,
77 std::string ldapBaseDN, std::string ldapBindDNPassword,
78 CreateIface::SearchScope ldapSearchScope, CreateIface::Type ldapType,
79 std::string groupNameAttribute, std::string userNameAttribute) override;
Ratan Guptae1f4db62019-04-11 18:57:42 +053080
81 /** @brief restarts given service
82 * @param[in] service - Service to be restarted.
83 */
84 virtual void restartService(const std::string& service);
85
86 /** @brief stops given service
87 * @param[in] service - Service to be stopped.
88 */
89 virtual void stopService(const std::string& service);
90
91 /** @brief start or stop the service depending on the given value
92 * @param[in] service - Service to be start/stop.
93 * @param[in] value - true to start the service otherwise stop.
94 */
95 virtual void startOrStopService(const std::string& service, bool value);
96
Ratan Gupta21e88cb2019-04-12 17:15:52 +053097 /** @brief Populate existing config into D-Bus properties
Ratan Guptae1f4db62019-04-11 18:57:42 +053098 */
Ratan Gupta21e88cb2019-04-12 17:15:52 +053099 virtual void restore();
Ratan Guptac5481d12019-04-12 18:31:05 +0530100 /** @brief enable/disable the ldap service
101 * @param[in] config - config which needs to be enabled/disabled
102 * @param[in] value - boolean value to start/stop
103 */
104 bool enableService(Config& config, bool value);
Ratan Gupta27d4c012019-04-12 13:03:35 +0530105
Ratan Guptae1f4db62019-04-11 18:57:42 +0530106 /* ldap service enabled property would be saved under
107 * this path.
108 */
109 std::string dbusPersistentPath;
110
111 protected:
112 std::string configFilePath{};
113 std::string tlsCacertFile{};
Ratan Gupta22f13f12019-04-29 15:36:40 +0530114 std::string tlsCertFile{};
Ratan Guptae1f4db62019-04-11 18:57:42 +0530115
116 /** @brief Persistent sdbusplus D-Bus bus connection. */
Patrick Williamsb3ef4e12022-07-22 19:26:55 -0500117 sdbusplus::bus_t& bus;
Ratan Guptae1f4db62019-04-11 18:57:42 +0530118
Ratan Gupta27d4c012019-04-12 13:03:35 +0530119 /* Below two config objects are default, which will always be there */
Ratan Guptae1f4db62019-04-11 18:57:42 +0530120
Ratan Gupta27d4c012019-04-12 13:03:35 +0530121 /* if need arises then we can have below map for additional account
122 * providers we need to create sub class of Config which will implement the
123 * delete interface as the default objects will not implement the delete
124 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
125
126 /** @brief Pointer to a openLDAP Config D-Bus object */
127 std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
128 /** @brief Pointer to a AD Config D-Bus object */
129 std::unique_ptr<Config> ADConfigPtr = nullptr;
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530130
131 /* Create the default active directory and the openldap config
132 * objects. */
133 virtual void createDefaultObjects();
Ratan Guptae1f4db62019-04-11 18:57:42 +0530134};
135} // namespace ldap
136} // namespace phosphor