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: 12a2bda3eb9a9f72946220c1e3199302e2c3884d (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
From c0bf911cbc33659adddebde767029ffc23251c61 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] 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>
---
 user_service.cpp | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/user_service.cpp b/user_service.cpp
index c3c45bd..4fdf7a1 100644
--- a/user_service.cpp
+++ b/user_service.cpp
@@ -143,28 +143,24 @@ 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::split(usersInGroup, output[0],
+                                    boost::algorithm::is_any_of(" "));
         }
         return usersInGroup;
     }
-- 
2.7.4