1 #pragma once 2 3 #include "config.h" 4 5 #include "ldap_config.hpp" 6 7 #include <phosphor-logging/elog-errors.hpp> 8 #include <phosphor-logging/elog.hpp> 9 #include <phosphor-logging/log.hpp> 10 #include <sdbusplus/bus.hpp> 11 #include <xyz/openbmc_project/Common/error.hpp> 12 #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> 13 #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> 14 15 #include <string> 16 namespace phosphor 17 { 18 namespace ldap 19 { 20 21 static constexpr auto defaultNslcdFile = "nslcd.conf.default"; 22 static constexpr auto nsSwitchFile = "nsswitch.conf"; 23 static auto openLDAPDbusObjectPath = 24 std::string(LDAP_CONFIG_ROOT) + "/openldap"; 25 static auto adDbusObjectPath = 26 std::string(LDAP_CONFIG_ROOT) + "/active_directory"; 27 28 using namespace phosphor::logging; 29 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 30 using CreateIface = sdbusplus::server::object_t< 31 sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>; 32 33 // class Config; 34 /** @class ConfigMgr 35 * @brief Creates LDAP server configuration. 36 * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create 37 * APIs, in order to create LDAP configuration. 38 */ 39 class ConfigMgr : public CreateIface 40 { 41 public: 42 ConfigMgr() = delete; 43 ~ConfigMgr() = default; 44 ConfigMgr(const ConfigMgr&) = delete; 45 ConfigMgr& operator=(const ConfigMgr&) = delete; 46 ConfigMgr(ConfigMgr&&) = delete; 47 ConfigMgr& operator=(ConfigMgr&&) = delete; 48 49 /** @brief ConfigMgr to put object onto bus at a dbus path. 50 * @param[in] bus - Bus to attach to. 51 * @param[in] path - Path to attach at. 52 * @param[in] filePath - LDAP configuration file. 53 * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property. 54 * @param[in] caCertFile - LDAP's CA certificate file. 55 */ 56 ConfigMgr(sdbusplus::bus_t& bus, const char* path, const char* filePath, 57 const char* dbusPersistentPath, const char* caCertFile, 58 const char* certFile) : 59 CreateIface(bus, path, CreateIface::action::defer_emit), 60 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), 61 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) 62 {} 63 64 /** @brief concrete implementation of the pure virtual funtion 65 xyz.openbmc_project.User.Ldap.Create.createConfig. 66 * @param[in] ldapServerURI - LDAP URI of the server. 67 * @param[in] ldapBindDN - distinguished name with which bind to bind 68 to the directory server for lookups. 69 * @param[in] ldapBaseDN - distinguished name to use as search base. 70 * @param[in] ldapBindDNPassword - credentials with which to bind. 71 * @param[in] ldapSearchScope - the search scope. 72 * @param[in] ldapType - Specifies the LDAP server type which can be AD 73 or openLDAP. 74 * @param[in] groupNameAttribute - Specifies attribute name that contains 75 * the name of the Group in the LDAP server. 76 * @param[in] usernameAttribute - Specifies attribute name that contains 77 * the username in the LDAP server. 78 * @returns the object path of the D-Bus object created. 79 */ 80 std::string createConfig(std::string ldapServerURI, std::string ldapBindDN, 81 std::string ldapBaseDN, 82 std::string ldapBindDNPassword, 83 CreateIface::SearchScope ldapSearchScope, 84 CreateIface::Type ldapType, 85 std::string groupNameAttribute, 86 std::string userNameAttribute) override; 87 88 /** @brief restarts given service 89 * @param[in] service - Service to be restarted. 90 */ 91 virtual void restartService(const std::string& service); 92 93 /** @brief stops given service 94 * @param[in] service - Service to be stopped. 95 */ 96 virtual void stopService(const std::string& service); 97 98 /** @brief start or stop the service depending on the given value 99 * @param[in] service - Service to be start/stop. 100 * @param[in] value - true to start the service otherwise stop. 101 */ 102 virtual void startOrStopService(const std::string& service, bool value); 103 104 /** @brief Populate existing config into D-Bus properties 105 */ 106 virtual void restore(); 107 /** @brief enable/disable the ldap service 108 * @param[in] config - config which needs to be enabled/disabled 109 * @param[in] value - boolean value to start/stop 110 */ 111 bool enableService(Config& config, bool value); 112 113 /* ldap service enabled property would be saved under 114 * this path. 115 */ 116 std::string dbusPersistentPath; 117 118 protected: 119 std::string configFilePath{}; 120 std::string tlsCacertFile{}; 121 std::string tlsCertFile{}; 122 123 /** @brief Persistent sdbusplus D-Bus bus connection. */ 124 sdbusplus::bus_t& bus; 125 126 /* Below two config objects are default, which will always be there */ 127 128 /* if need arises then we can have below map for additional account 129 * providers we need to create sub class of Config which will implement the 130 * delete interface as the default objects will not implement the delete 131 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/ 132 133 /** @brief Pointer to a openLDAP Config D-Bus object */ 134 std::unique_ptr<Config> openLDAPConfigPtr = nullptr; 135 /** @brief Pointer to a AD Config D-Bus object */ 136 std::unique_ptr<Config> ADConfigPtr = nullptr; 137 138 /* Create the default active directory and the openldap config 139 * objects. */ 140 virtual void createDefaultObjects(); 141 }; 142 } // namespace ldap 143 } // namespace phosphor 144