[users] More fine-grained group descriptions

Describe groups with more detail:
 - groups can be system groups (low GID) or not
 - groups may be pre-configured (e.g. come from the unpackfs stage)
This commit is contained in:
Adriaan de Groot 2020-10-13 17:35:07 +02:00
parent 5895f3fb71
commit d3135898fd
2 changed files with 55 additions and 5 deletions

View File

@ -590,8 +590,12 @@ Config::checkReady()
STATICTEST void
setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroups )
setConfigurationDefaultGroups( const QVariantMap& map, QList< GroupDescription >& defaultGroups )
{
defaultGroups.clear();
auto groupsFromConfig = map.value( "defaultGroups" ).toList();
cDebug() << groupsFromConfig;
#if 0
// '#' is not a valid group name; use that to distinguish an empty-list
// in the configuration (which is a legitimate, if unusual, choice)
// from a bad or missing configuration value.
@ -601,6 +605,7 @@ setConfigurationDefaultGroups( const QVariantMap& map, QStringList& defaultGroup
cWarning() << "Using fallback groups. Please check *defaultGroups* in users.conf";
defaultGroups = QStringList { "lp", "video", "network", "storage", "wheel", "audio" };
}
#endif
}
STATICTEST HostNameActions
@ -737,8 +742,13 @@ Config::createJobs() const
Calamares::Job* j;
j = new CreateUserJob(
loginName(), fullName().isEmpty() ? loginName() : fullName(), doAutoLogin(), defaultGroups() );
QStringList groupNames = std::accumulate(
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 ) );
j = new SetPasswordJob( loginName(), userPassword() );

View File

@ -15,6 +15,7 @@
#include "Job.h"
#include "utils/NamedEnum.h"
#include <QList>
#include <QObject>
#include <QVariantMap>
@ -30,6 +31,45 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( HostNameActions )
const NamedEnumTable< HostNameAction >& hostNameActionNames();
/** @brief Settings for a single group
*
* The list of defaultgroups from the configuration can be
* set up in a fine-grained way, with both user- and system-
* level groups; this class stores a configuration for each.
*/
class GroupDescription
{
public:
///@brief An invalid, empty group
GroupDescription() {}
///@brief A group with full details
GroupDescription( const QString& name, bool mustExistAlready = false, bool isSystem = false )
: m_name( name )
, m_isValid( !name.isEmpty() )
, m_mustAlreadyExist( mustExistAlready )
, m_isSystem( isSystem )
{
}
bool isValid() const { return m_isValid; }
bool isSystemGroup() const { return m_isSystem; }
QString name() const { return m_name; }
///@brief Equality of groups depends only on name and kind
bool operator==( const GroupDescription& rhs ) const
{
return rhs.name() == name() && rhs.isSystemGroup() == isSystemGroup();
}
private:
QString m_name;
bool m_isValid = false;
bool m_mustAlreadyExist = false;
bool m_isSystem = false;
};
class Config : public QObject
{
Q_OBJECT
@ -158,7 +198,7 @@ public:
/// Current setting for "require strong password"?
bool requireStrongPasswords() const { return m_requireStrongPasswords; }
const QStringList& defaultGroups() const { return m_defaultGroups; }
const QList< GroupDescription >& defaultGroups() const { return m_defaultGroups; }
// The user enters a password (and again in a separate UI element)
QString userPassword() const { return m_userPassword; }
@ -242,7 +282,7 @@ private:
PasswordStatus passwordStatus( const QString&, const QString& ) const;
void checkReady();
QStringList m_defaultGroups;
QList< GroupDescription > m_defaultGroups;
QString m_userShell;
QString m_autologinGroup;
QString m_sudoersGroup;