summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/users/phosphor-user-manager/0006-Use-groupmems-instead-of-getgrnam_r-due-to-overlay.patch
blob: 7a0eff80ee13a01a1636ca528037a4145e31dc93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 06064b3d6e56f4e13e6b85552f8525b74d9f1931 Mon Sep 17 00:00:00 2001
From: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Date: Mon, 24 Feb 2020 13:37:12 +0530
Subject: [PATCH 2/2] Use groupmems instead of getgrnam_r due to overlay

With JFFS2 overlay, getgrnam_r during initial time returns the
old group details as per the lower dir, instead of the overlay one
but at the same time groupmems where returning proper values, which
reads the file everytime. Hence replacing getgrnam_r with groupmems

Tested:
1. Verified that when added multiple user and then doing
BMC reset using ipmitool raw 6 2 doesn't reproduce the issue of
user with only ssh group. (on 38 version source + this fix)
2. Updated using redfish to version 39 + this fix, and made sure
issue doesn't happen.

Note: For testing purpose added debug statements to dump ouput of
both getgrnam_r & groupmems and able to see proper list only
in groupmems when the issue is reproduced

Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Signed-off-by: jayaprakash Mutyala <mutyalax.jayaprakash@intel.com>
---
 user_service.cpp | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/user_service.cpp b/user_service.cpp
index ad4e510..89b27ed 100644
--- a/user_service.cpp
+++ b/user_service.cpp
@@ -147,28 +147,26 @@ class ShadowService : public phosphor::user::UserServiceInterface
         getUsersInGroup(const std::string& groupName) const override
     {
         std::vector<std::string> usersInGroup;
-        // Should be more than enough to get the pwd structure.
-        std::array<char, 4096> buffer{};
-        struct group grp;
-        struct group* grpPtr = &grp;
-        struct group* resultPtr;
-
-        int status = getgrnam_r(groupName.c_str(), grpPtr, buffer.data(),
-                                buffer.max_size(), &resultPtr);
-
-        if (!status && (grpPtr == resultPtr))
+        std::vector<std::string> output;
+        try
         {
-            for (; *(grp.gr_mem) != NULL; ++(grp.gr_mem))
-            {
-                usersInGroup.emplace_back(*(grp.gr_mem));
-            }
+            output = phosphor::user::executeCmd("/usr/sbin/groupmems", "-l",
+                                                "-g", groupName.c_str());
         }
-        else
+        catch (const phosphor::user::InternalFailure& e)
         {
             phosphor::logging::log<phosphor::logging::level::ERR>(
                 "Group not found",
                 phosphor::logging::entry("GROUP=%s", groupName.c_str()));
             // Don't throw error, just return empty usersInGroup - fallback
+            return usersInGroup;
+        }
+        if (!output.empty())
+        {
+            boost::algorithm::trim_right(output[0]);
+            boost::algorithm::split(usersInGroup, output[0],
+                                    boost::algorithm::is_any_of("\t "),
+                                    boost::token_compress_on);
         }
         return usersInGroup;
     }
-- 
2.17.1