Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame^] | 1 | #include "ldap_config_mgr.hpp" |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 2 | #include "ldap_configuration.hpp" |
Ratan Gupta | 95a2931 | 2019-02-18 20:34:10 +0530 | [diff] [blame] | 3 | #include "ldap_serialize.hpp" |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 4 | #include "utils.hpp" |
Ratan Gupta | 95a2931 | 2019-02-18 20:34:10 +0530 | [diff] [blame] | 5 | #include <filesystem> |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 6 | #include <fstream> |
| 7 | #include <sstream> |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace ldap |
| 12 | { |
Ratan Gupta | e1f4db6 | 2019-04-11 18:57:42 +0530 | [diff] [blame^] | 13 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 14 | constexpr auto nslcdService = "nslcd.service"; |
Nagaraju Goruganti | dccee2b | 2018-09-25 08:51:06 -0500 | [diff] [blame] | 15 | constexpr auto nscdService = "nscd.service"; |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 16 | constexpr auto LDAPscheme = "ldap"; |
| 17 | constexpr auto LDAPSscheme = "ldaps"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 18 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 19 | using namespace phosphor::logging; |
| 20 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Ratan Gupta | 95a2931 | 2019-02-18 20:34:10 +0530 | [diff] [blame] | 21 | namespace fs = std::filesystem; |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 22 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 23 | |
| 24 | using Line = std::string; |
| 25 | using Key = std::string; |
| 26 | using Val = std::string; |
| 27 | using ConfigInfo = std::map<Key, Val>; |
| 28 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 29 | Config::Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath, |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 30 | const char* caCertFile, bool secureLDAP, |
| 31 | std::string lDAPServerURI, std::string lDAPBindDN, |
| 32 | std::string lDAPBaseDN, std::string&& lDAPBindDNPassword, |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 33 | ConfigIface::SearchScope lDAPSearchScope, |
| 34 | ConfigIface::Type lDAPType, bool lDAPServiceEnabled, |
| 35 | std::string userNameAttr, std::string groupNameAttr, |
| 36 | ConfigMgr& parent) : |
| 37 | Ifaces(bus, path, true), |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 38 | secureLDAP(secureLDAP), lDAPBindPassword(std::move(lDAPBindDNPassword)), |
| 39 | configFilePath(filePath), tlsCacertFile(caCertFile), bus(bus), |
| 40 | parent(parent) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 41 | { |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 42 | ConfigIface::lDAPServerURI(lDAPServerURI); |
| 43 | ConfigIface::lDAPBindDN(lDAPBindDN); |
| 44 | ConfigIface::lDAPBaseDN(lDAPBaseDN); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 45 | ConfigIface::lDAPSearchScope(lDAPSearchScope); |
| 46 | ConfigIface::lDAPType(lDAPType); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 47 | EnableIface::enabled(lDAPServiceEnabled); |
| 48 | ConfigIface::userNameAttribute(userNameAttr); |
| 49 | ConfigIface::groupNameAttribute(groupNameAttr); |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 50 | // Don't update the bindDN password under ConfigIface:: |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 51 | writeConfig(); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 52 | // Emit deferred signal. |
| 53 | this->emit_object_added(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 54 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 55 | } |
| 56 | |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 57 | void Config::delete_() |
| 58 | { |
| 59 | parent.deleteObject(); |
Nagaraju Goruganti | dccee2b | 2018-09-25 08:51:06 -0500 | [diff] [blame] | 60 | try |
| 61 | { |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 62 | fs::path configDir = fs::path(configFilePath.c_str()).parent_path(); |
| 63 | |
| 64 | fs::copy_file(configDir / defaultNslcdFile, LDAP_CONFIG_FILE, |
Nagaraju Goruganti | dccee2b | 2018-09-25 08:51:06 -0500 | [diff] [blame] | 65 | fs::copy_options::overwrite_existing); |
Nagaraju Goruganti | dccee2b | 2018-09-25 08:51:06 -0500 | [diff] [blame] | 66 | } |
| 67 | catch (const std::exception& e) |
| 68 | { |
| 69 | log<level::ERR>("Failed to rename Config Files while deleting Object", |
| 70 | entry("ERR=%s", e.what())); |
| 71 | elog<InternalFailure>(); |
| 72 | } |
| 73 | |
| 74 | parent.restartService(nscdService); |
| 75 | parent.stopService(nslcdService); |
Nagaraju Goruganti | 24194bd | 2018-09-18 09:55:09 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 78 | void Config::writeConfig() |
| 79 | { |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 80 | std::stringstream confData; |
Ratan Gupta | 9891f2f | 2018-10-06 12:07:35 +0530 | [diff] [blame] | 81 | auto isPwdTobeWritten = false; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 82 | std::string userNameAttr; |
Ratan Gupta | 9891f2f | 2018-10-06 12:07:35 +0530 | [diff] [blame] | 83 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 84 | confData << "uid root\n"; |
| 85 | confData << "gid root\n\n"; |
| 86 | confData << "ldap_version 3\n\n"; |
| 87 | confData << "timelimit 30\n"; |
| 88 | confData << "bind_timelimit 30\n"; |
| 89 | confData << "pagesize 1000\n"; |
| 90 | confData << "referrals off\n\n"; |
| 91 | confData << "uri " << lDAPServerURI() << "\n\n"; |
| 92 | confData << "base " << lDAPBaseDN() << "\n\n"; |
| 93 | confData << "binddn " << lDAPBindDN() << "\n"; |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 94 | if (!lDAPBindPassword.empty()) |
Nagaraju Goruganti | 1567547 | 2018-10-05 07:03:05 -0500 | [diff] [blame] | 95 | { |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 96 | confData << "bindpw " << lDAPBindPassword << "\n"; |
Ratan Gupta | 9891f2f | 2018-10-06 12:07:35 +0530 | [diff] [blame] | 97 | isPwdTobeWritten = true; |
Nagaraju Goruganti | 1567547 | 2018-10-05 07:03:05 -0500 | [diff] [blame] | 98 | } |
| 99 | confData << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 100 | switch (lDAPSearchScope()) |
| 101 | { |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 102 | case ConfigIface::SearchScope::sub: |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 103 | confData << "scope sub\n\n"; |
| 104 | break; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 105 | case ConfigIface::SearchScope::one: |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 106 | confData << "scope one\n\n"; |
| 107 | break; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 108 | case ConfigIface::SearchScope::base: |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 109 | confData << "scope base\n\n"; |
| 110 | break; |
| 111 | } |
| 112 | confData << "base passwd " << lDAPBaseDN() << "\n"; |
| 113 | confData << "base shadow " << lDAPBaseDN() << "\n\n"; |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 114 | if (secureLDAP == true) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 115 | { |
| 116 | confData << "ssl on\n"; |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 117 | confData << "tls_reqcert hard\n"; |
| 118 | confData << "tls_cacertFile " << tlsCacertFile.c_str() << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
Nagaraju Goruganti | 1567547 | 2018-10-05 07:03:05 -0500 | [diff] [blame] | 122 | confData << "ssl off\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 123 | } |
Nagaraju Goruganti | 1567547 | 2018-10-05 07:03:05 -0500 | [diff] [blame] | 124 | confData << "\n"; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 125 | if (lDAPType() == ConfigIface::Type::ActiveDirectory) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 126 | { |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 127 | if (ConfigIface::userNameAttribute().empty()) |
| 128 | { |
| 129 | ConfigIface::userNameAttribute("sAMAccountName"); |
| 130 | } |
| 131 | if (ConfigIface::groupNameAttribute().empty()) |
| 132 | { |
| 133 | ConfigIface::groupNameAttribute("primaryGroupID"); |
| 134 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 135 | confData << "filter passwd (&(objectClass=user)(objectClass=person)" |
| 136 | "(!(objectClass=computer)))\n"; |
| 137 | confData |
| 138 | << "filter group (|(objectclass=group)(objectclass=groupofnames) " |
| 139 | "(objectclass=groupofuniquenames))\n"; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 140 | confData << "map passwd uid " |
| 141 | << ConfigIface::userNameAttribute() << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 142 | confData << "map passwd uidNumber " |
| 143 | "objectSid:S-1-5-21-3623811015-3361044348-30300820\n"; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 144 | confData << "map passwd gidNumber " |
| 145 | << ConfigIface::groupNameAttribute() << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 146 | confData << "map passwd homeDirectory \"/home/$sAMAccountName\"\n"; |
| 147 | confData << "map passwd gecos displayName\n"; |
| 148 | confData << "map passwd loginShell \"/bin/bash\"\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 149 | confData << "map group gidNumber " |
| 150 | "objectSid:S-1-5-21-3623811015-3361044348-30300820\n"; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 151 | confData << "map group cn " |
| 152 | << ConfigIface::userNameAttribute() << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 153 | } |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 154 | else if (lDAPType() == ConfigIface::Type::OpenLdap) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 155 | { |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 156 | if (ConfigIface::userNameAttribute().empty()) |
| 157 | { |
raviteja-b | c3f56c5 | 2019-04-02 11:09:04 -0500 | [diff] [blame] | 158 | ConfigIface::userNameAttribute("cn"); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 159 | } |
| 160 | if (ConfigIface::groupNameAttribute().empty()) |
| 161 | { |
raviteja-b | c3f56c5 | 2019-04-02 11:09:04 -0500 | [diff] [blame] | 162 | ConfigIface::groupNameAttribute("gidNumber"); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 163 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 164 | confData << "filter passwd (objectclass=*)\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 165 | confData << "map passwd gecos displayName\n"; |
Nagaraju Goruganti | 808eda4 | 2018-10-10 08:48:12 -0500 | [diff] [blame] | 166 | confData << "filter group (objectclass=posixGroup)\n"; |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 167 | confData << "map passwd uid " |
| 168 | << ConfigIface::userNameAttribute() << "\n"; |
| 169 | confData << "map passwd gidNumber " |
| 170 | << ConfigIface::groupNameAttribute() << "\n"; |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 171 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 172 | try |
| 173 | { |
| 174 | std::fstream stream(configFilePath.c_str(), std::fstream::out); |
Ratan Gupta | 9891f2f | 2018-10-06 12:07:35 +0530 | [diff] [blame] | 175 | // remove the read permission from others if password is being written. |
| 176 | // nslcd forces this behaviour. |
| 177 | auto permission = fs::perms::owner_read | fs::perms::owner_write | |
| 178 | fs::perms::group_read; |
| 179 | if (isPwdTobeWritten) |
| 180 | { |
| 181 | fs::permissions(configFilePath, permission); |
| 182 | } |
| 183 | else |
| 184 | { |
| 185 | fs::permissions(configFilePath, |
| 186 | permission | fs::perms::others_read); |
| 187 | } |
| 188 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 189 | stream << confData.str(); |
| 190 | stream.flush(); |
| 191 | stream.close(); |
| 192 | } |
| 193 | catch (const std::exception& e) |
| 194 | { |
| 195 | log<level::ERR>(e.what()); |
| 196 | elog<InternalFailure>(); |
| 197 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | |
Ratan Gupta | 3a1c274 | 2019-03-20 06:49:42 +0530 | [diff] [blame] | 201 | std::string Config::lDAPBindDNPassword(std::string value) |
| 202 | { |
| 203 | // Don't update the D-bus object, this is just to |
| 204 | // facilitate if user wants to change the bind dn password |
| 205 | // once d-bus object gets created. |
| 206 | lDAPBindPassword = value; |
| 207 | try |
| 208 | { |
| 209 | writeConfig(); |
| 210 | parent.startOrStopService(nslcdService, enabled()); |
| 211 | } |
| 212 | catch (const InternalFailure& e) |
| 213 | { |
| 214 | throw; |
| 215 | } |
| 216 | catch (const std::exception& e) |
| 217 | { |
| 218 | log<level::ERR>(e.what()); |
| 219 | elog<InternalFailure>(); |
| 220 | } |
| 221 | return value; |
| 222 | } |
| 223 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 224 | std::string Config::lDAPServerURI(std::string value) |
| 225 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 226 | std::string val; |
| 227 | try |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 228 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 229 | if (value == lDAPServerURI()) |
| 230 | { |
| 231 | return value; |
| 232 | } |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 233 | if (isValidLDAPURI(value, LDAPSscheme)) |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 234 | { |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 235 | secureLDAP = true; |
| 236 | } |
| 237 | else if (isValidLDAPURI(value, LDAPscheme)) |
| 238 | { |
| 239 | secureLDAP = false; |
Nagaraju Goruganti | db60f58 | 2018-11-08 03:14:48 -0600 | [diff] [blame] | 240 | } |
| 241 | else |
| 242 | { |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 243 | log<level::ERR>("bad LDAP Server URI", |
| 244 | entry("LDAPSERVERURI=%s", value.c_str())); |
| 245 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPServerURI"), |
| 246 | Argument::ARGUMENT_VALUE(value.c_str())); |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 247 | } |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 248 | |
| 249 | if (secureLDAP && !fs::exists(tlsCacertFile.c_str())) |
| 250 | { |
| 251 | log<level::ERR>("LDAP server's CA certificate not provided", |
| 252 | entry("TLSCACERTFILE=%s", tlsCacertFile.c_str())); |
| 253 | elog<NoCACertificate>(); |
| 254 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 255 | val = ConfigIface::lDAPServerURI(value); |
| 256 | writeConfig(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 257 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 258 | } |
| 259 | catch (const InternalFailure& e) |
| 260 | { |
| 261 | throw; |
| 262 | } |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 263 | catch (const InvalidArgument& e) |
| 264 | { |
| 265 | throw; |
| 266 | } |
Nagaraju Goruganti | 3b4d06a | 2018-11-08 03:13:38 -0600 | [diff] [blame] | 267 | catch (const NoCACertificate& e) |
| 268 | { |
| 269 | throw; |
| 270 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 271 | catch (const std::exception& e) |
| 272 | { |
| 273 | log<level::ERR>(e.what()); |
| 274 | elog<InternalFailure>(); |
| 275 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 276 | return val; |
| 277 | } |
| 278 | |
| 279 | std::string Config::lDAPBindDN(std::string value) |
| 280 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 281 | std::string val; |
| 282 | try |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 283 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 284 | if (value == lDAPBindDN()) |
| 285 | { |
| 286 | return value; |
| 287 | } |
| 288 | |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 289 | if (value.empty()) |
| 290 | { |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 291 | log<level::ERR>("Not a valid LDAP BINDDN", |
| 292 | entry("LDAPBINDDN=%s", value.c_str())); |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 293 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPBindDN"), |
| 294 | Argument::ARGUMENT_VALUE(value.c_str())); |
| 295 | } |
| 296 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 297 | val = ConfigIface::lDAPBindDN(value); |
| 298 | writeConfig(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 299 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 300 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 301 | catch (const InternalFailure& e) |
| 302 | { |
| 303 | throw; |
| 304 | } |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 305 | catch (const InvalidArgument& e) |
| 306 | { |
| 307 | throw; |
| 308 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 309 | catch (const std::exception& e) |
| 310 | { |
| 311 | log<level::ERR>(e.what()); |
| 312 | elog<InternalFailure>(); |
| 313 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 314 | return val; |
| 315 | } |
| 316 | |
| 317 | std::string Config::lDAPBaseDN(std::string value) |
| 318 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 319 | std::string val; |
| 320 | try |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 321 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 322 | if (value == lDAPBaseDN()) |
| 323 | { |
| 324 | return value; |
| 325 | } |
| 326 | |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 327 | if (value.empty()) |
| 328 | { |
Nagaraju Goruganti | 59287f0 | 2018-10-12 07:00:20 -0500 | [diff] [blame] | 329 | log<level::ERR>("Not a valid LDAP BASEDN", |
| 330 | entry("BASEDN=%s", value.c_str())); |
Nagaraju Goruganti | b26799a | 2018-09-28 13:12:19 -0500 | [diff] [blame] | 331 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPBaseDN"), |
| 332 | Argument::ARGUMENT_VALUE(value.c_str())); |
| 333 | } |
| 334 | |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 335 | val = ConfigIface::lDAPBaseDN(value); |
| 336 | writeConfig(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 337 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 338 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 339 | catch (const InternalFailure& e) |
| 340 | { |
| 341 | throw; |
| 342 | } |
Nagaraju Goruganti | d514e5d | 2018-11-08 03:07:25 -0600 | [diff] [blame] | 343 | catch (const InvalidArgument& e) |
| 344 | { |
| 345 | throw; |
| 346 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 347 | catch (const std::exception& e) |
| 348 | { |
| 349 | log<level::ERR>(e.what()); |
| 350 | elog<InternalFailure>(); |
| 351 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 352 | return val; |
| 353 | } |
| 354 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 355 | ConfigIface::SearchScope Config::lDAPSearchScope(ConfigIface::SearchScope value) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 356 | { |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 357 | ConfigIface::SearchScope val; |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 358 | try |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 359 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 360 | if (value == lDAPSearchScope()) |
| 361 | { |
| 362 | return value; |
| 363 | } |
| 364 | |
| 365 | val = ConfigIface::lDAPSearchScope(value); |
| 366 | writeConfig(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 367 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 368 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 369 | catch (const InternalFailure& e) |
| 370 | { |
| 371 | throw; |
| 372 | } |
| 373 | catch (const std::exception& e) |
| 374 | { |
| 375 | log<level::ERR>(e.what()); |
| 376 | elog<InternalFailure>(); |
| 377 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 378 | return val; |
| 379 | } |
| 380 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 381 | ConfigIface::Type Config::lDAPType(ConfigIface::Type value) |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 382 | { |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 383 | ConfigIface::Type val; |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 384 | try |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 385 | { |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 386 | if (value == lDAPType()) |
| 387 | { |
| 388 | return value; |
| 389 | } |
| 390 | |
| 391 | val = ConfigIface::lDAPType(value); |
| 392 | writeConfig(); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 393 | parent.startOrStopService(nslcdService, enabled()); |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 394 | } |
Nagaraju Goruganti | f1940d9 | 2018-09-18 05:05:50 -0500 | [diff] [blame] | 395 | catch (const InternalFailure& e) |
| 396 | { |
| 397 | throw; |
| 398 | } |
| 399 | catch (const std::exception& e) |
| 400 | { |
| 401 | log<level::ERR>(e.what()); |
| 402 | elog<InternalFailure>(); |
| 403 | } |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 404 | return val; |
| 405 | } |
| 406 | |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 407 | bool Config::enabled(bool value) |
| 408 | { |
| 409 | bool isEnable; |
| 410 | try |
| 411 | { |
| 412 | if (value == enabled()) |
| 413 | { |
| 414 | return value; |
| 415 | } |
| 416 | isEnable = EnableIface::enabled(value); |
Ratan Gupta | 95a2931 | 2019-02-18 20:34:10 +0530 | [diff] [blame] | 417 | // save the enabled property. |
| 418 | serialize(*this, parent.dbusPersistentPath); |
Ratan Gupta | aeaf941 | 2019-02-11 04:41:52 -0600 | [diff] [blame] | 419 | parent.startOrStopService(nslcdService, value); |
| 420 | } |
| 421 | catch (const InternalFailure& e) |
| 422 | { |
| 423 | throw; |
| 424 | } |
| 425 | catch (const std::exception& e) |
| 426 | { |
| 427 | log<level::ERR>(e.what()); |
| 428 | elog<InternalFailure>(); |
| 429 | } |
| 430 | return isEnable; |
| 431 | } |
| 432 | |
| 433 | std::string Config::userNameAttribute(std::string value) |
| 434 | { |
| 435 | std::string val; |
| 436 | try |
| 437 | { |
| 438 | if (value == userNameAttribute()) |
| 439 | { |
| 440 | return value; |
| 441 | } |
| 442 | |
| 443 | val = ConfigIface::userNameAttribute(value); |
| 444 | writeConfig(); |
| 445 | parent.startOrStopService(nslcdService, enabled()); |
| 446 | } |
| 447 | catch (const InternalFailure& e) |
| 448 | { |
| 449 | throw; |
| 450 | } |
| 451 | catch (const std::exception& e) |
| 452 | { |
| 453 | log<level::ERR>(e.what()); |
| 454 | elog<InternalFailure>(); |
| 455 | } |
| 456 | return val; |
| 457 | } |
| 458 | |
| 459 | std::string Config::groupNameAttribute(std::string value) |
| 460 | { |
| 461 | std::string val; |
| 462 | try |
| 463 | { |
| 464 | if (value == groupNameAttribute()) |
| 465 | { |
| 466 | return value; |
| 467 | } |
| 468 | |
| 469 | val = ConfigIface::groupNameAttribute(value); |
| 470 | writeConfig(); |
| 471 | parent.startOrStopService(nslcdService, enabled()); |
| 472 | } |
| 473 | catch (const InternalFailure& e) |
| 474 | { |
| 475 | throw; |
| 476 | } |
| 477 | catch (const std::exception& e) |
| 478 | { |
| 479 | log<level::ERR>(e.what()); |
| 480 | elog<InternalFailure>(); |
| 481 | } |
| 482 | return val; |
| 483 | } |
| 484 | |
Nagaraju Goruganti | 997f5e0 | 2018-08-30 03:05:11 -0500 | [diff] [blame] | 485 | } // namespace ldap |
| 486 | } // namespace phosphor |