From 7d5a4eafa297933e18a3c4d7f6f3a0fd68bcce20 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 18 May 2022 14:06:00 +0200 Subject: [PATCH] [partition] Support KPMCore3 API (no testPassphrase in FS::luks) --- src/modules/partition/core/KPMHelpers.cpp | 40 ++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/KPMHelpers.cpp b/src/modules/partition/core/KPMHelpers.cpp index 6b4b5d28d..92c9edb22 100644 --- a/src/modules/partition/core/KPMHelpers.cpp +++ b/src/modules/partition/core/KPMHelpers.cpp @@ -129,6 +129,44 @@ clonePartition( Device* device, Partition* partition ) partition->activeFlags() ); } +#ifndef WITH_KPMCORE4API +// This function was added in KPMCore 4, implementation copied from src/fs/luks.cpp +/* + SPDX-FileCopyrightText: 2010 Volker Lanz + SPDX-FileCopyrightText: 2012-2019 Andrius Štikonas + SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac + SPDX-FileCopyrightText: 2016 Chantara Tith + SPDX-FileCopyrightText: 2017 Christian Morlok + SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho + SPDX-FileCopyrightText: 2020 Arnaud Ferraris + SPDX-FileCopyrightText: 2020 Gaël PORTAY + + SPDX-License-Identifier: GPL-3.0-or-later +*/ +static bool +testPassphrase( FS::luks* fs, const QString& deviceNode, const QString& passphrase ) +{ + ExternalCommand cmd( QStringLiteral( "cryptsetup" ), + { QStringLiteral( "open" ), + QStringLiteral( "--tries" ), + QStringLiteral( "1" ), + QStringLiteral( "--test-passphrase" ), + deviceNode } ); + if ( cmd.write( passphrase.toLocal8Bit() + '\n' ) && cmd.start( -1 ) && cmd.exitCode() == 0 ) + { + return true; + } + + return false; +} +#else +static bool +testPassphrase( FS::luks* fs, const QString& deviceNode, const QString& passphrase ) +{ + return fs->testPassphrase( deviceNode, passphrase ); +} +#endif + // Adapted from luks cryptOpen which always opens a dialog to ask for a passphrase int updateLuksDevice( Partition* partition, const QString& passphrase ) @@ -153,7 +191,7 @@ updateLuksDevice( Partition* partition, const QString& passphrase ) FS::luks* luksFs = dynamic_cast< FS::luks* >( &partition->fileSystem() ); // Test the given passphrase - if ( !luksFs->testPassphrase( deviceNode, passphrase ) ) + if ( !testPassphrase( luksFs, deviceNode, passphrase ) ) { cWarning() << Logger::SubEntry << "#3: Passphrase incorrect"; return 3;