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 = 21 std::string(LDAP_CONFIG_ROOT) + "/openldap"; 22 static auto adDbusObjectPath = 23 std::string(LDAP_CONFIG_ROOT) + "/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 */ ConfigMgr(sdbusplus::bus_t & bus,const char * path,const char * filePath,const char * dbusPersistentPath,const char * caCertFile,const char * certFile)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( 76 std::string ldapServerURI, std::string ldapBindDN, 77 std::string ldapBaseDN, std::string ldapBindDNPassword, 78 CreateIface::SearchScope ldapSearchScope, CreateIface::Type ldapType, 79 std::string groupNameAttribute, std::string userNameAttribute) override; 80 81 /** @brief restarts given service 82 * @param[in] service - Service to be restarted. 83 */ 84 virtual void restartService(const std::string& service); 85 86 /** @brief stops given service 87 * @param[in] service - Service to be stopped. 88 */ 89 virtual void stopService(const std::string& service); 90 91 /** @brief start or stop the service depending on the given value 92 * @param[in] service - Service to be start/stop. 93 * @param[in] value - true to start the service otherwise stop. 94 */ 95 virtual void startOrStopService(const std::string& service, bool value); 96 97 /** @brief Populate existing config into D-Bus properties 98 */ 99 virtual void restore(); 100 /** @brief enable/disable the ldap service 101 * @param[in] config - config which needs to be enabled/disabled 102 * @param[in] value - boolean value to start/stop 103 */ 104 bool enableService(Config& config, bool value); 105 106 /* 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 std::string tlsCertFile{}; 115 116 /** @brief Persistent sdbusplus D-Bus bus connection. */ 117 sdbusplus::bus_t& bus; 118 119 /* Below two config objects are default, which will always be there */ 120 121 /* if need arises then we can have below map for additional account 122 * providers we need to create sub class of Config which will implement the 123 * delete interface as the default objects will not implement the delete 124 * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/ 125 126 /** @brief Pointer to a openLDAP Config D-Bus object */ 127 std::unique_ptr<Config> openLDAPConfigPtr = nullptr; 128 /** @brief Pointer to a AD Config D-Bus object */ 129 std::unique_ptr<Config> ADConfigPtr = nullptr; 130 131 /* Create the default active directory and the openldap config 132 * objects. */ 133 virtual void createDefaultObjects(); 134 }; 135 } // namespace ldap 136 } // namespace phosphor 137