User Mgr: Update GetUserInfo to read ldap user privilege

Without this fix privilege mapping was fetched from the standalone
mapper application. Now with the recent changes privilege
mapping is part of the config object itself.

This fix is to address that change.

TestedBy:
1.Added privilege mapper for ldap user and
then GetUserInfo for ldap user and verified
if privilege is correct.
2.Created local user and verified local user info
through GetUserInfo and check privilege.

Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
Change-Id: Ie149cc1ef46370a899aa8312ce17448b6c00c0e9
diff --git a/user_mgr.cpp b/user_mgr.cpp
index 47edf7d..183afbe 100644
--- a/user_mgr.cpp
+++ b/user_mgr.cpp
@@ -831,12 +831,11 @@
     DbusUserObj objects;
     try
     {
-        std::string basePath = "/xyz/openbmc_project/user/ldap";
-        std::string interface = "xyz.openbmc_project.User.PrivilegeMapper";
+        std::string basePath = "/xyz/openbmc_project/user/ldap/openldap";
+        std::string interface = "xyz.openbmc_project.User.Ldap.Config";
 
         auto ldapMgmtService =
             getServiceName(std::move(basePath), std::move(interface));
-
         auto method = bus.new_method_call(
             ldapMgmtService.c_str(), ldapMgrObjBasePath,
             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
@@ -964,39 +963,74 @@
 
         std::string privilege;
         std::string groupName;
+        std::string ldapConfigPath;
 
         try
         {
-            for (const auto &objpath : objects)
+            for (const auto &obj : objects)
             {
-                auto iter = objpath.second.find(
-                    "xyz.openbmc_project.User.PrivilegeMapperEntry");
-                if (iter == objpath.second.end())
+                for (const auto &interface : obj.second)
                 {
-                    log<level::ERR>(
-                        "Error in finding privilege mapper entry interface");
-                    elog<InternalFailure>();
+                    if ((interface.first ==
+                         "xyz.openbmc_project.Object.Enable"))
+                    {
+                        for (const auto &property : interface.second)
+                        {
+                            auto value =
+                                sdbusplus::message::variant_ns::get<bool>(
+                                    property.second);
+                            if ((property.first == "Enabled") &&
+                                (value == true))
+                            {
+                                ldapConfigPath = obj.first;
+                                break;
+                            }
+                        }
+                    }
                 }
-                for (const auto &property : iter->second)
+                if (!ldapConfigPath.empty())
                 {
-                    auto value =
-                        sdbusplus::message::variant_ns::get<std::string>(
-                            property.second);
-                    if (property.first == "GroupName")
+                    break;
+                }
+            }
+
+            if (ldapConfigPath.empty())
+            {
+                return userInfo;
+            }
+
+            for (const auto &obj : objects)
+            {
+                for (const auto &interface : obj.second)
+                {
+                    if ((interface.first ==
+                         "xyz.openbmc_project.User.PrivilegeMapperEntry") &&
+                        (obj.first.str.find(ldapConfigPath) !=
+                         std::string::npos))
                     {
-                        groupName = value;
-                    }
-                    else if (property.first == "Privilege")
-                    {
-                        privilege = value;
-                    }
-                    if (groupName == ldapGroupName)
-                    {
-                        userInfo["UserPrivilege"] = privilege;
+
+                        for (const auto &property : interface.second)
+                        {
+                            auto value = sdbusplus::message::variant_ns::get<
+                                std::string>(property.second);
+                            if (property.first == "GroupName")
+                            {
+                                groupName = value;
+                            }
+                            else if (property.first == "Privilege")
+                            {
+                                privilege = value;
+                            }
+                            if (groupName == ldapGroupName)
+                            {
+                                userInfo["UserPrivilege"] = privilege;
+                            }
+                        }
                     }
                 }
             }
             auto priv = std::get<std::string>(userInfo["UserPrivilege"]);
+
             if (priv.empty())
             {
                 log<level::ERR>("LDAP group privilege mapping does not exist");