1#!/usr/local/bin/ksh93 -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# ident	"@(#)xattr_008_pos.ksh	1.2	08/02/27 SMI"
26#
27
28# $FreeBSD$
29
30. $STF_SUITE/include/libtest.kshlib
31. $STF_SUITE/tests/xattr/xattr_common.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID:  xattr_008_pos
38#
39# DESCRIPTION:
40# We verify that the special . and .. dirs work as expected for xattrs.
41#
42# STRATEGY:
43#	1. Create a file and an xattr on that file
44#	2. List the . directory, verifying the output
45#	3. Verify we're unable to list the ../ directory
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2006-12-05)
52#
53# __stc_assertion_end
54#
55################################################################################
56
57function cleanup {
58	typeset file
59
60	for file in $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID} \
61		$TESTDIR/myfile.${TESTCASE_ID} ; do
62		log_must $RM -f $file
63	done
64}
65
66log_assert "special . and .. dirs work as expected for xattrs"
67log_onexit cleanup
68
69test_requires RUNAT
70
71# create a file, and an xattr on it
72log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID}
73create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd
74
75if check_version "5.10"
76then
77	# listing the directory . should show one file
78	OUTPUT=$($RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS .)
79	if [ "$OUTPUT" != "passwd" ]
80	then
81	log_fail "Listing the . directory doesn't show \"passwd\" as expected."
82	fi
83	# list the directory . long form
84	log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS -a . > $TMPDIR/output.${TESTCASE_ID}"
85	# create a file that should be the same as the command above
86	create_expected_output $TMPDIR/expected-output.${TESTCASE_ID}  .  ..   passwd
87	# compare them
88	log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID}
89else
90	# listing the directory .
91	log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS  . > $TMPDIR/output.${TESTCASE_ID}"
92	create_expected_output  $TMPDIR/expected-output.${TESTCASE_ID}  \
93	SUNWattr_ro  SUNWattr_rw  passwd
94	log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID}
95	# list the directory . long form
96	log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS -a . > $TMPDIR/output.${TESTCASE_ID}"
97	create_expected_output  $TMPDIR/expected-output.${TESTCASE_ID} . ..  \
98	SUNWattr_ro  SUNWattr_rw  passwd
99	log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID}
100fi
101
102# list the directory .. expecting one file
103OUTPUT=$($RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS ..)
104if [ "$OUTPUT" != ".." ]
105then
106	log_fail "Listing the .. directory doesn't show \"..\" as expected."
107fi
108
109# verify we can't list ../
110log_mustnot eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS ../ > /dev/null 2>&1"
111
112log_pass "special . and .. dirs work as expected for xattrs"
113