All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/access01: Fix the test to run both under nobody and root
@ 2016-05-16  3:19 Xiao Yang
  2016-05-16 12:23 ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Xiao Yang @ 2016-05-16  3:19 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/access/access01.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index 7d19d08..a447607 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -27,6 +27,8 @@
  */
 #include <errno.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
 #include "tst_test.h"
 
 #define FNAME_RWX "accessfile_rwx"
@@ -117,8 +119,26 @@ static void verify_access(unsigned int n)
 		verify_success(tc);
 }
 
+static void verify_root(struct tcase *tc)
+{
+	if (!strcmp(tc->fname, FNAME_X))
+		tc->exp_errno = 0;
+
+	if (!strcmp(tc->fname, FNAME_R) || !strcmp(tc->fname, FNAME_W)) {
+		if (strstr(tc->name, "X_OK") == NULL)
+			tc->exp_errno = 0;
+	}
+}
+
 static void setup(void)
 {
+	unsigned int i;
+
+	if (geteuid() == 0) {
+		for (i = 0; i < ARRAY_SIZE(tcases); i++)
+			verify_root(&tcases[i]);
+	}
+
 	SAFE_TOUCH(FNAME_RWX, 0777, NULL);
 	SAFE_TOUCH(FNAME_R, 0444, NULL);
 	SAFE_TOUCH(FNAME_W, 0222, NULL);
-- 
1.8.3.1




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

* [LTP] [PATCH] syscalls/access01: Fix the test to run both under nobody and root
  2016-05-16  3:19 [LTP] [PATCH] syscalls/access01: Fix the test to run both under nobody and root Xiao Yang
@ 2016-05-16 12:23 ` Cyril Hrubis
  2016-05-17  1:03   ` Xiao Yang
  2016-05-17  6:01   ` [LTP] [PATCH v2] " Xiao Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Cyril Hrubis @ 2016-05-16 12:23 UTC (permalink / raw)
  To: ltp

Hi!
This is workaround rather than a complete solution.

What I have in mind for the testcase is to add field to the test
structure that describes if the particular testcase is expected to run
under root or not. Then we can add a few testcases that tests that R and
W flags are ignored for root.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] syscalls/access01: Fix the test to run both under nobody and root
  2016-05-16 12:23 ` Cyril Hrubis
@ 2016-05-17  1:03   ` Xiao Yang
  2016-05-17  6:01   ` [LTP] [PATCH v2] " Xiao Yang
  1 sibling, 0 replies; 5+ messages in thread
From: Xiao Yang @ 2016-05-17  1:03 UTC (permalink / raw)
  To: ltp


> Hi!
> This is workaround rather than a complete solution.
>
> What I have in mind for the testcase is to add field to the test
> structure that describes if the particular testcase is expected to run
> under root or not. Then we can add a few testcases that tests that R and
> W flags are ignored for root.
>
Thanks for your suggestion.
I will rewrite this patch.

Regards,
Xiao Yang




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

* [LTP] [PATCH v2] syscalls/access01: Fix the test to run both under nobody and root
  2016-05-16 12:23 ` Cyril Hrubis
  2016-05-17  1:03   ` Xiao Yang
@ 2016-05-17  6:01   ` Xiao Yang
  2016-05-17 13:45     ` Cyril Hrubis
  1 sibling, 1 reply; 5+ messages in thread
From: Xiao Yang @ 2016-05-17  6:01 UTC (permalink / raw)
  To: ltp

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/access/access01.c | 95 ++++++++++++++++++-----------
 1 file changed, 60 insertions(+), 35 deletions(-)

diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index 7d19d08..9f1f0c4 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -27,6 +27,7 @@
  */
 #include <errno.h>
 #include <unistd.h>
+#include <sys/types.h>
 #include "tst_test.h"
 
 #define FNAME_RWX "accessfile_rwx"
@@ -39,42 +40,54 @@ static struct tcase {
 	int mode;
 	char *name;
 	int exp_errno;
+	/*0: unspecified  1:nobody expected  2:root expected*/
+	int exp_user;
 } tcases[] = {
-	{FNAME_RWX, F_OK, "F_OK", 0},
-	{FNAME_RWX, X_OK, "X_OK", 0},
-	{FNAME_RWX, W_OK, "W_OK", 0},
-	{FNAME_RWX, R_OK, "R_OK", 0},
-
-	{FNAME_RWX, R_OK|W_OK, "R_OK|W_OK", 0},
-	{FNAME_RWX, R_OK|X_OK, "R_OK|X_OK", 0},
-	{FNAME_RWX, W_OK|X_OK, "W_OK|X_OK", 0},
-	{FNAME_RWX, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", 0},
-
-	{FNAME_X, X_OK, "X_OK", 0},
-	{FNAME_W, W_OK, "W_OK", 0},
-	{FNAME_R, R_OK, "R_OK", 0},
-
-	{FNAME_R, X_OK, "X_OK", EACCES},
-	{FNAME_R, W_OK, "W_OK", EACCES},
-	{FNAME_W, R_OK, "R_OK", EACCES},
-	{FNAME_W, X_OK, "X_OK", EACCES},
-	{FNAME_X, R_OK, "R_OK", EACCES},
-	{FNAME_X, W_OK, "W_OK", EACCES},
-
-	{FNAME_R, W_OK|X_OK, "W_OK|X_OK", EACCES},
-	{FNAME_R, R_OK|X_OK, "R_OK|X_OK", EACCES},
-	{FNAME_R, R_OK|W_OK, "R_OK|W_OK", EACCES},
-	{FNAME_R, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES},
-
-	{FNAME_W, W_OK|X_OK, "W_OK|X_OK", EACCES},
-	{FNAME_W, R_OK|X_OK, "R_OK|X_OK", EACCES},
-	{FNAME_W, R_OK|W_OK, "R_OK|W_OK", EACCES},
-	{FNAME_W, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES},
-
-	{FNAME_X, W_OK|X_OK, "W_OK|X_OK", EACCES},
-	{FNAME_X, R_OK|X_OK, "R_OK|X_OK", EACCES},
-	{FNAME_X, R_OK|W_OK, "R_OK|W_OK", EACCES},
-	{FNAME_X, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES},
+	{FNAME_RWX, F_OK, "F_OK", 0, 0},
+	{FNAME_RWX, X_OK, "X_OK", 0, 0},
+	{FNAME_RWX, W_OK, "W_OK", 0, 0},
+	{FNAME_RWX, R_OK, "R_OK", 0, 0},
+
+	{FNAME_RWX, R_OK|W_OK, "R_OK|W_OK", 0, 0},
+	{FNAME_RWX, R_OK|X_OK, "R_OK|X_OK", 0, 0},
+	{FNAME_RWX, W_OK|X_OK, "W_OK|X_OK", 0, 0},
+	{FNAME_RWX, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", 0, 0},
+
+	{FNAME_X, X_OK, "X_OK", 0, 0},
+	{FNAME_W, W_OK, "W_OK", 0, 0},
+	{FNAME_R, R_OK, "R_OK", 0, 0},
+
+	{FNAME_R, X_OK, "X_OK", EACCES, 0},
+	{FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{FNAME_W, X_OK, "X_OK", EACCES, 0},
+	{FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{FNAME_X, W_OK, "W_OK", EACCES, 1},
+
+	{FNAME_R, W_OK|X_OK, "W_OK|X_OK", EACCES, 0},
+	{FNAME_R, R_OK|X_OK, "R_OK|X_OK", EACCES, 0},
+	{FNAME_R, R_OK|W_OK, "R_OK|W_OK", EACCES, 1},
+	{FNAME_R, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES, 0},
+
+	{FNAME_W, W_OK|X_OK, "W_OK|X_OK", EACCES, 0},
+	{FNAME_W, R_OK|X_OK, "R_OK|X_OK", EACCES, 0},
+	{FNAME_W, R_OK|W_OK, "R_OK|W_OK", EACCES, 1},
+	{FNAME_W, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES, 0},
+
+	{FNAME_X, W_OK|X_OK, "W_OK|X_OK", EACCES, 1},
+	{FNAME_X, R_OK|X_OK, "R_OK|X_OK", EACCES, 1},
+	{FNAME_X, R_OK|W_OK, "R_OK|W_OK", EACCES, 1},
+	{FNAME_X, R_OK|W_OK|X_OK, "R_OK|W_OK|X_OK", EACCES, 1},
+
+	{FNAME_R, W_OK, "W_OK", 0, 2},
+	{FNAME_R, R_OK|W_OK, "R_OK|W_OK", 0, 2},
+
+	{FNAME_W, R_OK, "R_OK", 0, 2},
+	{FNAME_W, R_OK|W_OK, "R_OK|W_OK", 0, 2},
+
+	{FNAME_X, R_OK, "R_OK", 0, 2},
+	{FNAME_X, W_OK, "W_OK", 0, 2},
+	{FNAME_X, R_OK|W_OK, "R_OK|W_OK", 0, 2}
 };
 
 static void verify_success(struct tcase *tc)
@@ -109,6 +122,18 @@ static void verify_access(unsigned int n)
 {
 	struct tcase *tc = tcases + n;
 
+	if (tc->exp_user == 1 && geteuid() == 0) {
+		tst_res(TCONF, "access(%s, %s) is ignored for root",
+			tc->fname, tc->name);
+		return;
+	}
+
+	if (tc->exp_user == 2 && geteuid() != 0) {
+		tst_res(TCONF, "access(%s, %s) is ignored for nobody",
+			tc->fname, tc->name);
+		return;
+	}
+
 	TEST(access(tc->fname, tc->mode));
 
 	if (tc->exp_errno)
-- 
1.8.3.1




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

* [LTP] [PATCH v2] syscalls/access01: Fix the test to run both under nobody and root
  2016-05-17  6:01   ` [LTP] [PATCH v2] " Xiao Yang
@ 2016-05-17 13:45     ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2016-05-17 13:45 UTC (permalink / raw)
  To: ltp

Hi!
I've changed the test to fork a child and call setuid() instead of doing
TCONF when the test should be executed as a nobody and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2016-05-17 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-16  3:19 [LTP] [PATCH] syscalls/access01: Fix the test to run both under nobody and root Xiao Yang
2016-05-16 12:23 ` Cyril Hrubis
2016-05-17  1:03   ` Xiao Yang
2016-05-17  6:01   ` [LTP] [PATCH v2] " Xiao Yang
2016-05-17 13:45     ` Cyril Hrubis

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.