From owner-svn-src-head@FreeBSD.ORG Sun Feb 26 15:32:02 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9706D106564A; Sun, 26 Feb 2012 15:32:02 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7BFCC8FC08; Sun, 26 Feb 2012 15:32:02 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q1QFW2Hg071426; Sun, 26 Feb 2012 15:32:02 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q1QFW285071424; Sun, 26 Feb 2012 15:32:02 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201202261532.q1QFW285071424@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 26 Feb 2012 15:32:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r232184 - head/tools/regression/fifo/fifo_misc X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Feb 2012 15:32:02 -0000 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); }