From 02e9872a9994a3a79c18b05e98fd4f0f4eb6a34f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Oct 2020 23:30:28 +0200 Subject: [PATCH] [users] Handle detailed groups list Groups can be specified with must_exist and/or system set, so they fill in the groups list more carefully. --- src/modules/users/Config.cpp | 20 +++++++++++++++++++- src/modules/users/Config.h | 18 +++++++++++++----- src/modules/users/Tests.cpp | 4 ++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 45b273a46..d764df846 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -605,10 +605,13 @@ setConfigurationDefaultGroups( const QVariantMap& map, QList< GroupDescription > } else { + // By default give the user a handful of "traditional" groups, if + // none are specified at all. These are system (GID < 1000) groups. cWarning() << "Using fallback groups. Please check *defaultGroups* value in users.conf"; for ( const auto& s : { "lp", "video", "network", "storage", "wheel", "audio" } ) { - defaultGroups.append( GroupDescription( s, GroupDescription::CreateIfNeeded{}, GroupDescription::SystemGroup{} ) ); + defaultGroups.append( + GroupDescription( s, GroupDescription::CreateIfNeeded {}, GroupDescription::SystemGroup {} ) ); } } } @@ -620,6 +623,21 @@ setConfigurationDefaultGroups( const QVariantMap& map, QList< GroupDescription > { defaultGroups.append( GroupDescription( v.toString() ) ); } + else if ( v.type() == QVariant::Map ) + { + const auto innermap = v.toMap(); + QString name = CalamaresUtils::getString( innermap, "name" ); + if ( !name.isEmpty() ) + { + defaultGroups.append( GroupDescription( name, + CalamaresUtils::getBool( innermap, "must_exist", false ), + CalamaresUtils::getBool( innermap, "system", false ) ) ); + } + else + { + cWarning() << "Ignoring *defaultGroups* entry without a name" << v; + } + } else { cWarning() << "Unknown *defaultGroups* entry" << v; diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index 853d65b5f..04f37d231 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -41,16 +41,24 @@ class GroupDescription { public: // TODO: still too-weakly typed, add a macro to define strongly-typed bools - class MustExist : public std::true_type {}; - class CreateIfNeeded : public std::false_type {}; - class SystemGroup : public std::true_type {}; - class UserGroup : public std::false_type {}; + class MustExist : public std::true_type + { + }; + class CreateIfNeeded : public std::false_type + { + }; + class SystemGroup : public std::true_type + { + }; + class UserGroup : public std::false_type + { + }; ///@brief An invalid, empty group GroupDescription() {} ///@brief A group with full details - GroupDescription( const QString& name, bool mustExistAlready = CreateIfNeeded{}, bool isSystem = UserGroup{} ) + GroupDescription( const QString& name, bool mustExistAlready = CreateIfNeeded {}, bool isSystem = UserGroup {} ) : m_name( name ) , m_isValid( !name.isEmpty() ) , m_mustAlreadyExist( mustExistAlready ) diff --git a/src/modules/users/Tests.cpp b/src/modules/users/Tests.cpp index 1716034fc..0ffeeae51 100644 --- a/src/modules/users/Tests.cpp +++ b/src/modules/users/Tests.cpp @@ -95,7 +95,7 @@ UserTests::testDefaultGroups() QVERIFY( groups.isEmpty() ); setConfigurationDefaultGroups( missing, groups ); QCOMPARE( groups.count(), 6 ); // because of fallback! - QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup{} ) ) ); + QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup {} ) ) ); } { @@ -105,7 +105,7 @@ UserTests::testDefaultGroups() typeMismatch.insert( "defaultGroups", 1 ); setConfigurationDefaultGroups( typeMismatch, groups ); QCOMPARE( groups.count(), 6 ); // because of fallback! - QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup{} ) ) ); + QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup {} ) ) ); } }