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 https://opensource.org/licenses/CDDL-1.0.
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 DOS mode flags function correctly.
33#
34#
35# STRATEGY:
36#	1. ARCHIVE
37#	2. HIDDEN
38#	3. OFFLINE
39#	4. READONLY
40#	5. REPARSE
41#	6. SPARSE
42#	7. SYSTEM
43#
44
45verify_runnable "both"
46
47function cleanup
48{
49	rm -f $testfile
50}
51
52function hasflag
53{
54	typeset flag=$1
55	typeset path=$2
56
57	if is_linux; then
58		read_dos_attributes $path
59	else
60		ls -lo $path | awk '{ print $5 }'
61	fi | grep -qwF $flag
62}
63
64log_assert "Verify DOS mode flags function correctly"
65log_onexit cleanup
66
67testfile=$TESTDIR/testfile
68owner=$ZFS_ACL_STAFF1
69other=$ZFS_ACL_STAFF2
70
71if is_linux; then
72	changeflags=write_dos_attributes
73else
74	changeflags=chflags
75fi
76
77#
78# ARCHIVE
79#
80# This flag is set by ZFS when a file has been updated to indicate that
81# the file needs to be archived.
82#
83log_must touch $testfile
84log_must hasflag uarch $testfile
85log_must $changeflags nouarch $testfile
86log_must hasflag - $testfile
87log_must touch $testfile
88if ! is_linux; then
89	log_must hasflag uarch $testfile
90fi
91log_must rm $testfile
92log_must user_run $owner touch $testfile
93log_must hasflag uarch $testfile
94log_must user_run $owner $changeflags nouarch $testfile
95log_mustnot user_run $other $changeflags uarch $testfile
96log_must hasflag - $testfile
97log_must user_run $owner touch $testfile
98log_mustnot user_run $other $changeflags nouarch $testfile
99if ! is_linux; then
100	log_must hasflag uarch $testfile
101fi
102log_must user_run $owner rm $testfile
103
104#
105# HIDDEN
106#
107log_must touch $testfile
108log_must $changeflags hidden $testfile
109log_must hasflag hidden $testfile
110log_must $changeflags 0 $testfile
111log_must hasflag - $testfile
112log_must rm $testfile
113log_must user_run $owner touch $testfile
114log_must user_run $owner $changeflags hidden $testfile
115log_mustnot user_run $other $changeflags nohidden $testfile
116log_must hasflag hidden $testfile
117log_must user_run $owner $changeflags 0 $testfile
118log_mustnot user_run $other $changeflags hidden $testfile
119log_must hasflag - $testfile
120log_must user_run $owner rm $testfile
121
122
123#
124# OFFLINE
125#
126log_must touch $testfile
127log_must $changeflags offline $testfile
128log_must hasflag offline $testfile
129log_must $changeflags 0 $testfile
130log_must hasflag - $testfile
131log_must rm $testfile
132log_must user_run $owner touch $testfile
133log_must user_run $owner $changeflags offline $testfile
134log_mustnot user_run $other $changeflags nooffline $testfile
135log_must hasflag offline $testfile
136log_must user_run $owner $changeflags 0 $testfile
137log_mustnot user_run $other $changeflags offline $testfile
138log_must hasflag - $testfile
139log_must user_run $owner rm $testfile
140
141#
142# READONLY
143#
144# This flag prevents users from writing or appending to the file,
145# but root is always allowed the operation.
146#
147log_must touch $testfile
148log_must $changeflags rdonly $testfile
149log_must hasflag rdonly $testfile
150log_must eval "echo 'root write allowed' >> $testfile"
151log_must cat $testfile
152log_must $changeflags 0 $testfile
153log_must hasflag - $testfile
154log_must rm $testfile
155# It is required to still be able to write to an fd that was opened RW before
156# READONLY is set.  We have a special test program for that.
157log_must user_run $owner touch $testfile
158log_mustnot user_run $other $changeflags rdonly $testfile
159log_must user_run $owner dosmode_readonly_write $testfile
160log_mustnot user_run $other $changeflags nordonly $testfile
161log_must hasflag rdonly $testfile
162if ! is_linux; then
163	log_mustnot user_run $owner "echo 'user write forbidden' >> $testfile"
164fi
165log_must eval "echo 'root write allowed' >> $testfile"
166# We are still allowed to read and remove the file when READONLY is set.
167log_must user_run $owner cat $testfile
168log_must user_run $owner rm $testfile
169
170#
171# REPARSE
172#
173# not allowed to be changed
174
175#
176# SPARSE
177#
178log_must truncate -s 1m $testfile
179log_must $changeflags sparse $testfile
180log_must hasflag sparse $testfile
181log_must $changeflags 0 $testfile
182log_must hasflag - $testfile
183log_must rm $testfile
184log_must user_run $owner truncate -s 1m $testfile
185log_must user_run $owner $changeflags sparse $testfile
186log_mustnot user_run $other $changeflags nosparse $testfile
187log_must hasflag sparse $testfile
188log_must user_run $owner $changeflags 0 $testfile
189log_mustnot user_run $other $changeflags sparse $testfile
190log_must hasflag - $testfile
191log_must user_run $owner rm $testfile
192
193#
194# SYSTEM
195#
196log_must touch $testfile
197log_must $changeflags system $testfile
198log_must hasflag system $testfile
199log_must $changeflags 0 $testfile
200log_must hasflag - $testfile
201log_must rm $testfile
202log_must user_run $owner touch $testfile
203log_must user_run $owner $changeflags system $testfile
204log_mustnot user_run $other $changeflags nosystem $testfile
205log_must hasflag system $testfile
206log_must user_run $owner $changeflags 0 $testfile
207log_mustnot user_run $other $changeflags system $testfile
208log_must hasflag - $testfile
209log_must user_run $owner rm $testfile
210
211log_pass "DOS mode flags function correctly"
212