Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Ratan Gupta | 37fb3fe | 2019-04-13 12:54:18 +0530 | [diff] [blame] | 5 | #include "ldap_config.hpp" |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 6 | |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 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> |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 12 | #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> |
| 13 | #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 14 | |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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"; |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 23 | static auto openLDAPDbusObjectPath = |
| 24 | std::string(LDAP_CONFIG_ROOT) + "/openldap"; |
| 25 | static auto ADDbusObjectPath = |
| 26 | std::string(LDAP_CONFIG_ROOT) + "/active_directory"; |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 27 | |
| 28 | using namespace phosphor::logging; |
| 29 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 30 | using CreateIface = sdbusplus::server::object::object< |
| 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::bus& bus, const char* path, const char* filePath, |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 57 | const char* dbusPersistentPath, const char* caCertFile, |
| 58 | const char* certFile) : |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 59 | CreateIface(bus, path, true), |
| 60 | dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 61 | tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 62 | {} |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 63 | |
| 64 | /** @brief concrete implementation of the pure virtual funtion |
| 65 | xyz.openbmc_project.User.Ldap.Create.createConfig. |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 66 | * @param[in] ldapServerURI - LDAP URI of the server. |
| 67 | * @param[in] ldapBindDN - distinguished name with which bind to bind |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 68 | to the directory server for lookups. |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 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 |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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 | */ |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 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, |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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 | |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 104 | /** @brief Populate existing config into D-Bus properties |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 105 | */ |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 106 | virtual void restore(); |
Ratan Gupta | c5481d1 | 2019-04-12 18:31:05 +0530 | [diff] [blame] | 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); |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 112 | |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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{}; |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 121 | std::string tlsCertFile{}; |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 122 | |
| 123 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
| 124 | sdbusplus::bus::bus& bus; |
| 125 | |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 126 | /* Below two config objects are default, which will always be there */ |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 127 | |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 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; |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 137 | |
| 138 | /* Create the default active directory and the openldap config |
| 139 | * objects. */ |
| 140 | virtual void createDefaultObjects(); |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 141 | }; |
| 142 | } // namespace ldap |
| 143 | } // namespace phosphor |