From patchwork Tue Oct 6 13:42:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuriy Kolerov X-Patchwork-Id: 526774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id 97896140082 for ; Wed, 7 Oct 2015 00:42:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 5B18488C1A; Tue, 6 Oct 2015 13:42:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id auldYGwV5Zvn; Tue, 6 Oct 2015 13:42:36 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 69FF988ADC; Tue, 6 Oct 2015 13:42:36 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 84F0E1C10DA for ; Tue, 6 Oct 2015 13:42:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7F27191016 for ; Tue, 6 Oct 2015 13:42:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l9jhakqAgwke for ; Tue, 6 Oct 2015 13:42:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtprelay.synopsys.com (us01smtprelay-2.synopsys.com [198.182.60.111]) by whitealder.osuosl.org (Postfix) with ESMTPS id 3801691001 for ; Tue, 6 Oct 2015 13:42:34 +0000 (UTC) Received: from us02secmta1.synopsys.com (us02secmta1.synopsys.com [10.12.235.96]) by smtprelay.synopsys.com (Postfix) with ESMTP id B1FEB10C1661; Tue, 6 Oct 2015 06:42:33 -0700 (PDT) Received: from us02secmta1.internal.synopsys.com (us02secmta1.internal.synopsys.com [127.0.0.1]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id 8B7664E216; Tue, 6 Oct 2015 06:42:33 -0700 (PDT) Received: from mailhost.synopsys.com (unknown [10.13.184.66]) by us02secmta1.internal.synopsys.com (Service) with ESMTP id 521DA4E202; Tue, 6 Oct 2015 06:42:33 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 3B858180; Tue, 6 Oct 2015 06:42:33 -0700 (PDT) Received: from ykolerov-lab.internal.synopsys.com (ykolerov-lab.internal.synopsys.com [10.121.8.82]) by mailhost.synopsys.com (Postfix) with ESMTP id A513C17C; Tue, 6 Oct 2015 06:42:31 -0700 (PDT) From: Yuriy Kolerov To: uclibc@uclibc.org Subject: [LTP] [PATCH v2] syscalls/setregid02: Fix retrieving a group of user "nobody" Date: Tue, 6 Oct 2015 16:42:23 +0300 Message-Id: <1444138943-12185-1-git-send-email-yuriy.kolerov@synopsys.com> X-Mailer: git-send-email 2.2.0 MIME-Version: 1.0 Cc: Vineet.Gupta1@synopsys.com, Alexey.Brodkin@synopsys.com, chrubis@suse.cz X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" In setup this test sets UID and GID of the user "nobody". Then it expects that user "nobody" is in group "nobody" and tries to retrive a structure for group "nobody" using getgrnam(). However some Linux distributions use group "nogroup" for user "nobody". Thus it's necessary to retrieve a group of user "nobody" not by hardcoded name but by its GID. It's necessary because group "nobody" may not exist. I've replaced a variable "nobody" by more generic "ltpgroup". Then I've created 2 functions get_group_by_name and get_group_by_gid which are used instead of GET_GID macros. On my test system I have user "nobody" in group "nogroup". So I've got this error messages for this test: ----------->8---------- setregid02.c:160: getgrnam("nobody") failed: errno=SUCCESS(0): Success setregid02.c:160: Remaining cases broken ----------->8---------- Signed-off-by: Yuriy Kolerov --- testcases/kernel/syscalls/setregid/setregid02.c | 53 +++++++++++++++---------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index 5d4d044..9b233d5 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -40,7 +40,7 @@ static gid_t neg_one = -1; static struct passwd *ltpuser; -static struct group nobody, root, bin; +static struct group ltpgroup, root, bin, *junk; /* * The following structure contains all test data. Each structure in the array @@ -56,17 +56,17 @@ struct test_data_t { char *test_msg; } test_data[] = { { - &neg_one, &root.gr_gid, EPERM, &nobody, &nobody, + &neg_one, &root.gr_gid, EPERM, <pgroup, <pgroup, "After setregid(-1, root),"}, { - &neg_one, &bin.gr_gid, EPERM, &nobody, &nobody, + &neg_one, &bin.gr_gid, EPERM, <pgroup, <pgroup, "After setregid(-1, bin)"}, { - &root.gr_gid, &neg_one, EPERM, &nobody, &nobody, + &root.gr_gid, &neg_one, EPERM, <pgroup, <pgroup, "After setregid(root,-1),"}, { - &bin.gr_gid, &neg_one, EPERM, &nobody, &nobody, + &bin.gr_gid, &neg_one, EPERM, <pgroup, <pgroup, "After setregid(bin, -1),"}, { - &root.gr_gid, &bin.gr_gid, EPERM, &nobody, &nobody, + &root.gr_gid, &bin.gr_gid, EPERM, <pgroup, <pgroup, "After setregid(root, bin)"}, { - &bin.gr_gid, &root.gr_gid, EPERM, &nobody, &nobody, + &bin.gr_gid, &root.gr_gid, EPERM, <pgroup, <pgroup, "After setregid(bin, root),"} }; @@ -75,6 +75,8 @@ int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); static void setup(void); static void cleanup(void); static void gid_verify(struct group *ru, struct group *eu, char *when); +static struct group get_group_by_name(const char *name); +static struct group get_group_by_gid(gid_t gid); int main(int ac, char **av) { @@ -126,8 +128,6 @@ int main(int ac, char **av) static void setup(void) { - struct group *junk; - tst_require_root(); tst_sig(FORK, DEF_HANDLER, cleanup); @@ -147,22 +147,33 @@ static void setup(void) ltpuser->pw_uid); } -#define GET_GID(group) do { \ - junk = getgrnam(#group); \ - if (junk == NULL) { \ - tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", #group); \ - } \ - GID16_CHECK(junk->gr_gid, setregid, NULL); \ - group = *(junk); \ -} while (0) - - GET_GID(root); - GET_GID(nobody); - GET_GID(bin); + root = get_group_by_name("root"); + ltpgroup = get_group_by_gid(ltpuser->pw_gid); + bin = get_group_by_name("bin"); TEST_PAUSE; } +static struct group get_group_by_name(const char *name) +{ + junk = getgrnam(name); + if (junk == NULL) { + tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", name); + } + GID16_CHECK(junk->gr_gid, setregid, NULL); + return *junk; +} + +static struct group get_group_by_gid(gid_t gid) +{ + junk = getgrgid(gid); + if (junk == NULL) { + tst_brkm(TBROK|TERRNO, NULL, "getgrgid(\"%d\") failed", gid); + } + GID16_CHECK(junk->gr_gid, setregid, NULL); + return *junk; +} + static void cleanup(void) { }