1e1f4db62SRatan Gupta #pragma once 2e1f4db62SRatan Gupta 39638afb9SPatrick Williams #include "config.h" 49638afb9SPatrick Williams 537fb3feeSRatan Gupta #include "ldap_config.hpp" 6e1f4db62SRatan Gupta 79638afb9SPatrick Williams #include <sdbusplus/bus.hpp> 8e1f4db62SRatan Gupta #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> 9e1f4db62SRatan Gupta #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> 109638afb9SPatrick Williams 11e1f4db62SRatan Gupta #include <string> 12e8d664d1SJiaqing Zhao 13e1f4db62SRatan Gupta namespace phosphor 14e1f4db62SRatan Gupta { 15e1f4db62SRatan Gupta namespace ldap 16e1f4db62SRatan Gupta { 17e1f4db62SRatan Gupta 18e1f4db62SRatan Gupta static constexpr auto defaultNslcdFile = "nslcd.conf.default"; 19e1f4db62SRatan Gupta static constexpr auto nsSwitchFile = "nsswitch.conf"; 20*16c2b681SPatrick Williams static auto openLDAPDbusObjectPath = 21*16c2b681SPatrick Williams std::string(LDAP_CONFIG_ROOT) + "/openldap"; 22*16c2b681SPatrick Williams static auto adDbusObjectPath = 23*16c2b681SPatrick Williams std::string(LDAP_CONFIG_ROOT) + "/active_directory"; 24e1f4db62SRatan Gupta 25b3ef4e1aSPatrick Williams using CreateIface = sdbusplus::server::object_t< 26e1f4db62SRatan Gupta sdbusplus::xyz::openbmc_project::User::Ldap::server::Create>; 27e1f4db62SRatan Gupta 28e1f4db62SRatan Gupta // class Config; 29e1f4db62SRatan Gupta /** @class ConfigMgr 30e1f4db62SRatan Gupta * @brief Creates LDAP server configuration. 31e1f4db62SRatan Gupta * @details concrete implementation of xyz.openbmc_project.User.Ldap.Create 32e1f4db62SRatan Gupta * APIs, in order to create LDAP configuration. 33e1f4db62SRatan Gupta */ 34e1f4db62SRatan Gupta class ConfigMgr : public CreateIface 35e1f4db62SRatan Gupta { 36e1f4db62SRatan Gupta public: 37e1f4db62SRatan Gupta ConfigMgr() = delete; 38e1f4db62SRatan Gupta ~ConfigMgr() = default; 39e1f4db62SRatan Gupta ConfigMgr(const ConfigMgr&) = delete; 40e1f4db62SRatan Gupta ConfigMgr& operator=(const ConfigMgr&) = delete; 41e1f4db62SRatan Gupta ConfigMgr(ConfigMgr&&) = delete; 42e1f4db62SRatan Gupta ConfigMgr& operator=(ConfigMgr&&) = delete; 43e1f4db62SRatan Gupta 44e1f4db62SRatan Gupta /** @brief ConfigMgr to put object onto bus at a dbus path. 45e1f4db62SRatan Gupta * @param[in] bus - Bus to attach to. 46e1f4db62SRatan Gupta * @param[in] path - Path to attach at. 47e1f4db62SRatan Gupta * @param[in] filePath - LDAP configuration file. 48e1f4db62SRatan Gupta * @param[in] dbusPersistentPath - Persistent path for LDAP D-Bus property. 49e1f4db62SRatan Gupta * @param[in] caCertFile - LDAP's CA certificate file. 50e1f4db62SRatan Gupta */ ConfigMgr(sdbusplus::bus_t & bus,const char * path,const char * filePath,const char * dbusPersistentPath,const char * caCertFile,const char * certFile)51b3ef4e1aSPatrick Williams ConfigMgr(sdbusplus::bus_t& bus, const char* path, const char* filePath, 5222f13f18SRatan Gupta const char* dbusPersistentPath, const char* caCertFile, 5322f13f18SRatan Gupta const char* certFile) : 54224559b4SPatrick Williams CreateIface(bus, path, CreateIface::action::defer_emit), 55e1f4db62SRatan Gupta dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), 5622f13f18SRatan Gupta tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) 579638afb9SPatrick Williams {} 58e1f4db62SRatan Gupta 5946e773a9SManojkiran Eda /** @brief concrete implementation of the pure virtual function 60e1f4db62SRatan Gupta xyz.openbmc_project.User.Ldap.Create.createConfig. 61e6500a49SPatrick Williams * @param[in] ldapServerURI - LDAP URI of the server. 62e6500a49SPatrick Williams * @param[in] ldapBindDN - distinguished name with which bind to bind 63e1f4db62SRatan Gupta to the directory server for lookups. 64e6500a49SPatrick Williams * @param[in] ldapBaseDN - distinguished name to use as search base. 65e6500a49SPatrick Williams * @param[in] ldapBindDNPassword - credentials with which to bind. 66e6500a49SPatrick Williams * @param[in] ldapSearchScope - the search scope. 67e6500a49SPatrick Williams * @param[in] ldapType - Specifies the LDAP server type which can be AD 68e1f4db62SRatan Gupta or openLDAP. 69e1f4db62SRatan Gupta * @param[in] groupNameAttribute - Specifies attribute name that contains 70e1f4db62SRatan Gupta * the name of the Group in the LDAP server. 71e1f4db62SRatan Gupta * @param[in] usernameAttribute - Specifies attribute name that contains 72e1f4db62SRatan Gupta * the username in the LDAP server. 73e1f4db62SRatan Gupta * @returns the object path of the D-Bus object created. 74e1f4db62SRatan Gupta */ 75*16c2b681SPatrick Williams std::string createConfig( 76*16c2b681SPatrick Williams std::string ldapServerURI, std::string ldapBindDN, 77*16c2b681SPatrick Williams std::string ldapBaseDN, std::string ldapBindDNPassword, 78*16c2b681SPatrick Williams CreateIface::SearchScope ldapSearchScope, CreateIface::Type ldapType, 79*16c2b681SPatrick Williams std::string groupNameAttribute, std::string userNameAttribute) override; 80e1f4db62SRatan Gupta 81e1f4db62SRatan Gupta /** @brief restarts given service 82e1f4db62SRatan Gupta * @param[in] service - Service to be restarted. 83e1f4db62SRatan Gupta */ 84e1f4db62SRatan Gupta virtual void restartService(const std::string& service); 85e1f4db62SRatan Gupta 86e1f4db62SRatan Gupta /** @brief stops given service 87e1f4db62SRatan Gupta * @param[in] service - Service to be stopped. 88e1f4db62SRatan Gupta */ 89e1f4db62SRatan Gupta virtual void stopService(const std::string& service); 90e1f4db62SRatan Gupta 91e1f4db62SRatan Gupta /** @brief start or stop the service depending on the given value 92e1f4db62SRatan Gupta * @param[in] service - Service to be start/stop. 93e1f4db62SRatan Gupta * @param[in] value - true to start the service otherwise stop. 94e1f4db62SRatan Gupta */ 95e1f4db62SRatan Gupta virtual void startOrStopService(const std::string& service, bool value); 96e1f4db62SRatan Gupta 9721e88cb5SRatan Gupta /** @brief Populate existing config into D-Bus properties 98e1f4db62SRatan Gupta */ 9921e88cb5SRatan Gupta virtual void restore(); 100c5481d1cSRatan Gupta /** @brief enable/disable the ldap service 101c5481d1cSRatan Gupta * @param[in] config - config which needs to be enabled/disabled 102c5481d1cSRatan Gupta * @param[in] value - boolean value to start/stop 103c5481d1cSRatan Gupta */ 104c5481d1cSRatan Gupta bool enableService(Config& config, bool value); 10527d4c011SRatan Gupta 106e1f4db62SRatan Gupta /* ldap service enabled property would be saved under 107e1f4db62SRatan Gupta * this path. 108e1f4db62SRatan Gupta */ 109e1f4db62SRatan Gupta std::string dbusPersistentPath; 110e1f4db62SRatan Gupta 111e1f4db62SRatan Gupta protected: 112e1f4db62SRatan Gupta std::string configFilePath{}; 113e1f4db62SRatan Gupta std::string tlsCacertFile{}; 11422f13f18SRatan Gupta std::string tlsCertFile{}; 115e1f4db62SRatan Gupta 116e1f4db62SRatan Gupta /** @brief Persistent sdbusplus D-Bus bus connection. */ 117b3ef4e1aSPatrick Williams sdbusplus::bus_t& bus; 118e1f4db62SRatan Gupta 11927d4c011SRatan Gupta /* Below two config objects are default, which will always be there */ 120e1f4db62SRatan Gupta 12127d4c011SRatan Gupta /* if need arises then we can have below map for additional account 12227d4c011SRatan Gupta * providers we need to create sub class of Config which will implement the 12327d4c011SRatan Gupta * delete interface as the default objects will not implement the delete 12427d4c011SRatan Gupta * std::map<std::string, std::unique_ptr<NewConfig>> AdditionalProviders*/ 12527d4c011SRatan Gupta 12627d4c011SRatan Gupta /** @brief Pointer to a openLDAP Config D-Bus object */ 12727d4c011SRatan Gupta std::unique_ptr<Config> openLDAPConfigPtr = nullptr; 12827d4c011SRatan Gupta /** @brief Pointer to a AD Config D-Bus object */ 12927d4c011SRatan Gupta std::unique_ptr<Config> ADConfigPtr = nullptr; 13021e88cb5SRatan Gupta 13121e88cb5SRatan Gupta /* Create the default active directory and the openldap config 13221e88cb5SRatan Gupta * objects. */ 13321e88cb5SRatan Gupta virtual void createDefaultObjects(); 134e1f4db62SRatan Gupta }; 135e1f4db62SRatan Gupta } // namespace ldap 136e1f4db62SRatan Gupta } // namespace phosphor 137