All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/2] Convert chdir01 to the new API
@ 2020-07-24 12:50 Martin Doucha
  2020-07-24 12:50 ` [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user Martin Doucha
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Doucha @ 2020-07-24 12:50 UTC (permalink / raw)
  To: ltp

chdir02 and chdir03 were removed because the updated chdir01 makes them
redundant.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1:
- Require root privileges and run the test on all file systems
- Fixed expected return value for directory with 0644 access mode
- Added test case for chdir("/");
- Improved chdir() return value/errno checks

 runtest/quickhit                           |   2 +-
 runtest/syscalls                           |   2 -
 testcases/kernel/syscalls/chdir/.gitignore |   2 -
 testcases/kernel/syscalls/chdir/chdir01.c  | 247 ++++++++-------------
 testcases/kernel/syscalls/chdir/chdir02.c  | 163 --------------
 testcases/kernel/syscalls/chdir/chdir03.c  |  68 ------
 6 files changed, 91 insertions(+), 393 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/chdir/chdir02.c
 delete mode 100644 testcases/kernel/syscalls/chdir/chdir03.c

diff --git a/runtest/quickhit b/runtest/quickhit
index e01b838fb..b17318b65 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -24,7 +24,7 @@ brk01 brk01
 # Basic test for brk()
 #    TEST CASES
 # 	1.) brk(2) returns...
-chdir02 chdir02
+chdir01 chdir01
 # Basic test for chdir(2)
 #    TEST CASES
 # 	1.) chdir(2) returns...
diff --git a/runtest/syscalls b/runtest/syscalls
index c2bfc6df3..70b3277d3 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -55,8 +55,6 @@ cacheflush01 cacheflush01
 
 chdir01 chdir01
 chdir01A symlink01 -T chdir01
-chdir02 chdir02
-chdir03 chdir03
 chdir04 chdir04
 
 chmod01 chmod01
diff --git a/testcases/kernel/syscalls/chdir/.gitignore b/testcases/kernel/syscalls/chdir/.gitignore
index c1e4b9d07..1b15eb6b9 100644
--- a/testcases/kernel/syscalls/chdir/.gitignore
+++ b/testcases/kernel/syscalls/chdir/.gitignore
@@ -1,4 +1,2 @@
 /chdir01
-/chdir02
-/chdir03
 /chdir04
diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
index 81cf7c564..8868d328a 100644
--- a/testcases/kernel/syscalls/chdir/chdir01.c
+++ b/testcases/kernel/syscalls/chdir/chdir01.c
@@ -1,181 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   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 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
+ * Copyright (c) International Business Machines  Corp., 2001
+ *     07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2019 SUSE LLC <mdoucha@suse.cz>
  */
 
 /*
- * NAME
- * 	chdir01.c
- *
- * DESCRIPTION
- *	Check proper operation of chdir(): tests whether the
- *	system call can it change the current, working directory, and find a
- *	file there? Will it fail on a non-directory entry ?
- *
- * ALGORITHM
- * 	Make a directory "Testdirectory", and create a file in it. cd into
- * 	the directory and read the entry. It should be the file just
- * 	created.
- *
- * USAGE:  <for command-line>
- *  chdir01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -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
+ * Check that the chdir() syscall returns correct value and error code
+ * in various situations when called with root privileges
  */
 
 #include <stdio.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include<sys/stat.h>
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "chdir01";
-int TST_TOTAL = 2;
-
-void setup(void);
-void cleanup(void);
-static void checknames(char **, int, DIR *);
-
-char testdir[40] = "";
-
-int main(int ac, char **av)
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+
+#define MNTPOINT "mntpoint"
+
+#define FILE_NAME "testfile"
+#define DIR_NAME "subdir"
+#define BLOCKED_NAME "keep_out"
+#define LINK_NAME1 "symloop"
+#define LINK_NAME2 "symloop2"
+
+static char *workdir;
+static int skip_symlinks;
+
+static struct test_case {
+	const char *name;
+	int retval, experr;
+} testcase_list[] = {
+	{FILE_NAME, -1, ENOTDIR},
+	{BLOCKED_NAME, 0, 0},
+	{DIR_NAME, 0, 0},
+	{".", 0, 0},
+	{"..", 0, 0},
+	{"/", 0, 0},
+	{"missing", -1, ENOENT},
+	{LINK_NAME1, -1, ELOOP},
+};
+
+static void setup(void)
 {
-	DIR *ddir, *opendir();
+	char *cwd;
 	int fd;
-	char *filname = "chdirtest";
-	char *filenames[3];
-
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		SAFE_CHDIR(cleanup, testdir);
-
-		fd = SAFE_CREAT(cleanup, filname, 0000);
-		SAFE_CLOSE(cleanup, fd);
-		if ((ddir = opendir(".")) == NULL)
-			tst_brkm(TBROK | TERRNO, cleanup, "opendir(.) failed");
-
-		filenames[0] = ".";
-		filenames[1] = "..";
-		filenames[2] = filname;
-		checknames(filenames, sizeof(filenames) / sizeof(filenames[0]),
-			   ddir);
-		closedir(ddir);
-
-		TEST(chdir(filname));
-
-		if (TEST_RETURN != -1)
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-		else if (TEST_ERRNO != ENOTDIR)
-			tst_resm(TFAIL | TTERRNO,
-				 "failed unexpectedly; wanted ENOTDIR");
-		else
-			tst_resm(TPASS, "failed as expected with ENOTDIR");
-
-		SAFE_UNLINK(cleanup, filname);
-
-		SAFE_CHDIR(cleanup, "..");
-
-		/* ELOOP */
-		SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2");
-		SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1");
-
-		TEST(chdir("test_eloop1"));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-		} else if (TEST_ERRNO != ELOOP) {
-			tst_resm(TFAIL | TTERRNO,
-				 "failed unexpectedly; wanted ELOOP");
-		} else {
-			tst_resm(TPASS, "failed as expected with ELOOP");
-		}
-
-		SAFE_UNLINK(cleanup, "test_eloop1");
-		SAFE_UNLINK(cleanup, "test_eloop2");
-	}
-	cleanup();
-
-	tst_exit();
 
+	cwd = SAFE_GETCWD(NULL, 0);
+	workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2);
+	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
+	free(cwd);
+	SAFE_CHDIR(workdir);
+	SAFE_MKDIR(DIR_NAME, 0755);
+	SAFE_MKDIR(BLOCKED_NAME, 0644);
+
+	skip_symlinks = 0;
+	TEST(symlink(LINK_NAME1, LINK_NAME2));
+
+	if (!TST_RET)
+		SAFE_SYMLINK(LINK_NAME2, LINK_NAME1);
+	else if (TST_RET == -1 && TST_ERR == EPERM)
+		skip_symlinks = 1;
+	else
+		tst_brk(TBROK | TTERRNO, "Cannot create symlinks");
+
+	fd = SAFE_CREAT(FILE_NAME, 0644);
+	SAFE_CLOSE(fd);
 }
 
-void setup(void)
+static void run(unsigned int n)
 {
+	struct test_case *tc = testcase_list + n;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	if (tc->experr == ELOOP && skip_symlinks)
+		tst_brk(TCONF, "Skipping symlink loop test, not supported");
 
-	umask(0);
+	/* Reset current directory to mountpoint */
+	SAFE_CHDIR(workdir);
 
-	TEST_PAUSE;
+	TEST(chdir(tc->name));
 
-	tst_tmpdir();
+	if (TST_RET != tc->retval) {
+		tst_res(TFAIL | TTERRNO,
+			"chdir(\"%s\") returned unexpected value %ld",
+			tc->name, TST_RET);
+		return;
+	}
 
-	sprintf(testdir, "Testdir.%d", getpid());
+	if (TST_RET != 0 && TST_ERR != tc->experr) {
+		tst_res(TFAIL | TTERRNO,
+			"chdir(\"%s\") returned unexpected error", tc->name);
+		return;
+	}
 
-	SAFE_MKDIR(cleanup, testdir, 0700);
+	tst_res(TPASS | TTERRNO, "chdir(\"%s\") returned correct value",
+		tc->name);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	tst_rmdir();
+	free(workdir);
 }
 
-void checknames(char **pfilnames, int fnamecount, DIR * ddir)
-{
-	struct dirent *dir;
-	int i, found;
-
-	found = 0;
-	while ((dir = readdir(ddir)) != NULL) {
-		for (i = 0; i < fnamecount; i++) {
-			/*
-			 * if dir->d_name is not null terminated it is a bug
-			 * anyway
-			 */
-			if (strcmp(pfilnames[i], dir->d_name) == 0) {
-				tst_resm(TINFO, "Found file %s", dir->d_name);
-				found++;
-			}
-		}
-	}
-	if (found < fnamecount) {
-		tst_brkm(TFAIL, cleanup,
-			 "Some files do not exist, but they must exist");
-	}
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.test = run,
+	.tcnt = ARRAY_SIZE(testcase_list),
+	.setup = setup,
+	.cleanup = cleanup
+};
diff --git a/testcases/kernel/syscalls/chdir/chdir02.c b/testcases/kernel/syscalls/chdir/chdir02.c
deleted file mode 100644
index 6fc251c5f..000000000
--- a/testcases/kernel/syscalls/chdir/chdir02.c
+++ /dev/null
@@ -1,163 +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: chdir02.c,v 1.6 2009/08/28 11:32:19 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: chdir02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for chdir(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.) chdir(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 chdir(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
- *	chdir(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 "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "chdir02";
-int TST_TOTAL = 1;
-
-char *dirs[2] = { "/", "/tmp" };
-
-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(chdir(dirs[lc % 2]));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "chdir(%s) failed",
-				 dirs[lc % 2]);
-		} else {
-			tst_resm(TPASS, "chdir(%s) returned %ld",
-				 dirs[lc % 2], TEST_RETURN);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
diff --git a/testcases/kernel/syscalls/chdir/chdir03.c b/testcases/kernel/syscalls/chdir/chdir03.c
deleted file mode 100644
index 5beabdb1c..000000000
--- a/testcases/kernel/syscalls/chdir/chdir03.c
+++ /dev/null
@@ -1,68 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) International Business Machines Corp., 2001
- * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
- */
-
-/*
- * DESCRIPTION
- *	Testcase for testing that chdir(2) sets EACCES errno
- *
- * ALGORITHM
- *	1.	running as root, create a directory with perm 700
- *	2.	create a child process, sets its uid to nobody
- *	3.	this child attempts to chdir(2) to the directory created in 1
- *		and expects to get an EACCES.
- */
-
-#include <pwd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include "tst_test.h"
-
-#define DIRNAME "chdir03_dir"
-
-static uid_t nobody_uid;
-
-void verify_chdir(void)
-{
-	pid_t pid;
-
-	pid = SAFE_FORK();
-	if (!pid) {
-		SAFE_SETUID(nobody_uid);
-
-		TEST(chdir(DIRNAME));
-
-		if (TST_RET != -1) {
-			tst_res(TFAIL, "chdir() succeeded unexpectedly");
-			return;
-		}
-
-		if (TST_ERR != EACCES) {
-			tst_res(TFAIL | TTERRNO,
-				"chdir() should fail with EACCES");
-			return;
-		}
-
-		tst_res(TPASS | TTERRNO, "chdir() failed expectedly");
-	}
-}
-
-void setup(void)
-{
-	struct passwd *pw;
-
-	pw = SAFE_GETPWNAM("nobody");
-	nobody_uid = pw->pw_uid;
-
-	SAFE_MKDIR(DIRNAME, 0700);
-}
-
-static struct tst_test test = {
-	.setup = setup,
-	.test_all = verify_chdir,
-	.needs_tmpdir = 1,
-	.needs_root = 1,
-	.forks_child = 1,
-};
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user
  2020-07-24 12:50 [LTP] [PATCH v2 1/2] Convert chdir01 to the new API Martin Doucha
@ 2020-07-24 12:50 ` Martin Doucha
  2020-07-24 13:32   ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Doucha @ 2020-07-24 12:50 UTC (permalink / raw)
  To: ltp

chdir01 tests chdir() return values with root permissions. chdir02 does
the same test scenario with EUID set to nobody.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1: New patch

 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/chdir/.gitignore |   1 +
 testcases/kernel/syscalls/chdir/chdir02.c  | 134 +++++++++++++++++++++
 3 files changed, 136 insertions(+)
 create mode 100644 testcases/kernel/syscalls/chdir/chdir02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 70b3277d3..deadc21bc 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -54,6 +54,7 @@ capset04 capset04
 cacheflush01 cacheflush01
 
 chdir01 chdir01
+chdir02 chdir02
 chdir01A symlink01 -T chdir01
 chdir04 chdir04
 
diff --git a/testcases/kernel/syscalls/chdir/.gitignore b/testcases/kernel/syscalls/chdir/.gitignore
index 1b15eb6b9..3475c5e54 100644
--- a/testcases/kernel/syscalls/chdir/.gitignore
+++ b/testcases/kernel/syscalls/chdir/.gitignore
@@ -1,2 +1,3 @@
 /chdir01
+/chdir02
 /chdir04
diff --git a/testcases/kernel/syscalls/chdir/chdir02.c b/testcases/kernel/syscalls/chdir/chdir02.c
new file mode 100644
index 000000000..e62362808
--- /dev/null
+++ b/testcases/kernel/syscalls/chdir/chdir02.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *     07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2019 SUSE LLC <mdoucha@suse.cz>
+ */
+
+/*
+ * Check that the chdir() syscall returns correct value and error code
+ * in various situations when called by regular user
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pwd.h>
+
+#include "tst_test.h"
+
+#define MNTPOINT "mntpoint"
+
+#define FILE_NAME "testfile"
+#define DIR_NAME "subdir"
+#define BLOCKED_NAME "keep_out"
+#define LINK_NAME1 "symloop"
+#define LINK_NAME2 "symloop2"
+
+static char *workdir;
+static unsigned int skip_symlinks, skip_blocked;
+static struct passwd *ltpuser;
+
+static struct test_case {
+	const char *name;
+	int retval, experr;
+} testcase_list[] = {
+	{FILE_NAME, -1, ENOTDIR},
+	{BLOCKED_NAME, -1, EACCES},
+	{DIR_NAME, 0, 0},
+	{".", 0, 0},
+	{"..", 0, 0},
+	{"/", 0, 0},
+	{"missing", -1, ENOENT},
+	{LINK_NAME1, -1, ELOOP},
+};
+
+static void setup(void)
+{
+	char *cwd;
+	int fd;
+	struct stat statbuf;
+
+	cwd = SAFE_GETCWD(NULL, 0);
+	workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2);
+	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
+	free(cwd);
+	SAFE_CHDIR(workdir);
+	SAFE_MKDIR(DIR_NAME, 0755);
+	SAFE_MKDIR(BLOCKED_NAME, 0644);
+
+	/* FAT and NTFS override file and directory permissions */
+	SAFE_STAT(BLOCKED_NAME, &statbuf);
+	skip_blocked = statbuf.st_mode & 0111;
+	skip_symlinks = 0;
+	TEST(symlink(LINK_NAME1, LINK_NAME2));
+
+	if (!TST_RET)
+		SAFE_SYMLINK(LINK_NAME2, LINK_NAME1);
+	else if (TST_RET == -1 && TST_ERR == EPERM)
+		skip_symlinks = 1; /* man symlink(2): EPERM == unsupported */
+	else
+		tst_brk(TBROK | TTERRNO, "Cannot create symlinks");
+
+	fd = SAFE_CREAT(FILE_NAME, 0644);
+	SAFE_CLOSE(fd);
+
+	if (!ltpuser)
+		ltpuser = SAFE_GETPWNAM("nobody");
+
+	SAFE_SETEUID(ltpuser->pw_uid);
+}
+
+static void run(unsigned int n)
+{
+	struct test_case *tc = testcase_list + n;
+
+	if (tc->experr == EACCES && skip_blocked) {
+		tst_res(TCONF, "Skipping permission test, FS mangles dir mode");
+		return;
+	}
+
+	if (tc->experr == ELOOP && skip_symlinks) {
+		tst_res(TCONF, "Skipping symlink loop test, not supported");
+		return;
+	}
+
+	/* Reset current directory to mountpoint */
+	SAFE_CHDIR(workdir);
+
+	TEST(chdir(tc->name));
+
+	if (TST_RET != tc->retval) {
+		tst_res(TFAIL | TTERRNO,
+			"chdir(\"%s\") returned unexpected value %ld",
+			tc->name, TST_RET);
+		return;
+	}
+
+	if (TST_RET != 0 && TST_ERR != tc->experr) {
+		tst_res(TFAIL | TTERRNO,
+			"chdir(\"%s\") returned unexpected error", tc->name);
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "chdir(\"%s\") returned correct value",
+		tc->name);
+}
+
+static void cleanup(void)
+{
+	free(workdir);
+	SAFE_SETEUID(0);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.test = run,
+	.tcnt = ARRAY_SIZE(testcase_list),
+	.setup = setup,
+	.cleanup = cleanup
+};
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user
  2020-07-24 12:50 ` [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user Martin Doucha
@ 2020-07-24 13:32   ` Petr Vorel
  2020-07-24 14:47     ` Martin Doucha
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2020-07-24 13:32 UTC (permalink / raw)
  To: ltp

Hi Martin,

> +++ b/runtest/syscalls
> @@ -54,6 +54,7 @@ capset04 capset04
>  cacheflush01 cacheflush01

>  chdir01 chdir01
> +chdir02 chdir02
>  chdir01A symlink01 -T chdir01
>  chdir04 chdir04
You missed to add chdir02 to runtest/quickhit. I guess this was deliberate,
right?
(I wonder if we really need runtest/quickhit anyway).

I like both tests (nice work, thanks!), just don't like the duplicity. Isn't
there a way to use getopt parameter for one of the variants and have just single
test? But understand if you don't bother with it (maybe better duplicity but
simpler code).

Other that that LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user
  2020-07-24 13:32   ` Petr Vorel
@ 2020-07-24 14:47     ` Martin Doucha
  2020-07-24 15:32       ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Doucha @ 2020-07-24 14:47 UTC (permalink / raw)
  To: ltp

On 24. 07. 20 15:32, Petr Vorel wrote:
> Hi Martin,
> 
>> +++ b/runtest/syscalls
>> @@ -54,6 +54,7 @@ capset04 capset04
>>  cacheflush01 cacheflush01
> 
>>  chdir01 chdir01
>> +chdir02 chdir02
>>  chdir01A symlink01 -T chdir01
>>  chdir04 chdir04
> You missed to add chdir02 to runtest/quickhit. I guess this was deliberate,
> right?
> (I wonder if we really need runtest/quickhit anyway).

Yes, this was deliberate since only chdir02 was there originally (the
one that was checking only chdir("/"); and chdir("/etc");.

> I like both tests (nice work, thanks!), just don't like the duplicity. Isn't
> there a way to use getopt parameter for one of the variants and have just single
> test? But understand if you don't bother with it (maybe better duplicity but
> simpler code).
> 
> Other that that LGTM.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

I could add a second set of expected values to the test case list and do
it like this:

static void run(unsigned int n) {
	TEST(chdir(tc->name));
	/* result validation here */
	SAFE_SETEUID(ltpuser->pw_uid);
	TEST(chdir(tc->name));
	SAFE_SETEUID(0);
	/* result validation here */
}

Should I resubmit that as v3?

-- 
Martin Doucha   mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user
  2020-07-24 14:47     ` Martin Doucha
@ 2020-07-24 15:32       ` Petr Vorel
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2020-07-24 15:32 UTC (permalink / raw)
  To: ltp

Hi Martin,

> >> +++ b/runtest/syscalls
> >> @@ -54,6 +54,7 @@ capset04 capset04
> >>  cacheflush01 cacheflush01

> >>  chdir01 chdir01
> >> +chdir02 chdir02
> >>  chdir01A symlink01 -T chdir01
> >>  chdir04 chdir04
> > You missed to add chdir02 to runtest/quickhit. I guess this was deliberate,
> > right?
> > (I wonder if we really need runtest/quickhit anyway).

> Yes, this was deliberate since only chdir02 was there originally (the
> one that was checking only chdir("/"); and chdir("/etc");.
Understand, thanks for info.

> > I like both tests (nice work, thanks!), just don't like the duplicity. Isn't
> > there a way to use getopt parameter for one of the variants and have just single
> > test? But understand if you don't bother with it (maybe better duplicity but
> > simpler code).

> > Other that that LGTM.
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>

> I could add a second set of expected values to the test case list and do
> it like this:

> static void run(unsigned int n) {
> 	TEST(chdir(tc->name));
> 	/* result validation here */
> 	SAFE_SETEUID(ltpuser->pw_uid);
> 	TEST(chdir(tc->name));
> 	SAFE_SETEUID(0);
> 	/* result validation here */
> }
LGTM, thank you!

> Should I resubmit that as v3?
Yes, please.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-24 15:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 12:50 [LTP] [PATCH v2 1/2] Convert chdir01 to the new API Martin Doucha
2020-07-24 12:50 ` [LTP] [PATCH v2 2/2] Add chdir() test for unprivileged user Martin Doucha
2020-07-24 13:32   ` Petr Vorel
2020-07-24 14:47     ` Martin Doucha
2020-07-24 15:32       ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.