[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;
|
Calamares::Job* j;
|
||||||
|
|
||||||
QStringList groupNames = std::accumulate(
|
j = new CreateUserJob( this );
|
||||||
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 );
|
|
||||||
jobs.append( Calamares::job_ptr( j ) );
|
jobs.append( Calamares::job_ptr( j ) );
|
||||||
|
|
||||||
j = new SetPasswordJob( loginName(), userPassword() );
|
j = new SetPasswordJob( loginName(), userPassword() );
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "CreateUserJob.h"
|
#include "CreateUserJob.h"
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
@ -21,15 +23,9 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
|
||||||
CreateUserJob::CreateUserJob( const QString& userName,
|
CreateUserJob::CreateUserJob( const Config* config )
|
||||||
const QString& fullName,
|
|
||||||
bool autologin,
|
|
||||||
const QStringList& defaultGroups )
|
|
||||||
: Calamares::Job()
|
: Calamares::Job()
|
||||||
, m_userName( userName )
|
, m_config( config )
|
||||||
, m_fullName( fullName )
|
|
||||||
, m_autologin( autologin )
|
|
||||||
, m_defaultGroups( defaultGroups )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,21 +33,21 @@ CreateUserJob::CreateUserJob( const QString& userName,
|
|||||||
QString
|
QString
|
||||||
CreateUserJob::prettyName() const
|
CreateUserJob::prettyName() const
|
||||||
{
|
{
|
||||||
return tr( "Create user %1" ).arg( m_userName );
|
return tr( "Create user %1" ).arg( m_config->loginName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
CreateUserJob::prettyDescription() const
|
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
|
QString
|
||||||
CreateUserJob::prettyStatusMessage() const
|
CreateUserJob::prettyStatusMessage() const
|
||||||
{
|
{
|
||||||
return tr( "Creating user %1." ).arg( m_userName );
|
return tr( "Creating user %1." ).arg( m_config->loginName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
STATICTEST QStringList
|
STATICTEST QStringList
|
||||||
@ -86,16 +82,16 @@ groupsInTargetSystem( const QDir& targetRoot )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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__
|
#ifdef __FreeBSD__
|
||||||
CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group } );
|
CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group.name() } );
|
||||||
#else
|
#else
|
||||||
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group } );
|
CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group.name() } );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,19 +185,29 @@ CreateUserJob::exec()
|
|||||||
|
|
||||||
cDebug() << "[CREATEUSER]: preparing groups";
|
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 availableGroups = groupsInTargetSystem( destDir );
|
||||||
QStringList groupsForThisUser = m_defaultGroups;
|
ensureGroupsExistInTarget( defaultGroups, availableGroups );
|
||||||
if ( m_autologin && gs->contains( "autologinGroup" ) && !gs->value( "autologinGroup" ).toString().isEmpty() )
|
|
||||||
|
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.
|
// If we're looking to reuse the contents of an existing /home.
|
||||||
// This GS setting comes from the **partitioning** module.
|
// This GS setting comes from the **partitioning** module.
|
||||||
if ( gs->value( "reuseHome" ).toBool() )
|
if ( gs->value( "reuseHome" ).toBool() )
|
||||||
{
|
{
|
||||||
QString shellFriendlyHome = "/home/" + m_userName;
|
QString shellFriendlyHome = "/home/" + m_config->loginName();
|
||||||
QDir existingHome( destDir.absolutePath() + shellFriendlyHome );
|
QDir existingHome( destDir.absolutePath() + shellFriendlyHome );
|
||||||
if ( existingHome.exists() )
|
if ( existingHome.exists() )
|
||||||
{
|
{
|
||||||
@ -216,20 +222,20 @@ CreateUserJob::exec()
|
|||||||
|
|
||||||
cDebug() << "[CREATEUSER]: creating user";
|
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 )
|
if ( !useraddResult )
|
||||||
{
|
{
|
||||||
return useraddResult;
|
return useraddResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto usergroupsResult = setUserGroups( m_userName, groupsForThisUser );
|
auto usergroupsResult = setUserGroups( m_config->loginName(), groupsForThisUser );
|
||||||
if ( !usergroupsResult )
|
if ( !usergroupsResult )
|
||||||
{
|
{
|
||||||
return usergroupsResult;
|
return usergroupsResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString userGroup = QString( "%1:%2" ).arg( m_userName ).arg( m_userName );
|
QString userGroup = QString( "%1:%2" ).arg( m_config->loginName() ).arg( m_config->loginName() );
|
||||||
QString homeDir = QString( "/home/%1" ).arg( m_userName );
|
QString homeDir = QString( "/home/%1" ).arg( m_config->loginName() );
|
||||||
auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } );
|
auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( { "chown", "-R", userGroup, homeDir } );
|
||||||
if ( commandResult.getExitCode() )
|
if ( commandResult.getExitCode() )
|
||||||
{
|
{
|
||||||
|
@ -12,23 +12,20 @@
|
|||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
|
||||||
#include <QStringList>
|
class Config;
|
||||||
|
|
||||||
class CreateUserJob : public Calamares::Job
|
class CreateUserJob : public Calamares::Job
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CreateUserJob( const QString& userName, const QString& fullName, bool autologin, const QStringList& defaultGroups );
|
CreateUserJob( const Config* config );
|
||||||
QString prettyName() const override;
|
QString prettyName() const override;
|
||||||
QString prettyDescription() const override;
|
QString prettyDescription() const override;
|
||||||
QString prettyStatusMessage() const override;
|
QString prettyStatusMessage() const override;
|
||||||
Calamares::JobResult exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_userName;
|
const Config* m_config;
|
||||||
QString m_fullName;
|
|
||||||
bool m_autologin;
|
|
||||||
QStringList m_defaultGroups;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CREATEUSERJOB_H */
|
#endif /* CREATEUSERJOB_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user