[users] Handle system-group creating specially

This commit is contained in:
Adriaan de Groot 2020-10-22 14:07:40 +02:00
parent fa1d314b13
commit 03541470d5
3 changed files with 37 additions and 5 deletions

View File

@ -136,6 +136,24 @@ Config::setAutologinGroup( const QString& group )
}
}
QStringList
Config::groupsForThisUser() const
{
QStringList l;
l.reserve( defaultGroups().size() + 1 );
for ( const auto& g : defaultGroups() )
{
l << g.name();
}
if ( doAutoLogin() && !autologinGroup().isEmpty() )
{
l << autologinGroup();
}
return l;
}
void
Config::setSudoersGroup( const QString& group )
{

View File

@ -68,6 +68,7 @@ public:
bool isValid() const { return m_isValid; }
bool isSystemGroup() const { return m_isSystem; }
bool mustAlreadyExist() const { return m_mustAlreadyExist; }
QString name() const { return m_name; }
///@brief Equality of groups depends only on name and kind
@ -213,6 +214,11 @@ public:
bool requireStrongPasswords() const { return m_requireStrongPasswords; }
const QList< GroupDescription >& defaultGroups() const { return m_defaultGroups; }
/** @brief the names of all the groups for the current user
*
* Takes into account defaultGroups and autologin behavior.
*/
QStringList groupsForThisUser() const;
// The user enters a password (and again in a separate UI element)
QString userPassword() const { return m_userPassword; }

View File

@ -112,7 +112,6 @@ ensureGroupsExistInTarget( const QList< GroupDescription >& wantedGroups,
for ( const auto& group : wantedGroups )
{
int groupaddResult = 0;
if ( group.isValid() && !availableGroups.contains( group.name() ) )
{
if ( group.mustAlreadyExist() )
@ -122,13 +121,22 @@ ensureGroupsExistInTarget( const QList< GroupDescription >& wantedGroups,
continue;
}
QStringList cmd;
#ifdef __FreeBSD__
groupaddResult
= CalamaresUtils::System::instance()->targetEnvCall( { "pw", "groupadd", "-n", group.name() } );
if ( group.isSystemGroup() )
{
cWarning() << "Ignoring must-be-a-system group for" << group.name() << "on FreeBSD";
}
cmd = QStringList { "pw", "groupadd", "-n", group.name() };
#else
groupaddResult = CalamaresUtils::System::instance()->targetEnvCall( { "groupadd", group.name() } );
cmd << QStringLiteral( "groupadd" );
if ( group.isSystemGroup() )
{
cmd << "--system";
}
cmd << group.name();
#endif
if ( groupaddResult )
if ( CalamaresUtils::System::instance()->targetEnvCall( cmd ) )
{
failureCount++;
missingGroups.append( group.name() + QChar( '*' ) );