[machineid] Support multiple entropy files

main
Adriaan de Groot 4 years ago
parent 8b22786bd2
commit 8be5c2ed10

@ -57,14 +57,13 @@ MachineIdJob::exec()
QString target_systemd_machineid_file = QStringLiteral( "/etc/machine-id" );
QString target_dbus_machineid_file = QStringLiteral( "/var/lib/dbus/machine-id" );
QString target_entropy_file = QStringLiteral( "/var/lib/urandom/random-seed" );
const CalamaresUtils::System* system = CalamaresUtils::System::instance();
// Clear existing files
if ( m_entropy )
for ( const auto& entropy_file : m_entropy_files )
{
system->removeTargetFile( target_entropy_file );
system->removeTargetFile( entropy_file );
}
if ( m_dbus )
{
@ -76,12 +75,12 @@ MachineIdJob::exec()
}
//Create new files
if ( m_entropy )
for ( const auto& entropy_file : m_entropy_files )
{
auto r = MachineId::createEntropy( m_entropy_copy ? MachineId::EntropyGeneration::CopyFromHost
: MachineId::EntropyGeneration::New,
root,
target_entropy_file );
entropy_file );
if ( !r )
{
return r;
@ -89,6 +88,10 @@ MachineIdJob::exec()
}
if ( m_systemd )
{
if ( !system->createTargetParentDirs( target_systemd_machineid_file ) )
{
cWarning() << "Could not create systemd data-directory.";
}
auto r = MachineId::createSystemdMachineId( root, target_systemd_machineid_file );
if ( !r )
{
@ -143,8 +146,19 @@ MachineIdJob::setConfigurationMap( const QVariantMap& map )
// ignore it, though, if dbus is false
m_dbus_symlink = m_dbus && m_dbus_symlink;
m_entropy = CalamaresUtils::getBool( map, "entropy", false );
m_entropy_copy = CalamaresUtils::getBool( map, "entropy-copy", false );
m_entropy_files = CalamaresUtils::getStringList( map, "entropy-files" );
if ( CalamaresUtils::getBool( map, "entropy", false ) )
{
cWarning() << "MachineId:: configuration setting *entropy* is deprecated, use *entropy-files*.";
QString target_entropy_file = QStringLiteral( "/var/lib/urandom/random-seed" );
if ( !m_entropy_files.contains( target_entropy_file ) )
{
m_entropy_files.append( target_entropy_file );
}
}
}
CALAMARES_PLUGIN_FACTORY_DEFINITION( MachineIdJobFactory, registerPlugin< MachineIdJob >(); )

@ -11,6 +11,7 @@
#define MACHINEIDJOB_H
#include <QObject>
#include <QStringList>
#include <QVariantMap>
#include "CppJob.h"
@ -19,6 +20,9 @@
#include "DllMacro.h"
/** @brief Write 'random' data: machine id, entropy, UUIDs
*
*/
class PLUGINDLLEXPORT MachineIdJob : public Calamares::CppJob
{
Q_OBJECT
@ -33,14 +37,22 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
/** @brief The list of filenames to write full of entropy.
*
* The list may be empty (no entropy files are configure) or
* contain one or more filenames to be interpreted within the
* target system.
*/
QStringList entropyFileNames() const { return m_entropy_files; }
private:
bool m_systemd = false; ///< write systemd's files
bool m_dbus = false; ///< write dbus files
bool m_dbus_symlink = false; ///< .. or just symlink to systemd
bool m_entropy = false; ///< write an entropy file
bool m_entropy_copy = false; ///< copy from host system
QStringList m_entropy_files; ///< names of files to write
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( MachineIdJobFactory )

@ -19,7 +19,13 @@ dbus: true
# (ignored if dbus is false, or if there is no /etc/machine-id to point to).
dbus-symlink: true
# Whether to create an entropy file
# Whether to create an entropy file /var/lib/urandom/random-seed
#
# DEPRECATED: list the file in entropy-files instead
entropy: false
# Whether to copy entropy from the host
entropy-copy: false
# Which files to write (paths in the target)
entropy-files:
- /var/lib/urandom/random-seed
- /var/lib/systemd/random-seed

@ -9,7 +9,8 @@ properties:
systemd: { type: boolean, default: true }
dbus: { type: boolean, default: true }
"dbus-symlink": { type: boolean, default: true }
entropy: { type: boolean, default: false }
"entropy-copy": { type: boolean, default: false }
"entropy-files": { type: array, items: { type: string } }
# Deprecated properties
symlink: { type: boolean, default: true }
entropy: { type: boolean, default: false }

Loading…
Cancel
Save