Hi,

On our systems, root belongs to only one group. getgroups01 has this
result:

getgroups01    1  TPASS  :  getgroups failed as expected with EINVAL
getgroups01    2  TPASS  :  getgroups did not modify the gidset array
getgroups01    3  TCONF  :  getgroups01.c:129: getgroups returned 1; unable to 
test that using ngrps >=1 but less than number of grps
getgroups01    4  TPASS  :  getgroups(NGROUPS,gidset) returned 1 contains gid 0 
(from getgid)

Looks like we can set supplementary groups by setgroups() in setup(),
then 3# will succeed if running as privileged user. If we call
setgroups(), then initgroups() can be left out. With this patch, when
running as root:

getgroups01    1  TPASS  :  getgroups failed as expected with EINVAL
getgroups01    2  TPASS  :  getgroups did not modify the gidset array
getgroups01    3  TPASS  :  getgroups failed as expected with EINVAL
getgroups01    4  TPASS  :  getgroups(NGROUPS,gidset) returned 3 contains gid 0 
(from getgid)

running as unprivileged user:

getgroups01    1  TPASS  :  getgroups failed as expected with EINVAL
getgroups01    2  TPASS  :  getgroups did not modify the gidset array
getgroups01    3  TCONF  :  getgroups01.c:127: getgroups returned 1; unable to 
test that using ngrps >=1 but less than number of grps
getgroups01    4  TPASS  :  getgroups(NGROUPS,gidset) returned 1 contains gid 
1001 (from getgid)


>From caf7b59519b0f9323805aae9d6a607a30ea3ba4e Mon Sep 17 00:00:00 2001
From: Han Pingtian <ha...@linux.vnet.ibm.com>
Date: Thu, 4 Dec 2014 16:07:25 +0800
Subject: [PATCH] set supplementary groups instead of relying on system setting

On a system where root belongs to only one group, the 3# test of
getgroups01 will fail by TCONF. But if we call setgroups() to set
supplementary groups, the test can succeed if run as privileged user.

With this patch, it'll still fail by TCONF when being run by
unprivileged user.

Signed-off-by: Han Pingtian <ha...@linux.vnet.ibm.com>
---
 testcases/kernel/syscalls/getgroups/getgroups01.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/getgroups/getgroups01.c 
b/testcases/kernel/syscalls/getgroups/getgroups01.c
index 9fb4c98..28559d3 100644
--- a/testcases/kernel/syscalls/getgroups/getgroups01.c
+++ b/testcases/kernel/syscalls/getgroups/getgroups01.c
@@ -74,8 +74,6 @@ int main(int ac, char **av)
        int i;
        int entries;
 
-       initgroups("root", 0);
-
        if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
                tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
@@ -183,6 +181,9 @@ static void setup(void)
        tst_sig(FORK, DEF_HANDLER, cleanup);
 
        TEST_PAUSE;
+
+       GID_T init_gidset[3] = {0, 1, 2};
+       setgroups(3, init_gidset);
 }
 
 static void cleanup(void)
-- 
1.9.3


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to