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

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