[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:
parent
a86374386b
commit
02e9872a99
@ -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;
|
||||
|
@ -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 )
|
||||
|
@ -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 {} ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user