blob: e84e0b9100f01ced65a971beb19dc287b833b4e4 [file] [log] [blame]
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05001#include "ldap_configuration.hpp"
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -05002#include <ldap.h>
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -05003#include <experimental/filesystem>
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -05004#include <fstream>
5#include <sstream>
6
7namespace phosphor
8{
9namespace ldap
10{
11constexpr auto nslcdService = "nslcd.service";
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -050012constexpr auto nscdService = "nscd.service";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050013
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050014using namespace phosphor::logging;
15using namespace sdbusplus::xyz::openbmc_project::Common::Error;
16namespace fs = std::experimental::filesystem;
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -050017using Argument = xyz::openbmc_project::Common::InvalidArgument;
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -050018
19using Line = std::string;
20using Key = std::string;
21using Val = std::string;
22using ConfigInfo = std::map<Key, Val>;
23
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050024Config::Config(sdbusplus::bus::bus& bus, const char* path, const char* filePath,
25 bool secureLDAP, std::string lDAPServerURI,
26 std::string lDAPBindDN, std::string lDAPBaseDN,
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060027 std::string&& lDAPBindDNPassword,
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050028 ldap_base::Config::SearchScope lDAPSearchScope,
29 ldap_base::Config::Type lDAPType, ConfigMgr& parent) :
30 ConfigIface(bus, path, true),
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060031 secureLDAP(secureLDAP), configFilePath(filePath),
32 lDAPBindDNPassword(std::move(lDAPBindDNPassword)), bus(bus), parent(parent)
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050033{
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050034 ConfigIface::lDAPServerURI(lDAPServerURI);
35 ConfigIface::lDAPBindDN(lDAPBindDN);
36 ConfigIface::lDAPBaseDN(lDAPBaseDN);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050037 ConfigIface::lDAPSearchScope(lDAPSearchScope);
38 ConfigIface::lDAPType(lDAPType);
39 writeConfig();
40 parent.restartService(nslcdService);
41 // Emit deferred signal.
42 this->emit_object_added();
43}
44
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -050045void Config::delete_()
46{
47 parent.deleteObject();
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -050048 try
49 {
50 fs::copy_file(defaultNslcdFile, LDAP_CONFIG_FILE,
51 fs::copy_options::overwrite_existing);
52 fs::copy_file(nsSwitchFile, LDAPNsSwitchFile,
53 fs::copy_options::overwrite_existing);
54 fs::copy_file(linuxNsSwitchFile, nsSwitchFile,
55 fs::copy_options::overwrite_existing);
56 }
57 catch (const std::exception& e)
58 {
59 log<level::ERR>("Failed to rename Config Files while deleting Object",
60 entry("ERR=%s", e.what()));
61 elog<InternalFailure>();
62 }
63
64 parent.restartService(nscdService);
65 parent.stopService(nslcdService);
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -050066}
67
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050068void Config::writeConfig()
69{
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050070 std::stringstream confData;
Ratan Gupta9891f2f2018-10-06 12:07:35 +053071 auto isPwdTobeWritten = false;
72
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050073 confData << "uid root\n";
74 confData << "gid root\n\n";
75 confData << "ldap_version 3\n\n";
76 confData << "timelimit 30\n";
77 confData << "bind_timelimit 30\n";
78 confData << "pagesize 1000\n";
79 confData << "referrals off\n\n";
80 confData << "uri " << lDAPServerURI() << "\n\n";
81 confData << "base " << lDAPBaseDN() << "\n\n";
82 confData << "binddn " << lDAPBindDN() << "\n";
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060083 if (!lDAPBindDNPassword.empty())
Nagaraju Goruganti15675472018-10-05 07:03:05 -050084 {
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -060085 confData << "bindpw " << lDAPBindDNPassword << "\n";
Ratan Gupta9891f2f2018-10-06 12:07:35 +053086 isPwdTobeWritten = true;
Nagaraju Goruganti15675472018-10-05 07:03:05 -050087 }
88 confData << "\n";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -050089 switch (lDAPSearchScope())
90 {
91 case ldap_base::Config::SearchScope::sub:
92 confData << "scope sub\n\n";
93 break;
94 case ldap_base::Config::SearchScope::one:
95 confData << "scope one\n\n";
96 break;
97 case ldap_base::Config::SearchScope::base:
98 confData << "scope base\n\n";
99 break;
100 }
101 confData << "base passwd " << lDAPBaseDN() << "\n";
102 confData << "base shadow " << lDAPBaseDN() << "\n\n";
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600103 if (secureLDAP == true)
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500104 {
105 confData << "ssl on\n";
106 confData << "tls_reqcert allow\n";
107 confData << "tls_cert /etc/nslcd/certs/cert.pem\n";
108 }
109 else
110 {
Nagaraju Goruganti15675472018-10-05 07:03:05 -0500111 confData << "ssl off\n";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500112 }
Nagaraju Goruganti15675472018-10-05 07:03:05 -0500113 confData << "\n";
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500114 if (lDAPType() == ldap_base::Config::Type::ActiveDirectory)
115 {
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";
121 confData << "map passwd uid sAMAccountName\n";
122 confData << "map passwd uidNumber "
123 "objectSid:S-1-5-21-3623811015-3361044348-30300820\n";
124 confData << "map passwd gidNumber primaryGroupID\n";
125 confData << "map passwd homeDirectory \"/home/$sAMAccountName\"\n";
126 confData << "map passwd gecos displayName\n";
127 confData << "map passwd loginShell \"/bin/bash\"\n";
128 confData << "map group gidNumber primaryGroupID\n";
129 confData << "map group gidNumber "
130 "objectSid:S-1-5-21-3623811015-3361044348-30300820\n";
131 confData << "map group cn sAMAccountName\n";
132 }
133 else if (lDAPType() == ldap_base::Config::Type::OpenLdap)
134 {
135 confData << "filter passwd (objectclass=*)\n";
136 confData << "map passwd uid cn\n";
137 confData << "map passwd gecos displayName\n";
138 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500139 try
140 {
141 std::fstream stream(configFilePath.c_str(), std::fstream::out);
Ratan Gupta9891f2f2018-10-06 12:07:35 +0530142 // remove the read permission from others if password is being written.
143 // nslcd forces this behaviour.
144 auto permission = fs::perms::owner_read | fs::perms::owner_write |
145 fs::perms::group_read;
146 if (isPwdTobeWritten)
147 {
148 fs::permissions(configFilePath, permission);
149 }
150 else
151 {
152 fs::permissions(configFilePath,
153 permission | fs::perms::others_read);
154 }
155
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500156 stream << confData.str();
157 stream.flush();
158 stream.close();
159 }
160 catch (const std::exception& e)
161 {
162 log<level::ERR>(e.what());
163 elog<InternalFailure>();
164 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500165 return;
166}
167
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500168std::string Config::lDAPServerURI(std::string value)
169{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500170 std::string val;
171 try
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500172 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500173 if (value == lDAPServerURI())
174 {
175 return value;
176 }
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600177 if (secureLDAP)
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500178 {
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600179 if (!ldap_is_ldaps_url(value.c_str()))
180 {
181 log<level::ERR>("bad LDAPS Server URI",
182 entry("LDAPSSERVERURI=%s", value.c_str()));
183 elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPServerURI"),
184 Argument::ARGUMENT_VALUE(value.c_str()));
185 }
186 }
187 else
188 {
189 if (!ldap_is_ldap_url(value.c_str()))
190 {
191 log<level::ERR>("bad LDAP Server URI",
192 entry("LDAPSERVERURI=%s", value.c_str()));
193 elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPServerURI"),
194 Argument::ARGUMENT_VALUE(value.c_str()));
195 }
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500196 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500197 val = ConfigIface::lDAPServerURI(value);
198 writeConfig();
199 parent.restartService(nslcdService);
200 }
201 catch (const InternalFailure& e)
202 {
203 throw;
204 }
205 catch (const std::exception& e)
206 {
207 log<level::ERR>(e.what());
208 elog<InternalFailure>();
209 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500210 return val;
211}
212
213std::string Config::lDAPBindDN(std::string value)
214{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500215 std::string val;
216 try
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500217 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500218 if (value == lDAPBindDN())
219 {
220 return value;
221 }
222
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500223 if (value.empty())
224 {
225 log<level::ERR>("Not a valid LDAP BINDDN"),
226 entry("LDAPBINDDN=%s", value.c_str());
227 elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPBindDN"),
228 Argument::ARGUMENT_VALUE(value.c_str()));
229 }
230
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500231 val = ConfigIface::lDAPBindDN(value);
232 writeConfig();
233 parent.restartService(nslcdService);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500234 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500235 catch (const InternalFailure& e)
236 {
237 throw;
238 }
239 catch (const std::exception& e)
240 {
241 log<level::ERR>(e.what());
242 elog<InternalFailure>();
243 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500244 return val;
245}
246
247std::string Config::lDAPBaseDN(std::string value)
248{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500249 std::string val;
250 try
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500251 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500252 if (value == lDAPBaseDN())
253 {
254 return value;
255 }
256
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500257 if (value.empty())
258 {
259 log<level::ERR>("Not a valid LDAP BASEDN"),
260 entry("BASEDN=%s", value.c_str());
261 elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPBaseDN"),
262 Argument::ARGUMENT_VALUE(value.c_str()));
263 }
264
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500265 val = ConfigIface::lDAPBaseDN(value);
266 writeConfig();
267 parent.restartService(nslcdService);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500268 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500269 catch (const InternalFailure& e)
270 {
271 throw;
272 }
273 catch (const std::exception& e)
274 {
275 log<level::ERR>(e.what());
276 elog<InternalFailure>();
277 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500278 return val;
279}
280
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500281ldap_base::Config::SearchScope
282 Config::lDAPSearchScope(ldap_base::Config::SearchScope value)
283{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500284 ldap_base::Config::SearchScope val;
285 try
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500286 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500287 if (value == lDAPSearchScope())
288 {
289 return value;
290 }
291
292 val = ConfigIface::lDAPSearchScope(value);
293 writeConfig();
294 parent.restartService(nslcdService);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500295 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500296 catch (const InternalFailure& e)
297 {
298 throw;
299 }
300 catch (const std::exception& e)
301 {
302 log<level::ERR>(e.what());
303 elog<InternalFailure>();
304 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500305 return val;
306}
307
308ldap_base::Config::Type Config::lDAPType(ldap_base::Config::Type value)
309{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500310 ldap_base::Config::Type val;
311 try
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500312 {
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500313 if (value == lDAPType())
314 {
315 return value;
316 }
317
318 val = ConfigIface::lDAPType(value);
319 writeConfig();
320 parent.restartService(nslcdService);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500321 }
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500322 catch (const InternalFailure& e)
323 {
324 throw;
325 }
326 catch (const std::exception& e)
327 {
328 log<level::ERR>(e.what());
329 elog<InternalFailure>();
330 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500331 return val;
332}
333
334void ConfigMgr::restartService(const std::string& service)
335{
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500336 try
337 {
338 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
339 SYSTEMD_INTERFACE, "RestartUnit");
340 method.append(service.c_str(), "replace");
341 bus.call_noreply(method);
342 }
343 catch (const sdbusplus::exception::SdBusError& ex)
344 {
345 log<level::ERR>("Failed to restart nslcd service",
346 entry("ERR=%s", ex.what()));
347 elog<InternalFailure>();
348 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500349}
350
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -0500351void ConfigMgr::stopService(const std::string& service)
352{
353 try
354 {
355 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
356 SYSTEMD_INTERFACE, "StopUnit");
357 method.append(service.c_str(), "replace");
358 bus.call_noreply(method);
359 }
360 catch (const sdbusplus::exception::SdBusError& ex)
361 {
362 log<level::ERR>("Failed to stop nslcd service",
363 entry("ERR=%s", ex.what()));
364 elog<InternalFailure>();
365 }
366}
367
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -0500368void ConfigMgr::deleteObject()
369{
370 configPtr.reset(nullptr);
371}
372
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500373std::string
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600374 ConfigMgr::createConfig(std::string lDAPServerURI, std::string lDAPBindDN,
375 std::string lDAPBaseDN,
376 std::string lDAPBindDNPassword,
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500377 ldap_base::Create::SearchScope lDAPSearchScope,
378 ldap_base::Create::Type lDAPType)
379{
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600380 bool secureLDAP = false;
381
382 if (ldap_is_ldaps_url(lDAPServerURI.c_str()))
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500383 {
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600384 secureLDAP = true;
385 }
386 else if (ldap_is_ldap_url(lDAPServerURI.c_str()))
387 {
388 secureLDAP = false;
389 }
390 else
391 {
392 log<level::ERR>("bad LDAP Server URI",
393 entry("LDAPSERVERURI=%s", lDAPServerURI.c_str()));
Nagaraju Gorugantib26799a2018-09-28 13:12:19 -0500394 elog<InvalidArgument>(Argument::ARGUMENT_NAME("lDAPServerURI"),
395 Argument::ARGUMENT_VALUE(lDAPServerURI.c_str()));
396 }
397
398 if (lDAPBindDN.empty())
399 {
400 log<level::ERR>("Not a valid LDAP BINDDN"),
401 entry("LDAPBINDDN=%s", lDAPBindDN.c_str());
402 elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBindDN"),
403 Argument::ARGUMENT_VALUE(lDAPBindDN.c_str()));
404 }
405
406 if (lDAPBaseDN.empty())
407 {
408 log<level::ERR>("Not a valid LDAP BASEDN"),
409 entry("LDAPBASEDN=%s", lDAPBaseDN.c_str());
410 elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBaseDN"),
411 Argument::ARGUMENT_VALUE(lDAPBaseDN.c_str()));
412 }
413
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500414 // With current implementation we support only one LDAP server.
Nagaraju Goruganti24194bd2018-09-18 09:55:09 -0500415 deleteObject();
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -0500416 try
417 {
418 fs::copy_file(nsSwitchFile, linuxNsSwitchFile,
419 fs::copy_options::overwrite_existing);
420 fs::copy_file(LDAPNsSwitchFile, nsSwitchFile,
421 fs::copy_options::overwrite_existing);
422 }
423 catch (const std::exception& e)
424 {
425 log<level::ERR>("Failed to rename Config Files while creating Object",
426 entry("ERR=%s", e.what()));
427 elog<InternalFailure>();
428 }
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500429
430 auto objPath = std::string(LDAP_CONFIG_DBUS_OBJ_PATH);
431 configPtr = std::make_unique<Config>(
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600432 bus, objPath.c_str(), configFilePath.c_str(), secureLDAP, lDAPServerURI,
433 lDAPBindDN, lDAPBaseDN, std::move(lDAPBindDNPassword),
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500434 static_cast<ldap_base::Config::SearchScope>(lDAPSearchScope),
435 static_cast<ldap_base::Config::Type>(lDAPType), *this);
436
Nagaraju Gorugantidccee2b2018-09-25 08:51:06 -0500437 restartService(nslcdService);
438 restartService(nscdService);
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500439 return objPath;
440}
441
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500442void ConfigMgr::restore(const char* filePath)
443{
444 if (!fs::exists(filePath))
445 {
446 log<level::ERR>("Config file doesn't exists",
447 entry("LDAP_CONFIG_FILE=%s", LDAP_CONFIG_FILE));
448 return;
449 }
450
451 ConfigInfo configValues;
452
453 try
454 {
455 std::fstream stream(filePath, std::fstream::in);
456 Line line;
457 // read characters from stream and places them into line
458 while (std::getline(stream, line))
459 {
460 // remove leading and trailing extra spaces
461 auto firstScan = line.find_first_not_of(' ');
462 auto first =
463 (firstScan == std::string::npos ? line.length() : firstScan);
464 auto last = line.find_last_not_of(' ');
465 line = line.substr(first, last - first + 1);
466 // reduce multiple spaces between two words to a single space
467 auto pred = [](char a, char b) {
468 return (a == b && a == ' ') ? true : false;
469 };
470
471 auto lastPos = std::unique(line.begin(), line.end(), pred);
472
473 line.erase(lastPos, line.end());
474
475 // Ignore if line is empty or starts with '#'
476 if (line.empty() || line.at(0) == '#')
477 {
478 continue;
479 }
480
481 Key key;
482 std::istringstream isLine(line);
483 // extract characters from isLine and stores them into
484 // key until the delimitation character ' ' is found.
485 // If the delimiter is found, it is extracted and discarded
486 // the next input operation will begin after it.
487 if (std::getline(isLine, key, ' '))
488 {
489 Val value;
490 // extract characters after delimitation character ' '
491 if (std::getline(isLine, value, ' '))
492 {
493 // skip line if it starts with "base shadow" or
494 // "base passwd" because we would have 3 entries
495 // ("base lDAPBaseDN" , "base passwd lDAPBaseDN" and
496 // "base shadow lDAPBaseDN") for the property "lDAPBaseDN",
497 // one is enough to restore it.
498
499 if ((key == "base") &&
500 (value == "passwd" || value == "shadow"))
501 {
502 continue;
503 }
504 // skip the line if it starts with "map passwd".
505 // if config type is AD "map group" entry would be add to
506 // the map configValues. For OpenLdap config file no map
507 // entry would be there.
508 if ((key == "map") && (value == "passwd"))
509 {
510 continue;
511 }
512 configValues[key] = value;
513 }
514 }
515 }
516
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500517 ldap_base::Create::SearchScope lDAPSearchScope;
518 if (configValues["scope"] == "sub")
519 {
520 lDAPSearchScope = ldap_base::Create::SearchScope::sub;
521 }
522 else if (configValues["scope"] == "one")
523 {
524 lDAPSearchScope = ldap_base::Create::SearchScope::one;
525 }
526 else
527 {
528 lDAPSearchScope = ldap_base::Create::SearchScope::base;
529 }
530
531 ldap_base::Create::Type lDAPType;
532 // If the file is having a line which starts with "map group"
533 if (configValues["map"] == "group")
534 {
535 lDAPType = ldap_base::Create::Type::ActiveDirectory;
536 }
537 else
538 {
539 lDAPType = ldap_base::Create::Type::OpenLdap;
540 }
541
542 createConfig(
Nagaraju Gorugantidb60f582018-11-08 03:14:48 -0600543 std::move(configValues["uri"]), std::move(configValues["binddn"]),
544 std::move(configValues["base"]), std::move(configValues["bindpw"]),
545 lDAPSearchScope, lDAPType);
Nagaraju Gorugantif1940d92018-09-18 05:05:50 -0500546 }
547 catch (const InvalidArgument& e)
548 {
549 // Don't throw - we don't want to create a D-Bus
550 // object upon finding empty values in config, as
551 // this can be a default config.
552 }
553 catch (const InternalFailure& e)
554 {
555 throw;
556 }
557 catch (const std::exception& e)
558 {
559 log<level::ERR>(e.what());
560 elog<InternalFailure>();
561 }
562}
Nagaraju Goruganti997f5e02018-08-30 03:05:11 -0500563} // namespace ldap
564} // namespace phosphor