[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).
This commit is contained in:
parent
be27b44818
commit
8c3146a1cd
@ -25,6 +25,11 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
MachineIdJob::MachineIdJob( QObject* parent )
|
MachineIdJob::MachineIdJob( QObject* parent )
|
||||||
: Calamares::CppJob( parent )
|
: Calamares::CppJob( parent )
|
||||||
{
|
{
|
||||||
@ -40,10 +45,49 @@ MachineIdJob::prettyName() const
|
|||||||
return tr( "Generate machine-id." );
|
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
|
Calamares::JobResult
|
||||||
MachineIdJob::exec()
|
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();
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user