1*c03c5b1cSMartin Matuska#!/bin/ksh -p
2*c03c5b1cSMartin Matuska#
3*c03c5b1cSMartin Matuska# CDDL HEADER START
4*c03c5b1cSMartin Matuska#
5*c03c5b1cSMartin Matuska# The contents of this file are subject to the terms of the
6*c03c5b1cSMartin Matuska# Common Development and Distribution License (the "License").
7*c03c5b1cSMartin Matuska# You may not use this file except in compliance with the License.
8*c03c5b1cSMartin Matuska#
9*c03c5b1cSMartin Matuska# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*c03c5b1cSMartin Matuska# or http://www.opensolaris.org/os/licensing.
11*c03c5b1cSMartin Matuska# See the License for the specific language governing permissions
12*c03c5b1cSMartin Matuska# and limitations under the License.
13*c03c5b1cSMartin Matuska#
14*c03c5b1cSMartin Matuska# When distributing Covered Code, include this CDDL HEADER in each
15*c03c5b1cSMartin Matuska# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*c03c5b1cSMartin Matuska# If applicable, add the following below this CDDL HEADER, with the
17*c03c5b1cSMartin Matuska# fields enclosed by brackets "[]" replaced with your own identifying
18*c03c5b1cSMartin Matuska# information: Portions Copyright [yyyy] [name of copyright owner]
19*c03c5b1cSMartin Matuska#
20*c03c5b1cSMartin Matuska# CDDL HEADER END
21*c03c5b1cSMartin Matuska#
22*c03c5b1cSMartin Matuska
23*c03c5b1cSMartin Matuska#
24*c03c5b1cSMartin Matuska# Copyright (c) 2022 by Attila Fülöp <attila@fueloep.org>
25*c03c5b1cSMartin Matuska#
26*c03c5b1cSMartin Matuska
27*c03c5b1cSMartin Matuska. $STF_SUITE/include/libtest.shlib
28*c03c5b1cSMartin Matuska
29*c03c5b1cSMartin Matuska#
30*c03c5b1cSMartin Matuska# DESCRIPTION:
31*c03c5b1cSMartin Matuska#      ZFS should receive a raw send of a mix of unencrypted and encrypted
32*c03c5b1cSMartin Matuska#      child datasets
33*c03c5b1cSMartin Matuska#
34*c03c5b1cSMartin Matuska#      The layout of the datasets is:  enc/unenc/enc/unenc
35*c03c5b1cSMartin Matuska#
36*c03c5b1cSMartin Matuska# STRATEGY:
37*c03c5b1cSMartin Matuska# 1. Create the dataset hierarchy
38*c03c5b1cSMartin Matuska# 2. Snapshot the dataset hierarchy
39*c03c5b1cSMartin Matuska# 3. Send -Rw the dataset hierarchy and receive into a top-level dataset
40*c03c5b1cSMartin Matuska# 4. Check the encryption property of the received datasets
41*c03c5b1cSMartin Matuska
42*c03c5b1cSMartin Matuskaverify_runnable "both"
43*c03c5b1cSMartin Matuska
44*c03c5b1cSMartin Matuskafunction cleanup
45*c03c5b1cSMartin Matuska{
46*c03c5b1cSMartin Matuska	datasetexists "$TESTPOOL/$TESTFS1" && \
47*c03c5b1cSMartin Matuska		destroy_dataset "$TESTPOOL/$TESTFS1" -r
48*c03c5b1cSMartin Matuska
49*c03c5b1cSMartin Matuska	datasetexists "$TESTPOOL/$TESTFS2" && \
50*c03c5b1cSMartin Matuska		destroy_dataset "$TESTPOOL/$TESTFS2" -r
51*c03c5b1cSMartin Matuska}
52*c03c5b1cSMartin Matuska
53*c03c5b1cSMartin Matuskalog_onexit cleanup
54*c03c5b1cSMartin Matuska
55*c03c5b1cSMartin Matuskalog_assert "ZFS should receive a mix of un/encrypted childs"
56*c03c5b1cSMartin Matuska
57*c03c5b1cSMartin Matuskatypeset src="$TESTPOOL/$TESTFS1"
58*c03c5b1cSMartin Matuskatypeset dst="$TESTPOOL/$TESTFS2"
59*c03c5b1cSMartin Matuskatypeset snap="snap"
60*c03c5b1cSMartin Matuska
61*c03c5b1cSMartin Matuskaecho "password" | \
62*c03c5b1cSMartin Matuska	create_dataset "$src" -o encryption=on -o keyformat=passphrase
63*c03c5b1cSMartin Matuskacreate_dataset "$src/u" "-o encryption=off"
64*c03c5b1cSMartin Matuskaecho "password" | \
65*c03c5b1cSMartin Matuska	create_dataset "$src/u/e" -o encryption=on -o keyformat=passphrase
66*c03c5b1cSMartin Matuskacreate_dataset "$src/u/e/u" -o encryption=off
67*c03c5b1cSMartin Matuska
68*c03c5b1cSMartin Matuskalog_must zfs snapshot -r "$src@$snap"
69*c03c5b1cSMartin Matuskalog_must eval "zfs send -Rw $src@$snap | zfs receive -u $dst"
70*c03c5b1cSMartin Matuskalog_must test "$(get_prop 'encryption' $dst)" != "off"
71*c03c5b1cSMartin Matuskalog_must test "$(get_prop 'encryption' $dst/u)" == "off"
72*c03c5b1cSMartin Matuskalog_must test "$(get_prop 'encryption' $dst/u/e)" != "off"
73*c03c5b1cSMartin Matuskalog_must test "$(get_prop 'encryption' $dst/u/e/u)" == "off"
74*c03c5b1cSMartin Matuska
75*c03c5b1cSMartin Matuskalog_pass "ZFS can receive a mix of un/encrypted childs"
76