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