svn commit: r232184 - head/tools/regression/fifo/fifo_misc

[ Available lists | Index of svn-src-all | Month of Feb 2012 | Week of 26 Feb 2012 | Raw email | View thread | Wrap long lines | Reply | Tag ]
From
Jilles Tjoelker <jilles@FreeBSD.org>
Date
26 Feb 2012 15:32:02
Subject
svn commit: r232184 - head/tools/regression/fifo/fifo_misc
Message-ID
201202261532.q1QFW285071424@svn.freebsd.org


[ Hide this part ]
Author: jilles
Date: Sun Feb 26 15:32:02 2012
New Revision: 232184
URL: http://svn.freebsd.org/changeset/base/232184

Log:
Check fchmod()/fchown() in fifo_misc test.

Modified:
head/tools/regression/fifo/fifo_misc/fifo_misc.c

Modified: head/tools/regression/fifo/fifo_misc/fifo_misc.c
==============================================================================
--- head/tools/regression/fifo/fifo_misc/fifo_misc.c Sun Feb 26 15:14:29 2012 (r232183)
+++ head/tools/regression/fifo/fifo_misc/fifo_misc.c Sun Feb 26 15:32:02 2012 (r232184)
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2005 Robert N. M. Watson
+ * Copyright (c) 2012 Jilles Tjoelker
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -223,6 +224,97 @@ test_ioctl(void)
cleanfifo("testfifo", reader_fd, writer_fd);
}

+/*
+ * fchmod(2)/fchown(2) on FIFO should work.
+ */
+static void
+test_chmodchown(void)
+{
+ struct stat sb;
+ int reader_fd, writer_fd;
+ uid_t u;
+ gid_t g;
+
+ makefifo("testfifo", __func__);
+
+ if (openfifo("testfifo", __func__, &reader_fd, &writer_fd) < 0) {
+ warn("%s: openfifo", __func__);
+ cleanfifo("testfifo", -1, -1);
+ exit(-1);
+ }
+
+ if (fchmod(reader_fd, 0666) != 0) {
+ warn("%s: fchmod", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (stat("testfifo", &sb) != 0) {
+ warn("%s: stat", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if ((sb.st_mode & 0777) != 0666) {
+ warnx("%s: stat chmod result", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (fstat(writer_fd, &sb) != 0) {
+ warn("%s: fstat", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if ((sb.st_mode & 0777) != 0666) {
+ warnx("%s: fstat chmod result", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (fchown(reader_fd, -1, -1) != 0) {
+ warn("%s: fchown 1", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ u = geteuid();
+ if (u == 0)
+ u = 1;
+ g = getegid();
+ if (fchown(reader_fd, u, g) != 0) {
+ warn("%s: fchown 2", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+ if (stat("testfifo", &sb) != 0) {
+ warn("%s: stat", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (sb.st_uid != u || sb.st_gid != g) {
+ warnx("%s: stat chown result", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (fstat(writer_fd, &sb) != 0) {
+ warn("%s: fstat", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ if (sb.st_uid != u || sb.st_gid != g) {
+ warnx("%s: fstat chown result", __func__);
+ cleanfifo("testfifo", reader_fd, writer_fd);
+ exit(-1);
+ }
+
+ cleanfifo("testfifo", -1, -1);
+}
+
int
main(int argc, char *argv[])
{
@@ -238,6 +330,7 @@ main(int argc, char *argv[])
test_lseek();
test_truncate();
test_ioctl();
+ test_chmodchown();

return (0);
}


Elapsed time: 0.115 seconds