diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index f245aa866..1219c2a3c 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -337,4 +337,7 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) setSudoersGroup( CalamaresUtils::getString( configurationMap, "sudoersGroup" ) ); m_doAutoLogin = CalamaresUtils::getBool( configurationMap, "doAutologin", false ); + + m_writeRootPassword = CalamaresUtils::getBool( configurationMap, "setRootPassword", true ); + Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword", m_writeRootPassword ); } diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index e7ab8a736..d32ddc8f2 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -74,6 +74,8 @@ public: /// Should the user be automatically logged-in? bool doAutoLogin() const { return m_doAutoLogin; } + /// Should the root password be written (if false, no password is set and the root account is disabled for login) + bool writeRootPassword() const { return m_writeRootPassword; } static const QStringList& forbiddenLoginNames(); static const QStringList& forbiddenHostNames(); @@ -124,6 +126,7 @@ private: QString m_loginName; QString m_hostName; bool m_doAutoLogin = false; + bool m_writeRootPassword = true; bool m_customLoginName = false; bool m_customHostName = false; diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index c9eb227e7..268e6099e 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -105,7 +105,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) , m_readyHostname( false ) , m_readyPassword( false ) , m_readyRootPassword( false ) - , m_writeRootPassword( true ) { ui->setupUi( this ); @@ -119,22 +118,19 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) onRootPasswordTextChanged( ui->textBoxRootPassword->text() ); checkReady( isReady() ); } ); - connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { + connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( const int checked ) { /* When "reuse" is checked, hide the fields for explicitly * entering the root password. However, if we're going to * disable the root password anyway, hide them all regardless of * the checkbox -- so when writeRoot is false, checked needs * to be true, to hide them all. */ - if ( !m_writeRootPassword ) - { - checked = true; - } - ui->labelChooseRootPassword->setVisible( !checked ); - ui->labelRootPassword->setVisible( !checked ); - ui->labelRootPasswordError->setVisible( !checked ); - ui->textBoxRootPassword->setVisible( !checked ); - ui->textBoxVerifiedRootPassword->setVisible( !checked ); + const bool visible = m_config->writeRootPassword() ? !checked : false; + ui->labelChooseRootPassword->setVisible( visible ); + ui->labelRootPassword->setVisible( visible ); + ui->labelRootPasswordError->setVisible( visible ); + ui->textBoxRootPassword->setVisible( visible ); + ui->textBoxVerifiedRootPassword->setVisible( visible ); checkReady( isReady() ); } ); @@ -154,7 +150,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) } ); connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked ); - setWriteRootPassword( true ); + ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); ui->checkBoxReusePassword->setChecked( true ); ui->checkBoxValidatePassword->setChecked( true ); @@ -196,18 +192,16 @@ bool UsersPage::isReady() { bool readyFields = m_readyFullName && m_readyHostname && m_readyPassword && m_readyUsername; - if ( !m_writeRootPassword || ui->checkBoxReusePassword->isChecked() ) - { - return readyFields; - } - - return readyFields && m_readyRootPassword; + // If we're going to write a root password, we need a valid one (or reuse the user's password) + readyFields + &= m_config->writeRootPassword() ? ( m_readyRootPassword || ui->checkBoxReusePassword->isChecked() ) : true; + return readyFields; } QString UsersPage::getRootPassword() const { - if ( m_writeRootPassword ) + if ( m_config->writeRootPassword() ) { if ( ui->checkBoxReusePassword->isChecked() ) { @@ -248,7 +242,7 @@ UsersPage::createJobs( const QStringList& defaultGroupsList ) defaultGroupsList ); list.append( Calamares::job_ptr( j ) ); - if ( m_writeRootPassword ) + if ( m_config->writeRootPassword() ) { gs->insert( "reuseRootPassword", ui->checkBoxReusePassword->isChecked() ); } @@ -274,14 +268,6 @@ UsersPage::onActivate() } -void -UsersPage::setWriteRootPassword( bool write ) -{ - m_writeRootPassword = write; - ui->checkBoxReusePassword->setVisible( write ); -} - - void UsersPage::onFullNameTextEdited( const QString& fullName ) { diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 7cd522498..35f7f0938 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -51,7 +51,6 @@ public: void onActivate(); - void setWriteRootPassword( bool show ); void setPasswordCheckboxVisible( bool visible ); void setValidatePasswordDefault( bool checked ); void setReusePasswordDefault( bool checked ); @@ -101,8 +100,6 @@ private: bool m_readyHostname; bool m_readyPassword; bool m_readyRootPassword; - - bool m_writeRootPassword; }; #endif // USERSPAGE_H diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 0826b8a28..713811246 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -176,10 +176,6 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_defaultGroups = QStringList { "lp", "video", "network", "storage", "wheel", "audio" }; } - bool setRootPassword = getBool( configurationMap, "setRootPassword", true ); - Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword", setRootPassword ); - - m_widget->setWriteRootPassword( setRootPassword ); m_widget->setReusePasswordDefault( getBool( configurationMap, "doReusePassword", false ) ); if ( configurationMap.contains( "passwordRequirements" )