blob: 812528b0a597491c7602d55af9e5bc557c511723 [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,
55 const char* dbusPersistentPath, const char* caCertFile) :
56 CreateIface(bus, path, true),
57 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath),
58 bus(bus)
59 {
Ratan Guptae1f4db62019-04-11 18:57:42 +053060 }
61
62 /** @brief concrete implementation of the pure virtual funtion
63 xyz.openbmc_project.User.Ldap.Create.createConfig.
64 * @param[in] lDAPServerURI - LDAP URI of the server.
65 * @param[in] lDAPBindDN - distinguished name with which bind to bind
66 to the directory server for lookups.
67 * @param[in] lDAPBaseDN - distinguished name to use as search base.
68 * @param[in] lDAPBindDNPassword - credentials with which to bind.
69 * @param[in] lDAPSearchScope - the search scope.
70 * @param[in] lDAPType - Specifies the LDAP server type which can be AD
71 or openLDAP.
72 * @param[in] groupNameAttribute - Specifies attribute name that contains
73 * the name of the Group in the LDAP server.
74 * @param[in] usernameAttribute - Specifies attribute name that contains
75 * the username in the LDAP server.
76 * @returns the object path of the D-Bus object created.
77 */
78 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
79 std::string lDAPBaseDN,
80 std::string lDAPBindDNPassword,
81 CreateIface::SearchScope lDAPSearchScope,
82 CreateIface::Type lDAPType,
83 std::string groupNameAttribute,
84 std::string userNameAttribute) override;
85
86 /** @brief restarts given service
87 * @param[in] service - Service to be restarted.
88 */
89 virtual void restartService(const std::string& service);
90
91 /** @brief stops given service
92 * @param[in] service - Service to be stopped.
93 */
94 virtual void stopService(const std::string& service);
95
96 /** @brief start or stop the service depending on the given value
97 * @param[in] service - Service to be start/stop.
98 * @param[in] value - true to start the service otherwise stop.
99 */
100 virtual void startOrStopService(const std::string& service, bool value);
101
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530102 /** @brief Populate existing config into D-Bus properties
Ratan Guptae1f4db62019-04-11 18:57:42 +0530103 */
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530104 virtual void restore();
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{};
114
115 /** @brief Persistent sdbusplus D-Bus bus connection. */
116 sdbusplus::bus::bus& bus;
117
Ratan Gupta27d4c012019-04-12 13:03:35 +0530118 /* Below two config objects are default, which will always be there */
Ratan Guptae1f4db62019-04-11 18:57:42 +0530119
Ratan Gupta27d4c012019-04-12 13:03:35 +0530120 /* if need arises then we can have below map for additional account
121 * providers we need to create sub class of Config which will implement the
122 * delete interface as the default objects will not implement the delete
123 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
124
125 /** @brief Pointer to a openLDAP Config D-Bus object */
126 std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
127 /** @brief Pointer to a AD Config D-Bus object */
128 std::unique_ptr<Config> ADConfigPtr = nullptr;
Ratan Gupta21e88cb2019-04-12 17:15:52 +0530129
130 /* Create the default active directory and the openldap config
131 * objects. */
132 virtual void createDefaultObjects();
Ratan Guptae1f4db62019-04-11 18:57:42 +0530133};
134} // namespace ldap
135} // namespace phosphor