summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-09-27 14:22:42 +0530
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-10-01 20:01:51 -0400
commit2cb2e7208e512de2cc6be5361ec6aed480079eb4 (patch)
treefa9d08f3dd45801b49392175f62342b6463f8f81
parent9f630d9eb0ce1c103532a4304ea080066199094e (diff)
downloadphosphor-user-manager-2cb2e7208e512de2cc6be5361ec6aed480079eb4.tar.gz
phosphor-user-manager-2cb2e7208e512de2cc6be5361ec6aed480079eb4.zip
Handle empty privilege condition
This fixes issue, which may end up adding "," in the groups list, when privilege is empty. Allow adding privilege to the groups list only when it is not empty Change-Id: I42607c4835547eda4989f85521148a2716bedcb6 Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
-rw-r--r--user_mgr.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/user_mgr.cpp b/user_mgr.cpp
index 3987088..ebed493 100644
--- a/user_mgr.cpp
+++ b/user_mgr.cpp
@@ -263,12 +263,14 @@ void UserMgr::createUser(std::string userName,
// treat privilege as a group - This is to avoid using different file to
// store the same.
- if (groups.size() != 0)
+ if (!priv.empty())
{
- groups += ",";
+ if (groups.size() != 0)
+ {
+ groups += ",";
+ }
+ groups += priv;
}
- groups += priv;
-
try
{
executeCmd("/usr/sbin/useradd", userName.c_str(), "-G", groups.c_str(),
@@ -381,11 +383,14 @@ void UserMgr::updateGroupsAndPriv(const std::string &userName,
// treat privilege as a group - This is to avoid using different file to
// store the same.
- if (groups.size() != 0)
+ if (!priv.empty())
{
- groups += ",";
+ if (groups.size() != 0)
+ {
+ groups += ",";
+ }
+ groups += priv;
}
- groups += priv;
try
{
executeCmd("/usr/sbin/usermod", userName.c_str(), "-G", groups.c_str(),
OpenPOWER on IntegriCloud