linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: fstests@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org
Subject: [PATCH 2/3] common/encrypt: add helper function for filtering no-key names
Date: Sun, 18 Jul 2021 14:06:57 -0500	[thread overview]
Message-ID: <20210718190658.61621-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20210718190658.61621-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

Add a helper function _filter_nokey_filenames() which replaces no-key
filenames with "NOKEY_NAME".  Use it in generic/419 and generic/429.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 common/encrypt        | 17 +++++++++++++++++
 tests/generic/419     |  2 +-
 tests/generic/419.out |  2 +-
 tests/generic/429     | 10 +++-------
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/common/encrypt b/common/encrypt
index c4cc2d83..766a6d81 100644
--- a/common/encrypt
+++ b/common/encrypt
@@ -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"
+}
diff --git a/tests/generic/419 b/tests/generic/419
index 61f9d605..6be7865c 100755
--- a/tests/generic/419
+++ b/tests/generic/419
@@ -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
diff --git a/tests/generic/419.out b/tests/generic/419.out
index 1bba10fd..67bb7fb1 100644
--- a/tests/generic/419.out
+++ b/tests/generic/419.out
@@ -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
diff --git a/tests/generic/429 b/tests/generic/429
index ba2281c9..558e93ca 100755
--- a/tests/generic/429
+++ b/tests/generic/429
@@ -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
-- 
2.32.0


  parent reply	other threads:[~2021-07-18 19:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 19:06 [PATCH 0/3] xfstests: fscrypt no-key name updates Eric Biggers
2021-07-18 19:06 ` [PATCH 1/3] generic: update encryption tests to use term "no-key names" Eric Biggers
2021-07-18 19:06 ` Eric Biggers [this message]
2021-07-18 19:06 ` [PATCH 3/3] common/encrypt: accept '-' character in no-key names Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210718190658.61621-3-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --subject='Re: [PATCH 2/3] common/encrypt: add helper function for filtering no-key names' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).