Print this page
XXX Remove nawk(1)


  37         typeset obj=$1
  38         if (( ${#obj} == 0 )); then
  39                 return 1
  40         fi
  41 
  42         $LS -ld $obj | $AWK '{print $1}'
  43 }
  44 
  45 #
  46 # Get the given file/directory ACL
  47 #
  48 # $1 object -- file or directroy
  49 #
  50 function get_acl #<obj>
  51 {
  52         typeset obj=$1
  53         if (( ${#obj} == 0 )); then
  54                 return 1
  55         fi
  56 
  57         $LS -vd $obj | $NAWK '(NR != 1) {print $0}'
  58 }
  59 
  60 #
  61 # Get the given file/directory ACL
  62 #
  63 # $1 object -- file or directroy
  64 #
  65 function get_compact_acl #<obj>
  66 {
  67         typeset obj=$1
  68         if (( ${#obj} == 0 )); then
  69                 return 1
  70         fi
  71 
  72         $LS -Vd $obj | $NAWK '(NR != 1) {print $0}'
  73 }
  74 
  75 #
  76 # Check the given two files/directories have the same ACLs
  77 #
  78 # Return 0, if source object acl is equal to target object acl.
  79 #
  80 # $1 source object
  81 # $2 target object
  82 #
  83 function compare_acls #<src> <tgt>
  84 {
  85         typeset src=$1
  86         typeset tgt=$2
  87 
  88         (( ${#src} == 0 || ${#tgt} == 0 )) && return 1
  89         [[ $src == $tgt ]] && return 0
  90 
  91         typeset tmpsrc=/tmp/compare_acls.src.$$
  92         typeset tmptgt=/tmp/compare_acls.tgt.$$


 181                 return 1
 182         fi
 183 
 184         $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
 185 
 186         return $?
 187 }
 188 
 189 #
 190 # Check '+' is set for a given file/directory with 'ls [-v]' command
 191 #
 192 # $1 object -- file or directory.
 193 #
 194 function plus_sign_check_v #<obj>
 195 {
 196         typeset obj=$1
 197         if (( ${#obj} == 0 )); then
 198                 return 1
 199         fi
 200 
 201         $LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
 202 
 203         return $?
 204 }
 205 
 206 #
 207 # A wrapper function of c program
 208 #
 209 # $1 legal login name
 210 # $2-n commands and options
 211 #
 212 function chgusr_exec #<login_name> <commands> [...]
 213 {
 214         $CHG_USR_EXEC $@
 215         return $?
 216 }
 217 
 218 #
 219 # Export the current user for the following usr_exec operating.
 220 #
 221 # $1 legal login name


 231 # $1-n commands and options
 232 #
 233 function usr_exec #<commands> [...]
 234 {
 235         $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
 236         return $?
 237 }
 238 
 239 #
 240 # Count how many ACEs for the speficied file or directory.
 241 #
 242 # $1 file or directroy name
 243 #
 244 function count_ACE #<file or dir name>
 245 {
 246         if [[ ! -e $1 ]]; then
 247                 log_note "Need input file or directroy name."
 248                 return 1
 249         fi
 250 
 251         $LS -vd $1 | $NAWK 'BEGIN {count=0}
 252                         (NR != 1)&&(/[0-9]:/) {count++}
 253                         END {print count}'
 254 
 255         return 0
 256 }
 257 
 258 #
 259 # Get specified number ACE content of specified file or directory.
 260 #
 261 # $1 file or directory name
 262 # $2 specified number
 263 #
 264 function get_ACE #<file or dir name> <specified number> <verbose|compact>
 265 {
 266         if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then
 267                 return 1
 268         fi
 269 
 270         typeset file=$1
 271         typeset -i num=$2




  37         typeset obj=$1
  38         if (( ${#obj} == 0 )); then
  39                 return 1
  40         fi
  41 
  42         $LS -ld $obj | $AWK '{print $1}'
  43 }
  44 
  45 #
  46 # Get the given file/directory ACL
  47 #
  48 # $1 object -- file or directroy
  49 #
  50 function get_acl #<obj>
  51 {
  52         typeset obj=$1
  53         if (( ${#obj} == 0 )); then
  54                 return 1
  55         fi
  56 
  57         $LS -vd $obj | $AWK '(NR != 1) {print $0}'
  58 }
  59 
  60 #
  61 # Get the given file/directory ACL
  62 #
  63 # $1 object -- file or directroy
  64 #
  65 function get_compact_acl #<obj>
  66 {
  67         typeset obj=$1
  68         if (( ${#obj} == 0 )); then
  69                 return 1
  70         fi
  71 
  72         $LS -Vd $obj | $AWK '(NR != 1) {print $0}'
  73 }
  74 
  75 #
  76 # Check the given two files/directories have the same ACLs
  77 #
  78 # Return 0, if source object acl is equal to target object acl.
  79 #
  80 # $1 source object
  81 # $2 target object
  82 #
  83 function compare_acls #<src> <tgt>
  84 {
  85         typeset src=$1
  86         typeset tgt=$2
  87 
  88         (( ${#src} == 0 || ${#tgt} == 0 )) && return 1
  89         [[ $src == $tgt ]] && return 0
  90 
  91         typeset tmpsrc=/tmp/compare_acls.src.$$
  92         typeset tmptgt=/tmp/compare_acls.tgt.$$


 181                 return 1
 182         fi
 183 
 184         $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
 185 
 186         return $?
 187 }
 188 
 189 #
 190 # Check '+' is set for a given file/directory with 'ls [-v]' command
 191 #
 192 # $1 object -- file or directory.
 193 #
 194 function plus_sign_check_v #<obj>
 195 {
 196         typeset obj=$1
 197         if (( ${#obj} == 0 )); then
 198                 return 1
 199         fi
 200 
 201         $LS -vd $obj | $AWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
 202 
 203         return $?
 204 }
 205 
 206 #
 207 # A wrapper function of c program
 208 #
 209 # $1 legal login name
 210 # $2-n commands and options
 211 #
 212 function chgusr_exec #<login_name> <commands> [...]
 213 {
 214         $CHG_USR_EXEC $@
 215         return $?
 216 }
 217 
 218 #
 219 # Export the current user for the following usr_exec operating.
 220 #
 221 # $1 legal login name


 231 # $1-n commands and options
 232 #
 233 function usr_exec #<commands> [...]
 234 {
 235         $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
 236         return $?
 237 }
 238 
 239 #
 240 # Count how many ACEs for the speficied file or directory.
 241 #
 242 # $1 file or directroy name
 243 #
 244 function count_ACE #<file or dir name>
 245 {
 246         if [[ ! -e $1 ]]; then
 247                 log_note "Need input file or directroy name."
 248                 return 1
 249         fi
 250 
 251         $LS -vd $1 | $AWK 'BEGIN {count=0}
 252                         (NR != 1)&&(/[0-9]:/) {count++}
 253                         END {print count}'
 254 
 255         return 0
 256 }
 257 
 258 #
 259 # Get specified number ACE content of specified file or directory.
 260 #
 261 # $1 file or directory name
 262 # $2 specified number
 263 #
 264 function get_ACE #<file or dir name> <specified number> <verbose|compact>
 265 {
 266         if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then
 267                 return 1
 268         fi
 269 
 270         typeset file=$1
 271         typeset -i num=$2