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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2013 by Delphix. All rights reserved. 30# 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/userquota/userquota_common.kshlib 33 34# 35# 36# DESCRIPTION: 37# Check whether unprivileged user can chattr 38# 39# 40# STRATEGY: 41# 1. Create 3 files 42# 2. Use chattr to make them writable, immutable and appendonly 43# 3. Try to chattr with unprivileged user 44# 45 46set -A files writable immutable append 47 48function cleanup 49{ 50 for i in ${files[*]}; do 51 log_must chattr -ia $TESTDIR/$i 52 log_must rm -f $TESTDIR/$i 53 done 54 log_must chmod 0755 $TESTDIR 55} 56 57log_onexit cleanup 58 59log_assert "Check whether unprivileged user can chattr" 60 61log_must chmod 0777 $TESTDIR 62 63log_must user_run $QUSER1 touch $TESTDIR/writable 64log_must user_run $QUSER1 touch $TESTDIR/immutable 65log_must user_run $QUSER1 touch $TESTDIR/append 66 67log_must chattr -i $TESTDIR/writable 68log_must chattr +i $TESTDIR/immutable 69log_must chattr +a $TESTDIR/append 70 71log_must user_run $QUSER1 chattr -i $TESTDIR/writable 72log_must user_run $QUSER1 chattr -a $TESTDIR/writable 73log_must user_run $QUSER1 chattr +i $TESTDIR/immutable 74log_must user_run $QUSER1 chattr +a $TESTDIR/append 75 76log_mustnot user_run $QUSER1 chattr +i $TESTDIR/writable 77log_mustnot user_run $QUSER1 chattr +a $TESTDIR/writable 78log_mustnot user_run $QUSER1 chattr -i $TESTDIR/immutable 79log_mustnot user_run $QUSER1 chattr -a $TESTDIR/append 80 81log_pass "Unprivileged user cannot chattr as expected" 82