Blame SOURCES/0003-Improve-error-message-when-bind-is-given-an-invalid-.patch

64015d
From d393fbc256e22cc8019d18214e4d140d58f3302a Mon Sep 17 00:00:00 2001
64015d
From: Sergio Correia <scorreia@redhat.com>
64015d
Date: Wed, 13 May 2020 23:51:04 -0300
64015d
Subject: [PATCH 3/8] Improve error message when bind is given an invalid PIN
64015d
64015d
---
64015d
 src/luks/clevis-luks-bind.in          | 6 ++++++
64015d
 src/luks/clevis-luks-common-functions | 9 +++++++++
64015d
 2 files changed, 15 insertions(+)
64015d
64015d
diff --git a/src/luks/clevis-luks-bind.in b/src/luks/clevis-luks-bind.in
64015d
index a5d3c5f..89a5e22 100755
64015d
--- a/src/luks/clevis-luks-bind.in
64015d
+++ b/src/luks/clevis-luks-bind.in
64015d
@@ -19,6 +19,8 @@
64015d
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
64015d
 #
64015d
 
64015d
+. clevis-luks-common-functions
64015d
+
64015d
 SUMMARY="Binds a LUKS device using the specified policy"
64015d
 UUID=cb6e8904-81ff-40da-a84a-07ab9ab5715e
64015d
 
64015d
@@ -76,6 +78,10 @@ fi
64015d
 if ! PIN="${@:$((OPTIND++)):1}" || [ -z "$PIN" ]; then
64015d
     echo "Did not specify a pin!" >&2
64015d
     usage
64015d
+elif ! EXE=$(findexe clevis-encrypt-"${PIN}") \
64015d
+             || [ -z "${EXE}" ]; then
64015d
+    echo "'$PIN' is not a valid pin!" >&2
64015d
+    usage
64015d
 fi
64015d
 
64015d
 if ! CFG="${@:$((OPTIND++)):1}" || [ -z "$CFG" ]; then
64015d
diff --git a/src/luks/clevis-luks-common-functions b/src/luks/clevis-luks-common-functions
64015d
index d04fdb5..36f0bfd 100644
64015d
--- a/src/luks/clevis-luks-common-functions
64015d
+++ b/src/luks/clevis-luks-common-functions
64015d
@@ -108,6 +108,15 @@ clevis_luks_read_slot() {
64015d
     echo "${DATA_CODED}"
64015d
 }
64015d
 
64015d
+# findexe() finds an executable.
64015d
+findexe() {
64015d
+    while read -r -d: path; do
64015d
+        [ -f "${path}/${1}" ] && [ -x "${path}/${1}" ] && \
64015d
+          echo "${path}/${1}" && return 0
64015d
+    done <<< "${PATH}:"
64015d
+    return 1
64015d
+}
64015d
+
64015d
 # clevis_luks_used_slots() will return the list of used slots for a given LUKS
64015d
 # device.
64015d
 clevis_luks_used_slots() {
64015d
-- 
64015d
2.18.4
64015d