1*eb633035STom Caputi#!/bin/ksh -p
2*eb633035STom Caputi#
3*eb633035STom Caputi# CDDL HEADER START
4*eb633035STom Caputi#
5*eb633035STom Caputi# This file and its contents are supplied under the terms of the
6*eb633035STom Caputi# Common Development and Distribution License ("CDDL"), version 1.0.
7*eb633035STom Caputi# You may only use this file in accordance with the terms of version
8*eb633035STom Caputi# 1.0 of the CDDL.
9*eb633035STom Caputi#
10*eb633035STom Caputi# A full copy of the text of the CDDL should have accompanied this
11*eb633035STom Caputi# source.  A copy of the CDDL is also available via the Internet at
12*eb633035STom Caputi# http://www.illumos.org/license/CDDL.
13*eb633035STom Caputi#
14*eb633035STom Caputi# CDDL HEADER END
15*eb633035STom Caputi#
16*eb633035STom Caputi
17*eb633035STom Caputi#
18*eb633035STom Caputi# Copyright (c) 2017 Datto, Inc. All rights reserved.
19*eb633035STom Caputi#
20*eb633035STom Caputi
21*eb633035STom Caputi. $STF_SUITE/include/libtest.shlib
22*eb633035STom Caputi. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key.cfg
23*eb633035STom Caputi
24*eb633035STom Caputi# Return 0 is a dataset key is available, 1 otherwise
25*eb633035STom Caputi#
26*eb633035STom Caputi# $1 - dataset
27*eb633035STom Caputi#
28*eb633035STom Caputifunction key_available
29*eb633035STom Caputi{
30*eb633035STom Caputi	typeset ds=$1
31*eb633035STom Caputi
32*eb633035STom Caputi	datasetexists $ds || return 1
33*eb633035STom Caputi
34*eb633035STom Caputi	typeset val=$(get_prop keystatus $ds)
35*eb633035STom Caputi	if [[ "$val" == "none" ]]; then
36*eb633035STom Caputi		log_note "Dataset $ds is not encrypted"
37*eb633035STom Caputi	elif [[ "$val" == "available" ]]; then
38*eb633035STom Caputi		return 0
39*eb633035STom Caputi	fi
40*eb633035STom Caputi
41*eb633035STom Caputi	return 1
42*eb633035STom Caputi}
43*eb633035STom Caputi
44*eb633035STom Caputifunction key_unavailable
45*eb633035STom Caputi{
46*eb633035STom Caputi	key_available $1 && return 1
47*eb633035STom Caputi	return 0
48*eb633035STom Caputi}
49*eb633035STom Caputi
50*eb633035STom Caputifunction verify_keyformat
51*eb633035STom Caputi{
52*eb633035STom Caputi	typeset ds=$1
53*eb633035STom Caputi	typeset format=$2
54*eb633035STom Caputi	typeset fmt=$(get_prop keyformat $ds)
55*eb633035STom Caputi
56*eb633035STom Caputi	if [[ "$fmt" != "$format" ]]; then
57*eb633035STom Caputi		log_fail "Expected keyformat $format, got $fmt"
58*eb633035STom Caputi	fi
59*eb633035STom Caputi
60*eb633035STom Caputi	return 0
61*eb633035STom Caputi}
62*eb633035STom Caputi
63*eb633035STom Caputifunction verify_keylocation
64*eb633035STom Caputi{
65*eb633035STom Caputi	typeset ds=$1
66*eb633035STom Caputi	typeset location=$2
67*eb633035STom Caputi	typeset keyloc=$(get_prop keylocation $ds)
68*eb633035STom Caputi
69*eb633035STom Caputi	if [[ "$keyloc" != "$location" ]]; then
70*eb633035STom Caputi		log_fail "Expected keylocation $location, got $keyloc"
71*eb633035STom Caputi	fi
72*eb633035STom Caputi
73*eb633035STom Caputi	return 0
74*eb633035STom Caputi}
75*eb633035STom Caputi
76*eb633035STom Caputifunction verify_encryption_root
77*eb633035STom Caputi{
78*eb633035STom Caputi	typeset ds=$1
79*eb633035STom Caputi	typeset val=$2
80*eb633035STom Caputi	typeset eroot=$(get_prop encryptionroot $ds)
81*eb633035STom Caputi
82*eb633035STom Caputi	if [[ "$eroot" != "$val" ]]; then
83*eb633035STom Caputi		log_note "Expected encryption root '$val', got '$eroot'"
84*eb633035STom Caputi		return 1
85*eb633035STom Caputi	fi
86*eb633035STom Caputi
87*eb633035STom Caputi	return 0
88*eb633035STom Caputi}
89*eb633035STom Caputi
90*eb633035STom Caputifunction verify_origin
91*eb633035STom Caputi{
92*eb633035STom Caputi	typeset ds=$1
93*eb633035STom Caputi	typeset val=$2
94*eb633035STom Caputi	typeset orig=$(get_prop origin $ds)
95*eb633035STom Caputi
96*eb633035STom Caputi	if [[ "$orig" != "$val" ]]; then
97*eb633035STom Caputi		log_note "Expected origin '$val', got '$orig'"
98*eb633035STom Caputi		return 1
99*eb633035STom Caputi	fi
100*eb633035STom Caputi
101*eb633035STom Caputi	return 0
102*eb633035STom Caputi}
103