[users] Run CreateUserJob off of the Config object
- don't pass in copies or bits of the Config, hand over the whole Config - don't pluck some parts of the Config from Global Storage
This commit is contained in:
parent
02e9872a99
commit
ef70b2c32e
@ -780,13 +780,7 @@ Config::createJobs() const
|
||||
|
||||
Calamares::Job* j;
|
||||
|
||||
QStringList groupNames = std::accumulate(
|
||||
m_defaultGroups.begin(),
|
||||
m_defaultGroups.end(),
|
||||
QStringList(),
|
||||
[]( const QStringList& l, const GroupDescription& g ) { return QStringList( l ) << g.name(); } );
|
||||
|
||||
j = new CreateUserJob( loginName(), fullName().isEmpty() ? loginName() : fullName(), doAutoLogin(), groupNames );
|
||||
j = new CreateUserJob( this );
|
||||
jobs.append( Calamares::job_ptr( j ) );
|
||||
|
||||
j = new SetPasswordJob( loginName(), userPassword() );
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "CreateUserJob.h"
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
@ -21,15 +23,9 @@
|
||||
#include <QTextStream>
|
||||
|
||||
|
||||
CreateUserJob::CreateUserJob( const QString& userName,
|
||||
const QString& fullName,
|
||||
bool autologin,
|
||||
const QStringList& defaultGroups )
|
||||
CreateUserJob::CreateUserJob( const Config* config )
|
||||
: Calamares::Job()
|
||||
, m_userName( userName )
|
||||
, m_fullName( fullName )
|
||||
, m_autologin( autologin )
|
||||
, m_defaultGroups( defaultGroups )
|
||||
, m_config( config )
|
||||
{
|
||||
}
|
||||
|
||||
@ -37,21 +33,21 @@ CreateUserJob::CreateUserJob( const QString& userName,
|
||||
QString
|
||||
CreateUserJob::prettyName() const
|
||||
{
|
||||
return tr( "Create user %1" ).arg( m_userName );
|
||||
return tr( "Create user %1" ).arg( m_config->loginName() );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
CreateUserJob::prettyDescription() const
|
||||
{
|
||||
return tr( "Create user <strong>%1</strong>." ).arg( m_userName );
|
||||
return tr( "Create user <strong>%1</strong>." ).arg( m_config->loginName() );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
CreateUserJob::prettyStatusMessage() const
|
||||
{
|
||||
return tr( "Creating user %1." ).arg( m_userName );
|
||||
return tr( "Creating user %1." ).arg( m_config->loginName() );
|
||||
}
|
||||
|
||||
STATICTEST QStringList
|
||||
@ -86,16 +82,16 @@ groupsInTargetSystem( const QDir& targetRoot )
|
||||
}
|
||||
|
||||
static void
|
||||
ensureGroupsExistInTarget( const QStringList& wantedGroups, const QStringList& availableGroups )
|
||||
ensureGroupsExistInTarget( const QList< GroupDescription >& wantedGroups, const QStringList& availableGroups )
|
||||
{
|
||||
for ( const QString& group : wantedGroups )
|
||||
for ( const auto& group : wantedGroups )
|
||||
{
|
||||
if ( !availableGroups.contains( group ) )
|
||||
if ( group.isValid() && !availableGroups.contains( group.name() ) )
|
||||
{
|
||||
#ifdef __FreeBSD__
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group } );
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group.name() } );
|
||||
#else
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group } );
|
||||
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group.name() } );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -189,19 +185,29 @@ CreateUserJob::exec()
|
||||
|
||||
cDebug() << "[CREATEUSER]: preparing groups";
|
||||
|
||||
// loginName(), fullName().isEmpty() ? loginName() : fullName(), doAutoLogin(), groupNames );
|
||||
const auto& defaultGroups = m_config->defaultGroups();
|
||||
QStringList groupsForThisUser = std::accumulate(
|
||||
defaultGroups.begin(),
|
||||
defaultGroups.end(),
|
||||
QStringList(),
|
||||
[]( const QStringList& l, const GroupDescription& g ) { return QStringList( l ) << g.name(); } );
|
||||
|
||||
QStringList availableGroups = groupsInTargetSystem( destDir );
|
||||
QStringList groupsForThisUser = m_defaultGroups;
|
||||
if ( m_autologin && gs->contains( "autologinGroup" ) && !gs->value( "autologinGroup" ).toString().isEmpty() )
|
||||
ensureGroupsExistInTarget( defaultGroups, availableGroups );
|
||||
|
||||
if ( m_config->doAutoLogin() && !m_config->autologinGroup().isEmpty() )
|
||||
{
|
||||
groupsForThisUser << gs->value( "autologinGroup" ).toString();
|
||||
const QString autologinGroup = m_config->autologinGroup();
|
||||
groupsForThisUser << autologinGroup;
|
||||
ensureGroupsExistInTarget( QList< GroupDescription >() << GroupDescription( autologinGroup ), availableGroups );
|
||||
}
|
||||
ensureGroupsExistInTarget( groupsForThisUser, availableGroups );
|
||||
|
||||
// If we're looking to reuse the contents of an existing /home.
|
||||
// This GS setting comes from the **partitioning** module.
|
||||
if ( gs->value( "reuseHome" ).toBool() )
|
||||
{
|
||||
QString shellFriendlyHome = "/home/" + m_userName;
|
||||
QString shellFriendlyHome = "/home/" + m_config->loginName();
|
||||
QDir existingHome( destDir.absolutePath() + shellFriendlyHome );
|
||||
if ( existingHome.exists() )
|
||||
{
|
||||
@ -216,20 +222,20 @@ CreateUserJob::exec()
|
||||
|
||||
cDebug() << "[CREATEUSER]: creating user";
|
||||
|
||||
auto useraddResult = createUser( m_userName, m_fullName, gs->value( "userShell" ).toString() );
|
||||
auto useraddResult = createUser( m_config->loginName(), m_config->fullName(), m_config->userShell() );
|
||||
if ( !useraddResult )
|
||||
{
|
||||
return useraddResult;
|
||||
}
|
||||
|
||||
auto usergroupsResult = setUserGroups( m_userName, groupsForThisUser );
|
||||
auto usergroupsResult = setUserGroups( m_config->loginName(), groupsForThisUser );
|
||||
if ( !usergroupsResult )
|
||||
{
|
||||
return usergroupsResult;
|
||||
}
|
||||
|
||||
QString userGroup = QString( "%1:%2" ).arg( m_userName ).arg( m_userName );
|
||||
QString homeDir = QString( "/home/%1" ).arg( m_userName );
|
||||
QString userGroup = QString( "%1:%2" ).arg( m_config->loginName() ).arg( m_config->loginName() );
|
||||
QString homeDir = QString( "/home/%1" ).arg( m_config->loginName() );
|
||||
auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } );
|
||||
if ( commandResult.getExitCode() )
|
||||
{
|
||||
|
@ -12,23 +12,20 @@
|
||||
|
||||
#include "Job.h"
|
||||
|
||||
#include <QStringList>
|
||||
class Config;
|
||||
|
||||
class CreateUserJob : public Calamares::Job
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CreateUserJob( const QString& userName, const QString& fullName, bool autologin, const QStringList& defaultGroups );
|
||||
CreateUserJob( const Config* config );
|
||||
QString prettyName() const override;
|
||||
QString prettyDescription() const override;
|
||||
QString prettyStatusMessage() const override;
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
private:
|
||||
QString m_userName;
|
||||
QString m_fullName;
|
||||
bool m_autologin;
|
||||
QStringList m_defaultGroups;
|
||||
const Config* m_config;
|
||||
};
|
||||
|
||||
#endif /* CREATEUSERJOB_H */
|
||||
|
Loading…
Reference in New Issue
Block a user