[CRIU] [PATCH 2/2] test: different_creds -- Enhance the testing

Cyrill Gorcunov gorcunov at openvz.org
Wed Dec 23 07:55:29 PST 2015


To test c/r of creds we need more precise way,
so lets add a few additional creds to test.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/live/static/different_creds.c    | 59 +++++++++++++++++++++++++++---
 test/zdtm/live/static/different_creds.desc |  2 +-
 2 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/test/zdtm/live/static/different_creds.c b/test/zdtm/live/static/different_creds.c
index 3bdc9c646915..af7aa3c6f95a 100644
--- a/test/zdtm/live/static/different_creds.c
+++ b/test/zdtm/live/static/different_creds.c
@@ -17,21 +17,53 @@ const char *test_author	= "Tycho Andersen <tycho.andersen at canonical.com>";
 
 void *drop_caps_and_wait(void *arg)
 {
-	int fd = *((int *) arg);
+	int fd = *((int *) arg), i;
 	void *retcode = (void *)0xdeadbeaf;
 	cap_t caps;
 	char c;
 
+	typedef struct cap_set {
+		cap_flag_value_t	val;
+		cap_flag_value_t	new;
+		cap_flag_t		flag;
+		cap_value_t		bit;
+	} cap_set_t;
+
+	cap_set_t src[] = {
+		{
+			.val	= CAP_CLEAR,
+			.flag	= CAP_EFFECTIVE,
+			.bit	= CAP_CHOWN,
+		},
+		{
+			.val	= CAP_SET,
+			.flag	= CAP_EFFECTIVE,
+			.bit	= CAP_DAC_OVERRIDE,
+		},
+		{
+			.val	= CAP_CLEAR,
+			.flag	= CAP_INHERITABLE,
+			.bit	= CAP_SETPCAP,
+		},
+		{
+			.val	= CAP_SET,
+			.flag	= CAP_INHERITABLE,
+			.bit	= CAP_NET_BIND_SERVICE,
+		},
+	};
+
         caps = cap_get_proc();
         if (!caps) {
                 pr_perror("cap_get_proc");
                 return NULL;
         }
 
-        if (cap_clear_flag(caps, CAP_EFFECTIVE) < 0) {
-                pr_perror("cap_clear_flag");
-                goto die;
-        }
+	for (i = 0; i < ARRAY_SIZE(src); i++) {
+		if (cap_set_flag(caps, src[i].flag, 1, &src[i].bit, src[i].val) < 0) {
+			pr_perror("Can't setup CAP %s", cap_to_name(src[i].bit));
+			goto die;
+		}
+	}
 
         if (cap_set_proc(caps) < 0) {
                 pr_perror("cap_set_proc");
@@ -48,6 +80,18 @@ void *drop_caps_and_wait(void *arg)
 		goto die;
 	}
 
+	for (i = 0; i < ARRAY_SIZE(src); i++) {
+		if (cap_get_flag(caps, src[i].bit, src[i].flag, &src[i].new) < 0) {
+			pr_perror("Can't get CAP %s", cap_to_name(src[i].bit));
+			goto die;
+		}
+
+		if (src[i].val != src[i].new) {
+			pr_err("Val mismatch on CAP %s\n", cap_to_name(src[i].bit));
+			goto die;
+		}
+	}
+
 	retcode = NULL;
 die:
         cap_free(caps);
@@ -93,8 +137,11 @@ int main(int argc, char ** argv)
 		pr_perror("Unable to jount a thread");
 		return 1;
 	}
-	if (retcode != NULL)
+
+	if (retcode != NULL) {
+		fail("retcode returned %p", retcode);
 		return 1;
+	}
 
 	pass();
 
diff --git a/test/zdtm/live/static/different_creds.desc b/test/zdtm/live/static/different_creds.desc
index 2a2274648335..fa2c82d083ee 100644
--- a/test/zdtm/live/static/different_creds.desc
+++ b/test/zdtm/live/static/different_creds.desc
@@ -1 +1 @@
-{'flavor': 'h', 'flags': 'suid crfail'}
+{'flavor': 'h', 'flags': 'suid'}
-- 
2.5.0



More information about the CRIU mailing list