From patchwork Fri Mar 23 11:34:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 889916 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=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4071gH6dyVz9s0q for ; Fri, 23 Mar 2018 22:35:22 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C206F3E6AA8 for ; Fri, 23 Mar 2018 12:35:18 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 24A7E3E662C for ; Fri, 23 Mar 2018 12:35:17 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 591731000C6D for ; Fri, 23 Mar 2018 12:35:13 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38103681" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2018 19:35:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 0119848AE76A for ; Fri, 23 Mar 2018 19:34:59 +0800 (CST) Received: from localhost.localdomain (10.167.220.182) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 19:34:58 +0800 From: yang xu To: Date: Fri, 23 Mar 2018 19:34:48 +0800 Message-ID: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.182] X-yoursite-MailScanner-ID: 0119848AE76A.ABC72 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.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-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() 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: yang xu --- include/old/safe_macros.h | 6 ++++++ include/safe_macros_fn.h | 8 ++++++++ include/tst_safe_macros.h | 6 ++++++ lib/safe_macros.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/include/old/safe_macros.h b/include/old/safe_macros.h index e778d30..ad611f7 100644 --- a/include/old/safe_macros.h +++ b/include/old/safe_macros.h @@ -82,6 +82,12 @@ #define SAFE_SETUID(cleanup_fn, uid) \ safe_setuid(__FILE__, __LINE__, cleanup_fn, (uid)) +#define SAFE_SETREGID(rgid, egid) \ + safe_setregid(__FILE__, __LINE__, NULL, (rgid), (egid)) + +#define SAFE_SETREUID(ruid, euid) \ + safe_setreuid(__FILE__, __LINE__, NULL, (ruid), (euid)) + #define SAFE_GETRESUID(cleanup_fn, ruid, euid, suid) \ safe_getresuid(__FILE__, __LINE__, cleanup_fn, (ruid), (euid), (suid)) diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h index 3df9528..001f45c 100644 --- a/include/safe_macros_fn.h +++ b/include/safe_macros_fn.h @@ -83,6 +83,14 @@ int safe_setgid(const char *file, const int lineno, int safe_setuid(const char *file, const int lineno, void (*cleanup_fn)(void), uid_t uid); +int safe_setregid(const char *file, const int lineno, + void (*cleanup_fn)(void), + gid_t rgid, gid_t egid); + +int safe_setreuid(const char *file, const int lineno, + void (*cleanup_fn)(void), + uid_t ruid, uid_t euid); + int safe_getresuid(const char *file, const int lineno, void (*cleanup_fn)(void), uid_t *ruid, uid_t *euid, uid_t *suid); diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index f115a7b..e378c40 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -109,6 +109,12 @@ static inline int safe_dup(const char *file, const int lineno, #define SAFE_SETUID(uid) \ safe_setuid(__FILE__, __LINE__, NULL, (uid)) +#define SAFE_SETREGID(rgid, egid) \ + safe_setregid(__FILE__, __LINE__, NULL, (rgid), (egid)) + +#define SAFE_SETREUID(ruid, euid) \ + safe_setreuid(__FILE__, __LINE__, NULL, (ruid), (euid)) + #define SAFE_GETRESUID(ruid, euid, suid) \ safe_getresuid(__FILE__, __LINE__, NULL, (ruid), (euid), (suid)) diff --git a/lib/safe_macros.c b/lib/safe_macros.c index abdeca0..0cf3a5f 100644 --- a/lib/safe_macros.c +++ b/lib/safe_macros.c @@ -318,6 +318,38 @@ int safe_setuid(const char *file, const int lineno, void (*cleanup_fn) (void), return rval; } +int safe_setregid(const char *file, const int lineno, void (*cleanup_fn)(void), + gid_t rgid, gid_t egid) +{ + int rval; + + rval = setregid(rgid, egid); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: setregid(%p, %p) failed", + file, lineno, rgid, egid); + } + + return rval; +} + + +int safe_setreuid(const char *file, const int lineno, void (*cleanup_fn)(void), + uid_t ruid, uid_t euid) +{ + int rval; + + rval = setreuid(ruid, euid); + if (rval == -1) { + tst_brkm(TBROK | TERRNO, cleanup_fn, + "%s:%d: setreuid(%p, %p) failed", + file, lineno, ruid, euid); + } + + return rval; +} + + int safe_getresuid(const char *file, const int lineno, void (*cleanup_fn)(void), uid_t *ruid, uid_t *euid, uid_t *suid) { From patchwork Fri Mar 23 11:34:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 889918 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 4071gR2tggz9s0q for ; Fri, 23 Mar 2018 22:35:31 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C0E343E7046 for ; Fri, 23 Mar 2018 12:35:28 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 6F7ED3E706F for ; Fri, 23 Mar 2018 12:35:25 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 211DB20152A for ; Fri, 23 Mar 2018 12:35:20 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38103680" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2018 19:35:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 8C61D4D0EFF3 for ; Fri, 23 Mar 2018 19:34:59 +0800 (CST) Received: from localhost.localdomain (10.167.220.182) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 19:34:59 +0800 From: yang xu To: Date: Fri, 23 Mar 2018 19:34:49 +0800 Message-ID: <1521804892-5783-2-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> References: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.182] X-yoursite-MailScanner-ID: 8C61D4D0EFF3.A1888 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.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-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 2/5] syscalls/mkdir01, 03: Cleanup && Convert to new API 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" 1) Take use of some safe macros 2) Remove duplicate tests mkdir01 3) Use tst_get_bad_addr to get a bad addr Signed-off-by: yang xu --- testcases/kernel/syscalls/mkdir/mkdir01.c | 203 ------------------------------ testcases/kernel/syscalls/mkdir/mkdir03.c | 32 ++--- 2 files changed, 12 insertions(+), 223 deletions(-) delete mode 100644 testcases/kernel/syscalls/mkdir/mkdir01.c diff --git a/testcases/kernel/syscalls/mkdir/mkdir01.c b/testcases/kernel/syscalls/mkdir/mkdir01.c deleted file mode 100644 index 84012c0..0000000 --- a/testcases/kernel/syscalls/mkdir/mkdir01.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * - */ -/* $Id: mkdir01.c,v 1.7 2009/03/23 13:35:54 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : mkdir01 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic errno test for mkdir(2) - * - * PARENT DOCUMENT : mkstds02 - * - * TEST CASE TOTAL : 2 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : Bill Branum - * - * CO-PILOT : Kathy Olmsted - * - * DATE STARTED : 4/15/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * mkdir(2) test for errno(s) EFAULT. - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * DETAILED DESCRIPTION - * This test will verify that mkdir(2) returns a value of - * -1 and sets errno to EFAULT when the path argument points - * outside (above/below) the allocated address space of the - * process. - * - * Setup: - * Setup signal handling. - * Create and make current a temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno. - * If doing functional test - * check the errno returned and print result message - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Remove the temporary directory. - * Exit. - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "test.h" - -void setup(); -void cleanup(); - -char *TCID = "mkdir01"; -int TST_TOTAL = 1; - -char *bad_addr = 0; - -int main(int ac, char **av) -{ - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * TEST CASE: 1 - * mkdir() call with pointer below allocated address space. - */ - - /* Call mkdir(2) */ - TEST(mkdir(bad_addr, 0777)); - - /* check return code */ - if (TEST_RETURN == -1) { - } - - if (TEST_RETURN == -1) { - if (TEST_ERRNO == EFAULT) { - tst_resm(TPASS, - "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s", - TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, - "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)", - TEST_ERRNO, - strerror(TEST_ERRNO), EFAULT); - } - } else { - tst_resm(TFAIL, - "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); - - } - - } - - cleanup(); - tst_exit(); -} - -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - - bad_addr = tst_get_bad_addr(cleanup); -} - -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); - - /* - * Exit with return code appropriate for results. - */ - -} diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c index 5d7f1e1..9441afe 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir03.c +++ b/testcases/kernel/syscalls/mkdir/mkdir03.c @@ -46,20 +46,18 @@ static char long_dir[PATH_MAX + 2] = {[0 ... PATH_MAX + 1] = 'a'}; static char loop_dir[PATH_MAX] = "."; struct tcase; -static void prot_none_pathname(struct tcase *tc); static struct tcase { char *pathname; int exp_errno; - void (*setupfunc)(struct tcase *tc); } TC[] = { - {NULL, EFAULT, prot_none_pathname}, - {long_dir, ENAMETOOLONG, NULL}, - {TST_EEXIST, EEXIST, NULL}, - {TST_ENOENT, ENOENT, NULL}, - {TST_ENOTDIR_DIR, ENOTDIR, NULL}, - {loop_dir, ELOOP, NULL}, - {TST_EROFS, EROFS, NULL}, + {NULL, EFAULT}, + {long_dir, ENAMETOOLONG}, + {TST_EEXIST, EEXIST}, + {TST_ENOENT, ENOENT}, + {TST_ENOTDIR_DIR, ENOTDIR}, + {loop_dir, ELOOP}, + {TST_EROFS, EROFS}, }; static void verify_mkdir(unsigned int n) @@ -82,12 +80,6 @@ static void verify_mkdir(unsigned int n) } } -static void prot_none_pathname(struct tcase *tc) -{ - tc->pathname = SAFE_MMAP(0, 1, PROT_NONE, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); -} - static void setup(void) { unsigned int i; @@ -95,15 +87,15 @@ static void setup(void) SAFE_TOUCH(TST_EEXIST, MODE, NULL); SAFE_TOUCH(TST_ENOTDIR_FILE, MODE, NULL); + for (i = 0; i < ARRAY_SIZE(TC); i++) { + if (TC[i].exp_errno == EFAULT) + TC[i].pathname = tst_get_bad_addr(NULL); + } + SAFE_MKDIR("test_eloop", DIR_MODE); SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop"); for (i = 0; i < 43; i++) strcat(loop_dir, "/test_eloop"); - - for (i = 0; i < ARRAY_SIZE(TC); i++) { - if (TC[i].setupfunc) - TC[i].setupfunc(&TC[i]); - } } static struct tst_test test = { From patchwork Fri Mar 23 11:34:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 889920 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 4071gZ13zJz9s0q for ; Fri, 23 Mar 2018 22:35:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2DBE03E662D for ; Fri, 23 Mar 2018 12:35:35 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id D1B2C3E7061 for ; Fri, 23 Mar 2018 12:35:27 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 59FBB207B64 for ; Fri, 23 Mar 2018 12:35:24 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38103684" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2018 19:35:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 47A2D48AE76B for ; Fri, 23 Mar 2018 19:35:00 +0800 (CST) Received: from localhost.localdomain (10.167.220.182) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 19:35:00 +0800 From: yang xu To: Date: Fri, 23 Mar 2018 19:34:50 +0800 Message-ID: <1521804892-5783-3-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> References: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.182] X-yoursite-MailScanner-ID: 47A2D48AE76B.AD736 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.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-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 3/5] syscalls/mkdir02: Cleanup && Convert to new API 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" 1) Take use of some safe macros 2 Remove temporary directory in loops Signed-off-by: yang xu --- testcases/kernel/syscalls/mkdir/mkdir02.c | 384 ++++++++---------------------- 1 file changed, 99 insertions(+), 285 deletions(-) diff --git a/testcases/kernel/syscalls/mkdir/mkdir02.c b/testcases/kernel/syscalls/mkdir/mkdir02.c index 87d1345..63e6f3f 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir02.c +++ b/testcases/kernel/syscalls/mkdir/mkdir02.c @@ -1,345 +1,159 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -/* - * NAME - * mkdir02 - * - * DESCRIPTION - * This test will verify that new directory created - * by mkdir(2) inherites the group ID from the parent - * directory and S_ISGID bit, if the S_ISGID bit is set - * in the parent directory. - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * Create temporary directory. - * Give write permission on temporary directory for all users. - * set up umask - * - * Test: - * Loop if the proper options are given. - * fork the first child as ltpuser1 - * create a directory tstdir1 with S_ISGID set - * fork the second child as ltpuser2 - * create a directtory tstdir2 user tstdir1 - * check tstdir2's group ID and the S_ISGID bit - * if they are the same as tstdir1's - * PASS - * else FAIL - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created.* - * USAGE - * mkdir02 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. +/* DESCRIPTION + * This test will verify that new directory created by mkdir(2) inherites + * the group ID from the parent directory and S_ISGID bit, if the S_ISGID + * bit is set in the parent directory. */ #include -#include -#include #include #include -#include #include #include #include +#include +#include "tst_test.h" -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); - -#define PERMS 0777 +#define PERMS 0777 +#define TESTDIR1 "testdir1" +#define TESTDIR2 "testdir1/testdir2" static uid_t nobody_uid, bin_uid; static gid_t nobody_gid, bin_gid; -char *TCID = "mkdir02"; -int TST_TOTAL = 1; - -char tstdir1[100]; -char tstdir2[100]; - -int main(int ac, char **av) +static void verify_mkdir(void) { - int lc; struct stat buf, buf1; pid_t pid, pid1; - int rval, status; + int status; - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); + /* check the inherited group ID */ /* - * perform global setup for test - */ - setup(); + * first, fork the first child, set to ltpuser1's uid and gid, + * create a directory, with S_ISGID bit set + */ - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { + pid = SAFE_FORK(); + if (pid == 0) { - tst_count = 0; + SAFE_SETREGID(nobody_gid, nobody_gid); - /* check the inherited group ID */ + /* being ltupuser1 */ + SAFE_SETREUID(nobody_uid, nobody_uid); - /* - * first, fork the first child, set to ltpuser1's uid and gid, - * create a directory, with S_ISGID bit set + /* create a direcoty with S_ISGID bit set + * and the group ID is ltpuser1 */ + SAFE_MKDIR(TESTDIR1, PERMS); - sprintf(tstdir1, "tstdir1.%d", getpid()); + SAFE_STAT(TESTDIR1, &buf1); - if ((pid = FORK_OR_VFORK()) < 0) { - tst_brkm(TFAIL, cleanup, "fork() failed"); + SAFE_CHMOD(TESTDIR1, buf1.st_mode | S_ISGID); - } + /* Successfully create the parent directory */ + exit(0); - if (pid == 0) { /* first child */ - rval = setregid(nobody_gid, nobody_gid); - if (rval < 0) { - perror("setregid"); - tst_resm(TFAIL, "setregid failed to " - "to set the real gid to %d and " - "effective gid to %d", - nobody_gid, nobody_gid); - exit(1); - - } - /* being ltupuser1 */ - rval = setreuid(nobody_uid, nobody_uid); - if (rval < 0) { - perror("setreuid"); - tst_resm(TFAIL, "setreuid failed to " - "to set the real uid to %d and " - "effective uid to %d", - nobody_uid, nobody_uid); - exit(1); - - } - - /* - * create a direcoty with S_ISGID bit set - * and the group ID is ltpuser1 - */ - if (mkdir(tstdir1, PERMS) != 0) { - perror("mkdir"); - tst_resm(TFAIL, "mkdir() failed to create" - " a directory with Set " - " group ID turn on "); - exit(1); - - } - if (stat(tstdir1, &buf1) == -1) { - perror("stat"); - tst_resm(TFAIL, - "failed to stat the new directory" - "in mkdir()"); - exit(1); - - } - if (chmod(tstdir1, buf1.st_mode | S_ISGID) != 0) { - perror("chmod"); - tst_resm(TFAIL, "failed to set S_ISGID bit"); - exit(1); - - } - - /* Successfully create the parent directory */ - exit(0); + } - } - wait(&status); - if (WEXITSTATUS(status) != 0) { - tst_brkm(TFAIL, cleanup, - "Test to attempt to make a directory" - " inherits group ID FAILED "); - } + SAFE_WAITPID(pid, &status, 0); + if (WEXITSTATUS(status) != 0) { + tst_brk(TFAIL, "Test to attempt to make a directory" + " inherits group ID FAILED "); + } + + /* + * fork the second child process, set to ltpuser2's uid and gid + * create a sub directory under the directory + * just created by child process 1 + * check the group ID of the sub directory + * should inherit from parent directory + */ + + pid1 = SAFE_FORK(); + if (pid1 == 0) { + + /* being user ltpuser2 */ + SAFE_SETREGID(bin_gid, bin_gid); + + SAFE_SETREUID(bin_uid, bin_uid); + + SAFE_MKDIR(TESTDIR2, PERMS); /* - * fork the second child process, set to ltpuser2's uid and gid - * create a sub directory under the directory - * just created by child process 1 - * check the group ID of the sub directory - * should inherit from parent directory + * check the group ID + * should not be the same as the current processs's + * since parent directory is set with S_ISGID bit */ + SAFE_STAT(TESTDIR2, &buf); - sprintf(tstdir2, "%s/tstdir2.%d", tstdir1, getpid()); - if ((pid1 = FORK_OR_VFORK()) < 0) { - perror("fork failed"); - tst_brkm(TFAIL, cleanup, "fork() failed"); - - } else if (pid1 == 0) { /* second child */ - - /* being user ltpuser2 */ - rval = setregid(bin_gid, bin_gid); - if (rval < 0) { - tst_resm(TFAIL, "setregid failed to " - "to set the real gid to %d and " - "effective gid to %d", - bin_gid, bin_gid); - perror("setregid"); - exit(1); - - } - rval = setreuid(bin_uid, bin_uid); - if (rval < 0) { - tst_resm(TFAIL, "setreuid failed to " - "to set the real uid to %d and " - "effective uid to %d", - bin_uid, bin_uid); - perror("setreuid"); - exit(1); - - } - - /* - * create a sub direcoty - * under the directory just created - * by ltpuser1 - */ - if (mkdir(tstdir2, PERMS) != 0) { - tst_resm(TFAIL, "mkdir() failed to create" - " a directory %s under %s ", tstdir2, - tstdir1); - exit(1); - - } - /* - * check the group ID - * should not be the same as the current processs's - * since parent directory is set with S_ISGID bit - */ - if (stat(tstdir2, &buf) == -1) { - tst_resm(TFAIL, - "failed to stat the new directory" - "in mkdir()"); - exit(1); - - } - if (stat(tstdir1, &buf1) == -1) { - tst_resm(TFAIL, - "failed to stat the new directory" - "in mkdir()"); - exit(1); - - } - if (buf.st_gid != buf1.st_gid) { - tst_resm(TFAIL, "mkdir() FAILED to inherit " - " the group ID %d from parent " - " directory %d", - buf.st_gid, buf1.st_gid); - exit(1); - - } - - /* check the S_ISGID bit */ - if (!(buf.st_mode & S_ISGID)) { - tst_resm(TFAIL, "mkdir() FAILED to inherit " - " the S_ISGID bit from parent " - " directory"); - exit(1); - - } - /* PASS */ - exit(0); + SAFE_STAT(TESTDIR1, &buf1); + if (buf.st_gid != buf1.st_gid) { + tst_res(TFAIL, "mkdir() FAILED to inherit the group ID" + " %d from parent directory %d", + buf.st_gid, buf1.st_gid); + exit(1); } - waitpid(pid1, &status, 0); - if (WEXITSTATUS(status) == 0) { - tst_resm(TPASS, "Test to attempt to make a directory" - " inherits group ID SUCCEEDED "); - } else { - tst_resm(TFAIL, "Test to attempt to make a directory" - " inherits group ID FAILED"); - cleanup(); + if (!(buf.st_mode & S_ISGID)) { + tst_res(TFAIL, "mkdir() FAILED to inherit " + " the S_ISGID bit from parent directory"); + exit(1); } + exit(0); + } - /* - * cleanup and exit - */ - cleanup(); + SAFE_WAITPID(pid1, &status, 0); + if (WEXITSTATUS(status) == 0) { + tst_res(TPASS, "Test to attempt to make a directory" + " inherits group ID SUCCEEDED"); + } else { + tst_res(TFAIL, "Test to attempt to make a directory" + " inherits group ID FAILED"); + } - tst_exit(); + /* rmdir() TESTDIR1 TESTDIR2 for loop test*/ + SAFE_RMDIR(TESTDIR2); + SAFE_RMDIR(TESTDIR1); } -/* - * setup() - performs all ONE TIME setup for this test. - */ + void setup(void) { struct passwd *pw; - tst_require_root(); - - pw = SAFE_GETPWNAM(NULL, "nobody"); + pw = SAFE_GETPWNAM("nobody"); nobody_uid = pw->pw_uid; nobody_gid = pw->pw_gid; - pw = SAFE_GETPWNAM(NULL, "bin"); + pw = SAFE_GETPWNAM("bin"); bin_uid = pw->pw_uid; bin_gid = pw->pw_gid; - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - umask(0); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); - - /* - * Exit with return code appropriate for results. - */ - -} +static struct tst_test test = { + .setup = setup, + .needs_tmpdir = 1, + .needs_root = 1, + .test_all = verify_mkdir, + .forks_child = 1, +}; From patchwork Fri Mar 23 11:34:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 889919 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=2001:1418:10:5::2; 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 [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4071gW1lDwz9s0q for ; Fri, 23 Mar 2018 22:35:35 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5BB643E7098 for ; Fri, 23 Mar 2018 12:35:32 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id E710E3E705B for ; Fri, 23 Mar 2018 12:35:26 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id B7F7010019D3 for ; Fri, 23 Mar 2018 12:35:24 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38103682" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2018 19:35:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 0207348AE76C for ; Fri, 23 Mar 2018 19:35:01 +0800 (CST) Received: from localhost.localdomain (10.167.220.182) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 19:35:00 +0800 From: yang xu To: Date: Fri, 23 Mar 2018 19:34:51 +0800 Message-ID: <1521804892-5783-4-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> References: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.182] X-yoursite-MailScanner-ID: 0207348AE76C.AA76C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.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-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 4/5] syscalls/mkdir04: Cleanup && Convert to new API 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" 1) Take use of some safe macros 2 Remove temporary directory in loop Signed-off-by: yang xu --- testcases/kernel/syscalls/mkdir/mkdir04.c | 275 +++++++++--------------------- 1 file changed, 78 insertions(+), 197 deletions(-) diff --git a/testcases/kernel/syscalls/mkdir/mkdir04.c b/testcases/kernel/syscalls/mkdir/mkdir04.c index 3e0d199..562f784 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir04.c +++ b/testcases/kernel/syscalls/mkdir/mkdir04.c @@ -1,241 +1,122 @@ -/* +/* Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -/* - * NAME - * mkdir04 - * - * DESCRIPTION - * - * ALGORITHM - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * Create temporary directory. - * - * Test: - * Loop if the proper options are given. - * fork the first child - * set to be ltpuser1 - * create a dirctory tstdir1 with 0700 permission - * fork the second child - * set to ltpuser2 - * try to create a subdirectory tstdir2 under tstdir1 - * check the returnvalue, if succeeded (return=0) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the errno - * if equals to EACCES, - * Issue Pass message. - * Otherwise, - * Issue Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * USAGE - * mkdir04 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None. - * +/* DESCRIPTION + * fork the first child + * set to be ltpuser1 + * create a dirctory TESTDIR with 0700 permission + * fork the second child + * set to ltpuser2 + * try to create a subdirectory TESTDIR1 under tstdir1 + * check the returnvalue, if succeeded (return=0) + * Log the errno and Issue a FAIL message. + * Otherwise, + * Verify the errno + * if equals to EACCES, + * Issue Pass message. + * Otherwise, + * Issue Fail message. */ #include -#include -#include #include #include -#include #include #include #include - -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); -int fail; +#include +#include "tst_test.h" #define PERMS 0700 +#define TESTDIR "testdir" +#define TESTDIR1 "testdir/testfile" static uid_t nobody_uid, bin_uid; -char *TCID = "mkdir04"; -int TST_TOTAL = 1; -int fail; - -char tstdir1[100]; -char tstdir2[100]; - -int main(int ac, char **av) +static void verify_mkdir(void) { - int lc; - int rval; - pid_t pid, pid1; int status; + pid_t pid, pid1; - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; + pid = SAFE_FORK(); + if (pid == 0) { + SAFE_SETREUID(nobody_uid, nobody_uid); - /* Initialize the test directories name */ - sprintf(tstdir1, "tstdir1.%d", getpid()); - if ((pid = FORK_OR_VFORK()) < 0) { - tst_brkm(TBROK, cleanup, "fork #1 failed"); + if (mkdir(TESTDIR, PERMS) == -1) { + tst_res(TFAIL | TERRNO, "mkdir(%s, %#o) Failed", + TESTDIR, PERMS); + exit(1); } - if (pid == 0) { /* first child */ - rval = setreuid(nobody_uid, nobody_uid); - if (rval < 0) { - tst_resm(TFAIL | TERRNO, "setreuid failed to " - "to set the real uid to %d and " - "effective uid to %d", - nobody_uid, nobody_uid); - exit(1); - } - /* create the parent directory with 0700 permits */ - if (mkdir(tstdir1, PERMS) == -1) { - tst_resm(TFAIL | TERRNO, - "mkdir(%s, %#o) Failed", - tstdir1, PERMS); - exit(1); - } - /* create tstdir1 succeeded */ - exit(0); - } - wait(&status); - if (WEXITSTATUS(status) != 0) { - tst_brkm(TFAIL, cleanup, - "Test to check mkdir EACCES failed" - "in create parent directory"); - } + exit(0); + } - sprintf(tstdir2, "%s/tst", tstdir1); + SAFE_WAITPID(pid, &status, 0); + if (WEXITSTATUS(status) != 0) { + tst_brk(TFAIL, "Test to check mkdir EACCES failed" + "in create parent directory"); + } - if ((pid1 = FORK_OR_VFORK()) < 0) { - tst_brkm(TBROK, cleanup, "fork #2 failed"); - } + pid1 = SAFE_FORK(); + if (pid1 == 0) { + SAFE_SETREUID(bin_uid, bin_uid); - if (pid1 == 0) { /* second child */ - rval = setreuid(bin_uid, bin_uid); - if (rval < 0) { - tst_resm(TFAIL | TERRNO, "setreuid failed to " - "to set the real uid to %d and " - "effective uid to %d", - bin_uid, bin_uid); - exit(1); - } - if (mkdir(tstdir2, PERMS) != -1) { - tst_resm(TFAIL, "mkdir(%s, %#o) unexpected " - "succeeded", tstdir2, PERMS); - exit(1); - } - if (errno != EACCES) { - tst_resm(TFAIL, "Expected EACCES got %d", - errno); - exit(1); - } - /* PASS */ - exit(0); + if (mkdir(TESTDIR1, PERMS) != -1) { + tst_res(TFAIL, "mkdir(%s, %#o) unexpected " + "succeeded", TESTDIR1, PERMS); + exit(1); } - waitpid(pid1, &status, 0); - if (WEXITSTATUS(status) == 0) { - tst_resm(TPASS, "Test to attempt to creat a directory " - "in a directory having no permissions " - "SUCCEEDED in setting errno to EACCES"); - } else { - tst_resm(TFAIL, "Test to attempt to creat a directory " - "in a directory having no permissions FAILED"); - cleanup(); + if (errno != EACCES) { + tst_res(TFAIL, "Expected EACCES got %d", errno); + exit(1); } + + exit(0); } - /* - * cleanup and exit - */ - cleanup(); - tst_exit(); + SAFE_WAITPID(pid1, &status, 0); + if (WEXITSTATUS(status) == 0) { + tst_res(TPASS, "Test to attempt to creat a directory " + "in a directory having no permissions " + "SUCCEEDED in setting errno to EACCES"); + } else { + tst_brk(TFAIL, "Test to attempt to creat a directory " + "in a directory having no permissions FAILED"); + } + /* rmdir() TESTDIR for loop test*/ + SAFE_RMDIR(TESTDIR); } -/* - * setup() - performs all ONE TIME setup for this test. - */ void setup(void) { struct passwd *pw; - tst_require_root(); - - pw = SAFE_GETPWNAM(NULL, "nobody"); + pw = SAFE_GETPWNAM("nobody"); nobody_uid = pw->pw_uid; - pw = SAFE_GETPWNAM(NULL, "bin"); + pw = SAFE_GETPWNAM("bin"); bin_uid = pw->pw_uid; - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Create a temporary directory and make it current. */ - tst_tmpdir(); - umask(0); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - /* - * Remove the temporary directory. - */ - tst_rmdir(); - - /* - * Exit with return code appropriate for results. - */ - -} +static struct tst_test test = { + .test_all = verify_mkdir, + .needs_tmpdir = 1, + .needs_root = 1, + .setup = setup, + .forks_child = 1, +}; From patchwork Fri Mar 23 11:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang xu X-Patchwork-Id: 889917 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 4071gM6P0Gz9s1B for ; Fri, 23 Mar 2018 22:35:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8B0CB3E7032 for ; Fri, 23 Mar 2018 12:35:24 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 399813E662D for ; Fri, 23 Mar 2018 12:35:23 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id E95081000DF2 for ; Fri, 23 Mar 2018 12:35:17 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38103683" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Mar 2018 19:35:03 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id AC39448AE76D for ; Fri, 23 Mar 2018 19:35:01 +0800 (CST) Received: from localhost.localdomain (10.167.220.182) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 19:35:01 +0800 From: yang xu To: Date: Fri, 23 Mar 2018 19:34:52 +0800 Message-ID: <1521804892-5783-5-git-send-email-xuyang.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> References: <1521804892-5783-1-git-send-email-xuyang.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.182] X-yoursite-MailScanner-ID: AC39448AE76D.AEE2C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang.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-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 5/5] syscalls/mkdir05, 08: Cleanup && Convert to new API 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" 1) Take use of some safe macros 2) Remove duplicate tests mkdir08 Signed-off-by: yang xu --- testcases/kernel/syscalls/mkdir/mkdir05.c | 147 ++++++---------------- testcases/kernel/syscalls/mkdir/mkdir08.c | 196 ------------------------------ 2 files changed, 38 insertions(+), 305 deletions(-) delete mode 100644 testcases/kernel/syscalls/mkdir/mkdir08.c diff --git a/testcases/kernel/syscalls/mkdir/mkdir05.c b/testcases/kernel/syscalls/mkdir/mkdir05.c index 3d25c43..d5ae930 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir05.c +++ b/testcases/kernel/syscalls/mkdir/mkdir05.c @@ -1,6 +1,5 @@ -/* - * Copyright (c) International Business Machines Corp., 2001 - * 07/2001 Ported by Wayne Boyer +/* Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,137 +12,67 @@ * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program. If not, see . */ -/* - * DESCRIPTION - * This test will verify the mkdir(2) syscall basic functionality +/* DESCRIPTION + * This test will verify the mkdir(2) creates a new directory successfully and + * it is owned by the effective group ID of the process. */ #include -#include -#include #include #include -#include #include #include -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); +#include "tst_test.h" #define PERMS 0777 +#define TESTDIR "testdir" -char *TCID = "mkdir05"; -int TST_TOTAL = 1; - -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -char tstdir1[100]; - -int main(int ac, char **av) +static void verify_mkdir(void) { - int lc; struct stat buf; - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * TEST mkdir() base functionality - */ - - /* Initialize the test directory name */ - sprintf(tstdir1, "tstdir1.%d", getpid()); - - /* Call mkdir(2) using the TEST macro */ - TEST(mkdir(tstdir1, PERMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "mkdir(%s, %#o) Failed", - tstdir1, PERMS); - continue; - } - - SAFE_STAT(cleanup, tstdir1, &buf); - /* check the owner */ - if (buf.st_uid != geteuid()) { - tst_resm(TFAIL, "mkdir() FAILED to set owner ID" - " as process's effective ID"); - continue; - } - /* check the group ID */ - if (buf.st_gid != getegid()) { - tst_resm(TFAIL, "mkdir() failed to set group ID" - " as the process's group ID"); - continue; - } - tst_resm(TPASS, "mkdir() functionality is correct"); - - /* clean up things in case we are looping */ - SAFE_RMDIR(cleanup, tstdir1); - + TEST(mkdir(TESTDIR, PERMS)); + if (TEST_RETURN == -1) { + tst_res(TFAIL | TTERRNO, "mkdir() Failed"); + return; } - cleanup(); - tst_exit(); -} - -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) -{ - tst_require_root(); + SAFE_STAT(TESTDIR, &buf); - ltpuser = getpwnam(nobody_uid); - if (setuid(ltpuser->pw_uid) == -1) { - tst_resm(TINFO, "setuid failed to " - "to set the effective uid to %d", ltpuser->pw_uid); - perror("setuid"); + if (buf.st_uid != geteuid()) { + tst_res(TFAIL, "mkdir() FAILED to set owner ID " + "as process's effective ID"); + return; } - tst_sig(FORK, DEF_HANDLER, cleanup); + if (buf.st_gid != getegid()) { + tst_res(TFAIL, "mkdir() failed to set group ID " + "as the process's group ID"); + return; + } - TEST_PAUSE; + tst_res(TPASS, "mkdir() functionality is correct"); - /* Create a temporary directory and make it current. */ - tst_tmpdir(); + SAFE_RMDIR(TESTDIR); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +void setup(void) { + struct passwd *pw; + static uid_t nobody_uid; - /* - * Remove the temporary directory. - */ - tst_rmdir(); - - /* - * Exit with return code appropriate for results. - */ + pw = SAFE_GETPWNAM("nobody"); + nobody_uid = pw->pw_uid; + SAFE_SETUID(nobody_uid); } + +static struct tst_test test = { + .test_all = verify_mkdir, + .needs_tmpdir = 1, + .needs_root = 1, + .setup = setup, +}; diff --git a/testcases/kernel/syscalls/mkdir/mkdir08.c b/testcases/kernel/syscalls/mkdir/mkdir08.c deleted file mode 100644 index ead218a..0000000 --- a/testcases/kernel/syscalls/mkdir/mkdir08.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * - */ -/* $Id: mkdir08.c,v 1.6 2009/11/02 13:57:17 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : mkdir08 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for mkdir(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) mkdir(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the mkdir(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * mkdir(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" - -void setup(); -void cleanup(); - -char *TCID = "mkdir08"; -int TST_TOTAL = 1; - -char fname[255]; - -int main(int ac, char **av) -{ - int lc; - - /*************************************************************** - * parse standard options - ***************************************************************/ - tst_parse_opts(ac, av, NULL, NULL); - - /*************************************************************** - * perform global setup for test - ***************************************************************/ - setup(); - - /*************************************************************** - * check looping state if -c option given - ***************************************************************/ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call mkdir(2) - */ - TEST(mkdir(fname, 0777)); - - /* check return code */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "mkdir(%s) Failed, errno=%d : %s", - fname, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TPASS, "mkdir(%s) returned %ld", fname, - TEST_RETURN); - SAFE_RMDIR(cleanup, fname); - } - - } - - cleanup(); - tst_exit(); -} - -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - sprintf(fname, "./dir_%d", getpid()); -} - -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) -{ - - tst_rmdir(); - -}