4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29 # Copyright 2016 Nexenta Systems, Inc.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/delegate/delegate.cfg
36 # Cleanup exist user/group.
38 function cleanup_user_group
41 for i in $STAFF1 $STAFF2 $OTHER1 $OTHER2 ; do
44 for i in $STAFF_GROUP $OTHER_GROUP ; do
52 # Restore test file system to the original status.
54 function restore_root_datasets
56 if datasetexists $ROOT_TESTFS ; then
57 log_must zfs destroy -Rf $ROOT_TESTFS
59 log_must zfs create $ROOT_TESTFS
61 if is_global_zone ; then
62 if datasetexists $ROOT_TESTVOL ; then
63 log_must zfs destroy -Rf $ROOT_TESTVOL
65 log_must zfs create -V $VOLSIZE $ROOT_TESTVOL
72 # Verify the specified user have permission on the dataset
75 # $2 permissions which are separated by comma(,)
81 typeset permissions=$2
84 if [[ -z $@ || -z $permissions || -z $dtst ]]; then
88 typeset type=$(get_prop type $dtst)
89 permissions=$(echo $permissions | tr -s "," " ")
94 for perm in $permissions; do
96 if [[ $type == "filesystem" ]]; then
97 check_fs_perm $user $perm $dtst
99 elif [[ $type == "volume" ]]; then
100 check_vol_perm $user $perm $dtst
104 if ((ret != 0)) ; then
105 log_note "Fail: $user should have $perm " \
116 # Verify the specified user have no permission on the dataset
119 # $2 permissions which are separated by comma(,)
122 function verify_noperm
125 typeset permissions=$2
128 if [[ -z $@ || -z $permissions || -z $dtst ]]; then
132 typeset type=$(get_prop type $dtst)
133 permissions=$(echo $permissions | tr -s "," " ")
138 for perm in $permissions; do
140 if [[ $type == "filesystem" ]]; then
141 check_fs_perm $user $perm $dtst
143 elif [[ $type == "volume" ]]; then
144 check_vol_perm $user $perm $dtst
148 if ((ret == 0)) ; then
149 log_note "Fail: $user should not have $perm " \
168 verify_send $user $perm $dtst
172 verify_allow $user $perm $dtst
176 verify_userprop $user $perm $dtst
179 compression|checksum|readonly)
180 verify_ccr $user $perm $dtst
184 verify_copies $user $perm $dtst
188 verify_reservation $user $perm $dtst
199 function check_fs_perm
208 verify_fs_create $user $perm $fs
212 verify_fs_destroy $user $perm $fs
216 verify_fs_snapshot $user $perm $fs
220 verify_fs_rollback $user $perm $fs
224 verify_fs_clone $user $perm $fs
228 verify_fs_rename $user $perm $fs
232 verify_fs_mount $user $perm $fs
236 verify_fs_share $user $perm $fs
240 verify_fs_mountpoint $user $perm $fs
244 verify_fs_promote $user $perm $fs
248 verify_fs_canmount $user $perm $fs
252 verify_fs_recordsize $user $perm $fs
256 verify_fs_quota $user $perm $fs
260 verify_fs_aclmode $user $perm $fs
264 verify_fs_aclinherit $user $perm $fs
268 verify_fs_snapdir $user $perm $fs
271 atime|exec|devices|setuid|xattr)
272 verify_fs_aedsx $user $perm $fs
276 verify_fs_zoned $user $perm $fs
280 verify_fs_sharenfs $user $perm $fs
284 verify_fs_receive $user $perm $fs
288 common_perm $user $perm $fs
296 function check_vol_perm
305 verify_vol_destroy $user $perm $vol
309 verify_vol_snapshot $user $perm $vol
313 verify_vol_rollback $user $perm $vol
317 verify_vol_clone $user $perm $vol
321 verify_vol_rename $user $perm $vol
325 verify_vol_promote $user $perm $vol
329 verify_vol_volsize $user $perm $vol
333 common_perm $user $perm $vol
341 function setup_unallow_testenv
343 log_must restore_root_datasets
345 log_must zfs create $SUBFS
347 for dtst in $DATASETS ; do
348 log_must zfs allow -l $STAFF1 $LOCAL_SET $dtst
349 log_must zfs allow -d $STAFF2 $DESC_SET $dtst
350 log_must zfs allow $OTHER1 $LOCAL_DESC_SET $dtst
351 log_must zfs allow $OTHER2 $LOCAL_DESC_SET $dtst
353 log_must verify_perm $dtst $LOCAL_SET $STAFF1
354 log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER1
355 log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2
356 if [[ $dtst == $ROOT_TESTFS ]]; then
357 log_must verify_perm $SUBFS $DESC_SET $STAFF2
358 log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1
359 log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2
367 # Verify permission send for specified user on the dataset
379 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
380 typeset snap=$dtst@snap.$stamp
384 log_must zfs snapshot $snap
385 typeset bak_user=/tmp/bak.$user.$stamp
386 typeset bak_root=/tmp/bak.root.$stamp
388 user_run $user eval "zfs send $snap > $bak_user"
389 log_must eval "zfs send $snap > $bak_root"
391 if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then
395 rm -rf $bak_user > /dev/null
396 rm -rf $bak_root > /dev/null
401 function verify_fs_receive
408 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
409 typeset newfs=$fs/newfs.$stamp
410 typeset newvol=$fs/newvol.$stamp
411 typeset bak_user=/tmp/bak.$user.$stamp
412 typeset bak_root=/tmp/bak.root.$stamp
414 log_must zfs create $newfs
415 typeset datasets="$newfs"
416 if is_global_zone ; then
417 log_must zfs create -V $VOLSIZE $newvol
418 datasets="$newfs $newvol"
421 for dtst in $datasets ; do
423 typeset dtstsnap=$dtst@snap.$stamp
424 log_must zfs snapshot $dtstsnap
426 log_must eval "zfs send $dtstsnap > $bak_root"
427 log_must zfs destroy -rf $dtst
429 user_run $user eval "zfs receive $dtst < $bak_root"
430 if datasetexists $dtstsnap ; then
434 log_must zfs allow $user create $fs
435 user_run $user eval "zfs receive $dtst < $bak_root"
436 log_must zfs unallow $user create $fs
437 if datasetexists $dtstsnap ; then
441 log_must zfs allow $user mount $fs
442 user_run $user eval "zfs receive $dtst < $bak_root"
443 log_must zfs unallow $user mount $fs
444 if datasetexists $dtstsnap ; then
448 log_must zfs allow $user mount,create $fs
449 user_run $user eval "zfs receive $dtst < $bak_root"
450 log_must zfs unallow $user mount,create $fs
451 if ! datasetexists $dtstsnap ; then
455 # check the data integrity
456 log_must eval "zfs send $dtstsnap > $bak_user"
457 log_must zfs destroy -rf $dtst
458 log_must eval "zfs receive $dtst < $bak_root"
459 log_must eval "zfs send $dtstsnap > $bak_root"
460 log_must zfs destroy -rf $dtst
461 if [[ $(checksum $bak_user) != $(checksum $bak_root) ]]; then
465 rm -rf $bak_user > /dev/null
466 rm -rf $bak_root > /dev/null
473 function verify_userprop
479 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
481 user_run $user zfs set "$user:ts=$stamp" $dtst
482 if [[ $stamp != $(get_prop "$user:ts" $dtst) ]]; then
497 set -A modes "on" "off"
498 oldval=$(get_prop $perm $dtst)
499 if [[ $oldval == "on" ]]; then
501 elif [[ $oldval == "off" ]]; then
504 log_note "$user zfs set $perm=${modes[$n]} $dtst"
505 user_run $user zfs set $perm=${modes[$n]} $dtst
506 if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
513 function verify_copies
522 oldval=$(get_prop $perm $dtst)
523 if [[ $oldval -eq 1 ]]; then
525 elif [[ $oldval -eq 2 ]]; then
527 elif [[ $oldval -eq 3 ]]; then
530 log_note "$user zfs set $perm=${modes[$n]} $dtst"
531 user_run $user zfs set $perm=${modes[$n]} $dtst
532 if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then
539 function verify_reservation
545 typeset value32m=$(( 1024 * 1024 * 32 ))
546 typeset oldval=$(get_prop reservation $dtst)
547 user_run $user zfs set reservation=$value32m $dtst
548 if [[ $value32m != $(get_prop reservation $dtst) ]]; then
549 log_must zfs set reservation=$oldval $dtst
553 log_must zfs set reservation=$oldval $dtst
557 function verify_fs_create
563 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
564 typeset newfs=$fs/nfs.$stamp
565 typeset newvol=$fs/nvol.$stamp
567 user_run $user zfs create $newfs
568 if datasetexists $newfs ; then
572 log_must zfs allow $user mount $fs
573 user_run $user zfs create $newfs
574 log_must zfs unallow $user mount $fs
575 if ! datasetexists $newfs ; then
579 log_must zfs destroy $newfs
581 if is_global_zone ; then
582 # mount permission is required for sparse volume
583 user_run $user zfs create -V 150m -s $newvol
584 if datasetexists $newvol ; then
588 log_must zfs allow $user mount $fs
589 user_run $user zfs create -V 150m -s $newvol
590 log_must zfs unallow $user mount $fs
591 if ! datasetexists $newvol ; then
594 log_must zfs destroy $newvol
596 # mount and reserveration permission are
597 # required for normal volume
598 user_run $user zfs create -V 150m $newvol
599 if datasetexists $newvol ; then
603 log_must zfs allow $user mount $fs
604 user_run $user zfs create -V 150m $newvol
605 log_must zfs unallow $user mount $fs
606 if datasetexists $newvol ; then
610 log_must zfs allow $user reservation $fs
611 user_run $user zfs create -V 150m $newvol
612 log_must zfs unallow $user reservation $fs
613 if datasetexists $newvol ; then
617 log_must zfs allow $user refreservation $fs
618 user_run $user zfs create -V 150m $newvol
619 log_must zfs unallow $user refreservation $fs
620 if datasetexists $newvol ; then
624 log_must zfs allow $user mount $fs
625 log_must zfs allow $user reservation $fs
626 log_must zfs allow $user refreservation $fs
627 user_run $user zfs create -V 150m $newvol
628 log_must zfs unallow $user mount $fs
629 log_must zfs unallow $user reservation $fs
630 log_must zfs unallow $user refreservation $fs
631 if ! datasetexists $newvol ; then
634 log_must zfs destroy $newvol
640 function verify_fs_destroy
646 if ! ismounted $fs ; then
647 user_run $user zfs destroy $fs
648 if datasetexists $fs ; then
653 if ismounted $fs ; then
654 user_run $user zfs destroy $fs
655 if ! datasetexists $fs ; then
659 # mount permission is required
660 log_must zfs allow $user mount $fs
661 user_run $user zfs destroy $fs
662 if datasetexists $fs ; then
670 # Verify that given the correct delegation, a regular user can:
671 # Take a snapshot of an unmounted dataset
672 # Take a snapshot of an mounted dataset
673 # Create a snapshot by making a directory in the .zfs/snapshot directory
674 function verify_fs_snapshot
680 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
681 typeset snap=$fs@snap.$stamp
682 typeset mntpt=$(get_prop mountpoint $fs)
684 if [[ "yes" == $(get_prop mounted $fs) ]]; then
685 log_must zfs umount $fs
688 user_run $user zfs snapshot $snap
689 if ! datasetexists $snap ; then
692 log_must zfs destroy $snap
694 if [[ "no" == $(get_prop mounted $fs) ]]; then
695 log_must zfs mount $fs
698 user_run $user zfs snapshot $snap
699 if ! datasetexists $snap ; then
702 log_must zfs destroy $snap
704 typeset snapdir=${mntpt}/.zfs/snapshot/snap.$stamp
705 user_run $user mkdir $snapdir
706 if ! datasetexists $snap ; then
709 log_must zfs destroy $snap
714 function verify_fs_rollback
721 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
722 typeset snap=$fs@snap.$stamp
723 typeset mntpt=$(get_prop mountpoint $fs)
725 oldval=$(datasetcksum $fs)
726 log_must zfs snapshot $snap
728 if ! ismounted $fs; then
729 log_must zfs mount $fs
731 log_must touch $mntpt/testfile.$stamp
733 user_run $user zfs rollback -R $snap
734 if is_global_zone ; then
735 if [[ $oldval != $(datasetcksum $fs) ]]; then
739 # datasetcksum can not be used in local zone
740 if [[ -e $mntpt/testfile.$stamp ]]; then
748 function verify_fs_clone
754 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
755 typeset basefs=${fs%/*}
756 typeset snap=$fs@snap.$stamp
757 typeset clone=$basefs/cfs.$stamp
759 log_must zfs snapshot $snap
760 user_run $user zfs clone $snap $clone
761 if datasetexists $clone ; then
765 log_must zfs allow $user create $basefs
766 user_run $user zfs clone $snap $clone
767 log_must zfs unallow $user create $basefs
768 if datasetexists $clone ; then
772 log_must zfs allow $user mount $basefs
773 user_run $user zfs clone $snap $clone
774 log_must zfs unallow $user mount $basefs
775 if datasetexists $clone ; then
779 log_must zfs allow $user mount $basefs
780 log_must zfs allow $user create $basefs
781 user_run $user zfs clone $snap $clone
782 log_must zfs unallow $user create $basefs
783 log_must zfs unallow $user mount $basefs
784 if ! datasetexists $clone ; then
788 log_must zfs destroy -R $snap
793 function verify_fs_rename
799 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
800 typeset basefs=${fs%/*}
801 typeset snap=$fs@snap.$stamp
802 typeset renamefs=$basefs/nfs.$stamp
804 if ! ismounted $fs; then
805 log_must zfs mount $fs
809 user_run $user zfs rename $fs $renamefs
810 if datasetexists $renamefs ; then
815 log_must zfs allow $user create $basefs
816 user_run $user zfs rename $fs $renamefs
817 log_must zfs unallow $user create $basefs
818 if datasetexists $renamefs ; then
823 log_must zfs allow $user mount $basefs
824 user_run $user zfs rename $fs $renamefs
825 log_must zfs unallow $user mount $basefs
826 if datasetexists $renamefs ; then
831 log_must zfs allow $user mount $fs
832 user_run $user zfs rename $fs $renamefs
833 if datasetexists $renamefs ; then
834 log_must zfs unallow $user mount $renamefs
837 log_must zfs unallow $user mount $fs
840 log_must zfs allow $user create $basefs
841 log_must zfs allow $user mount $fs
842 user_run $user zfs rename $fs $renamefs
843 log_must zfs unallow $user create $basefs
844 if datasetexists $renamefs ; then
845 log_must zfs unallow $user mount $renamefs
848 log_must zfs unallow $user mount $fs
851 log_must zfs allow $user mount $basefs
852 log_must zfs allow $user mount $fs
853 user_run $user zfs rename $fs $renamefs
854 log_must zfs unallow $user mount $basefs
855 if datasetexists $renamefs ; then
856 log_must zfs unallow $user mount $renamefs
859 log_must zfs unallow $user mount $fs
862 log_must zfs allow $user create $basefs
863 log_must zfs allow $user mount $basefs
864 user_run $user zfs rename $fs $renamefs
865 log_must zfs unallow $user mount $basefs
866 log_must zfs unallow $user create $basefs
867 if ! datasetexists $renamefs ; then
871 log_must zfs rename $renamefs $fs
876 function verify_fs_mount
882 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
883 typeset mntpt=$(get_prop mountpoint $fs)
884 typeset newmntpt=/tmp/mnt.$stamp
886 if ismounted $fs ; then
887 user_run $user zfs unmount $fs
888 if ismounted $fs ; then
893 if ! ismounted $fs ; then
894 log_must zfs set mountpoint=$newmntpt $fs
895 log_must rm -rf $newmntpt
896 log_must mkdir $newmntpt
898 user_run $user zfs mount $fs
899 if ismounted $fs ; then
903 # mountpoint's owner must be the user
904 log_must chown $user $newmntpt
905 user_run $user zfs mount $fs
906 if ! ismounted $fs ; then
909 log_must zfs umount $fs
910 log_must rm -rf $newmntpt
911 log_must zfs set mountpoint=$mntpt $fs
917 function verify_fs_share
924 svcadm enable -rs nfs/server
925 typeset stat=$(svcs -H -o STA nfs/server:default)
926 if [[ $stat != "ON" ]]; then
927 log_fail "Could not enable nfs/server"
930 log_must zfs set sharenfs=on $fs
933 user_run $user zfs share $fs
934 if ! is_shared $fs; then
939 log_must zfs set sharenfs=off $fs
944 function verify_fs_mountpoint
950 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
951 typeset mntpt=$(get_prop mountpoint $fs)
952 typeset newmntpt=/tmp/mnt.$stamp
954 if ! ismounted $fs ; then
955 user_run $user zfs set mountpoint=$newmntpt $fs
957 $(get_prop mountpoint $fs) ]] ; then
960 log_must zfs set mountpoint=$mntpt $fs
963 if ismounted $fs ; then
964 user_run $user zfs set mountpoint=$newmntpt $fs
965 if [[ $mntpt != $(get_prop mountpoint $fs) ]]; then
969 # require mount permission when fs is mounted
970 log_must zfs allow $user mount $fs
971 user_run $user zfs set mountpoint=$newmntpt $fs
972 log_must zfs unallow $user mount $fs
974 $(get_prop mountpoint $fs) ]] ; then
977 log_must zfs set mountpoint=$mntpt $fs
983 function verify_fs_promote
989 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
990 typeset basefs=${fs%/*}
991 typeset snap=$fs@snap.$stamp
992 typeset clone=$basefs/cfs.$stamp
994 log_must zfs snapshot $snap
995 log_must zfs clone $snap $clone
996 log_must zfs promote $clone
998 typeset fs_orig=$(get_prop origin $fs)
999 typeset clone_orig=$(get_prop origin $clone)
1001 user_run $user zfs promote $fs
1002 # promote should fail if original fs does not have
1003 # promote permission
1004 if [[ $fs_orig != $(get_prop origin $fs) || \
1005 $clone_orig != $(get_prop origin $clone) ]]; then
1009 log_must zfs allow $user promote $clone
1010 user_run $user zfs promote $fs
1011 log_must zfs unallow $user promote $clone
1012 if [[ $fs_orig != $(get_prop origin $fs) || \
1013 $clone_orig != $(get_prop origin $clone) ]]; then
1017 log_must zfs allow $user mount $fs
1018 user_run $user zfs promote $fs
1019 log_must zfs unallow $user mount $fs
1020 if [[ $fs_orig != $(get_prop origin $fs) || \
1021 $clone_orig != $(get_prop origin $clone) ]]; then
1025 log_must zfs allow $user mount $fs
1026 log_must zfs allow $user promote $clone
1027 user_run $user zfs promote $fs
1028 log_must zfs unallow $user promote $clone
1029 log_must zfs unallow $user mount $fs
1030 if [[ $snap != $(get_prop origin $clone) || \
1031 $clone_orig != $(get_prop origin $fs) ]]; then
1038 function verify_fs_canmount
1045 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1047 if ! ismounted $fs ; then
1048 set -A modes "on" "off"
1049 oldval=$(get_prop $perm $fs)
1050 if [[ $oldval == "on" ]]; then
1052 elif [[ $oldval == "off" ]]; then
1055 log_note "$user zfs set $perm=${modes[$n]} $fs"
1056 user_run $user zfs set $perm=${modes[$n]} $fs
1057 if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
1064 if ismounted $fs ; then
1065 # property value does not change if
1066 # no mount permission
1067 set -A modes "on" "off"
1068 oldval=$(get_prop $perm $fs)
1069 if [[ $oldval == "on" ]]; then
1071 elif [[ $oldval == "off" ]]; then
1074 log_note "$user zfs set $perm=${modes[$n]} $fs"
1075 log_must zfs allow $user mount $fs
1076 user_run $user zfs set $perm=${modes[$n]} $fs
1077 log_must zfs unallow $user mount $fs
1078 if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
1086 function verify_fs_recordsize
1092 typeset value8k=$(( 1024 * 8 ))
1093 user_run $user zfs set recordsize=$value8k $fs
1094 if [[ $value8k != $(get_prop recordsize $fs) ]]; then
1101 function verify_fs_quota
1107 typeset value32m=$(( 1024 * 1024 * 32 ))
1108 user_run $user zfs set quota=$value32m $fs
1109 if [[ $value32m != $(get_prop quota $fs) ]]; then
1116 function verify_fs_aclmode
1123 set -A modes "discard" "groupmask" "passthrough"
1124 oldval=$(get_prop $perm $fs)
1125 if [[ $oldval == "discard" ]]; then
1127 elif [[ $oldval == "groupmask" ]]; then
1129 elif [[ $oldval == "passthrough" ]]; then
1132 log_note "$user zfs set aclmode=${modes[$n]} $fs"
1133 user_run $user zfs set aclmode=${modes[$n]} $fs
1134 if [[ ${modes[$n]} != $(get_prop aclmode $fs) ]]; then
1141 function verify_fs_aclinherit
1148 # PSARC/2008/231 change the default value of aclinherit to "restricted"
1149 # but still keep the old interface of "secure"
1153 set -A modes "discard" "noallow" "secure" "passthrough"
1154 oldval=$(get_prop $perm $fs)
1155 if [[ $oldval == "discard" ]]; then
1157 elif [[ $oldval == "noallow" ]]; then
1159 elif [[ $oldval == "secure" || $oldval == "restricted" ]]; then
1161 elif [[ $oldval == "passthrough" ]]; then
1164 log_note "$user zfs set aclinherit=${modes[$n]} $fs"
1165 user_run $user zfs set aclinherit=${modes[$n]} $fs
1167 typeset newval=$(get_prop aclinherit $fs)
1168 if [[ ${modes[$n]} == "secure" && $newval == "restricted" ]]; then
1170 elif [[ ${modes[$n]} != $(get_prop aclinherit $fs) ]]; then
1177 function verify_fs_snapdir
1184 set -A modes "visible" "hidden"
1185 oldval=$(get_prop $perm $fs)
1186 if [[ $oldval == "visible" ]]; then
1188 elif [[ $oldval == "hidden" ]]; then
1191 log_note "$user zfs set snapdir=${modes[$n]} $fs"
1192 user_run $user zfs set snapdir=${modes[$n]} $fs
1193 if [[ ${modes[$n]} != $(get_prop snapdir $fs) ]]; then
1200 function verify_fs_aedsx
1207 set -A modes "on" "off"
1208 oldval=$(get_prop $perm $fs)
1209 if [[ $oldval == "on" ]]; then
1211 elif [[ $oldval == "off" ]]; then
1214 log_note "$user zfs set $perm=${modes[$n]} $fs"
1215 user_run $user zfs set $perm=${modes[$n]} $fs
1216 if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then
1223 function verify_fs_zoned
1230 set -A modes "on" "off"
1231 oldval=$(get_prop $perm $fs)
1232 if [[ $oldval == "on" ]]; then
1234 elif [[ $oldval == "off" ]]; then
1237 log_note "$user zfs set $perm=${modes[$n]} $fs"
1238 if is_global_zone ; then
1239 if ! ismounted $fs ; then
1240 user_run $user zfs set \
1241 $perm=${modes[$n]} $fs
1242 if [[ ${modes[$n]} != \
1243 $(get_prop $perm $fs) ]]; then
1246 if [[ $n -eq 0 ]]; then
1247 log_mustnot zfs mount $fs
1249 log_must zfs mount $fs
1253 if ismounted $fs; then
1254 # n always is 1 in this case
1255 user_run $user zfs set \
1256 $perm=${modes[$n]} $fs
1258 $(get_prop $perm $fs) ]]; then
1262 # mount permission is needed
1264 log_must zfs allow $user mount $fs
1265 user_run $user zfs set \
1266 $perm=${modes[$n]} $fs
1267 log_must zfs unallow $user mount $fs
1268 if [[ ${modes[$n]} != \
1269 $(get_prop $perm $fs) ]]; then
1275 if ! is_global_zone; then
1276 user_run $user zfs set $perm=${modes[$n]} $fs
1277 if [[ $oldval != $(get_prop $perm $fs) ]]; then
1285 function verify_fs_sharenfs
1292 omode=$(get_prop $perm $fs)
1293 if [[ $omode == "off" ]]; then
1299 log_note "$user zfs set $perm=$nmode $fs"
1300 user_run $user zfs set $perm=$nmode $fs
1301 if [[ $(get_prop $perm $fs) != $nmode ]]; then
1305 log_note "$user zfs set $perm=$omode $fs"
1306 user_run $user zfs set $perm=$omode $fs
1307 if [[ $(get_prop $perm $fs) != $omode ]]; then
1314 function verify_vol_destroy
1320 user_run $user zfs destroy $vol
1321 if ! datasetexists $vol ; then
1325 # mount permission is required
1326 log_must zfs allow $user mount $vol
1327 user_run $user zfs destroy $vol
1328 if datasetexists $vol ; then
1335 function verify_vol_snapshot
1341 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1342 typeset basevol=${vol%/*}
1343 typeset snap=$vol@snap.$stamp
1345 user_run $user zfs snapshot $snap
1346 if datasetexists $snap ; then
1350 log_must zfs allow $user mount $vol
1351 user_run $user zfs snapshot $snap
1352 log_must zfs unallow $user mount $vol
1353 if ! datasetexists $snap ; then
1360 function verify_vol_rollback
1366 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1367 typeset basevol=${vol%/*}
1368 typeset snap=$vol@snap.$stamp
1371 log_must zfs snapshot $snap
1372 oldval=$(datasetcksum $vol)
1374 log_must dd if=/dev/random of=/dev/zvol/rdsk/$vol \
1377 user_run $user zfs rollback -R $snap
1379 if [[ $oldval == $(datasetcksum $vol) ]]; then
1383 # rollback on volume has to be with mount permission
1384 log_must zfs allow $user mount $vol
1385 user_run $user zfs rollback -R $snap
1387 log_must zfs unallow $user mount $vol
1388 if [[ $oldval != $(datasetcksum $vol) ]]; then
1395 function verify_vol_clone
1401 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1402 typeset basevol=${vol%/*}
1403 typeset snap=$vol@snap.$stamp
1404 typeset clone=$basevol/cvol.$stamp
1406 log_must zfs snapshot $snap
1408 user_run $user zfs clone $snap $clone
1409 if datasetexists $clone ; then
1413 log_must zfs allow $user create $basevol
1414 user_run $user zfs clone $snap $clone
1415 log_must zfs unallow $user create $basevol
1416 if datasetexists $clone ; then
1420 log_must zfs allow $user mount $basevol
1421 user_run $user zfs clone $snap $clone
1422 log_must zfs unallow $user mount $basevol
1423 if datasetexists $clone ; then
1427 # require create permission on parent and
1428 # mount permission on itself as well
1429 log_must zfs allow $user mount $basevol
1430 log_must zfs allow $user create $basevol
1431 user_run $user zfs clone $snap $clone
1432 log_must zfs unallow $user create $basevol
1433 log_must zfs unallow $user mount $basevol
1434 if ! datasetexists $clone ; then
1441 function verify_vol_rename
1447 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1448 typeset basevol=${vol%/*}
1449 typeset snap=$vol@snap.$stamp
1450 typeset clone=$basevol/cvol.$stamp
1451 typeset renamevol=$basevol/nvol.$stamp
1453 user_run $user zfs rename $vol $renamevol
1454 if datasetexists $renamevol ; then
1458 log_must zfs allow $user create $basevol
1459 user_run $user zfs rename $vol $renamevol
1460 log_must zfs unallow $user create $basevol
1461 if datasetexists $renamevol ; then
1465 log_must zfs allow $user mount $basevol
1466 user_run $user zfs rename $vol $renamevol
1467 log_must zfs unallow $user mount $basevol
1468 if datasetexists $renamevol ; then
1472 # require both create permission on parent and
1473 # mount permission on parent as well
1474 log_must zfs allow $user mount $basevol
1475 log_must zfs allow $user create $basevol
1476 user_run $user zfs rename $vol $renamevol
1477 log_must zfs unallow $user mount $basevol
1478 log_must zfs unallow $user create $basevol
1479 if ! datasetexists $renamevol ; then
1483 log_must zfs rename $renamevol $vol
1488 function verify_vol_promote
1494 typeset stamp=${perm}.${user}.$(date +'%F-%H%M%S')
1495 typeset basevol=${vol%/*}
1496 typeset snap=$vol@snap.$stamp
1497 typeset clone=$basevol/cvol.$stamp
1499 log_must zfs snapshot $snap
1500 log_must zfs clone $snap $clone
1501 log_must zfs promote $clone
1503 typeset vol_orig=$(get_prop origin $vol)
1504 typeset clone_orig=$(get_prop origin $clone)
1506 # promote should fail if $vol and $clone
1507 # miss either mount or promote permission
1509 user_run $user zfs promote $vol
1510 if [[ $vol_orig != $(get_prop origin $vol) || \
1511 $clone_orig != $(get_prop origin $clone) ]];
1516 # promote should fail if $vol and $clone
1517 # miss either mount or promote permission
1519 log_must zfs allow $user promote $clone
1520 user_run $user zfs promote $vol
1521 log_must zfs unallow $user promote $clone
1522 if [[ $vol_orig != $(get_prop origin $vol) || \
1523 $clone_orig != $(get_prop origin $clone) ]];
1528 # promote should fail if $vol and $clone
1529 # miss either mount or promote permission
1531 log_must zfs allow $user mount $vol
1532 user_run $user zfs promote $vol
1533 log_must zfs unallow $user mount $vol
1534 if [[ $vol_orig != $(get_prop origin $vol) || \
1535 $clone_orig != $(get_prop origin $clone) ]];
1540 # promote should fail if $vol and $clone
1541 # miss either mount or promote permission
1543 log_must zfs allow $user mount $clone
1544 user_run $user zfs promote $vol
1545 log_must zfs unallow $user mount $clone
1546 if [[ $vol_orig != $(get_prop origin $vol) || \
1547 $clone_orig != $(get_prop origin $clone) ]];
1552 # promote should fail if $vol and $clone
1553 # miss either mount or promote permission
1555 log_must zfs allow $user promote $clone
1556 log_must zfs allow $user mount $vol
1557 user_run $user zfs promote $vol
1558 log_must zfs unallow $user promote $clone
1559 log_must zfs unallow $user mount $vol
1560 if [[ $vol_orig != $(get_prop origin $vol) || \
1561 $clone_orig != $(get_prop origin $clone) ]];
1566 # promote should fail if $vol and $clone
1567 # miss either mount or promote permission
1569 log_must zfs allow $user promote $clone
1570 log_must zfs allow $user mount $clone
1571 user_run $user zfs promote $vol
1572 log_must zfs unallow $user promote $clone
1573 log_must zfs unallow $user mount $vol
1574 if [[ $vol_orig != $(get_prop origin $vol) || \
1575 $clone_orig != $(get_prop origin $clone) ]];
1580 # promote should fail if $vol and $clone
1581 # miss either mount or promote permission
1583 log_must zfs allow $user mount $vol
1584 log_must zfs allow $user mount $clone
1585 user_run $user zfs promote $vol
1586 log_must zfs unallow $user mount $vol
1587 log_must zfs unallow $user mount $clone
1588 if [[ $vol_orig != $(get_prop origin $vol) || \
1589 $clone_orig != $(get_prop origin $clone) ]];
1594 # promote only succeeds when $vol and $clone
1595 # have both mount and promote permission
1597 log_must zfs allow $user promote $clone
1598 log_must zfs allow $user mount $vol
1599 log_must zfs allow $user mount $clone
1600 user_run $user zfs promote $vol
1601 log_must zfs unallow $user promote $clone
1602 log_must zfs unallow $user mount $vol
1603 log_must zfs unallow $user mount $clone
1604 if [[ $snap != $(get_prop origin $clone) || \
1605 $clone_orig != $(get_prop origin $vol) ]]; then
1612 function verify_vol_volsize
1619 oldval=$(get_prop volsize $vol)
1620 (( newval = oldval * 2 ))
1622 reserv_size=$(get_prop refreservation $vol)
1624 if [[ "0" == $reserv_size ]]; then
1626 user_run $user zfs set volsize=$newval $vol
1627 if [[ $oldval == $(get_prop volsize $vol) ]];
1633 # normal volume, reservation permission
1635 user_run $user zfs set volsize=$newval $vol
1636 if [[ $newval == $(get_prop volsize $vol) ]];
1641 log_must zfs allow $user reservation $vol
1642 log_must zfs allow $user refreservation $vol
1643 user_run $user zfs set volsize=$newval $vol
1644 log_must zfs unallow $user reservation $vol
1645 log_must zfs unallow $user refreservation $vol
1646 if [[ $oldval == $(get_prop volsize $vol) ]];
1655 function verify_allow
1663 user_run $user zfs allow $user allow $dtst
1665 if [[ $ret -eq 0 ]]; then
1669 log_must zfs allow $user copies $dtst
1670 user_run $user zfs allow $user copies $dtst
1672 log_must zfs unallow $user copies $dtst
1673 if [[ $ret -eq 1 ]]; then