@@ -920,3 +920,20 @@ _verify_ciphertext_for_encryption_policy()
"$crypt_util_contents_args" \
"$crypt_util_filename_args"
}
+
+# Replace no-key filenames in the given directory with "NOKEY_NAME".
+#
+# No-key filenames are the filenames that the filesystem shows when userspace
+# lists an encrypted directory without the directory's encryption key being
+# present. These will differ on every run of the test, even when using the same
+# encryption key, hence the need for this filtering in some cases.
+#
+# Note, this may replace "regular" names too, as technically we can only tell
+# whether a name is definitely a regular name, or either a regular or no-key
+# name. A directory will only contain one type of name at a time, though.
+_filter_nokey_filenames()
+{
+ local dir=$1
+
+ sed "s|${dir}${dir:+/}[A-Za-z0-9+,_]\+|${dir}${dir:+/}NOKEY_NAME|g"
+}
@@ -41,7 +41,7 @@ _scratch_cycle_mount
# in a way that does not assume any particular filenames.
efile1=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | head -1)
efile2=$(find $SCRATCH_MNT/edir -maxdepth 1 -type f | tail -1)
-mv $efile1 $efile2 |& _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/FILENAME|g'
+mv $efile1 $efile2 |& _filter_scratch | _filter_nokey_filenames edir
$here/src/renameat2 -x $efile1 $efile2
# success, all done
@@ -1,3 +1,3 @@
QA output created by 419
-mv: cannot move 'SCRATCH_MNT/edir/FILENAME' to 'SCRATCH_MNT/edir/FILENAME': Required key not available
+mv: cannot move 'SCRATCH_MNT/edir/NOKEY_NAME' to 'SCRATCH_MNT/edir/NOKEY_NAME': Required key not available
Required key not available
@@ -52,18 +52,13 @@ _set_encpolicy $SCRATCH_MNT/edir $keydesc
echo contents_@@@ > $SCRATCH_MNT/edir/@@@ # not valid base64
echo contents_abcd > $SCRATCH_MNT/edir/abcd # valid base64
-filter_nokey_filenames()
-{
- _filter_scratch | sed 's|edir/[a-zA-Z0-9+,_]\+|edir/NOKEY_NAME|g'
-}
-
show_file_contents()
{
echo "--- Contents of files using plaintext names:"
cat $SCRATCH_MNT/edir/@@@ |& _filter_scratch
cat $SCRATCH_MNT/edir/abcd |& _filter_scratch
echo "--- Contents of files using no-key names:"
- cat ${nokey_names[@]} |& filter_nokey_filenames
+ cat ${nokey_names[@]} |& _filter_scratch | _filter_nokey_filenames edir
}
show_directory_with_key()
@@ -83,7 +78,8 @@ _unlink_session_encryption_key $keydesc
_scratch_cycle_mount
echo "--- Directory listing:"
nokey_names=( $(find $SCRATCH_MNT/edir -mindepth 1 | sort) )
-printf '%s\n' "${nokey_names[@]}" | filter_nokey_filenames
+printf '%s\n' "${nokey_names[@]}" | \
+ _filter_scratch | _filter_nokey_filenames edir
show_file_contents
# Without remounting or dropping caches, add the encryption key and view the