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 <sdbusplus/bus.hpp> |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 8 | #include <xyz/openbmc_project/User/Ldap/Config/server.hpp> |
| 9 | #include <xyz/openbmc_project/User/Ldap/Create/server.hpp> |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 10 | |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 11 | #include <string> |
Jiaqing Zhao | e8d664d | 2022-07-05 21:22:54 +0800 | [diff] [blame] | 12 | |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 13 | namespace phosphor |
| 14 | { |
| 15 | namespace ldap |
| 16 | { |
| 17 | |
| 18 | static constexpr auto defaultNslcdFile = "nslcd.conf.default"; |
| 19 | static constexpr auto nsSwitchFile = "nsswitch.conf"; |
Patrick Williams | b704304 | 2023-05-10 07:50:52 -0500 | [diff] [blame] | 20 | static auto openLDAPDbusObjectPath = std::string(LDAP_CONFIG_ROOT) + |
| 21 | "/openldap"; |
| 22 | static auto adDbusObjectPath = std::string(LDAP_CONFIG_ROOT) + |
| 23 | "/active_directory"; |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 24 | |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 25 | using CreateIface = sdbusplus::server::object_t< |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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 | */ |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 51 | ConfigMgr(sdbusplus::bus_t& bus, const char* path, const char* filePath, |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 52 | const char* dbusPersistentPath, const char* caCertFile, |
| 53 | const char* certFile) : |
Patrick Williams | 224559b | 2022-04-05 16:10:39 -0500 | [diff] [blame] | 54 | CreateIface(bus, path, CreateIface::action::defer_emit), |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 55 | dbusPersistentPath(dbusPersistentPath), configFilePath(filePath), |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 56 | tlsCacertFile(caCertFile), tlsCertFile(certFile), bus(bus) |
Patrick Williams | 9638afb | 2021-02-22 17:16:24 -0600 | [diff] [blame] | 57 | {} |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 58 | |
Manojkiran Eda | 46e773a | 2024-06-17 14:45:33 +0530 | [diff] [blame^] | 59 | /** @brief concrete implementation of the pure virtual function |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 60 | xyz.openbmc_project.User.Ldap.Create.createConfig. |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 61 | * @param[in] ldapServerURI - LDAP URI of the server. |
| 62 | * @param[in] ldapBindDN - distinguished name with which bind to bind |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 63 | to the directory server for lookups. |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 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 |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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 | */ |
Patrick Williams | e6500a4 | 2021-05-01 05:58:23 -0500 | [diff] [blame] | 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, |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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 | |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 99 | /** @brief Populate existing config into D-Bus properties |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 100 | */ |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 101 | virtual void restore(); |
Ratan Gupta | c5481d1 | 2019-04-12 18:31:05 +0530 | [diff] [blame] | 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); |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 107 | |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 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{}; |
Ratan Gupta | 22f13f1 | 2019-04-29 15:36:40 +0530 | [diff] [blame] | 116 | std::string tlsCertFile{}; |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 117 | |
| 118 | /** @brief Persistent sdbusplus D-Bus bus connection. */ |
Patrick Williams | b3ef4e1 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 119 | sdbusplus::bus_t& bus; |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 120 | |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 121 | /* Below two config objects are default, which will always be there */ |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 122 | |
Ratan Gupta | 27d4c01 | 2019-04-12 13:03:35 +0530 | [diff] [blame] | 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; |
Ratan Gupta | 21e88cb | 2019-04-12 17:15:52 +0530 | [diff] [blame] | 132 | |
| 133 | /* Create the default active directory and the openldap config |
| 134 | * objects. */ |
| 135 | virtual void createDefaultObjects(); |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame] | 136 | }; |
| 137 | } // namespace ldap |
| 138 | } // namespace phosphor |