All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/7] syscalls/mkdir04: Simplify test and use any existing users
Date: Fri,  3 Sep 2021 17:48:46 +0200	[thread overview]
Message-ID: <20210903154848.18705-6-mdoucha@suse.cz> (raw)
In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz>

mkdir04 does not need to fork() in setup(). Usernames such as "bin" may not
exist on some systems. Find and use any two unprivileged users instead of
specific named users.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 testcases/kernel/syscalls/mkdir/mkdir04.c | 30 ++++++-----------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/testcases/kernel/syscalls/mkdir/mkdir04.c b/testcases/kernel/syscalls/mkdir/mkdir04.c
index 87512a4be..3880611d7 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir04.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir04.c
@@ -7,20 +7,16 @@
  * user with restrictive permissions and that the errno is set to EACCESS.
  */
 
+#define _XOPEN_SOURCE 500
 #include <errno.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include "tst_test.h"
+#include "tst_uid.h"
 
 #define TESTDIR	 "testdir"
 #define TESTSUBDIR "testdir/testdir"
 
-static uid_t nobody_uid, bin_uid;
-
 static void verify_mkdir(void)
 {
 	if (mkdir(TESTSUBDIR, 0777) != -1) {
@@ -39,24 +35,15 @@ static void verify_mkdir(void)
 
 static void setup(void)
 {
-	struct passwd *pw;
-	pid_t pid;
-
-	pw = SAFE_GETPWNAM("nobody");
-	nobody_uid = pw->pw_uid;
-	pw = SAFE_GETPWNAM("bin");
-	bin_uid = pw->pw_uid;
+	uid_t test_users[2];
 
-	pid = SAFE_FORK();
-	if (pid == 0) {
-		SAFE_SETREUID(nobody_uid, nobody_uid);
-		SAFE_MKDIR(TESTDIR, 0700);
-		exit(0);
-	}
+	tst_get_uids(2, test_users);
+	endpwent();
 
-	tst_reap_children();
+	SAFE_MKDIR(TESTDIR, 0700);
+	SAFE_CHOWN(TESTDIR, test_users[0], getgid());
 
-	SAFE_SETREUID(bin_uid, bin_uid);
+	SAFE_SETREUID(test_users[1], test_users[1]);
 }
 
 static struct tst_test test = {
@@ -64,5 +51,4 @@ static struct tst_test test = {
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.setup = setup,
-	.forks_child = 1,
 };
-- 
2.33.0


  parent reply	other threads:[~2021-09-03 15:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 15:48 [LTP] [PATCH 0/7] UID/GID lookup fixes Martin Doucha
2021-09-03 15:48 ` [LTP] [PATCH 1/7] chmod05, fchmod05: Use free GID instead of "bin" group Martin Doucha
2021-09-06 12:20   ` Cyril Hrubis
2021-09-06 12:20     ` Cyril Hrubis
2021-09-03 15:48 ` [LTP] [PATCH 2/7] Simplify syscalls/mkdir02 Martin Doucha
2021-09-06 12:20   ` Cyril Hrubis
2021-09-06 12:20     ` Cyril Hrubis
2021-09-03 15:48 ` [LTP] [PATCH 3/7] Add user/group ID lookup helper functions Martin Doucha
2021-09-06 12:21   ` Cyril Hrubis
2021-09-06 12:21     ` Cyril Hrubis
2021-09-06 12:40       ` Martin Doucha
2021-09-06 12:40         ` Martin Doucha
2021-09-03 15:48 ` [LTP] [PATCH 4/7] syscalls/kill05: Use any two unprivileged users Martin Doucha
2021-09-06 12:28   ` Cyril Hrubis
2021-09-06 12:28     ` Cyril Hrubis
2021-09-06 12:47       ` Martin Doucha
2021-09-06 12:47         ` Martin Doucha
2021-09-06 12:50           ` Cyril Hrubis
2021-09-06 12:50             ` Cyril Hrubis
2021-09-06 13:01               ` Martin Doucha
2021-09-06 13:01                 ` Martin Doucha
2021-09-06 13:05                   ` Cyril Hrubis
2021-09-06 13:05                     ` Cyril Hrubis
2021-09-06 13:27                       ` Martin Doucha
2021-09-06 13:27                         ` Martin Doucha
2021-09-06 13:02               ` Cyril Hrubis
2021-09-06 13:02                 ` Cyril Hrubis
2021-09-03 15:48 ` Martin Doucha [this message]
2021-09-03 15:48 ` [LTP] [PATCH 6/7] syscalls/setregid02-04: Simplify GID handling Martin Doucha
2021-09-03 15:48 ` [LTP] [PATCH 7/7] syscalls/setregid02-04: Eliminate named group lookups Martin Doucha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210903154848.18705-6-mdoucha@suse.cz \
    --to=mdoucha@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.