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 const char* certFile) : 57 CreateIface(bus, path, true), 58 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), 59 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) 60 { 61 } 62 63 /** @brief concrete implementation of the pure virtual funtion 64 xyz.openbmc_project.User.Ldap.Create.createConfig. 65 * @param[in] lDAPServerURI - LDAP URI of the server. 66 * @param[in] lDAPBindDN - distinguished name with which bind to bind 67 to the directory server for lookups. 68 * @param[in] lDAPBaseDN - distinguished name to use as search base. 69 * @param[in] lDAPBindDNPassword - credentials with which to bind. 70 * @param[in] lDAPSearchScope - the search scope. 71 * @param[in] lDAPType - Specifies the LDAP server type which can be AD 72 or openLDAP. 73 * @param[in] groupNameAttribute - Specifies attribute name that contains 74 * the name of the Group in the LDAP server. 75 * @param[in] usernameAttribute - Specifies attribute name that contains 76 * the username in the LDAP server. 77 * @returns the object path of the D-Bus object created. 78 */ 79 std::string createConfig(std::string lDAPServerURI, std::string lDAPBindDN, 80 std::string lDAPBaseDN, 81 std::string lDAPBindDNPassword, 82 CreateIface::SearchScope lDAPSearchScope, 83 CreateIface::Type lDAPType, 84 std::string groupNameAttribute, 85 std::string userNameAttribute) override; 86 87 /** @brief restarts given service 88 * @param[in] service - Service to be restarted. 89 */ 90 virtual void restartService(const std::string& service); 91 92 /** @brief stops given service 93 * @param[in] service - Service to be stopped. 94 */ 95 virtual void stopService(const std::string& service); 96 97 /** @brief start or stop the service depending on the given value 98 * @param[in] service - Service to be start/stop. 99 * @param[in] value - true to start the service otherwise stop. 100 */ 101 virtual void startOrStopService(const std::string& service, bool value); 102 103 /** @brief Populate existing config into D-Bus properties 104 */ 105 virtual void restore(); 106 /** @brief enable/disable the ldap service 107 * @param[in] config - config which needs to be enabled/disabled 108 * @param[in] value - boolean value to start/stop 109 */ 110 bool enableService(Config& config, bool value); 111 112 /* ldap service enabled property would be saved under 113 * this path. 114 */ 115 std::string dbusPersistentPath; 116 117 protected: 118 std::string configFilePath{}; 119 std::string tlsCacertFile{}; 120 std::string tlsCertFile{}; 121 122 /** @brief Persistent sdbusplus D-Bus bus connection. */ 123 sdbusplus::bus::bus& bus; 124 125 /* Below two config objects are default, which will always be there */ 126 127 /* if need arises then we can have below map for additional account 128 * providers we need to create sub class of Config which will implement the 129 * delete interface as the default objects will not implement the delete 130 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/ 131 132 /** @brief Pointer to a openLDAP Config D-Bus object */ 133 std::unique_ptr<Config> openLDAPConfigPtr = nullptr; 134 /** @brief Pointer to a AD Config D-Bus object */ 135 std::unique_ptr<Config> ADConfigPtr = nullptr; 136 137 /* Create the default active directory and the openldap config 138 * objects. */ 139 virtual void createDefaultObjects(); 140 }; 141 } // namespace ldap 142 } // namespace phosphor 143