test: pty01 -- Add custom uid/gid

Submitted by Cyrill Gorcunov on Aug. 31, 2016, 8:53 a.m.

Details

Message ID 1472633582-8946-1-git-send-email-gorcunov@openvz.org
State Rejected
Series "tty: Restore peers uid, gid"
Headers show

Commit Message

Cyrill Gorcunov Aug. 31, 2016, 8:53 a.m.
Signed-off-by: Cyrill Gorcunov <gorcunov@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

Patch hide | download patch | download mbox

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@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'}