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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33
34#
35# DESCRIPTION:
36# Verify that '/usr/bin/ls' command option supports ZFS ACL
37#
38# STRATEGY:
39# 1. Create file and  directory in zfs filesystem
40# 2. Verify that 'ls [-dv]' can list the ACEs of ACL of
41#    file/directroy
42# 3. Change the file/directory's acl
43# 4. Verify that 'ls -l' can use the '+' to indicate the non-trivial
44#    acl.
45#
46
47verify_runnable "both"
48
49function cleanup
50{
51	(( ${#cwd} != 0 )) && cd $cwd
52	[[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR/*
53	(( ${#mask} != 0 )) && log_must umask $mask
54}
55
56log_assert "Verify that 'ls' command supports ZFS ACLs."
57
58log_onexit cleanup
59
60file=$TESTFILE0
61dir=dir.$$
62cwd=$PWD
63mask=`umask`
64spec_ace="everyone@:write_acl:allow"
65
66umask 0022
67
68log_note "Create file and directory in the zfs filesystem. "
69cd $TESTDIR
70log_must touch $file
71log_must mkdir $dir
72
73log_note "Verify that 'ls [-dv]' can list file/directory ACEs of its acl."
74
75typeset -i ace_num=0
76for obj in $file $dir
77do
78	typeset ls_str=""
79	if [[ -f $obj ]]; then
80		ls_str="ls -v"
81	else
82		ls_str="ls -dv"
83	fi
84
85	for ace_type in "owner@" "group@" "everyone@"
86	do
87		$ls_str $obj | grep $ace_type > /dev/null 2>&1
88		(( $? == 0 )) && (( ace_num += 1 ))
89	done
90
91	(( ace_num < 1 )) && \
92		log_fail "'ls [-dv] fails to list file/directroy acls."
93done
94
95log_note "Verify that 'ls [-dl] [-dv]' can output '+' to indicate " \
96	"the acl existent."
97
98for obj in $file $dir
99do
100	chmod A0+$spec_ace $obj
101
102	log_must eval "ls -ld -vd $obj | grep "+" > /dev/null"
103	log_must plus_sign_check_v $obj
104
105	log_must eval "ls -ld -vd $obj | grep $spec_ace > /dev/null"
106	log_must plus_sign_check_l $obj
107done
108
109log_pass "'ls' command succeeds to support ZFS ACLs."
110