Blame SOURCES/0004-systemd-drop-ncat-dependency.patch

9742fa
From 8f0fcf2e7384ad757042e7e6a0850f655eb70b7e Mon Sep 17 00:00:00 2001
9742fa
From: Sergio Correia <scorreia@redhat.com>
9742fa
Date: Thu, 18 Nov 2021 16:45:58 -0300
9742fa
Subject: [PATCH 4/4] systemd: drop ncat dependency
9742fa
9742fa
When using systemd, i.e., clevis-luks-askpass, we use ncat to send
9742fa
the decrypted password to the systemd socket as per systemd's password
9742fa
agents specification [1].
9742fa
9742fa
However, systemd itself has a utility that does exactly that,
9742fa
systemd-reply-password.
9742fa
9742fa
In this commit we drop the ncat dependency and instead use
9742fa
systemd-reply-password in clevis-luks-askpass.
9742fa
9742fa
[1] https://systemd.io/PASSWORD_AGENTS/
9742fa
---
9742fa
 ...is-luks-askpass => clevis-luks-askpass.in} |  2 +-
9742fa
 .../systemd/dracut/clevis/module-setup.sh.in  |  4 ++--
9742fa
 src/luks/systemd/meson.build                  | 19 +++++++++++++++++--
9742fa
 3 files changed, 20 insertions(+), 5 deletions(-)
9742fa
 rename src/luks/systemd/{clevis-luks-askpass => clevis-luks-askpass.in} (97%)
9742fa
9742fa
diff --git a/src/luks/systemd/clevis-luks-askpass b/src/luks/systemd/clevis-luks-askpass.in
9742fa
similarity index 97%
9742fa
rename from src/luks/systemd/clevis-luks-askpass
9742fa
rename to src/luks/systemd/clevis-luks-askpass.in
9742fa
index f19671f..a6699c9 100755
9742fa
--- a/src/luks/systemd/clevis-luks-askpass
9742fa
+++ b/src/luks/systemd/clevis-luks-askpass.in
9742fa
@@ -58,7 +58,7 @@ while true; do
9742fa
         fi
9742fa
 
9742fa
         uuid="$(cryptsetup luksUUID "${d}")"
9742fa
-        if ! printf '+%s' "${pt}" | ncat -U -u --send-only "${s}"; then
9742fa
+        if ! printf '%s' "${pt}" | @SYSTEMD_REPLY_PASS@ 1 "${s}"; then
9742fa
             echo "Unable to unlock ${d} (UUID=${uuid}) with recovered passphrase" >&2
9742fa
             continue
9742fa
         fi
9742fa
diff --git a/src/luks/systemd/dracut/clevis/module-setup.sh.in b/src/luks/systemd/dracut/clevis/module-setup.sh.in
9742fa
index ebf969f..d46c6e2 100755
9742fa
--- a/src/luks/systemd/dracut/clevis/module-setup.sh.in
9742fa
+++ b/src/luks/systemd/dracut/clevis/module-setup.sh.in
9742fa
@@ -36,6 +36,7 @@ install() {
9742fa
 
9742fa
     inst_multiple \
9742fa
         /etc/services \
9742fa
+        @SYSTEMD_REPLY_PASS@ \
9742fa
         @libexecdir@/clevis-luks-askpass \
9742fa
         clevis-luks-common-functions \
9742fa
         grep sed cut \
9742fa
@@ -45,8 +46,7 @@ install() {
9742fa
         luksmeta \
9742fa
         clevis \
9742fa
         mktemp \
9742fa
-        jose \
9742fa
-        ncat
9742fa
+        jose
9742fa
 
9742fa
     dracut_need_initqueue
9742fa
 }
9742fa
diff --git a/src/luks/systemd/meson.build b/src/luks/systemd/meson.build
9742fa
index 369e7f7..e3b3d91 100644
9742fa
--- a/src/luks/systemd/meson.build
9742fa
+++ b/src/luks/systemd/meson.build
9742fa
@@ -1,6 +1,15 @@
9742fa
 systemd = dependency('systemd', required: false)
9742fa
 
9742fa
-if systemd.found()
9742fa
+sd_reply_pass = find_program(
9742fa
+  join_paths(get_option('prefix'), get_option('libdir'), 'systemd', 'systemd-reply-password'),
9742fa
+  join_paths(get_option('prefix'), 'lib', 'systemd', 'systemd-reply-password'),
9742fa
+  join_paths('/', 'usr', get_option('libdir'), 'systemd', 'systemd-reply-password'),
9742fa
+  join_paths('/', 'usr', 'lib', 'systemd', 'systemd-reply-password'),
9742fa
+  required: false
9742fa
+)
9742fa
+
9742fa
+if systemd.found() and sd_reply_pass.found()
9742fa
+  data.set('SYSTEMD_REPLY_PASS', sd_reply_pass.path())
9742fa
   subdir('dracut')
9742fa
 
9742fa
   unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
9742fa
@@ -12,8 +21,14 @@ if systemd.found()
9742fa
     configuration: data,
9742fa
   )
9742fa
 
9742fa
+  configure_file(
9742fa
+    input: 'clevis-luks-askpass.in',
9742fa
+    output: 'clevis-luks-askpass',
9742fa
+    install_dir: libexecdir,
9742fa
+    configuration: data
9742fa
+  )
9742fa
+
9742fa
   install_data('clevis-luks-askpass.path', install_dir: unitdir)
9742fa
-  install_data('clevis-luks-askpass', install_dir: libexecdir)
9742fa
 else
9742fa
   warning('Will not install systemd support due to missing dependencies!')
9742fa
 endif
9742fa
-- 
9742fa
2.33.1
9742fa