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 https://opensource.org/licenses/CDDL-1.0.
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. $STF_SUITE/tests/functional/slog/slog.kshlib
29
30verify_runnable "global"
31
32function cleanup_fs
33{
34	cleanup
35}
36
37log_assert "Verify ZIL replay results in correct SUID/SGID bits for unprivileged write to SUID/SGID files"
38log_onexit cleanup_fs
39log_must setup
40
41#
42# 1. Create a file system (TESTFS)
43#
44log_must zpool destroy "$TESTPOOL"
45log_must zpool create $TESTPOOL $VDEV log mirror $LDEV
46log_must zfs set compression=on $TESTPOOL
47log_must zfs create -o mountpoint="$TESTDIR" $TESTPOOL/$TESTFS
48
49# Make all the writes from suid_write_to_file.c sync
50log_must zfs set sync=always "$TESTPOOL/$TESTFS"
51
52#
53# This dd command works around an issue where ZIL records aren't created
54# after freezing the pool unless a ZIL header already exists. Create a file
55# synchronously to force ZFS to write one out.
56#
57log_must dd if=/dev/zero of=$TESTDIR/sync \
58    conv=fdatasync,fsync bs=1 count=1
59
60#
61# 2. Freeze TESTFS
62#
63log_must zpool freeze $TESTPOOL
64
65#
66# 3. Unprivileged write to a setuid file
67#
68log_must suid_write_to_file "NONE"      "PRECRASH"
69log_must suid_write_to_file "SUID"      "PRECRASH"
70log_must suid_write_to_file "SGID"      "PRECRASH"
71log_must suid_write_to_file "SUID_SGID" "PRECRASH"
72
73#
74# 4. Unmount filesystem and export the pool
75#
76# At this stage TESTFS is empty again and frozen, the intent log contains
77# a complete set of deltas to replay.
78#
79log_must zfs unmount $TESTPOOL/$TESTFS
80
81log_note "List transactions to replay:"
82log_must zdb -iv $TESTPOOL/$TESTFS
83
84log_must zpool export $TESTPOOL
85
86#
87# 5. Remount TESTFS <which replays the intent log>
88#
89# Import the pool to unfreeze it and claim log blocks.  It has to be
90# `zpool import -f` because we can't write a frozen pool's labels!
91#
92log_must zpool import -f -d $VDIR $TESTPOOL
93
94log_must suid_write_to_file "NONE"      "REPLAY"
95log_must suid_write_to_file "SUID"      "REPLAY"
96log_must suid_write_to_file "SGID"      "REPLAY"
97log_must suid_write_to_file "SUID_SGID" "REPLAY"
98
99log_pass
100