Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/fs/vfs New testcase that check file flags with unprivi...



details:   https://anonhg.NetBSD.org/src/rev/f99d319837fc
branches:  trunk
changeset: 778560:f99d319837fc
user:      njoly <njoly%NetBSD.org@localhost>
date:      Wed Apr 04 18:53:34 2012 +0000

description:
New testcase that check file flags with unprivileged credentials.

diffstat:

 tests/fs/vfs/t_unpriv.c |  50 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 49 insertions(+), 1 deletions(-)

diffs (81 lines):

diff -r 194a8cfb039a -r f99d319837fc tests/fs/vfs/t_unpriv.c
--- a/tests/fs/vfs/t_unpriv.c   Wed Apr 04 17:47:03 2012 +0000
+++ b/tests/fs/vfs/t_unpriv.c   Wed Apr 04 18:53:34 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_unpriv.c,v 1.8 2012/03/26 15:13:20 njoly Exp $       */
+/*     $NetBSD: t_unpriv.c,v 1.9 2012/04/04 18:53:34 njoly Exp $       */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -26,6 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <sys/stat.h>
 #include <sys/time.h>
 
 #include <atf-c.h>
@@ -157,9 +158,55 @@
        FSTEST_EXIT();
 }
 
+static void
+flags(const atf_tc_t *tc, const char *mp)
+{
+       const char *name = "file.test";
+       int fd, fflags;
+       struct stat st;
+
+       FSTEST_ENTER();
+
+       if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1)
+               atf_tc_fail_errno("open");
+       if (rump_sys_close(fd) == -1)
+               atf_tc_fail_errno("close");
+
+       if (rump_sys_stat(name, &st) == -1)
+               atf_tc_fail_errno("stat");
+       if (rump_sys_chflags(name, st.st_flags) == -1) {
+               if (errno == EOPNOTSUPP)
+                       atf_tc_skip("file flags not supported by file system");
+               atf_tc_fail_errno("chflags");
+       }
+
+       fflags = st.st_flags | UF_IMMUTABLE;
+
+       rump_pub_lwproc_rfork(RUMP_RFCFDG);
+       if (rump_sys_setuid(1) == -1)
+               atf_tc_fail_errno("setuid");
+       fflags |= UF_IMMUTABLE;
+       if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM)
+               atf_tc_fail_errno("chflags");
+       rump_pub_lwproc_releaselwp();
+
+       if (rump_sys_chflags(name, fflags) == -1)
+               atf_tc_fail_errno("chflags");
+
+       fflags &= ~UF_IMMUTABLE;
+       if (rump_sys_chflags(name, fflags) == -1)
+               atf_tc_fail_errno("chflags");
+
+       if (rump_sys_unlink(name) == -1)
+               atf_tc_fail_errno("unlink");
+
+       FSTEST_EXIT();
+}
+
 ATF_TC_FSAPPLY(owner, "owner unprivileged checks");
 ATF_TC_FSAPPLY(dirperms, "directory permission checks");
 ATF_TC_FSAPPLY(times, "time set checks");
+ATF_TC_FSAPPLY(flags, "file flags checks");
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -167,6 +214,7 @@
        ATF_TP_FSAPPLY(owner);
        ATF_TP_FSAPPLY(dirperms);
        ATF_TP_FSAPPLY(times);
+       ATF_TP_FSAPPLY(flags);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index