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# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2012 by Delphix. All rights reserved.
30# Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
31#
32
33. $STF_SUITE/tests/functional/acl/acl_common.kshlib
34. $STF_SUITE/tests/functional/acl/cifs/cifs.kshlib
35
36#
37# DESCRIPTION:
38#	Verify the ability to continue writing to a file
39#	after opening the file read/write, and setting
40#	the DOS Readonly flag on that file.
41#
42# STRATEGY:
43#	Run the special program "dos_ro"
44
45verify_runnable "both"
46
47function cleanup
48{
49	if [[ -n $gobject ]]; then
50		destroy_object $gobject
51	fi
52
53	for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do
54		mtpt=$(get_prop mountpoint $fs)
55		log_must rm -rf $mtpt/file.* $mtpt/dir.*
56	done
57
58	[[ -f $TESTFILE ]] && rm $TESTFILE
59}
60
61#
62# Set the special attribute to the given node
63#
64# $1: The given node (file/dir)
65# $2: The special attribute to be set
66#
67function set_attribute
68{
69	typeset object=$1
70	typeset attr=$2
71
72	if [[ -z $attr ]]; then
73		attr="AHRSadimu"
74		if [[ -f $object ]]; then
75			attr="${attr}q"
76		fi
77	fi
78	chmod S+c${attr} $object
79	return $?
80}
81
82#
83# Clear the special attribute to the given node
84#
85# $1: The given node (file/dir)
86# $2: The special attribute to be cleared
87#
88function clear_attribute
89{
90	typeset object=$1
91	typeset attr=$2
92
93	if [[ -z $attr ]]; then
94		if is_global_zone ; then
95			attr="AHRSadimu"
96			if [[ -f $object ]]; then
97				attr="${attr}q"
98			fi
99		else
100			attr="AHRS"
101		fi
102	fi
103
104	chmod S-c${attr} $object
105	return $?
106}
107
108FILES="file.0 file.1"
109FS="$TESTPOOL $TESTPOOL/$TESTFS"
110ATTRS="R"
111
112TESTFILE=/tmp/tfile
113TESTDIR=tdir
114TESTATTR=tattr
115TESTACL=user:$ZFS_ACL_OTHER1:write_data:allow
116TESTMODE=777
117TESTSTR="ZFS test suites"
118
119log_assert "Verify writable open handle still works after " \
120    "setting the DOS Readonly flag on a file."
121log_onexit cleanup
122
123echo "$TESTSTR" > $TESTFILE
124
125typeset gobject
126typeset gattr
127for fs in $FS ; do
128	mtpt=$(get_prop mountpoint $fs)
129	chmod 777 $mtpt
130	for user in root $ZFS_ACL_STAFF1; do
131		log_must set_cur_usr $user
132		for file in $FILES ; do
133			gobject=$mtpt/$file
134			create_object "file" $gobject $ZFS_ACL_CUR_USER
135			log_must dos_ro $gobject
136			destroy_object $gobject
137		done
138	done
139done
140
141log_pass "Writable handle OK after setting DOS R/O flag."
142