From 8a6e4af511b0a5294e7236f4309cf2ab1c41cb4d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 27 Jul 2020 13:45:00 +0200 Subject: [PATCH] [users] FreeBSD support creating user - call pw useradd and pw usermod as needed; the code paths are basically the same in invoking a program in the target system to do the work. --- src/modules/users/CreateUserJob.cpp | 35 ++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index e052fa266..0fe931fa8 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -93,19 +93,33 @@ ensureGroupsExistInTarget( const QStringList& wantedGroups, const QStringList& a static Calamares::JobResult createUser( const QString& loginName, const QString& fullName, const QString& shell ) { - QStringList useradd { "useradd", "-m", "-U" }; + QStringList useraddCommand; +#ifdef __FreeBSD__ + useraddCommand << "pw" + << "useradd" + << "-n" << loginName << "-m" + << "-c" << fullName; + if ( !shell.isEmpty() ) + { + useraddCommand << "-s" << shell; + } +#else + useraddCommand << "useradd" + << "-m" + << "-U"; if ( !shell.isEmpty() ) { useradd << "-s" << shell; } useradd << "-c" << fullName; useradd << loginName; +#endif - auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( useradd ); + auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( useraddCommand ); if ( commandResult.getExitCode() ) { cError() << "useradd failed" << commandResult.getExitCode(); - return commandResult.explainProcess( useradd, std::chrono::seconds( 10 ) /* bogus timeout */ ); + return commandResult.explainProcess( useraddCommand, std::chrono::seconds( 10 ) /* bogus timeout */ ); } return Calamares::JobResult::ok(); } @@ -113,12 +127,21 @@ createUser( const QString& loginName, const QString& fullName, const QString& sh static Calamares::JobResult setUserGroups( const QString& loginName, const QStringList& groups ) { - auto commandResult - = CalamaresUtils::System::instance()->targetEnvCommand( { "usermod", "-aG", groups.join( ',' ), loginName } ); + QStringList setgroupsCommand; +#ifdef __FreeBSD__ + setgroupsCommand << "pw" + << "usermod" + << "-n" << loginName << "-G" << groups.join( ',' ); +#else + setgroupsCommand << "usermod" + << "-aG" << groups.join( ',' ) << loginName; +#endif + + auto commandResult = CalamaresUtils::System::instance()->targetEnvCommand( setgroupsCommand ); if ( commandResult.getExitCode() ) { cError() << "usermod failed" << commandResult.getExitCode(); - return commandResult.explainProcess( "usermod", std::chrono::seconds( 10 ) /* bogus timeout */ ); + return commandResult.explainProcess( setgroupsCommand, std::chrono::seconds( 10 ) /* bogus timeout */ ); } return Calamares::JobResult::ok(); }