* [LTP] [PATCH 2/5] syscalls/mkdir01, 03: Cleanup && Convert to new API
2018-03-23 11:34 [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() yang xu
@ 2018-03-23 11:34 ` yang xu
2018-04-17 14:39 ` Cyril Hrubis
2018-03-23 11:34 ` [LTP] [PATCH 3/5] syscalls/mkdir02: " yang xu
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: yang xu @ 2018-03-23 11:34 UTC (permalink / raw)
To: 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 <xuyang.jy@cn.fujitsu.com>
---
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 <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <unistd.h>
-#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 = {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH 3/5] syscalls/mkdir02: Cleanup && Convert to new API
2018-03-23 11:34 [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() yang xu
2018-03-23 11:34 ` [LTP] [PATCH 2/5] syscalls/mkdir01, 03: Cleanup && Convert to new API yang xu
@ 2018-03-23 11:34 ` yang xu
2018-04-18 12:14 ` Cyril Hrubis
2018-03-23 11:34 ` [LTP] [PATCH 4/5] syscalls/mkdir04: " yang xu
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: yang xu @ 2018-03-23 11:34 UTC (permalink / raw)
To: ltp
1) Take use of some safe macros
2 Remove temporary directory in loops
Signed-off-by: yang xu <xuyang.jy@cn.fujitsu.com>
---
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 <http://www.gnu.org/licenses/>.
*/
-/*
- * 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 <errno.h>
-#include <string.h>
-#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
#include <pwd.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <stdlib.h>
+#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,
+};
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH 4/5] syscalls/mkdir04: Cleanup && Convert to new API
2018-03-23 11:34 [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() yang xu
2018-03-23 11:34 ` [LTP] [PATCH 2/5] syscalls/mkdir01, 03: Cleanup && Convert to new API yang xu
2018-03-23 11:34 ` [LTP] [PATCH 3/5] syscalls/mkdir02: " yang xu
@ 2018-03-23 11:34 ` yang xu
2018-04-18 13:43 ` Cyril Hrubis
2018-03-23 11:34 ` [LTP] [PATCH 5/5] syscalls/mkdir05, 08: " yang xu
2018-04-18 12:13 ` [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() Cyril Hrubis
4 siblings, 1 reply; 10+ messages in thread
From: yang xu @ 2018-03-23 11:34 UTC (permalink / raw)
To: ltp
1) Take use of some safe macros
2 Remove temporary directory in loop
Signed-off-by: yang xu <xuyang.jy@cn.fujitsu.com>
---
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 <http://www.gnu.org/licenses/>.
*/
-/*
- * 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 <errno.h>
-#include <string.h>
-#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
#include <pwd.h>
#include <sys/wait.h>
#include <unistd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void cleanup();
-int fail;
+#include <stdlib.h>
+#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,
+};
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH 5/5] syscalls/mkdir05, 08: Cleanup && Convert to new API
2018-03-23 11:34 [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() yang xu
` (2 preceding siblings ...)
2018-03-23 11:34 ` [LTP] [PATCH 4/5] syscalls/mkdir04: " yang xu
@ 2018-03-23 11:34 ` yang xu
2018-04-18 14:18 ` Cyril Hrubis
2018-04-18 12:13 ` [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() Cyril Hrubis
4 siblings, 1 reply; 10+ messages in thread
From: yang xu @ 2018-03-23 11:34 UTC (permalink / raw)
To: ltp
1) Take use of some safe macros
2) Remove duplicate tests mkdir08
Signed-off-by: yang xu <xuyang.jy@cn.fujitsu.com>
---
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 <http://www.gnu.org/licenses/>.
*/
-/*
- * 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 <errno.h>
-#include <string.h>
-#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
-#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 <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#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();
-
-}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID()
2018-03-23 11:34 [LTP] [PATCH 1/5] SAFE_MACROS: Add SAFE_SETREUID()/SAFE_SETREGID() yang xu
` (3 preceding siblings ...)
2018-03-23 11:34 ` [LTP] [PATCH 5/5] syscalls/mkdir05, 08: " yang xu
@ 2018-04-18 12:13 ` Cyril Hrubis
4 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2018-04-18 12:13 UTC (permalink / raw)
To: ltp
Hi!
I've reworked this patch and pushed, thanks.
The main things I've fixed here are:
* Don't add the macros to the old library since as a general rule we
should not add new functionality there
* Fixed the gid_t and uid_t printing, these are integer types so
printing them with %p is wrong
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 10+ messages in thread