From 6aa5be192b04edbaab45ef494db4f5ef5fb9fa6f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 22 May 2018 11:43:14 -0400 Subject: [PATCH 1/5] [netinstall] Drop unused includes --- src/modules/netinstall/NetInstallPage.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index 37c489135..5272d83fd 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -30,19 +30,11 @@ #include "utils/Retranslator.h" #include "utils/YamlUtils.h" -#include -#include -#include - #include #include #include #include -#include -#include -#include -#include #include From 3a59574128fb37f58a836f572264d9a27930cb88 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 22 May 2018 11:45:39 -0400 Subject: [PATCH 2/5] [users] Factor out command-line to useradd - This is prep-work for #964, which was caused by #955 - Original assumption was that distro's would have a working useradd configuration; @abucodonosor already pointed out that this was probably not the case, but I ignored that. --- src/modules/users/CreateUserJob.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index d4d299e39..96b14c365 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -146,13 +146,12 @@ CreateUserJob::exec() } } - int ec = CalamaresUtils::System::instance()-> - targetEnvCall( { "useradd", - "-m", - "-U", - "-c", - m_fullName, - m_userName } ); + QStringList useradd{ "useradd", "-m", "-U" }; + // TODO: shell-settings + useradd << "-c" << m_fullName; + useradd << m_userName; + + int ec = CalamaresUtils::System::instance()->targetEnvCall( useradd ); if ( ec ) return Calamares::JobResult::error( tr( "Cannot create user %1." ) .arg( m_userName ), From ed15edabf9be0b1a68c9521068c31ebfc8578322 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 23 May 2018 03:30:51 -0400 Subject: [PATCH 3/5] [users] Document passwordRequirements and code --- src/modules/users/UsersPage.h | 6 ++++++ src/modules/users/users.conf | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 5990d8693..817f73d0b 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -52,6 +52,12 @@ public: void setAutologinDefault( bool checked ); void setReusePasswordDefault( bool checked ); + /** @brief Process entries in the passwordRequirements config entry + * + * Called once for each item in the config entry, which should + * be a key-value pair. What makes sense as a value depends on + * the key. Supported keys are documented in users.conf. + */ void addPasswordCheck( const QString& key, const QVariant& value ); protected slots: diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index 6111a6e80..be0221c8b 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -72,5 +72,5 @@ passwordRequirements: minLength: -1 # Password at least this many characters maxLength: -1 # Password at most this many characters libpwquality: - - minlen=8 - - minclass=2 + - minlen=0 + - minclass=0 From 0d24c1db6ce843392e5dab672bb0a0b4d3bc7b64 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 23 May 2018 05:23:46 -0400 Subject: [PATCH 4/5] [users] Introduce userShell setting - Add a *userShell* key, which can be left out (default, backwards- compatible) to retain the old /bin/bash behavior, or explicitly set to empty to defer to useradd-configuration, or explicitly set to something non-empty to use that shell. --- src/modules/users/CreateUserJob.cpp | 4 +++- src/modules/users/UsersViewStep.cpp | 11 ++++++++++- src/modules/users/users.conf | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 96b14c365..7d4ded545 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -147,7 +147,9 @@ CreateUserJob::exec() } QStringList useradd{ "useradd", "-m", "-U" }; - // TODO: shell-settings + QString shell = gs->value( "userShell" ).toString(); + if ( !shell.isEmpty() ) + useradd << "-s" << shell; useradd << "-c" << m_fullName; useradd << m_userName; diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 015d7e997..37d86819e 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -22,9 +22,11 @@ #include "UsersPage.h" +#include "utils/CalamaresUtils.h" #include "utils/Logger.h" -#include "JobQueue.h" + #include "GlobalStorage.h" +#include "JobQueue.h" CALAMARES_PLUGIN_FACTORY_DEFINITION( UsersViewStepFactory, registerPlugin(); ) @@ -181,5 +183,12 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) m_widget->addPasswordCheck( i.key(), i.value() ); } } + + QString shell( QLatin1Literal( "/bin/bash" ) ); // as if it's not set at all + if ( configurationMap.contains( "userShell" ) ) + shell = CalamaresUtils::getString( configurationMap, "userShell" ); + // Now it might be explicitly set to empty, which is ok + + Calamares::JobQueue::instance()->globalStorage()->insert( "userShell", shell ); } diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index be0221c8b..0c40faeff 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -74,3 +74,12 @@ passwordRequirements: libpwquality: - minlen=0 - minclass=0 + +# Shell to be used for the regular user of the target system. +# There are three possible kinds of settings: +# - unset (i.e. commented out, the default), act as if set to /bin/bash +# - empty (explicit), don't pass shell information to useradd at all +# and rely on a correct configuration file in /etc/default/useradd +# - set, non-empty, use that path as shell. No validation is done +# that the shell actually exists or is executable. +# userShell: /bin/bash From 01ff1efc5dc2b054db1c4bd5ccdc8f1bef269795 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 23 May 2018 07:03:59 -0400 Subject: [PATCH 5/5] [users] Improve explanation when useradd fails --- src/modules/users/CreateUserJob.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 7d4ded545..119028059 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac + * Copyright 2018, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -153,14 +154,14 @@ CreateUserJob::exec() useradd << "-c" << m_fullName; useradd << m_userName; - int ec = CalamaresUtils::System::instance()->targetEnvCall( useradd ); - if ( ec ) - return Calamares::JobResult::error( tr( "Cannot create user %1." ) - .arg( m_userName ), - tr( "useradd terminated with error code %1." ) - .arg( ec ) ); + auto pres = CalamaresUtils::System::instance()->targetEnvCommand( useradd ); + if ( pres.getExitCode() ) + { + cError() << "useradd failed" << pres.getExitCode(); + return pres.explainProcess( useradd, 10 /* bogus timeout */ ); + } - ec = CalamaresUtils::System::instance()-> + int ec = CalamaresUtils::System::instance()-> targetEnvCall( { "usermod", "-aG", defaultGroups,