|
| 1 | +#!/bin/ksh -p |
| 2 | +# |
| 3 | +# CDDL HEADER START |
| 4 | +# |
| 5 | +# The contents of this file are subject to the terms of the |
| 6 | +# Common Development and Distribution License (the "License"). |
| 7 | +# You may not use this file except in compliance with the License. |
| 8 | +# |
| 9 | +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
| 10 | +# or http://www.opensolaris.org/os/licensing. |
| 11 | +# See the License for the specific language governing permissions |
| 12 | +# and limitations under the License. |
| 13 | +# |
| 14 | +# When distributing Covered Code, include this CDDL HEADER in each |
| 15 | +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
| 16 | +# If applicable, add the following below this CDDL HEADER, with the |
| 17 | +# fields enclosed by brackets "[]" replaced with your own identifying |
| 18 | +# information: Portions Copyright [yyyy] [name of copyright owner] |
| 19 | +# |
| 20 | +# CDDL HEADER END |
| 21 | +# |
| 22 | + |
| 23 | +# |
| 24 | +# Portions Copyright 2021 iXsystems, Inc. |
| 25 | +# |
| 26 | + |
| 27 | +. $STF_SUITE/include/libtest.shlib |
| 28 | +. $STF_SUITE/tests/functional/acl/acl_common.kshlib |
| 29 | + |
| 30 | +# |
| 31 | +# DESCRIPTION: |
| 32 | +# Verify that POSIX mode bits function correctly. |
| 33 | +# |
| 34 | +# These tests are incomplete and will be added to over time. |
| 35 | +# |
| 36 | +# NOTE: Creating directory entries behaves differently between platforms. |
| 37 | +# The parent directory's group is used on FreeBSD, while the effective |
| 38 | +# group is used on Linux. We chown to the effective group when creating |
| 39 | +# directories and files in these tests to achieve consistency across all |
| 40 | +# platforms. |
| 41 | +# |
| 42 | +# STRATEGY: |
| 43 | +# 1. Sanity check the POSIX mode test on tmpfs |
| 44 | +# 2. Test POSIX mode bits on ZFS |
| 45 | +# |
| 46 | + |
| 47 | +verify_runnable "both" |
| 48 | + |
| 49 | +function cleanup |
| 50 | +{ |
| 51 | + umount -f $tmpdir |
| 52 | + rm -rf $tmpdir $TESTDIR/dir |
| 53 | +} |
| 54 | + |
| 55 | +log_assert "Verify POSIX mode bits function correctly" |
| 56 | +log_onexit cleanup |
| 57 | + |
| 58 | +owner=$ZFS_ACL_STAFF1 |
| 59 | +other=$ZFS_ACL_STAFF2 |
| 60 | +group=$ZFS_ACL_STAFF_GROUP |
| 61 | +if is_linux; then |
| 62 | + wheel=root |
| 63 | +else |
| 64 | + wheel=wheel |
| 65 | +fi |
| 66 | + |
| 67 | +function test_posix_mode # base |
| 68 | +{ |
| 69 | + typeset base=$1 |
| 70 | + typeset dir=$base/dir |
| 71 | + typeset file=$dir/file |
| 72 | + |
| 73 | + # dir owned by root |
| 74 | + log_must mkdir $dir |
| 75 | + log_must chown :$wheel $dir |
| 76 | + log_must chmod 007 $dir |
| 77 | + |
| 78 | + # file owned by root |
| 79 | + log_must touch $file |
| 80 | + log_must chown :$wheel $file |
| 81 | + log_must ls -la $dir |
| 82 | + log_must rm $file |
| 83 | + |
| 84 | + log_must touch $file |
| 85 | + log_must chown :$wheel $file |
| 86 | + log_must user_run $other rm $file |
| 87 | + |
| 88 | + # file owned by user |
| 89 | + log_must user_run $owner touch $file |
| 90 | + log_must chown :$group $file |
| 91 | + log_must ls -la $dir |
| 92 | + log_must user_run $owner rm $file |
| 93 | + |
| 94 | + log_must user_run $owner touch $file |
| 95 | + log_must chown :$group $file |
| 96 | + log_must user_run $other rm $file |
| 97 | + |
| 98 | + log_must user_run $owner touch $file |
| 99 | + log_must chown :$group $file |
| 100 | + log_must rm $file |
| 101 | + |
| 102 | + log_must rm -rf $dir |
| 103 | + |
| 104 | + # dir owned by user |
| 105 | + log_must user_run $owner mkdir $dir |
| 106 | + log_must chown :$group $dir |
| 107 | + log_must user_run $owner chmod 007 $dir |
| 108 | + |
| 109 | + # file owned by root |
| 110 | + log_must touch $file |
| 111 | + log_must chown :$wheel $file |
| 112 | + log_must ls -la $dir |
| 113 | + log_must rm $file |
| 114 | + |
| 115 | + log_must touch $file |
| 116 | + log_must chown :$wheel $file |
| 117 | + log_mustnot user_run $other rm $file |
| 118 | + log_must rm $file |
| 119 | + |
| 120 | + # file owned by user |
| 121 | + log_mustnot user_run $owner touch $file |
| 122 | + log_must touch $file |
| 123 | + log_must chown $owner:$group $file |
| 124 | + log_must ls -la $dir |
| 125 | + log_mustnot user_run $owner rm $file |
| 126 | + log_mustnot user_run $other rm $file |
| 127 | + log_must rm $file |
| 128 | + |
| 129 | + log_must rm -rf $dir |
| 130 | +} |
| 131 | + |
| 132 | +# Sanity check on tmpfs first |
| 133 | +tmpdir=$(TMPDIR=$TEST_BASE_DIR mktemp -d) |
| 134 | +log_must mount -t tmpfs tmp $tmpdir |
| 135 | +log_must chmod 777 $tmpdir |
| 136 | + |
| 137 | +test_posix_mode $tmpdir |
| 138 | + |
| 139 | +log_must umount $tmpdir |
| 140 | +log_must rmdir $tmpdir |
| 141 | + |
| 142 | +# Verify ZFS |
| 143 | +test_posix_mode $TESTDIR |
| 144 | + |
| 145 | +log_pass "POSIX mode bits function correctly" |
0 commit comments