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_002
29#
30# DESCRIPTION:
31#	Copy ACLs to/from and smbfs mount with cpio
32#
33# STRATEGY:
34#       1. run "mount -F smbfs //server/public /export/mnt"
35#       2. create a file, make sure it has an ACL
36#       3. cpio -oP -O archive.cpio
37#	4. remove the file
38#	5. cpio -iP -I archive.cpio
39#	6. verify extracted ACL matches original
40#
41
42. $STF_SUITE/include/libtest.ksh
43
44tc_id="acl002"
45tc_desc="Verify we can save/restore ACLs with cpio"
46print_test_case $tc_id - $tc_desc
47
48if [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
49	[[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
50    set -x
51fi
52
53server=$(server_name) || return
54
55testdir_init $TDIR
56smbmount_clean $TMNT
57smbmount_init $TMNT
58
59cmd="mount -F smbfs -oacl //$TUSER:$TPASS@$server/public $TMNT"
60cti_execute -i '' FAIL $cmd
61if [[ $? != 0 ]]; then
62	cti_fail "FAIL: $cmd"
63	return
64else
65	cti_report "PASS: $cmd"
66fi
67
68# Require that the mount supports ACLs
69smbmount_getmntopts $TMNT |grep /acl/ >/dev/null
70if [[ $? != 0 ]]; then
71	smbmount_clean $TMNT
72	cti_unsupported "UNSUPPORTED (no ACLs in this mount)"
73	return
74fi
75
76# create a file, make sure it has an ACL
77cmd="cp /etc/passwd $TMNT/$tc_id"
78cti_execute_cmd $cmd
79if [[ $? != 0 ]]; then
80	cti_fail "FAIL: $cmd"
81	smbmount_clean $TMNT
82	return
83fi
84cmd="ls -V $TMNT/$tc_id"
85cti_execute_cmd $cmd
86if [[ $? != 0 ]]; then
87	cti_fail "FAIL: $cmd"
88	smbmount_clean $TMNT
89	return
90fi
91tail +2 cti_stdout > acl_save
92
93#       3. cpio -oP -O archive.cpio
94cmd="echo $tc_id | \
95 ( cd $TMNT ; cpio -ocP -O $TDIR/$tc_id.cpio )"
96cti_execute_cmd $cmd
97if [[ $? != 0 ]]; then
98	cti_fail "FAIL: $cmd"
99	smbmount_clean $TMNT
100	return
101fi
102
103#	4. remove the file
104cti_execute_cmd "rm -f $TMNT/$tc_id"
105
106#	5. cpio -iP -I archive.cpio
107cmd="( cd $TMNT ; cpio -icP -I $TDIR/$tc_id.cpio )"
108cti_execute_cmd $cmd
109if [[ $? != 0 ]]; then
110	cti_fail "FAIL: $cmd"
111	smbmount_clean $TMNT
112	return
113fi
114
115#	6. verify extracted ACL matches original
116cmd="ls -V $TMNT/$tc_id"
117cti_execute_cmd $cmd
118if [[ $? != 0 ]]; then
119	cti_fail "FAIL: $cmd"
120	smbmount_clean $TMNT
121	return
122fi
123tail +2 cti_stdout > acl_test
124
125cmd="diff acl_save acl_test"
126cti_execute_cmd $cmd
127if [[ $? != 0 ]]; then
128	cti_fail "FAIL: $cmd"
129	smbmount_clean $TMNT
130	return
131fi
132
133cti_execute_cmd "rm $TDIR/$tc_id.cpio"
134cti_execute_cmd "rm $TMNT/$tc_id"
135smbmount_clean $TMNT
136
137cti_pass "${tc_id}: PASS"
138