From f6c50564cd5f2314ee3b6ef449519bd193910b1b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 4 Jul 2019 13:45:02 +0200 Subject: [PATCH] [luksbootkeyfile] Extract devices that need cryptsetup - Rename classes and functions to be more descriptive (a LuksDevice is .. information for a LUKS device, for instance). - Move the smarts of unpacking a QVariantMap to LuksDevice. - Apply code formatting --- .../luksbootkeyfile/LuksBootKeyFileJob.cpp | 66 +++++++++++++------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp index c05cb970d..6589c5330 100644 --- a/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp +++ b/src/modules/luksbootkeyfile/LuksBootKeyFileJob.cpp @@ -38,20 +38,41 @@ LuksBootKeyFileJob::prettyName() const return tr( "Configuring LUKS key file." ); } -struct LuksPassphrase +struct LuksDevice { + LuksDevice( const QMap< QString, QVariant >& pinfo ) + : isValid( false ) + , isRoot( false ) + { + if ( pinfo.contains( "luksMapperName" ) ) + { + QString fs = pinfo[ "fs" ].toString(); + QString mountPoint = pinfo[ "mountPoint" ].toString(); + + if ( !mountPoint.isEmpty() || fs == QStringLiteral( "linuxswap" ) ) + { + isValid = true; + isRoot = mountPoint == '/'; + device = pinfo[ "device" ].toString(); + passphrase = pinfo[ "luksPassphrase" ].toString(); + } + } + } + + bool isValid; + bool isRoot; QString device; QString passphrase; }; -struct GlobalSettings +struct LuksDeviceList { - GlobalSettings( const QVariant& partitions ) + LuksDeviceList( const QVariant& partitions ) : valid( false ) { - if ( partitions.canConvert() ) + if ( partitions.canConvert< QVariantList >() ) { - filesystems = getPartitionInfo( partitions.toList() ); + devices = getLuksDevices( partitions.toList() ); valid = true; } } @@ -62,27 +83,26 @@ struct GlobalSettings * so there's maps with keys inside), returns just the list of * luks passphrases for each device. */ - static QList< LuksPassphrase > getPartitionInfo( const QVariantList& list ) + static QList< LuksDevice > + getLuksDevices( const QVariantList& list ) { - int count = 0; - for( const auto& p : list ) + QList< LuksDevice > luksItems; + + for ( const auto& p : list ) { - if ( p.canConvert< QVariantMap>() ) + if ( p.canConvert< QVariantMap >() ) { - auto pinfo = p.toMap(); - QString device = pinfo["device"].toString(); - QString fs = pinfo["fs"].toString(); - QString mountPoint = pinfo["mountPoint"].toString(); - QString uuid = pinfo["uuid"].toString(); - - cDebug() << count << "D=" << device << mountPoint << '(' << fs << ')'; + LuksDevice d( p.toMap() ); + if ( d.isValid ) + { + luksItems.append( d ); + } } - count++; } - return QList< LuksPassphrase >(); + return luksItems; } - QList< LuksPassphrase > filesystems; + QList< LuksDevice > devices; bool valid; }; @@ -103,7 +123,13 @@ LuksBootKeyFileJob::exec() Calamares::JobResult::InvalidConfiguration ); } - GlobalSettings s( gs->value( "partitions" ) ); + LuksDeviceList s( gs->value( "partitions" ) ); + cDebug() << "There are" << s.devices.count() << "LUKS partitions"; + for ( const auto& p : s.devices ) + { + cDebug() << Logger::SubEntry << p.isRoot << p.device << p.passphrase; + } + return Calamares::JobResult::ok(); }