1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# CDDL HEADER START 5# 6# The contents of this file are subject to the terms of the 7# Common Development and Distribution License (the "License"). 8# You may not use this file except in compliance with the License. 9# 10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11# or https://opensource.org/licenses/CDDL-1.0. 12# See the License for the specific language governing permissions 13# and limitations under the License. 14# 15# When distributing Covered Code, include this CDDL HEADER in each 16# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17# If applicable, add the following below this CDDL HEADER, with the 18# fields enclosed by brackets "[]" replaced with your own identifying 19# information: Portions Copyright [yyyy] [name of copyright owner] 20# 21# CDDL HEADER END 22# 23 24# 25# Portions Copyright 2021 iXsystems, Inc. 26# 27 28. $STF_SUITE/include/libtest.shlib 29. $STF_SUITE/tests/functional/acl/acl_common.kshlib 30 31# 32# DESCRIPTION: 33# Verify that DOS mode flags function correctly. 34# 35# 36# STRATEGY: 37# 1. ARCHIVE 38# 2. HIDDEN 39# 3. OFFLINE 40# 4. READONLY 41# 5. REPARSE 42# 6. SPARSE 43# 7. SYSTEM 44# 45 46verify_runnable "both" 47 48function cleanup 49{ 50 rm -f $testfile 51} 52 53function hasflag 54{ 55 typeset flag=$1 56 typeset path=$2 57 58 if is_linux; then 59 read_dos_attributes $path 60 else 61 ls -lo $path | awk '{ print $5 }' 62 fi | grep -qwF $flag 63} 64 65log_assert "Verify DOS mode flags function correctly" 66log_onexit cleanup 67 68testfile=$TESTDIR/testfile 69owner=$ZFS_ACL_STAFF1 70other=$ZFS_ACL_STAFF2 71 72if is_linux; then 73 changeflags=write_dos_attributes 74else 75 changeflags=chflags 76fi 77 78# 79# ARCHIVE 80# 81# This flag is set by ZFS when a file has been updated to indicate that 82# the file needs to be archived. 83# 84log_must touch $testfile 85log_must hasflag uarch $testfile 86log_must $changeflags nouarch $testfile 87log_must hasflag - $testfile 88log_must touch $testfile 89if ! is_linux; then 90 log_must hasflag uarch $testfile 91fi 92log_must rm $testfile 93log_must user_run $owner touch $testfile 94log_must hasflag uarch $testfile 95log_must user_run $owner $changeflags nouarch $testfile 96log_mustnot user_run $other $changeflags uarch $testfile 97log_must hasflag - $testfile 98log_must user_run $owner touch $testfile 99log_mustnot user_run $other $changeflags nouarch $testfile 100if ! is_linux; then 101 log_must hasflag uarch $testfile 102fi 103log_must user_run $owner rm $testfile 104 105# 106# HIDDEN 107# 108log_must touch $testfile 109log_must $changeflags hidden $testfile 110log_must hasflag hidden $testfile 111log_must $changeflags 0 $testfile 112log_must hasflag - $testfile 113log_must rm $testfile 114log_must user_run $owner touch $testfile 115log_must user_run $owner $changeflags hidden $testfile 116log_mustnot user_run $other $changeflags nohidden $testfile 117log_must hasflag hidden $testfile 118log_must user_run $owner $changeflags 0 $testfile 119log_mustnot user_run $other $changeflags hidden $testfile 120log_must hasflag - $testfile 121log_must user_run $owner rm $testfile 122 123 124# 125# OFFLINE 126# 127log_must touch $testfile 128log_must $changeflags offline $testfile 129log_must hasflag offline $testfile 130log_must $changeflags 0 $testfile 131log_must hasflag - $testfile 132log_must rm $testfile 133log_must user_run $owner touch $testfile 134log_must user_run $owner $changeflags offline $testfile 135log_mustnot user_run $other $changeflags nooffline $testfile 136log_must hasflag offline $testfile 137log_must user_run $owner $changeflags 0 $testfile 138log_mustnot user_run $other $changeflags offline $testfile 139log_must hasflag - $testfile 140log_must user_run $owner rm $testfile 141 142# 143# READONLY 144# 145# This flag prevents users from writing or appending to the file, 146# but root is always allowed the operation. 147# 148log_must touch $testfile 149log_must $changeflags rdonly $testfile 150log_must hasflag rdonly $testfile 151log_must eval "echo 'root write allowed' >> $testfile" 152log_must cat $testfile 153log_must $changeflags 0 $testfile 154log_must hasflag - $testfile 155log_must rm $testfile 156# It is required to still be able to write to an fd that was opened RW before 157# READONLY is set. We have a special test program for that. 158log_must user_run $owner touch $testfile 159log_mustnot user_run $other $changeflags rdonly $testfile 160log_must user_run $owner dosmode_readonly_write $testfile 161log_mustnot user_run $other $changeflags nordonly $testfile 162log_must hasflag rdonly $testfile 163if ! is_linux; then 164 log_mustnot user_run $owner "echo 'user write forbidden' >> $testfile" 165fi 166log_must eval "echo 'root write allowed' >> $testfile" 167# We are still allowed to read and remove the file when READONLY is set. 168log_must user_run $owner cat $testfile 169log_must user_run $owner rm $testfile 170 171# 172# REPARSE 173# 174# not allowed to be changed 175 176# 177# SPARSE 178# 179log_must truncate -s 1m $testfile 180log_must $changeflags sparse $testfile 181log_must hasflag sparse $testfile 182log_must $changeflags 0 $testfile 183log_must hasflag - $testfile 184log_must rm $testfile 185log_must user_run $owner truncate -s 1m $testfile 186log_must user_run $owner $changeflags sparse $testfile 187log_mustnot user_run $other $changeflags nosparse $testfile 188log_must hasflag sparse $testfile 189log_must user_run $owner $changeflags 0 $testfile 190log_mustnot user_run $other $changeflags sparse $testfile 191log_must hasflag - $testfile 192log_must user_run $owner rm $testfile 193 194# 195# SYSTEM 196# 197log_must touch $testfile 198log_must $changeflags system $testfile 199log_must hasflag system $testfile 200log_must $changeflags 0 $testfile 201log_must hasflag - $testfile 202log_must rm $testfile 203log_must user_run $owner touch $testfile 204log_must user_run $owner $changeflags system $testfile 205log_mustnot user_run $other $changeflags nosystem $testfile 206log_must hasflag system $testfile 207log_must user_run $owner $changeflags 0 $testfile 208log_mustnot user_run $other $changeflags system $testfile 209log_must hasflag - $testfile 210log_must user_run $owner rm $testfile 211 212log_pass "DOS mode flags function correctly" 213