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 2010 Sun Microsystems, Inc.  All rights reserved.
25#
26
27#
28# ID: acl_005
29#
30# DESCRIPTION:
31#	Verify we can take ownership (chown)
32#
33# STRATEGY:
34#       1. run "mount -F smbfs //$TUSER@..." $TMNT
35#       2. run "mount -F smbfs //$TUSER1@..." $TMNT2
36#       3. create file2, as $TUSER1 and get owner UID
37#       4. create a file as $TUSER
38#	5. give $TUSER1 full control
39#       6. chown UID $TMNT2/file
40#	7. verify $TUSER1 owns it
41#
42
43. $STF_SUITE/include/libtest.ksh
44
45tc_id="acl005"
46tc_desc="Verify we can take ownership (chown)"
47print_test_case $tc_id - $tc_desc
48
49if [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
50	[[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
51    set -x
52fi
53
54server=$(server_name) || return
55
56smbmount_clean $TMNT
57smbmount_clean $TMNT2
58
59smbmount_init $TMNT
60smbmount_init $TMNT2
61
62#       1. run "mount -F smbfs //$TUSER@..." $TMNT
63
64cmd="mount -F smbfs -oacl //$TUSER:$TPASS@$server/public $TMNT"
65cti_execute -i '' FAIL $cmd
66if [[ $? != 0 ]]; then
67	cti_fail "FAIL: $cmd"
68	return
69else
70	cti_report "PASS: $cmd"
71fi
72
73# Require that the mount supports ACLs
74smbmount_getmntopts $TMNT |grep /acl/ >/dev/null
75if [[ $? != 0 ]]; then
76	smbmount_clean $TMNT
77	cti_unsupported "UNSUPPORTED (no ACLs in this mount)"
78	return
79fi
80
81#       2. run "mount -F smbfs //$TUSER1@..." $TMNT2
82
83cmd="mount -F smbfs -oacl //$TUSER1:$TPASS@$server/public $TMNT2"
84cti_execute -i '' FAIL $cmd
85if [[ $? != 0 ]]; then
86	cti_fail "FAIL: $cmd"
87	smbmount_clean $TMNT
88	return
89else
90	cti_report "PASS: $cmd"
91fi
92
93#       3. create a file2 as $TUSER1 and get owner UID
94
95cmd="touch $TMNT2/${tc_id}B"
96cti_execute_cmd $cmd
97if [[ $? != 0 ]]; then
98	cti_fail "FAIL: $cmd"
99	smbmount_clean $TMNT
100	smbmount_clean $TMNT2
101	return
102fi
103cmd="ls -l $TMNT/${tc_id}B"
104cti_execute_cmd $cmd
105if [[ $? != 0 ]]; then
106	cti_fail "FAIL: $cmd"
107	smbmount_clean $TMNT
108	smbmount_clean $TMNT2
109	return
110fi
111# Get the ephemereal UID and GID for $TUSER1
112read mode cnt uid gid junk < cti_stdout
113cti_execute_cmd "rm $TMNT2/${tc_id}B"
114
115#       4. create a file, as $TUSER
116
117cmd="cp /etc/passwd $TMNT/$tc_id"
118cti_execute_cmd $cmd
119if [[ $? != 0 ]]; then
120	cti_fail "FAIL: $cmd"
121	smbmount_clean $TMNT
122	smbmount_clean $TMNT2
123	return
124fi
125cmd="ls -l $TMNT/$tc_id"
126cti_execute_cmd $cmd
127if [[ $? != 0 ]]; then
128	cti_fail "FAIL: $cmd"
129	smbmount_clean $TMNT
130	smbmount_clean $TMNT2
131	return
132fi
133cp cti_stdout out_save
134
135#	5. give $TUSER1 full control
136cmd="chmod A+user:${uid}:rwxpdDaARWcCos::allow $TMNT/$tc_id"
137cti_execute_cmd $cmd
138if [[ $? != 0 ]]; then
139	cti_fail "FAIL: $cmd"
140	smbmount_clean $TMNT
141	smbmount_clean $TMNT2
142	return
143fi
144
145#       6. chown UID $TMNT2/file
146
147cmd="sudo -n chown ${uid} $TMNT2/$tc_id"
148cti_execute_cmd $cmd
149if [[ $? != 0 ]]; then
150	cti_fail "FAIL: $cmd"
151	smbmount_clean $TMNT
152	smbmount_clean $TMNT2
153	return
154fi
155
156#	6. verify $TUSER1 owns it
157
158cmd="ls -l $TMNT2/$tc_id"
159cti_execute_cmd $cmd
160if [[ $? != 0 ]]; then
161	cti_fail "FAIL: $cmd"
162	smbmount_clean $TMNT
163	smbmount_clean $TMNT2
164	return
165fi
166cp cti_stdout out_test
167
168# The new owner should be different...
169cmd="diff out_save out_test"
170cti_execute_cmd $cmd
171if [[ $? == 0 ]]; then
172	cti_fail "FAIL: owner should have changed"
173	smbmount_clean $TMNT
174	smbmount_clean $TMNT2
175	return
176fi
177
178# The new owner should contain $uid
179grep " $uid " out_test >/dev/null
180if [[ $? != 0 ]]; then
181	cti_fail "FAIL: did not find $uid"
182	smbmount_clean $TMNT
183	smbmount_clean $TMNT2
184	return
185fi
186
187cti_execute_cmd "rm $TMNT/$tc_id"
188smbmount_clean $TMNT
189smbmount_clean $TMNT2
190
191cti_pass "${tc_id}: PASS"
192