Enable encoding/decoding object paths

Any string used to form a Dbus object path needs to be encoded.
This commit enables encoding the User Name before using it in the
Object path and enables decoding while converting it back to User
Name to display to the user.
This commit replaces string computation of User Name with
object_path.filename() function which decodes and gives the User
Name string.

Tested:
 - ipmitool user set name "_test_123"
 - Successfully created /xyz/openbmc_project/user/_test_123
   Object Path
 - ipmitool user list 3
   Displayed the user _test_123

 - busctl call xyz.openbmc_project.User.Manager
   /xyz/openbmc_project/user xyz.openbmc_project.User.Manager
   CreateUser sassb _test_6566 4 "ipmi" "redfish" "ssh" "web"
   priv-admin true
 - Successfully created /xyz/openbmc_project/user/test_6566
   Object Path
 - ipmitool user list 3
   Displayed "_teste66" which implies successfull decode of
   object path.

Signed-off-by: P Dheeraj Srujan Kumar <p.dheeraj.srujan.kumar@intel.com>
Change-Id: I75d479cfa4888c5db31ae551bdcc504106bf25fa
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp
index b36a2e6..2459de7 100644
--- a/user_channel/user_mgmt.cpp
+++ b/user_channel/user_mgmt.cpp
@@ -199,13 +199,8 @@
 
 int getUserNameFromPath(const std::string& path, std::string& userName)
 {
-    constexpr size_t length = strlen(userObjBasePath);
-    if (((length + 1) >= path.size()) ||
-        path.compare(0, length, userObjBasePath))
-    {
-        return -EINVAL;
-    }
-    userName.assign(path, length + 1, path.size());
+    sdbusplus::message::object_path objPath(path);
+    userName.assign(objPath.filename());
     return 0;
 }
 
@@ -595,7 +590,10 @@
         return false;
     }
 
-    std::string usersPath = std::string(userObjBasePath) + "/" + userName;
+    sdbusplus::message::object_path tempUserPath(userObjBasePath);
+    tempUserPath /= userName;
+    std::string usersPath(tempUserPath);
+
     if (properties.find(usersPath) != properties.end())
     {
         log<level::DEBUG>("User name already exists",
@@ -816,7 +814,9 @@
     }
     if (userInfo->userEnabled != enabledState)
     {
-        std::string userPath = std::string(userObjBasePath) + "/" + userName;
+        sdbusplus::message::object_path tempUserPath(userObjBasePath);
+        tempUserPath /= userName;
+        std::string userPath(tempUserPath);
         setDbusProperty(bus, getUserServiceName(), userPath, usersInterface,
                         userEnabledProperty, enabledState);
         userInfo->userEnabled = enabledState;
@@ -916,7 +916,9 @@
     if (chNum == syncIndex &&
         privAccess.privilege != userInfo->userPrivAccess[syncIndex].privilege)
     {
-        std::string userPath = std::string(userObjBasePath) + "/" + userName;
+        sdbusplus::message::object_path tempUserPath(userObjBasePath);
+        tempUserPath /= userName;
+        std::string userPath(tempUserPath);
         setDbusProperty(bus, getUserServiceName(), userPath, usersInterface,
                         userPrivProperty, priv);
     }
@@ -1024,7 +1026,9 @@
     if (userName.empty() && !oldUser.empty())
     {
         // Delete existing user
-        std::string userPath = std::string(userObjBasePath) + "/" + oldUser;
+        sdbusplus::message::object_path tempUserPath(userObjBasePath);
+        tempUserPath /= oldUser;
+        std::string userPath(tempUserPath);
         try
         {
             auto method = bus.new_method_call(
@@ -1692,8 +1696,9 @@
             std::string userName(
                 reinterpret_cast<char*>(userData->user[usrIdx].userName), 0,
                 ipmiMaxUserName);
-            std::string usersPath =
-                std::string(userObjBasePath) + "/" + userName;
+            sdbusplus::message::object_path tempUserPath(userObjBasePath);
+            tempUserPath /= userName;
+            std::string usersPath(tempUserPath);
 
             auto usrObj = managedObjs.find(usersPath);
             if (usrObj != managedObjs.end())