diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index dc50f42c5..fff6e3960 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -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 ) { diff --git a/src/modules/users/Config.h b/src/modules/users/Config.h index 57da73e30..d4bfee4a4 100644 --- a/src/modules/users/Config.h +++ b/src/modules/users/Config.h @@ -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; } diff --git a/src/modules/users/MiscJobs.cpp b/src/modules/users/MiscJobs.cpp index 04880d1d8..b6fbe55db 100644 --- a/src/modules/users/MiscJobs.cpp +++ b/src/modules/users/MiscJobs.cpp @@ -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( '*' ) );