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

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