From 2cb2e7208e512de2cc6be5361ec6aed480079eb4 Mon Sep 17 00:00:00 2001 From: Richard Marian Thomaiyar Date: Thu, 27 Sep 2018 14:22:42 +0530 Subject: 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 --- user_mgr.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'user_mgr.cpp') 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(), -- cgit v1.2.1