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 2007 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# 36# Attempting to read an xattr on a file for which we have no permissions 37# should fail. 38# 39# STRATEGY: 40# 1. Create a file with an xattr 41# 2. Set the file permissions to 000 42# 3. Check that we're unable to read the xattr as a non-root user 43# 4. Check that we're unable to write an xattr as a non-root user 44# 45 46function cleanup 47{ 48 rm -f $testfile $tempfile 49} 50 51log_assert "read/write xattr on a file with no permissions fails" 52log_onexit cleanup 53 54typeset testfile=$TESTDIR/testfile.$$ 55typeset tempfile=/tmp/tempfile.$$ 56 57log_must touch $testfile 58create_xattr $testfile passwd /etc/passwd 59 60log_must chmod 000 $testfile 61if is_illumos; then 62 log_mustnot su $ZFS_USER -c "runat $testfile cat passwd" 63 log_mustnot su $ZFS_USER -c "runat $testfile cp /etc/passwd ." 64else 65 log_mustnot user_run $ZFS_USER " 66. $STF_SUITE/include/libtest.shlib 67get_xattr passwd $testfile >$tempfile 68" 69 log_mustnot diff -q /etc/passwd $tempfile 70 log_must rm $tempfile 71 72 log_mustnot user_run $ZFS_USER " 73. $STF_SUITE/include/libtest.shlib 74set_xattr_stdin passwd $testfile </etc/group 75" 76 log_must chmod 644 $testfile 77 get_xattr passwd $testfile >$tempfile 78 log_must diff -q /etc/passwd $tempfile 79 log_must rm $tempfile 80fi 81 82log_pass "read/write xattr on a file with no permissions fails" 83