diff options
author | jilles <jilles@FreeBSD.org> | 2012-02-26 15:32:02 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-02-26 15:32:02 +0000 |
commit | e3b7e38d118afe935e1dab0b8ac2813702f25db1 (patch) | |
tree | a414dd72e1b3bb6b10111d351a1f9eb1a319606c /tools | |
parent | 06d1ac3238bbb36d2fd71d3e7638421d54b4e928 (diff) | |
download | FreeBSD-src-e3b7e38d118afe935e1dab0b8ac2813702f25db1.zip FreeBSD-src-e3b7e38d118afe935e1dab0b8ac2813702f25db1.tar.gz |
Check fchmod()/fchown() in fifo_misc test.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/fifo/fifo_misc/fifo_misc.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tools/regression/fifo/fifo_misc/fifo_misc.c b/tools/regression/fifo/fifo_misc/fifo_misc.c index 5e04b06..4215212 100644 --- a/tools/regression/fifo/fifo_misc/fifo_misc.c +++ b/tools/regression/fifo/fifo_misc/fifo_misc.c @@ -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); } |