From 8c3146a1cd7ea3d6918d29c67904a9704073f72e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 1 Oct 2019 15:46:54 +0200 Subject: [PATCH] [machineid] Start implementing module logic - remove existing files for each kind of random-generation that is enabled. There's a helper function for the case that Cala is no longer setuid and needs help to remove those files from the target (e.g. a setuid helper). --- src/modules/machineid/MachineIdJob.cpp | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/modules/machineid/MachineIdJob.cpp b/src/modules/machineid/MachineIdJob.cpp index 3fd539e80..b8fc3334a 100644 --- a/src/modules/machineid/MachineIdJob.cpp +++ b/src/modules/machineid/MachineIdJob.cpp @@ -25,6 +25,11 @@ #include "utils/Logger.h" #include "utils/Variant.h" +#include "GlobalStorage.h" +#include "JobQueue.h" + +#include + MachineIdJob::MachineIdJob( QObject* parent ) : Calamares::CppJob( parent ) { @@ -40,10 +45,49 @@ MachineIdJob::prettyName() const return tr( "Generate machine-id." ); } +// might need to use a helper to remove the file +static void +removeFile( const QString& fileName ) +{ + QFile::remove( fileName ); +} Calamares::JobResult MachineIdJob::exec() { + QString root; + + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + if ( gs && gs->contains( "rootMountPoint" ) ) + { + root = gs->value( "rootMountPoint" ).toString(); + } + else + { + cWarning() << "No *rootMountPoint* defined."; + return Calamares::JobResult::internalError( tr( "Configuration Error" ), + tr( "No root mount point is set for MachineId." ), + Calamares::JobResult::InvalidConfiguration ); + } + + QString target_systemd_machineid_file = root + QStringLiteral( "/etc/machine-id" ); + QString target_dbus_machineid_file = root + QStringLiteral( "/var/lib/dbus/machine-id" ); + QString target_entropy_file = root + QStringLiteral( "/var/lib/urandom/random-seed" ); + + // Clear existing files + if ( m_entropy ) + { + removeFile( target_entropy_file ); + } + if ( m_dbus ) + { + removeFile( target_dbus_machineid_file ); + } + if ( m_systemd ) + { + removeFile( target_systemd_machineid_file ); + } + return Calamares::JobResult::ok(); }