#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2016 by Delphix. All rights reserved.
#
#
#
# $1 object -- file or directroy
#
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
}
#
#
# $1 object -- file or directroy
#
function get_acl #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
}
#
#
# $1 object -- file or directroy
#
function get_compact_acl #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
}
#
# Check the given two files/directories have the same ACLs
#
# Return 0, if source object acl is equal to target object acl.
#
# $1 source object
# $2 target object
#
function compare_acls #<src> <tgt>
{
typeset src=$1
typeset tgt=$2
(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
typeset tmpsrc=/tmp/compare_acls.src.$$
typeset tmptgt=/tmp/compare_acls.tgt.$$
typeset -i ret=0
ret=$?
return $ret
fi
ret=$?
return $ret
}
#
# Check that the given two objects have the same modes.
# Return 0, if their modes are equal with each other. Otherwise, return 1.
#
# $1 source object
# $2 target object
#
function compare_modes #<src> <tgt>
{
typeset src=$1
typeset tgt=$2
typeset -i i=0
set -A mode
(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
typeset obj
do
(( i = i + 1 ))
done
return 0
}
#
# Check that the given two objects have the same xattrs.
# Return 0, if their xattrs are equal with each other. Otherwise, return 1.
#
# $1 source object
# $2 target object
#
function compare_xattrs #<src> <tgt>
{
typeset src=$1
typeset tgt=$2
(( ${#src} == 0 || ${#tgt} == 0 )) && return 1
typeset tmpsrc=/tmp/compare_xattrs.src.$$
typeset tmptgt=/tmp/compare_xattrs.tgt.$$
typeset -i ret=0
ret=$?
return $ret
}
#
#
# $1 object -- file or directory.
#
function plus_sign_check_l #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
return $?
}
#
#
# $1 object -- file or directory.
#
function plus_sign_check_v #<obj>
{
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
return $?
}
#
# A wrapper function of c program
#
# $1 legal login name
# $2-n commands and options
#
function chgusr_exec #<login_name> <commands> [...]
{
chg_usr_exec $@
return $?
}
#
# Export the current user for the following usr_exec operating.
#
# $1 legal login name
#
function set_cur_usr #<login_name>
{
export ZFS_ACL_CUR_USER=$1
}
#
# Run commands by $ZFS_ACL_CUR_USER
#
# $1-n commands and options
#
function usr_exec #<commands> [...]
{
return $?
}
#
# Count how many ACEs for the speficied file or directory.
#
# $1 file or directroy name
#
function count_ACE #<file or dir name>
{
if [[ ! -e $1 ]]; then
log_note "Need input file or directroy name."
return 1
fi
(NR != 1)&&(/[0-9]:/) {count++}
END {print count}'
return 0
}
#
# Get specified number ACE content of specified file or directory.
#
# $1 file or directory name
# $2 specified number
#
function get_ACE #<file or dir name> <specified number> <verbose|compact>
{
return 1
fi
typeset file=$1
typeset -i num=$2
typeset -i next_num=-1
typeset tmpfile=/tmp/tmp_get_ACE.$$
typeset line=""
typeset args
;;
;;
"only verbose|compact is supported."
;;
esac
while read line; do
[[ -z $line ]] && continue
fi
break
fi
print -n $line
fi
else
print -n $line
fi
fi
done < $tmpfile
}
#
#
function cleanup_user_group
{
return 0
}
#
# Clean up testfile and test directory
#
function cleanup
{
if [[ -d $TESTDIR ]]; then
cd $TESTDIR
fi
}
#
# According to specified access or acl_spec, do relevant operating by using the
# specified user.
#
# $1 specified user
# $2 node
# $3 acl_spec or access
#
function rwx_node #user node acl_spec|access
{
typeset user=$1
typeset node=$2
typeset acl_spec=$3
log_note "node or acl_spec are not defined."
return 1
fi
if [[ -d $node ]]; then
return $? ;;
*:write_data:*|write_data)
fi
chgusr_exec $user touch ${node}/tmpfile > \
return $? ;;
return $? ;;
esac
else
return $? ;;
*:write_data:*|write_data)
return $? ;;
ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
return $? ;;
esac
fi
}
#
#
# $1 object -- file or directroy
#
function get_xattr #<obj>
{
typeset obj=$1
typeset xattr
if (( ${#obj} == 0 )); then
return 1
fi
/usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
done
}
#
#
function get_owner #node
{
typeset node=$1
typeset value
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
elif [[ -e $node ]]; then
fi
echo $value
}
#
#
function get_group #node
{
typeset node=$1
typeset value
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
elif [[ -e $node ]]; then
fi
echo $value
}
#
# Get the group name that a UID belongs to
#
function get_user_group #uid
{
typeset uid=$1
typeset value
if [[ -z $uid ]]; then
log_fail "UID not defined."
fi
if [[ $? -eq 0 ]]; then
echo $value
else
log_fail "Invalid UID (uid)."
fi
}
#
# Get the specified item of the specified string
#
# $1: Item number, count from 0.
# $2-n: strings
#
function getitem
{
typeset -i n=$1
shift
(( n += 1 ))
eval echo \${$n}
}
#
# This function calculate the specified directory files checksum and write
# to the specified array.
#
# $1 directory in which the files will be cksum.
# $2 file array name which was used to store file cksum information.
# $3 attribute array name which was used to store attribute information.
#
function cksum_files #<dir> <file_array_name> <attribute_array_name>
{
typeset dir=$1
typeset farr_name=$2
typeset aarr_name=$3
[[ ! -d $dir ]] && return
cd $dir
typeset -i i=0
typeset -i n=0
eval $farr_name[$i]=\$\(\cksum $f\)
typeset -i j=0
eval $aarr_name[$n]=\$\(\runat \$f \cksum \
attribute.$j\)
(( j += 1 ))
(( n += 1 ))
done
(( i += 1 ))
done
cd $oldpwd
}
#
# This function compare two cksum results array.
#
# $1 The array name which stored the cksum before operation.
# $2 The array name which stored the cksum after operation.
#
function compare_cksum #<array1> <array2>
{
typeset before=$1
typeset after=$2
eval typeset -i count=\${#$before[@]}
typeset -i i=0
return 1
fi
(( i += 1 ))
done
return 0
}
#
# This function calculate all the files cksum information in current directory
# and output them to the specified file.
#
# $1 directory from which the files will be cksum.
# $2 cksum output file
#
function record_cksum #<outfile>
{
typeset dir=$1
typeset outfile=$2
}
#
# The function create_files creates the directories and files that the script
# will operate on to test extended attribute functionality.
#
# $1 The base directory in which to create directories and files.
#
function create_files #<directory>
{
typeset basedir=$1
#
# Create the original file and its attribute files.
#
usr_exec file_write -o create -f $RES_DIR/file \
-b 1024 -d 0 -c 1
cd $INI_DIR
typeset -i i=0
typeset -i j=0
(( j += 1 ))
done
(( i += 1 ))
done
cd $oldpwd
}