xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/rsend/recv_secpolicy.ksh (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright 2019 Joyent, Inc.
19#
20
21. $STF_SUITE/tests/functional/rsend/rsend.kshlib
22
23#
24# DESCRIPTION:
25# Verify that the parent dataset is passed to the kernel's zfs_secpolicy_recv
26# function during a zfs receive.
27#
28# STRATEGY:
29# 1. Create a hierarchy of datasets.
30# 2. Take a snapshot of the final child dataset and send it to a file.
31# 3. Use DTrace to run the zfs recv command and simultaneously monitor the
32#    zc_name member of the zfs_cmd_t structure that is validated in
33#    zfs_secpolicy_recv.
34# 4. Verify that the zc_name member is the parent dataset, as expected.
35#
36
37verify_runnable "both"
38
39function cleanup
40{
41	destroy_dataset $TESTPOOL/testfs2 "-r"
42	destroy_dataset $TESTPOOL/testfs1 "-r"
43	[[ -f $sendfile ]] && log_must rm $sendfile
44}
45log_onexit cleanup
46
47log_assert "Verify zfs_secpolicy_recv is passed the proper trimmed name"
48
49typeset sendfile=$TESTDIR/sendfile
50
51log_must zfs create $TESTPOOL/testfs1
52log_must zfs create $TESTPOOL/testfs1/data
53log_must zfs create $TESTPOOL/testfs1/data/foo
54
55log_must zfs create $TESTPOOL/testfs2
56log_must zfs create $TESTPOOL/testfs2/data
57
58log_must mkfile 4k /$TESTPOOL/testfs1/data/foo/testfile0
59
60log_must zfs snap $TESTPOOL/testfs1/data/foo@1
61
62log_must eval "zfs send $TESTPOOL/testfs1/data/foo@1 > $sendfile"
63
64zc_name=$(/usr/sbin/dtrace -q -n \
65   'fbt::zfs_secpolicy_recv:entry {printf("%s", stringof(args[0]->zc_name));}' \
66    -c "zfs receive $TESTPOOL/testfs2/data/foo" < $sendfile)
67
68[[ "$zc_name" == "$TESTPOOL/testfs2/data" ]] || \
69    log_fail "zc_name mismatch: $zc_name != $TESTPOOL/testfs2/data"
70
71log_pass "zfs_secpolicy_recv is passed the proper trimmed name"
72