xref: /freebsd/tests/sys/geom/class/eli/delkey_test.sh (revision 49b49cda41feabe3439f7318e8bf40e3896c7bf4)
1#!/bin/sh
2# $FreeBSD$
3
4. $(dirname $0)/conf.sh
5
6base=`basename $0`
7sectors=100
8keyfile1=`mktemp $base.XXXXXX` || exit 1
9keyfile2=`mktemp $base.XXXXXX` || exit 1
10keyfile3=`mktemp $base.XXXXXX` || exit 1
11keyfile4=`mktemp $base.XXXXXX` || exit 1
12mdconfig -a -t malloc -s `expr $sectors + 1` -u $no || exit 1
13
14echo "1..14"
15
16dd if=/dev/random of=${keyfile1} bs=512 count=16 >/dev/null 2>&1
17dd if=/dev/random of=${keyfile2} bs=512 count=16 >/dev/null 2>&1
18dd if=/dev/random of=${keyfile3} bs=512 count=16 >/dev/null 2>&1
19dd if=/dev/random of=${keyfile4} bs=512 count=16 >/dev/null 2>&1
20
21geli init -B none -P -K $keyfile1 md${no}
22geli attach -p -k $keyfile1 md${no}
23geli setkey -n 1 -P -K $keyfile2 md${no}
24
25# Remove key 0 for attached provider.
26geli delkey -n 0 md${no}
27if [ $? -eq 0 ]; then
28	echo "ok 1"
29else
30	echo "not ok 1"
31fi
32geli detach md${no}
33
34# We cannot use keyfile1 anymore.
35geli attach -p -k $keyfile1 md${no} 2>/dev/null
36if [ $? -ne 0 ]; then
37	echo "ok 2"
38else
39	echo "not ok 2"
40fi
41
42# Attach with key 1.
43geli attach -p -k $keyfile2 md${no}
44if [ $? -eq 0 ]; then
45	echo "ok 3"
46else
47	echo "not ok 3"
48fi
49
50# We cannot remove last key without -f option (for attached provider).
51geli delkey -n 1 md${no} 2>/dev/null
52if [ $? -ne 0 ]; then
53	echo "ok 4"
54else
55	echo "not ok 4"
56fi
57
58# Remove last key for attached provider.
59geli delkey -f -n 1 md${no}
60if [ $? -eq 0 ]; then
61	echo "ok 5"
62else
63	echo "not ok 5"
64fi
65
66# If there are no valid keys, but provider is attached, we can save situation.
67geli setkey -n 0 -P -K $keyfile3 md${no}
68if [ $? -eq 0 ]; then
69	echo "ok 6"
70else
71	echo "not ok 6"
72fi
73geli detach md${no}
74
75# We cannot use keyfile2 anymore.
76geli attach -p -k $keyfile2 md${no} 2>/dev/null
77if [ $? -ne 0 ]; then
78	echo "ok 7"
79else
80	echo "not ok 7"
81fi
82
83# Attach with key 0.
84geli attach -p -k $keyfile3 md${no}
85if [ $? -eq 0 ]; then
86	echo "ok 8"
87else
88	echo "not ok 8"
89fi
90
91# Setup key 1.
92geli setkey -n 1 -P -K $keyfile4 md${no}
93if [ $? -eq 0 ]; then
94	echo "ok 9"
95else
96	echo "not ok 9"
97fi
98geli detach md${no}
99
100# Remove key 1 for detached provider.
101geli delkey -n 1 md${no}
102if [ $? -eq 0 ]; then
103	echo "ok 10"
104else
105	echo "not ok 10"
106fi
107
108# We cannot use keyfile4 anymore.
109geli attach -p -k $keyfile4 md${no} 2>/dev/null
110if [ $? -ne 0 ]; then
111	echo "ok 11"
112else
113	echo "not ok 11"
114fi
115
116# We cannot remove last key without -f option (for detached provider).
117geli delkey -n 0 md${no} 2>/dev/null
118if [ $? -ne 0 ]; then
119	echo "ok 12"
120else
121	echo "not ok 12"
122fi
123
124# Remove last key for detached provider.
125geli delkey -f -n 0 md${no}
126if [ $? -eq 0 ]; then
127	echo "ok 13"
128else
129	echo "not ok 13"
130fi
131
132# We cannot use keyfile3 anymore.
133geli attach -p -k $keyfile3 md${no} 2>/dev/null
134if [ $? -ne 0 ]; then
135	echo "ok 14"
136else
137	echo "not ok 14"
138fi
139
140rm -f $keyfile1 $keyfile2 $keyfile3 $keyfile4
141