3 # this verifies that SEC_STD_WRITE_OWNER only effectively grants take-ownership
4 # permissions but NOT give-ownership.
8 echo "Usage: $0 SERVER SERVER_IP USERNAME PASSWORD PREFIX SMBCLIENT SMBCACLS NET SHARE"
22 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
23 SMBCACLS="$VALGRIND ${SMBCACLS}"
24 NET="$VALGRIND ${NET}"
27 incdir=$(dirname $0)/../../../testprogs/blackbox
35 $SMBCLIENT //$SERVER/$share -U $USERNAME%$PASSWORD -c "rm $fname"
36 $SMBCLIENT //$SERVER/$share -U $USERNAME%$PASSWORD -c "ls" | grep "$fname" && return 1
37 $SMBCLIENT //$SERVER/$share -U $USERNAME%$PASSWORD -c "lcd $PREFIX; put $fname" || return 1
44 $SMBCLIENT //$SERVER/$share -U $USERNAME%$PASSWORD -c "rm $fname"
52 echo "$SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD -C '$owner'"
53 $SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD -C "$owner" || return 1
60 local expected_owner=$3
63 echo "$SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD"
64 $SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD
65 actual_owner=$($SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD | sed -rn 's/^OWNER:(.*)/\1/p')
66 echo "actual_owner = $actual_owner"
67 if ! test "x$actual_owner" = "x$expected_owner"; then
68 echo "Actual owner of $share/$fname is [$actual_owner] expected [$expected_owner]"
80 local_ace=$(printf '%s' "$ace" | sed 's|\\|/|')
83 out=$($SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD)
91 echo "$out" | grep "$local_ace" && return 0
94 $SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD -a "$ace"
101 out=$($SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD)
102 if [ $? -ne 0 ]; then
103 echo "get new acl failed"
109 echo "Checking if new ACL has \"$local_ace\""
110 echo "$out" | grep "$local_ace" || return 1
119 local expected_error=$4
122 out=$($SMBCACLS //$SERVER/$share $fname -U $USERNAME%$PASSWORD -C "$user") && return 1
123 # it failed, now check it returned the expected error code
124 echo "$out" | grep $expected_error || return 1
128 testit "create testfile" setup_testfile $SHARE afile || failed=$(expr $failed + 1)
129 testit "verify owner" win_owner_is $SHARE afile "$SERVER/$USERNAME" || failed=$(expr $failed + 1)
131 # Grant SeRestorePrivilege to the user and full rights on the file
132 testit "grant SeRestorePrivilege" $NET rpc rights grant $USERNAME SeRestorePrivilege -U $USERNAME%$PASSWORD -I $SERVER_IP || failed=$(expr $failed + 1)
133 testit "grant full rights" add_ace $SHARE afile "ACL:$SERVER\\$USERNAME:ALLOWED/0x0/FULL" || failed=$(expr $failed + 1)
135 # We have SeRestorePrivilege, so both give and take ownership must succeed
136 testit "give owner with SeRestorePrivilege" set_win_owner $SHARE afile "$SERVER\user1" || failed=$(expr $failed + 1)
137 testit "verify owner" win_owner_is $SHARE afile "$SERVER/user1" || failed=$(expr $failed + 1)
138 testit "take owner" set_win_owner $SHARE afile "$SERVER\\$USERNAME" || failed=$(expr $failed + 1)
139 testit "verify owner" win_owner_is $SHARE afile "$SERVER/$USERNAME" || failed=$(expr $failed + 1)
141 # Revoke SeRestorePrivilege, give ownership must fail now with NT_STATUS_INVALID_OWNER
142 testit "revoke SeRestorePrivilege" $NET rpc rights revoke $USERNAME SeRestorePrivilege -U $USERNAME%$PASSWORD -I $SERVER_IP || failed=$(expr $failed + 1)
143 testit "give owner without SeRestorePrivilege" chown_give_fails $SHARE afile "$SERVER\user1" NT_STATUS_INVALID_OWNER || failed=$(expr $failed + 1)
145 testit "delete testfile" remove_testfile $SHARE afile || failed=$(expr $failed + 1)