From patchwork Fri Mar 16 07:12:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 886629 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 402cBL1fj8z9sMl for ; Fri, 16 Mar 2018 18:13:27 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 44ACE3E6E3D for ; Fri, 16 Mar 2018 08:13:25 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 183D93E6D99 for ; Fri, 16 Mar 2018 08:13:22 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 55D801A0120F for ; Fri, 16 Mar 2018 08:13:19 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="37874288" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Mar 2018 15:13:06 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id D59A248AE762 for ; Fri, 16 Mar 2018 15:13:06 +0800 (CST) Received: from localhost.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 16 Mar 2018 15:13:06 +0800 From: Jinhui Huang To: Date: Fri, 16 Mar 2018 15:12:56 +0800 Message-ID: <1521184376-3649-2-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1521184376-3649-1-git-send-email-huangjh.jy@cn.fujitsu.com> References: <1521184376-3649-1-git-send-email-huangjh.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: D59A248AE762.AF050 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] Make use of SAFE_GETGRNAM() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Jinhui Huang --- testcases/kernel/syscalls/chmod/chmod05.c | 4 +--- testcases/kernel/syscalls/chmod/chmod07.c | 3 +-- testcases/kernel/syscalls/creat/creat08.c | 16 +++++----------- testcases/kernel/syscalls/fchmod/fchmod02.c | 4 +--- testcases/kernel/syscalls/fchmod/fchmod05.c | 5 +---- testcases/kernel/syscalls/open/open10.c | 14 ++++---------- testcases/kernel/syscalls/setregid/setregid02.c | 5 +---- testcases/kernel/syscalls/setregid/setregid03.c | 5 +---- testcases/kernel/syscalls/setregid/setregid04.c | 6 ++---- 9 files changed, 17 insertions(+), 45 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c index 3cf4db5..c3bea4e 100644 --- a/testcases/kernel/syscalls/chmod/chmod05.c +++ b/testcases/kernel/syscalls/chmod/chmod05.c @@ -187,9 +187,7 @@ void setup(void) tst_brkm(TBROK | TERRNO, cleanup, "getpwnam(\"nobody\") failed"); - bin_group = getgrnam("bin"); - if (bin_group == NULL) - tst_brkm(TBROK | TERRNO, cleanup, "getgrnam(\"bin\") failed"); + bin_group = SAFE_GETGRNAM(cleanup, "bin"); /* * Create a test directory under temporary directory with specified diff --git a/testcases/kernel/syscalls/chmod/chmod07.c b/testcases/kernel/syscalls/chmod/chmod07.c index 6a39388..ae52b21 100644 --- a/testcases/kernel/syscalls/chmod/chmod07.c +++ b/testcases/kernel/syscalls/chmod/chmod07.c @@ -174,8 +174,7 @@ void setup(void) user1_uid = ltpuser->pw_uid; /* Get the group id of guest user - ltpuser1 */ - if ((ltpgroup = getgrnam(LTPGRP)) == NULL) - tst_brkm(TBROK, cleanup, "getgrnam failed"); + ltpgroup = SAFE_GETGRNAM(cleanup, LTPGRP); group1_gid = ltpgroup->gr_gid; fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE); diff --git a/testcases/kernel/syscalls/creat/creat08.c b/testcases/kernel/syscalls/creat/creat08.c index 50f2b39..377dff1 100644 --- a/testcases/kernel/syscalls/creat/creat08.c +++ b/testcases/kernel/syscalls/creat/creat08.c @@ -119,18 +119,12 @@ int main(int ac, char **av) /* * Get the group IDs of group1 and group2. */ - if ((group = getgrnam("nobody")) == NULL) { - if ((group = getgrnam("nogroup")) == NULL) { - tst_brkm(TBROK | TERRNO, cleanup, - "getgrnam(\"nobody\") and " - "getgrnam(\"nogroup\") failed"); - } - } + group = getgrnam("nobody"); + if (group == NULL) + group = SAFE_GETGRNAM(cleanup, "nogroup"); + group1_gid = group->gr_gid; - if ((group = getgrnam("bin")) == NULL) { - tst_brkm(TBROK | TERRNO, cleanup, - "getgrnam(\"bin\") failed"); - } + group = SAFE_GETGRNAM(cleanup, "bin"); group2_gid = group->gr_gid; /*--------------------------------------------------------------*/ diff --git a/testcases/kernel/syscalls/fchmod/fchmod02.c b/testcases/kernel/syscalls/fchmod/fchmod02.c index ea2bdb4..f9f8ab3 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod02.c +++ b/testcases/kernel/syscalls/fchmod/fchmod02.c @@ -177,9 +177,7 @@ void setup(void) user1_uid = ltpuser->pw_uid; /* Get the group id of guest user - ltpuser1 */ - if ((ltpgroup = getgrnam(LTPGRP)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/group", LTPGRP); - } + ltpgroup = SAFE_GETGRNAM(cleanup, LTPGRP); group1_gid = ltpgroup->gr_gid; /* diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c index cdd3d07..93b4fc5 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod05.c +++ b/testcases/kernel/syscalls/fchmod/fchmod05.c @@ -178,10 +178,7 @@ void setup(void) tst_brkm(TBROK, cleanup, "Couldn't find uid of nobody: %s", strerror(errno)); - bin_group = getgrnam("bin"); - if (!bin_group) - tst_brkm(TBROK, cleanup, - "Couldn't find gid of bin: %s", strerror(errno)); + bin_group = SAFE_GETGRNAM(cleanup, "bin"); /* * Create a test directory under temporary directory with specified diff --git a/testcases/kernel/syscalls/open/open10.c b/testcases/kernel/syscalls/open/open10.c index 613f228..2c1a588 100644 --- a/testcases/kernel/syscalls/open/open10.c +++ b/testcases/kernel/syscalls/open/open10.c @@ -42,6 +42,7 @@ #include #include #include "test.h" +#include "safe_macros.h" char *TCID = "open10"; int TST_TOTAL = 1; @@ -106,18 +107,11 @@ int main(int ac, char *av[]) * Get the group IDs of group1 and group2. */ group = getgrnam("nobody"); - if (group == NULL) { - group = getgrnam("nogroup"); - if (group == NULL) { - tst_brkm(TBROK, cleanup, - "nobody/nogroup not in /etc/group"); - } - } - group1_gid = group->gr_gid; - group = getgrnam("bin"); if (group == NULL) - tst_brkm(TBROK, cleanup, "bin not in /etc/group"); + group = SAFE_GETGRNAM(cleanup, "nogroup"); + group1_gid = group->gr_gid; + group = SAFE_GETGRNAM(cleanup, "bin"); group2_gid = group->gr_gid; /* diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index 21d1c82..d7e141d 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -148,10 +148,7 @@ static void setup(void) static struct group get_group_by_name(const char *name) { - struct group *ret = getgrnam(name); - - if (ret == NULL) - tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", name); + struct group *ret = SAFE_GETGRNAM(NULL, name); GID16_CHECK(ret->gr_gid, setregid, NULL); diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c index a51719e..6cadee5 100644 --- a/testcases/kernel/syscalls/setregid/setregid03.c +++ b/testcases/kernel/syscalls/setregid/setregid03.c @@ -186,10 +186,7 @@ static void setup(void) nobody = *(getpwnam("nobody")); #define GET_GID(group) do { \ - junk = getgrnam(#group); \ - if (junk == NULL) { \ - tst_brkm(TBROK, NULL, "%s must be a valid group", #group); \ - } \ + junk = SAFE_GETGRNAM(NULL, #group); \ GID16_CHECK(junk->gr_gid, setregid, NULL); \ group = *(junk); \ } while (0) diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c index 0e0aae7..71f3c8b 100644 --- a/testcases/kernel/syscalls/setregid/setregid04.c +++ b/testcases/kernel/syscalls/setregid/setregid04.c @@ -30,6 +30,7 @@ #include "test.h" #include "compat_16.h" +#include "safe_macros.h" TCID_DEFINE(setregid04); @@ -111,10 +112,7 @@ int main(int ac, char **av) } #define SAFE_GETGROUP(GROUPNAME) \ - if (getgrnam(#GROUPNAME) == NULL) { \ - tst_brkm(TBROK, NULL, "Couldn't find the `" #GROUPNAME "' group"); \ - } \ - GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); + GROUPNAME ## _gr = *(SAFE_GETGRNAM(NULL, #GROUPNAME)); static void setup(void) {