1 #pragma once 2 3 #include "config.h" 4 5 #include "ldap_config.hpp" 6 7 #include <sdbusplus/bus.hpp> 8 #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> 9 #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> 10 11 #include <string> 12 13 namespace phosphor 14 { 15 namespace ldap 16 { 17 18 static constexpr auto defaultNslcdFile = "nslcd.conf.default"; 19 static constexpr auto nsSwitchFile = "nsswitch.conf"; 20 static auto openLDAPDbusObjectPath = std::string(LDAP_CONFIG_ROOT) + 21 "/openldap"; 22 static auto adDbusObjectPath = std::string(LDAP_CONFIG_ROOT) + 23 "/active_directory"; 24 25 using CreateIface = sdbusplus::server::object_t< 26 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 */ 34 class 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 */ 51 ConfigMgr(sdbusplus::bus_t& bus, const char* path, const char* filePath, 52 const char* dbusPersistentPath, const char* caCertFile, 53 const char* certFile) : 54 CreateIface(bus, path, CreateIface::action::defer_emit), 55 dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), 56 tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) 57 {} 58 59 /** @brief concrete implementation of the pure virtual function 60 xyz.openbmc_project.User.Ldap.Create.createConfig. 61 * @param[in] ldapServerURI - LDAP URI of the server. 62 * @param[in] ldapBindDN - distinguished name with which bind to bind 63 to the directory server for lookups. 64 * @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 68 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 */ 75 std::string createConfig(std::string ldapServerURI, std::string ldapBindDN, 76 std::string ldapBaseDN, 77 std::string ldapBindDNPassword, 78 CreateIface::SearchScope ldapSearchScope, 79 CreateIface::Type ldapType, 80 std::string groupNameAttribute, 81 std::string userNameAttribute) override; 82 83 /** @brief restarts given service 84 * @param[in] service - Service to be restarted. 85 */ 86 virtual void restartService(const std::string& service); 87 88 /** @brief stops given service 89 * @param[in] service - Service to be stopped. 90 */ 91 virtual void stopService(const std::string& service); 92 93 /** @brief start or stop the service depending on the given value 94 * @param[in] service - Service to be start/stop. 95 * @param[in] value - true to start the service otherwise stop. 96 */ 97 virtual void startOrStopService(const std::string& service, bool value); 98 99 /** @brief Populate existing config into D-Bus properties 100 */ 101 virtual void restore(); 102 /** @brief enable/disable the ldap service 103 * @param[in] config - config which needs to be enabled/disabled 104 * @param[in] value - boolean value to start/stop 105 */ 106 bool enableService(Config& config, bool value); 107 108 /* ldap service enabled property would be saved under 109 * this path. 110 */ 111 std::string dbusPersistentPath; 112 113 protected: 114 std::string configFilePath{}; 115 std::string tlsCacertFile{}; 116 std::string tlsCertFile{}; 117 118 /** @brief Persistent sdbusplus D-Bus bus connection. */ 119 sdbusplus::bus_t& bus; 120 121 /* Below two config objects are default, which will always be there */ 122 123 /* if need arises then we can have below map for additional account 124 * providers we need to create sub class of Config which will implement the 125 * delete interface as the default objects will not implement the delete 126 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/ 127 128 /** @brief Pointer to a openLDAP Config D-Bus object */ 129 std::unique_ptr<Config> openLDAPConfigPtr = nullptr; 130 /** @brief Pointer to a AD Config D-Bus object */ 131 std::unique_ptr<Config> ADConfigPtr = nullptr; 132 133 /* Create the default active directory and the openldap config 134 * objects. */ 135 virtual void createDefaultObjects(); 136 }; 137 } // namespace ldap 138 } // namespace phosphor 139