[CRIU] [PATCH] test: pty01 -- Add custom uid/gid

Cyrill Gorcunov gorcunov at openvz.org
Wed Aug 31 01:53:02 PDT 2016


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/static/pty01.c    | 26 +++++++++++++++++++++++++-
 test/zdtm/static/pty01.desc |  1 +
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 test/zdtm/static/pty01.desc

diff --git a/test/zdtm/static/pty01.c b/test/zdtm/static/pty01.c
index 46710e280bca..151e96339dd4 100644
--- a/test/zdtm/static/pty01.c
+++ b/test/zdtm/static/pty01.c
@@ -1,6 +1,7 @@
 #define _XOPEN_SOURCE
+#define _DEFAULT_SOURCE
+
 #include <stdlib.h>
-#include "zdtmtst.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -9,6 +10,8 @@
 #include <termios.h>
 #include <signal.h>
 
+#include "zdtmtst.h"
+
 const char *test_doc	= "Check two pts on ptmx";
 const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
 
@@ -19,6 +22,10 @@ int main(int argc, char *argv[])
 	char buf[sizeof(teststr)];
 	int master, slave1, slave2, ret;
 	char *slavename;
+	struct stat st;
+
+	uid_t new_uid = 33333;
+	gid_t new_gid = 44444;
 
 	test_init(argc, argv);
 
@@ -44,11 +51,28 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	if (fchown(slave1, new_uid, new_gid)) {
+		pr_perror("Can't set uid/gid on %s", slavename);
+		return 1;
+	}
+
 	test_daemon();
 	test_waitsig();
 
 	signal(SIGHUP, SIG_IGN);
 
+	if (fstat(slave1, &st)) {
+		pr_perror("Can't fetch stat on %s", slavename);
+		return 1;
+	}
+
+	if (st.st_uid != new_uid || st.st_gid != new_gid) {
+		fail("UID/GID mismatch (got %d/%d but %d/%d expected)",
+		     (int)st.st_uid, (int)st.st_gid,
+		     (int)new_uid, (int)new_gid);
+		return 1;
+	}
+
 	ret = write(master, teststr, sizeof(teststr) - 1);
 	if (ret != sizeof(teststr) - 1) {
 		pr_perror("write(master) failed");
diff --git a/test/zdtm/static/pty01.desc b/test/zdtm/static/pty01.desc
new file mode 100644
index 000000000000..2eac7e654bf2
--- /dev/null
+++ b/test/zdtm/static/pty01.desc
@@ -0,0 +1 @@
+{'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list