From 9e8458135454bce61baf71310e8e713aea4c4395 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 8 Oct 2014 15:35:27 +0200 Subject: [PATCH] Only add wheel to sudoers if a wheel group is defined in conf. --- src/modules/users/CreateUserJob.cpp | 27 +++++++++++++++++---------- src/modules/users/UsersViewStep.cpp | 7 +++++++ src/modules/users/users.conf | 3 ++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 060e2b4bc..9260a8062 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -57,20 +57,27 @@ CreateUserJob::exec() { Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); QDir destDir( gs->value( "rootMountPoint" ).toString() ); - QFileInfo sudoersFi( destDir.absoluteFilePath( "etc/sudoers.d/10-installer" ) ); - if ( !sudoersFi.absoluteDir().exists() ) - return Calamares::JobResult::error( tr( "Sudoers dir is not writable." ) ); + if ( gs->contains( "sudoersGroup" ) && + !gs->value( "sudoersGroup" ).toString().isEmpty() ) + { + QFileInfo sudoersFi( destDir.absoluteFilePath( "etc/sudoers.d/10-installer" ) ); + + if ( !sudoersFi.absoluteDir().exists() ) + return Calamares::JobResult::error( tr( "Sudoers dir is not writable." ) ); - QFile sudoersFile( sudoersFi.absoluteFilePath() ); - if (!sudoersFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) - return Calamares::JobResult::error( tr( "Cannot create sudoers file for writing." ) ); + QFile sudoersFile( sudoersFi.absoluteFilePath() ); + if (!sudoersFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) + return Calamares::JobResult::error( tr( "Cannot create sudoers file for writing." ) ); - QTextStream sudoersOut( &sudoersFile ); - sudoersOut << QString( "%1 ALL=(ALL) ALL\n" ).arg( m_userName ); + QString sudoersGroup = gs->value( "sudoersGroup" ).toString(); - if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) ) - return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) ); + QTextStream sudoersOut( &sudoersFile ); + sudoersOut << QString( "%%1 ALL=(ALL) ALL\n" ).arg( sudoersGroup ); + + if ( QProcess::execute( "chmod", { "440", sudoersFi.absoluteFilePath() } ) ) + return Calamares::JobResult::error( tr( "Cannot chmod sudoers file." ) ); + } QFileInfo groupsFi( destDir.absoluteFilePath( "etc/group" ) ); QFile groupsFile( groupsFi.absoluteFilePath() ); diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 399fd8542..9b823242c 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -130,5 +130,12 @@ UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap ) Calamares::JobQueue::instance()->globalStorage()->insert( "autologinGroup", configurationMap.value( "autologinGroup" ).toString() ); } + + if ( configurationMap.contains( "sudoersGroup" ) && + configurationMap.value( "sudoersGroup" ).type() == QVariant::String ) + { + Calamares::JobQueue::instance()->globalStorage()->insert( "sudoersGroup", + configurationMap.value( "sudoersGroup" ).toString() ); + } } diff --git a/src/modules/users/users.conf b/src/modules/users/users.conf index 7be6997b8..aab7a4065 100644 --- a/src/modules/users/users.conf +++ b/src/modules/users/users.conf @@ -7,4 +7,5 @@ defaultGroups: - storage - wheel - audio -autologinGroup: autologin \ No newline at end of file +autologinGroup: autologin +sudoersGroup: wheel