[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.
This commit is contained in:
Adriaan de Groot 2020-10-13 23:30:28 +02:00
parent a86374386b
commit 02e9872a99
3 changed files with 34 additions and 8 deletions

View File

@ -605,10 +605,13 @@ setConfigurationDefaultGroups( const QVariantMap& map, QList< GroupDescription >
} }
else 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"; cWarning() << "Using fallback groups. Please check *defaultGroups* value in users.conf";
for ( const auto& s : { "lp", "video", "network", "storage", "wheel", "audio" } ) 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() ) ); 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 else
{ {
cWarning() << "Unknown *defaultGroups* entry" << v; cWarning() << "Unknown *defaultGroups* entry" << v;

View File

@ -41,16 +41,24 @@ class GroupDescription
{ {
public: public:
// TODO: still too-weakly typed, add a macro to define strongly-typed bools // TODO: still too-weakly typed, add a macro to define strongly-typed bools
class MustExist : public std::true_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 {}; class CreateIfNeeded : public std::false_type
{
};
class SystemGroup : public std::true_type
{
};
class UserGroup : public std::false_type
{
};
///@brief An invalid, empty group ///@brief An invalid, empty group
GroupDescription() {} GroupDescription() {}
///@brief A group with full details ///@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_name( name )
, m_isValid( !name.isEmpty() ) , m_isValid( !name.isEmpty() )
, m_mustAlreadyExist( mustExistAlready ) , m_mustAlreadyExist( mustExistAlready )

View File

@ -95,7 +95,7 @@ UserTests::testDefaultGroups()
QVERIFY( groups.isEmpty() ); QVERIFY( groups.isEmpty() );
setConfigurationDefaultGroups( missing, groups ); setConfigurationDefaultGroups( missing, groups );
QCOMPARE( groups.count(), 6 ); // because of fallback! 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 ); typeMismatch.insert( "defaultGroups", 1 );
setConfigurationDefaultGroups( typeMismatch, groups ); setConfigurationDefaultGroups( typeMismatch, groups );
QCOMPARE( groups.count(), 6 ); // because of fallback! QCOMPARE( groups.count(), 6 ); // because of fallback!
QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup{} ) ) ); QVERIFY( groups.contains( GroupDescription( "lp", false, GroupDescription::SystemGroup {} ) ) );
} }
} }