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