1 #pragma once
2 
3 #include "ldap_config.hpp"
4 
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>
14 namespace phosphor
15 {
16 namespace ldap
17 {
18 
19 static constexpr auto defaultNslcdFile = "nslcd.conf.default";
20 static constexpr auto nsSwitchFile = "nsswitch.conf";
21 static auto openLDAPDbusObjectPath =
22     std::string(LDAP_CONFIG_ROOT) + "/openldap";
23 static auto ADDbusObjectPath =
24     std::string(LDAP_CONFIG_ROOT) + "/active_directory";
25 
26 using namespace phosphor::logging;
27 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
28 using 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  */
37 class 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     {
60     }
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 
102     /** @brief delete the config D-Bus object.
103      */
104     void deleteObject();
105 
106     /* Create the default active directory and the openldap config
107      * objects. */
108     virtual void createDefaultObjects();
109 
110     /* ldap service enabled property would be saved under
111      * this path.
112      */
113     std::string dbusPersistentPath;
114 
115   protected:
116     std::string configFilePath{};
117     std::string tlsCacertFile{};
118 
119     /** @brief Persistent sdbusplus D-Bus bus connection. */
120     sdbusplus::bus::bus& bus;
121 
122     /* Below two config objects are default, which will always be there */
123 
124     /* if need arises then we can have below map for additional account
125      * providers we need to create sub class of Config which will implement the
126      * delete interface as the default objects will not implement the delete
127      * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/
128 
129     /** @brief Pointer to a openLDAP Config D-Bus object */
130     std::unique_ptr<Config> openLDAPConfigPtr = nullptr;
131     /** @brief Pointer to a AD Config D-Bus object */
132     std::unique_ptr<Config> ADConfigPtr = nullptr;
133 };
134 } // namespace ldap
135 } // namespace phosphor
136