From f3aec1f4b138a89077ae04ac1a5fdcd9fc6980f3 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sat, 3 Apr 2021 00:50:06 +0100 Subject: [PATCH] Pass LUKS password as needed when resizing open mapping (#59) This is the final piece which enables GParted to pass the LUKS passphrase when resizing an open LUKS encryption mapping when 'cryptsetup resize' will prompt for it. Closes #59 - Resize of LUKS2 encrypted file system fails with "Nothing to read on input" --- src/luks.cc | 9 +++++++-- tests/Makefile.am | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/luks.cc b/src/luks.cc index fa72e5c9..fa7fa5b6 100644 --- a/src/luks.cc +++ b/src/luks.cc @@ -16,6 +16,7 @@ #include "FileSystem.h" #include "LUKS_Info.h" +#include "PasswordRAMStore.h" #include "Utils.h" #include "luks.h" @@ -158,8 +159,12 @@ bool luks::resize( const Partition & partition_new, OperationDetail & operationd // device sector size. size = "--size " + Utils::num_to_str( ( partition_new.get_byte_length() - mapping.offset ) / 512LL ) + " "; - return ! execute_command( "cryptsetup -v " + size + "resize " + Glib::shell_quote( mapping.name ), - operationdetail, EXEC_CHECK_STATUS ); + const char *pw = NULL; + if (mapping.key_loc == KEYLOC_KeyRing) + pw = PasswordRAMStore::lookup(partition_new.uuid); + + return ! execute_command("cryptsetup -v " + size + "resize " + Glib::shell_quote(mapping.name), + pw, operationdetail, EXEC_CHECK_STATUS); } } //GParted diff --git a/tests/Makefile.am b/tests/Makefile.am index ed6cbeda..bbd0ba8e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,6 +40,7 @@ test_SupportedFileSystems_LDADD = \ $(top_builddir)/src/Partition.$(OBJEXT) \ $(top_builddir)/src/PartitionLUKS.$(OBJEXT) \ $(top_builddir)/src/PartitionVector.$(OBJEXT) \ + $(top_builddir)/src/PasswordRAMStore.$(OBJEXT) \ $(top_builddir)/src/PipeCapture.$(OBJEXT) \ $(top_builddir)/src/Proc_Partitions_Info.$(OBJEXT) \ $(top_builddir)/src/ProgressBar.$(OBJEXT) \