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# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25
26#
27# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
28#
29
30. $STF_SUITE/include/libtest.shlib
31. $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
32
33#
34# DESCRIPTION:
35# We verify that the special . and .. dirs work as expected for xattrs.
36#
37# STRATEGY:
38#	1. Create a file and an xattr on that file
39#	2. List the . directory, verifying the output
40#	3. Verify we're unable to list the ../ directory
41#
42
43function cleanup {
44	typeset file
45
46	for file in /tmp/output.$$ /tmp/expected-output.$$ \
47		$TESTDIR/myfile.$$ ; do
48		log_must rm -f $file
49	done
50}
51
52log_assert "special . and .. dirs work as expected for xattrs"
53log_onexit cleanup
54
55# create a file, and an xattr on it
56log_must touch $TESTDIR/myfile.$$
57create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
58
59# listing the directory .
60log_must eval "runat $TESTDIR/myfile.$$ ls  . > /tmp/output.$$"
61create_expected_output  /tmp/expected-output.$$  \
62    SUNWattr_ro  SUNWattr_rw  passwd
63log_must diff /tmp/output.$$ /tmp/expected-output.$$
64# list the directory . long form
65log_must eval "runat $TESTDIR/myfile.$$ ls -a . > /tmp/output.$$"
66create_expected_output  /tmp/expected-output.$$ . ..  \
67    SUNWattr_ro  SUNWattr_rw  passwd
68log_must diff /tmp/output.$$ /tmp/expected-output.$$
69
70# list the directory .. expecting one file
71OUTPUT=$(runat $TESTDIR/myfile.$$ ls ..)
72if [ "$OUTPUT" != ".." ]
73then
74	log_fail "Listing the .. directory doesn't show \"..\" as expected."
75fi
76
77# verify we can't list ../
78log_mustnot eval "runat $TESTDIR/myfile.$$ ls ../ > /dev/null 2>&1"
79
80log_pass "special . and .. dirs work as expected for xattrs"
81