All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/3] syscalls/fchown: Convert fchown{01, 02, 03} to the new API
@ 2021-05-06 13:09 Xie Ziyao
  2021-05-06 13:09 ` [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 " Xie Ziyao
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Xie Ziyao @ 2021-05-06 13:09 UTC (permalink / raw)
  To: ltp

Xie Ziyao (3):
  syscalls/fchown: Convert fchown01 to the new API
  syscalls/fchown: Convert fchown02 to the new API
  syscalls/fchown: Convert fchown03 to the new API

 testcases/kernel/syscalls/fchown/fchown01.c | 110 ++++--------
 testcases/kernel/syscalls/fchown/fchown02.c | 175 ++++++-------------
 testcases/kernel/syscalls/fchown/fchown03.c | 177 ++++++++------------
 3 files changed, 149 insertions(+), 313 deletions(-)

--
2.17.1


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

* [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 to the new API
  2021-05-06 13:09 [LTP] [PATCH 0/3] syscalls/fchown: Convert fchown{01, 02, 03} to the new API Xie Ziyao
@ 2021-05-06 13:09 ` Xie Ziyao
  2021-05-25 14:56   ` Petr Vorel
  2021-05-06 13:09 ` [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 " Xie Ziyao
  2021-05-06 13:09 ` [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 " Xie Ziyao
  2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-06 13:09 UTC (permalink / raw)
  To: ltp

Cleanup and convert fchown01 to the new API.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/fchown/fchown01.c | 110 ++++++--------------
 1 file changed, 30 insertions(+), 80 deletions(-)

diff --git a/testcases/kernel/syscalls/fchown/fchown01.c b/testcases/kernel/syscalls/fchown/fchown01.c
index 23cc78787..32fc53d6c 100644
--- a/testcases/kernel/syscalls/fchown/fchown01.c
+++ b/testcases/kernel/syscalls/fchown/fchown01.c
@@ -1,100 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *    AUTHOR		: William Roske
- *    CO-PILOT		: Dave Fenner
- *
- * 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/
+ * AUTHOR: William Roske
+ * CO-PILOT: Dave Fenner
+ */
+
+/*\
+ * [Description]
  *
+ * Basic test for fchown(). Call fchown() on a fd and expect it to pass.
  */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>

-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>

-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
+#include "compat_tst_16.h"

-TCID_DEFINE(fchown01);
-int TST_TOTAL = 1;
+#define FILENAME "fchown01_testfile"
+#define MODE 0700

 static int fd;
+static int uid, gid;

-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		UID16_CHECK(geteuid(), "fchown", cleanup)
-		GID16_CHECK(getegid(), "fchown", cleanup)
-
-		TEST(FCHOWN(cleanup, fd, geteuid(), getegid()));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "fchown failed");
-		} else {
-			tst_resm(TPASS,
-				 "fchown(fd, geteuid(), getegid()) "
-				 "returned %ld", TEST_RETURN);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS(FCHOWN(fd, uid, gid));
 }

 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-	fd = SAFE_OPEN(cleanup, "tempfile", O_RDWR | O_CREAT, 0700);
+	UID16_CHECK(uid = geteuid(), "fchown");
+	GID16_CHECK(gid = getegid(), "fchown");
+	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, MODE);
 }

 static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "Failed to close fd");
-
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
--
2.17.1


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

* [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 to the new API
  2021-05-06 13:09 [LTP] [PATCH 0/3] syscalls/fchown: Convert fchown{01, 02, 03} to the new API Xie Ziyao
  2021-05-06 13:09 ` [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 " Xie Ziyao
@ 2021-05-06 13:09 ` Xie Ziyao
  2021-05-25 14:57   ` Petr Vorel
  2021-05-06 13:09 ` [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 " Xie Ziyao
  2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-06 13:09 UTC (permalink / raw)
  To: ltp

1. Cleanup and convert fchown02 to the new API;
2. Remove useless testcase {0, NULL, NULL, 0, 0, 0}.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/fchown/fchown02.c | 175 ++++++--------------
 1 file changed, 52 insertions(+), 123 deletions(-)

diff --git a/testcases/kernel/syscalls/fchown/fchown02.c b/testcases/kernel/syscalls/fchown/fchown02.c
index 0fef74dee..a99962911 100644
--- a/testcases/kernel/syscalls/fchown/fchown02.c
+++ b/testcases/kernel/syscalls/fchown/fchown02.c
@@ -1,158 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
+ * 07/2001 Ported by Wayne Boyer
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * 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
  */

-/*
- * Test Description:
- *  Verify that, when fchown(2) invoked by super-user to change the owner and
- *  group of a file specified by file descriptor to any numeric
- *  owner(uid)/group(gid) values,
- *	- clears setuid and setgid bits set on an executable file.
- *	- preserves setgid bit set on a non-group-executable file.
+/*\
+ * [Description]
+ *
+ * Verify that fchown(2) invoked by super-user:
+ *  - clears setuid and setgid bits set on an executable file
+ *  - preserves setgid bit set on a non-group-executable file
  */

 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
-
-#define FILE_MODE	S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-#define NEW_PERMS1	S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID
-#define NEW_PERMS2	S_IFREG | S_IRWXU | S_ISGID
-#define EXP_PERMS	S_IFREG | S_IRWXU | S_IRWXG
+
+#include "tst_test.h"
+#include "compat_tst_16.h"
+#include "tst_safe_macros.h"
+
+#define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define NEW_PERMS1	(S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID)
+#define NEW_PERMS2	(S_IFREG|S_IRWXU|S_ISGID)
+#define EXP_PERMS	(S_IFREG|S_IRWXU|S_IRWXG)
 #define TESTFILE1	"testfile1"
 #define TESTFILE2	"testfile2"

-TCID_DEFINE(fchown02);
-int TST_TOTAL = 2;
-static int fd1;
-static int fd2;
+static int fd1, fd2;

-struct test_case {
+struct test_case_t {
 	int *fd;
-	char *pathname;
-	char *desc;
-	uid_t user_id;
-	gid_t group_id;
-	int test_flag;
+	const char *filename;
+	mode_t set_mode;
+	mode_t exp_mode;
 } tc[] = {
-	{&fd1, TESTFILE1, "Setuid/Setgid bits cleared", 700, 701, 1},
-	{&fd2, TESTFILE2, "Setgid bit not cleared", 700, 701, 2},
-	{0, NULL, NULL, 0, 0, 0}
+	{&fd1, TESTFILE1, NEW_PERMS1, EXP_PERMS},
+	{&fd2, TESTFILE2, NEW_PERMS2, NEW_PERMS2}
 };

-static void setup(void);
-static void cleanup(void);
-
-static void verify_fchown(struct test_case *t)
+static void run(unsigned int i)
 {
-	struct stat stat_buf;
+	uid_t uid;
+	gid_t gid;

-	TEST(FCHOWN(cleanup, *t->fd, t->user_id, t->group_id));
-
-	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "fchown() Fails on %s", t->pathname);
-		return;
-	}
-
-	SAFE_FSTAT(cleanup, *t->fd, &stat_buf);
-
-	if ((stat_buf.st_uid != t->user_id) ||
-	    (stat_buf.st_gid != t->group_id)) {
-		tst_resm(TFAIL,
-		         "%s: Incorrect ownership expected %d %d, have %d %d",
-		         t->pathname, t->user_id, t->group_id,
-		         stat_buf.st_uid, stat_buf.st_gid);
-	}
-
-	switch (t->test_flag) {
-	case 1:
-		if (((stat_buf.st_mode & (S_ISUID | S_ISGID)))) {
-			tst_resm(TFAIL, "%s: Incorrect mode "
-					"permissions %#o, Expected "
-					"%#o", t->pathname, NEW_PERMS1,
-					 EXP_PERMS);
-			return;
-		}
-	break;
-	case 2:
-		if ((!(stat_buf.st_mode & S_ISGID))) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect mode "
-				 "permissions %#o, Expected "
-				 "%#o", t->pathname,
-				 stat_buf.st_mode, NEW_PERMS2);
-			return;
-		}
-	break;
-	}
-
-	tst_resm(TPASS, "fchown() on %s succeeds : %s", t->pathname, t->desc);
-}
+	UID16_CHECK((uid = geteuid()), "fchown");
+	GID16_CHECK((gid = getegid()), "fchown");

-int main(int ac, char **av)
-{
-	int lc, i;
+	SAFE_CHMOD(tc[i].filename, tc[i].set_mode);

-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS(FCHOWN(*tc[i].fd, uid, gid));

-	setup();
+	struct stat stat_buf;
+	SAFE_STAT(tc[i].filename, &stat_buf);

-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		for (i = 0; tc[i].desc != NULL; i++)
-			verify_fchown(tc + i);
-	}
+	if (stat_buf.st_uid != uid || stat_buf.st_gid != gid)
+		tst_res(TFAIL, "%s: owner set to (uid=%d, gid=%d), expected (uid=%d, gid=%d)",
+			tc[i].filename, stat_buf.st_uid, stat_buf.st_gid, uid, gid);

-	cleanup();
-	tst_exit();
+	if (stat_buf.st_mode != tc[i].exp_mode)
+		tst_res(TFAIL, "%s: wrong mode permissions %#o, expected %#o",
+			tc[i].filename, stat_buf.st_mode, tc[i].exp_mode);
 }

 static void setup(void)
 {
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd1 = SAFE_OPEN(cleanup, TESTFILE1, O_RDWR | O_CREAT, FILE_MODE);
-	SAFE_CHMOD(cleanup, TESTFILE1, NEW_PERMS1);
-	fd2 = SAFE_OPEN(cleanup, TESTFILE2, O_RDWR | O_CREAT, FILE_MODE);
-	SAFE_CHMOD(cleanup, TESTFILE2, NEW_PERMS2);
+	for (unsigned int i = 0; i < ARRAY_SIZE(tc); ++i)
+		*tc[i].fd = SAFE_OPEN(tc[i].filename, O_RDWR | O_CREAT, FILE_MODE);
 }

 static void cleanup(void)
 {
-	if (fd1 > 0 && close(fd1))
-		tst_resm(TWARN | TERRNO, "Failed to close fd1");
-
-	if (fd2 > 0 && close(fd2))
-		tst_resm(TWARN | TERRNO, "Failed to close fd2");
-
-	tst_rmdir();
+	for (unsigned int i = 0; i < ARRAY_SIZE(tc); ++i)
+		SAFE_CLOSE(*tc[i].fd);
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run,
+};
--
2.17.1


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

* [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 to the new API
  2021-05-06 13:09 [LTP] [PATCH 0/3] syscalls/fchown: Convert fchown{01, 02, 03} to the new API Xie Ziyao
  2021-05-06 13:09 ` [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 " Xie Ziyao
  2021-05-06 13:09 ` [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 " Xie Ziyao
@ 2021-05-06 13:09 ` Xie Ziyao
  2021-05-25 14:58   ` Petr Vorel
  2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-06 13:09 UTC (permalink / raw)
  To: ltp

Cleanup and convert fchown03 to the new API.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/fchown/fchown03.c | 177 ++++++++------------
 1 file changed, 67 insertions(+), 110 deletions(-)

diff --git a/testcases/kernel/syscalls/fchown/fchown03.c b/testcases/kernel/syscalls/fchown/fchown03.c
index f7fe994fd..a69ec86ae 100644
--- a/testcases/kernel/syscalls/fchown/fchown03.c
+++ b/testcases/kernel/syscalls/fchown/fchown03.c
@@ -1,139 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
+ * 07/2001 Ported by Wayne Boyer
+ */
+
+/*\
+ * [Description]
  *
- * 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.
+ * Verify that, fchown(2) succeeds to change the group of a file specified
+ * by path when called by non-root user with the following constraints:
  *
- * 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.
+ * - euid of the process is equal to the owner of the file;
+ * - the intended gid is either egid, or one of the supplementary gids
+ *   of the process.
  *
- * 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
- */
-
-/*
- * Test Description:
- *  Verify that, fchown(2) succeeds to change the group of a file specified
- *  by path when called by non-root user with the following constraints,
- *	- euid of the process is equal to the owner of the file.
- *	- the intended gid is either egid, or one of the supplementary gids
- *	  of the process.
- *  Also, verify that fchown() clears the setuid/setgid bits set on the file.
+ * Also verify that fchown() clears the setuid/setgid bits set on the file.
  */

-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <grp.h>
 #include <pwd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>

-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
-
-#define FILE_MODE (mode_t)(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
-#define NEW_PERMS (mode_t)(S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID)
-#define FCHOWN_PERMS	(mode_t)(NEW_PERMS & ~(S_ISUID | S_ISGID))
-#define TESTFILE	"testfile"
+#include "tst_test.h"
+#include "compat_tst_16.h"

-TCID_DEFINE(fchown03);
-int TST_TOTAL = 1;
+#define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define NEW_PERMS	(S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID)
+#define FILENAME	"fchown03_testfile"

-static int fildes;
-char nobody_uid[] = "nobody";
+static int fd;
 static struct passwd *ltpuser;

-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void check_owner(struct stat *s, uid_t exp_uid, gid_t exp_gid)
 {
-	struct stat stat_buf;
-	int lc;
-	uid_t user_id;
-	gid_t group_id;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		user_id = geteuid();
-		GID16_CHECK((group_id = getegid()), "fchown", cleanup)
-
-		TEST(FCHOWN(cleanup, fildes, -1, group_id));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "fchown() on %s Fails, errno=%d",
-				 TESTFILE, TEST_ERRNO);
-			continue;
-		}
+	if (s->st_uid != exp_uid || s->st_gid != exp_gid)
+		tst_res(TFAIL, "%s: wrong owner set to (uid=%d, gid=%d),"
+			       " expected (uid=%d, gid=%d)",
+			FILENAME, s->st_uid, s->st_gid, exp_uid, exp_gid);
+}

-		SAFE_FSTAT(cleanup, fildes, &stat_buf);
+static void check_mode(struct stat *s, mode_t exp_mode)
+{
+	if (s->st_mode != exp_mode)
+		tst_res(TFAIL, "%s: wrong mode permissions %#o, expected %#o",
+			FILENAME, s->st_mode, exp_mode);
+}

-		if ((stat_buf.st_uid != user_id) ||
-		    (stat_buf.st_gid != group_id)) {
-			tst_resm(TFAIL, "%s: Incorrect "
-				 "ownership set, Expected %d %d",
-				 TESTFILE, user_id, group_id);
-			continue;
-		}
+static void run(void)
+{
+	SAFE_SETEUID(0);
+	SAFE_FCHOWN(fd, -1, 0);
+	SAFE_FCHMOD(fd, NEW_PERMS);
+	SAFE_SETEUID(ltpuser->pw_uid);

-		if (stat_buf.st_mode != FCHOWN_PERMS) {
-			tst_resm(TFAIL, "%s: Incorrect mode permissions"
-				 " %#o, Expected %#o", TESTFILE,
-				 stat_buf.st_mode, FCHOWN_PERMS);
-		} else {
-			tst_resm(TPASS, "fchown() on %s succeeds: "
-				 "Setuid/gid bits cleared", TESTFILE);
-		}
-	}
+	uid_t uid;
+	gid_t gid;
+	UID16_CHECK((uid = geteuid()), "fchown");
+	GID16_CHECK((gid = getegid()), "fchown");

-	cleanup();
-	tst_exit();
+	struct stat stat_buf;
+	SAFE_STAT(FILENAME, &stat_buf);
+	check_owner(&stat_buf, uid, 0);
+	check_mode(&stat_buf, NEW_PERMS);
+
+	TST_EXP_PASS(FCHOWN(fd, -1, gid), "fchown(fd, %d, %d)", -1, gid);
+	SAFE_STAT(FILENAME, &stat_buf);
+	check_owner(&stat_buf, uid, gid);
+	check_mode(&stat_buf, NEW_PERMS & ~(S_ISUID | S_ISGID));
 }

 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEGID(ltpuser->pw_gid);
+	SAFE_SETEUID(ltpuser->pw_uid);

-	ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
-	SAFE_SETEUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fildes = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-
-	SAFE_SETEUID(cleanup, 0);
-
-	SAFE_FCHOWN(cleanup, fildes, -1, 0);
-	SAFE_FCHMOD(cleanup, fildes, NEW_PERMS);
-
-	SAFE_SETEGID(cleanup, ltpuser->pw_gid);
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, FILE_MODE);
 }

 static void cleanup(void)
 {
-	if (fildes > 0 && close(fildes))
-		tst_resm(TWARN | TERRNO, "close(%s) Failed", TESTFILE);
-
-	tst_rmdir();
+	SAFE_SETEGID(0);
+	SAFE_SETEUID(0);
+	SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
--
2.17.1


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

* [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 to the new API
  2021-05-06 13:09 ` [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 " Xie Ziyao
@ 2021-05-25 14:56   ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2021-05-25 14:56 UTC (permalink / raw)
  To: ltp

Hi,

merged with these changes, thanks!

Kind regards,
Petr

diff --git testcases/kernel/syscalls/fchown/fchown01.c testcases/kernel/syscalls/fchown/fchown01.c
index 32fc53d6c..77913ce32 100644
--- testcases/kernel/syscalls/fchown/fchown01.c
+++ testcases/kernel/syscalls/fchown/fchown01.c
@@ -1,8 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2006-2021
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * AUTHOR: William Roske
- * CO-PILOT: Dave Fenner
+ * Author: William Roske
+ * Ported to LTP: Dave Fenner
  */
 
 /*\
@@ -22,7 +23,8 @@
 #define MODE 0700
 
 static int fd;
-static int uid, gid;
+static uid_t uid;
+static gid_t gid;
 
 static void run(void)
 {

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

* [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 to the new API
  2021-05-06 13:09 ` [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 " Xie Ziyao
@ 2021-05-25 14:57   ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2021-05-25 14:57 UTC (permalink / raw)
  To: ltp

Hi Ziyao,

thanks! Merged with these changes (NOTE: "for (unsigned int i = 0" breaks on
older compilers, which are represented with CentOS in our travis).

Kind regards,
Petr

diff --git testcases/kernel/syscalls/fchown/fchown02.c testcases/kernel/syscalls/fchown/fchown02.c
index a99962911..d541f0450 100644
--- testcases/kernel/syscalls/fchown/fchown02.c
+++ testcases/kernel/syscalls/fchown/fchown02.c
@@ -1,8 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2003-2021
+ * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 Ported by Wayne Boyer
- * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
 /*\
@@ -43,6 +44,7 @@ struct test_case_t {
 
 static void run(unsigned int i)
 {
+	struct stat stat_buf;
 	uid_t uid;
 	gid_t gid;
 
@@ -53,7 +55,6 @@ static void run(unsigned int i)
 
 	TST_EXP_PASS(FCHOWN(*tc[i].fd, uid, gid));
 
-	struct stat stat_buf;
 	SAFE_STAT(tc[i].filename, &stat_buf);
 
 	if (stat_buf.st_uid != uid || stat_buf.st_gid != gid)
@@ -67,13 +68,17 @@ static void run(unsigned int i)
 
 static void setup(void)
 {
-	for (unsigned int i = 0; i < ARRAY_SIZE(tc); ++i)
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(tc); i++)
 		*tc[i].fd = SAFE_OPEN(tc[i].filename, O_RDWR | O_CREAT, FILE_MODE);
 }
 
 static void cleanup(void)
 {
-	for (unsigned int i = 0; i < ARRAY_SIZE(tc); ++i)
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(tc); i++)
 		SAFE_CLOSE(*tc[i].fd);
 }
 

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

* [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 to the new API
  2021-05-06 13:09 ` [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 " Xie Ziyao
@ 2021-05-25 14:58   ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2021-05-25 14:58 UTC (permalink / raw)
  To: ltp

Hi Ziyao,

Merged with these changes below. Thanks!

Kind regards,
Petr

diff --git testcases/kernel/syscalls/fchown/fchown03.c testcases/kernel/syscalls/fchown/fchown03.c
index a69ec86ae..752d9c394 100644
--- testcases/kernel/syscalls/fchown/fchown03.c
+++ testcases/kernel/syscalls/fchown/fchown03.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2001-2021
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 Ported by Wayne Boyer
  */
@@ -10,7 +11,7 @@
  * Verify that, fchown(2) succeeds to change the group of a file specified
  * by path when called by non-root user with the following constraints:
  *
- * - euid of the process is equal to the owner of the file;
+ * - euid of the process is equal to the owner of the file
  * - the intended gid is either egid, or one of the supplementary gids
  *   of the process.
  *
@@ -36,8 +37,7 @@ static struct passwd *ltpuser;
 static void check_owner(struct stat *s, uid_t exp_uid, gid_t exp_gid)
 {
 	if (s->st_uid != exp_uid || s->st_gid != exp_gid)
-		tst_res(TFAIL, "%s: wrong owner set to (uid=%d, gid=%d),"
-			       " expected (uid=%d, gid=%d)",
+		tst_res(TFAIL, "%s: wrong owner set to (uid=%d, gid=%d), expected (uid=%d, gid=%d)",
 			FILENAME, s->st_uid, s->st_gid, exp_uid, exp_gid);
 }
 
@@ -50,17 +50,18 @@ static void check_mode(struct stat *s, mode_t exp_mode)
 
 static void run(void)
 {
+	uid_t uid;
+	gid_t gid;
+	struct stat stat_buf;
+
 	SAFE_SETEUID(0);
 	SAFE_FCHOWN(fd, -1, 0);
 	SAFE_FCHMOD(fd, NEW_PERMS);
 	SAFE_SETEUID(ltpuser->pw_uid);
 
-	uid_t uid;
-	gid_t gid;
 	UID16_CHECK((uid = geteuid()), "fchown");
 	GID16_CHECK((gid = getegid()), "fchown");
 
-	struct stat stat_buf;
 	SAFE_STAT(FILENAME, &stat_buf);
 	check_owner(&stat_buf, uid, 0);
 	check_mode(&stat_buf, NEW_PERMS);

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

end of thread, other threads:[~2021-05-25 14:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 13:09 [LTP] [PATCH 0/3] syscalls/fchown: Convert fchown{01, 02, 03} to the new API Xie Ziyao
2021-05-06 13:09 ` [LTP] [PATCH 1/3] syscalls/fchown: Convert fchown01 " Xie Ziyao
2021-05-25 14:56   ` Petr Vorel
2021-05-06 13:09 ` [LTP] [PATCH 2/3] syscalls/fchown: Convert fchown02 " Xie Ziyao
2021-05-25 14:57   ` Petr Vorel
2021-05-06 13:09 ` [LTP] [PATCH 3/3] syscalls/fchown: Convert fchown03 " Xie Ziyao
2021-05-25 14:58   ` 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.