0abbac90ea7aa6a1bf76f3703aea099529feabe0
[xfstests-dev.git] / tests / generic / 419
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test generic/419
6 #
7 # Try to rename files in an encrypted directory, without access to the
8 # encryption key.  This should fail with ENOKEY.  Test both a regular rename and
9 # a cross rename.  This is a regression test for:
10 #       173b8439e1ba ("ext4: don't allow encrypted operations without keys")
11 #       363fa4e078cb ("f2fs: don't allow encrypted operations without keys")
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/encrypt
32 . ./common/renameat2
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38 _supported_fs generic
39 _supported_os Linux
40 _require_scratch_encryption
41 _require_command "$KEYCTL_PROG" keyctl
42 _require_renameat2 exchange
43
44 _new_session_keyring
45
46 _scratch_mkfs_encrypted &>> $seqres.full
47 _scratch_mount
48
49 mkdir $SCRATCH_MNT/edir
50 keydesc=$(_generate_encryption_key)
51 _set_encpolicy $SCRATCH_MNT/edir $keydesc
52 echo a > $SCRATCH_MNT/edir/a
53 echo b > $SCRATCH_MNT/edir/b
54 _unlink_encryption_key $keydesc
55 _scratch_cycle_mount
56
57 # Note that because encrypted filenames are unpredictable, this needs to be
58 # written in a way that does not assume any particular filenames.
59 efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
60 efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
61 mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
62 src/renameat2 -x $efile1 $efile2
63
64 # success, all done
65 status=0
66 exit