Skip to content

Commit b01e2fe

Browse files
committed
Enable encoding object paths of User Name
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
1 parent ce89bfc commit b01e2fe

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

test/user_mgr_test.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class TestUserMgr : public testing::Test
3333
std::vector<std::string> groupNames,
3434
const std::string& priv, bool enabled)
3535
{
36-
std::string userObj = std::string(usersObjPath) + "/" + userName;
36+
sdbusplus::message::object_path tempObjPath(usersObjPath);
37+
tempObjPath /= userName;
38+
std::string userObj(tempObjPath);
3739
mockManager.usersList.emplace(
3840
userName, std::move(std::make_unique<phosphor::user::Users>(
3941
mockManager.bus, userObj.c_str(), groupNames, priv,

user_mgr.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ void UserMgr::createUser(std::string userName,
334334
}
335335

336336
// Add the users object before sending out the signal
337-
std::string userObj = std::string(usersObjPath) + "/" + userName;
337+
sdbusplus::message::object_path tempObjPath(usersObjPath);
338+
tempObjPath /= userName;
339+
std::string userObj(tempObjPath);
338340
std::sort(groupNames.begin(), groupNames.end());
339341
usersList.emplace(
340342
userName, std::move(std::make_unique<phosphor::user::Users>(
@@ -392,7 +394,9 @@ void UserMgr::renameUser(std::string userName, std::string newUserName)
392394
std::string priv = user.get()->userPrivilege();
393395
std::vector<std::string> groupNames = user.get()->userGroups();
394396
bool enabled = user.get()->userEnabled();
395-
std::string newUserObj = std::string(usersObjPath) + "/" + newUserName;
397+
sdbusplus::message::object_path tempObjPath(usersObjPath);
398+
tempObjPath /= newUserName;
399+
std::string newUserObj(tempObjPath);
396400
// Special group 'ipmi' needs a way to identify user renamed, in order to
397401
// update encrypted password. It can't rely only on InterfacesRemoved &
398402
// InterfacesAdded. So first send out userRenamed signal.
@@ -1159,7 +1163,9 @@ void UserMgr::initUserObjects(void)
11591163
}
11601164
}
11611165
// Add user objects to the Users path.
1162-
auto objPath = std::string(usersObjPath) + "/" + user;
1166+
sdbusplus::message::object_path tempObjPath(usersObjPath);
1167+
tempObjPath /= user;
1168+
std::string objPath(tempObjPath);
11631169
std::sort(userGroups.begin(), userGroups.end());
11641170
usersList.emplace(user,
11651171
std::move(std::make_unique<phosphor::user::Users>(

users.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Users::Users(sdbusplus::bus::bus& bus, const char* path,
6262
std::vector<std::string> groups, std::string priv, bool enabled,
6363
UserMgr& parent) :
6464
Interfaces(bus, path, true),
65-
userName(std::filesystem::path(path).filename()), manager(parent)
65+
userName(sdbusplus::message::object_path(path).filename()), manager(parent)
6666
{
6767
UsersIface::userPrivilege(priv, true);
6868
UsersIface::userGroups(groups, true);

0 commit comments

Comments
 (0)