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