Skip to content

Commit

Permalink
Enable encoding object paths of User Name
Browse files Browse the repository at this point in the history
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.
This commit also replaces the old method of
std::filesystem::path(path).filename() with object_path.filename()
which correctly decodes and gets the User name from the Object
path.

Tested:
 - 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/_5ftest_5f6566
   Object Path
 - ipmitool user list 3
   Displayed "_5ftest_5f6566" (Due to Absence of Decoding in
   phosphor-host-ipmid)
   With the changes in ipmid at https://gerrit.openbmc-project.xyz
   /c/openbmc/phosphor-host-ipmid/+/49621 this name will be
   correctly decoded to _test_6566.

 - ipmitool user set name "_test_123"
 - Successfully created /xyz/openbmc_project/user/_5ftest_5f123
   Object Path
 - ipmitool user list 3
   Displayed the user _test_123 (Due to Absence of Decoding in
   phosphor-host-ipmid)

 - busctl call xyz.openbmc_project.User.Manager
   /xyz/openbmc_project/user xyz.openbmc_project.User.Manager
   RenameUser ss _test_6566 _test_7576
 - Successfully created /xyz/openbmc_project/user/_5ftest_5f7576
   Object Path
 - ipmitool user list 3
   Displayed "_5ftest_5f7576" (Due to Absence of Decoding in
   phosphor-host-ipmid)

Signed-off-by: P Dheeraj Srujan Kumar <[email protected]>
Change-Id: If39bdc74b67fa1931ea451d3cb5befa77daee83c
  • Loading branch information
dheerajpdsk committed Dec 23, 2021
1 parent ce89bfc commit b01e2fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion test/user_mgr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class TestUserMgr : public testing::Test
std::vector<std::string> groupNames,
const std::string& priv, bool enabled)
{
std::string userObj = std::string(usersObjPath) + "/" + userName;
sdbusplus::message::object_path tempObjPath(usersObjPath);
tempObjPath /= userName;
std::string userObj(tempObjPath);
mockManager.usersList.emplace(
userName, std::move(std::make_unique<phosphor::user::Users>(
mockManager.bus, userObj.c_str(), groupNames, priv,
Expand Down
12 changes: 9 additions & 3 deletions user_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ void UserMgr::createUser(std::string userName,
}

// Add the users object before sending out the signal
std::string userObj = std::string(usersObjPath) + "/" + userName;
sdbusplus::message::object_path tempObjPath(usersObjPath);
tempObjPath /= userName;
std::string userObj(tempObjPath);
std::sort(groupNames.begin(), groupNames.end());
usersList.emplace(
userName, std::move(std::make_unique<phosphor::user::Users>(
Expand Down Expand Up @@ -392,7 +394,9 @@ void UserMgr::renameUser(std::string userName, std::string newUserName)
std::string priv = user.get()->userPrivilege();
std::vector<std::string> groupNames = user.get()->userGroups();
bool enabled = user.get()->userEnabled();
std::string newUserObj = std::string(usersObjPath) + "/" + newUserName;
sdbusplus::message::object_path tempObjPath(usersObjPath);
tempObjPath /= newUserName;
std::string newUserObj(tempObjPath);
// Special group 'ipmi' needs a way to identify user renamed, in order to
// update encrypted password. It can't rely only on InterfacesRemoved &
// InterfacesAdded. So first send out userRenamed signal.
Expand Down Expand Up @@ -1159,7 +1163,9 @@ void UserMgr::initUserObjects(void)
}
}
// Add user objects to the Users path.
auto objPath = std::string(usersObjPath) + "/" + user;
sdbusplus::message::object_path tempObjPath(usersObjPath);
tempObjPath /= user;
std::string objPath(tempObjPath);
std::sort(userGroups.begin(), userGroups.end());
usersList.emplace(user,
std::move(std::make_unique<phosphor::user::Users>(
Expand Down
2 changes: 1 addition & 1 deletion users.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Users::Users(sdbusplus::bus::bus& bus, const char* path,
std::vector<std::string> groups, std::string priv, bool enabled,
UserMgr& parent) :
Interfaces(bus, path, true),
userName(std::filesystem::path(path).filename()), manager(parent)
userName(sdbusplus::message::object_path(path).filename()), manager(parent)
{
UsersIface::userPrivilege(priv, true);
UsersIface::userGroups(groups, true);
Expand Down

0 comments on commit b01e2fe

Please sign in to comment.