diff --git a/Base/usr/share/man/man8/usermod.md b/Base/usr/share/man/man8/usermod.md index 97108d680d..e522150db7 100644 --- a/Base/usr/share/man/man8/usermod.md +++ b/Base/usr/share/man/man8/usermod.md @@ -5,7 +5,7 @@ usermod - modify a user account ## Synopsis ```sh -$ usermod [--uid uid] [--gid group] [--lock] [--unlock] [--home new-home] [--move] [--shell path-to-shell] [--gecos general-info] +$ usermod [--uid uid] [--gid group] [--groups groups] [--lock] [--unlock] [--home new-home] [--move] [--shell path-to-shell] [--gecos general-info] ``` ## Description @@ -19,6 +19,7 @@ This program must be run as root. * `--version`: Print version * `-u uid`, `--uid uid`: The new numerical value of the user's ID * `-g group`, `--gid group`: The group name or number of the user's new initial login group +* `-G groups`, `--groups groups`: Set the user's supplementary groups. Groups are specified with a comma-separated list. Group names or numbers may be used * `-L`, `--lock`: Lock password * `-U`, `--unlock`: Unlock password * `-d new-home`, `--home new-home`: The user's new login directory diff --git a/Userland/Utilities/usermod.cpp b/Userland/Utilities/usermod.cpp index a2b6413c39..0d79cb0f84 100644 --- a/Userland/Utilities/usermod.cpp +++ b/Userland/Utilities/usermod.cpp @@ -57,6 +57,7 @@ ErrorOr serenity_main(Main::Arguments arguments) StringView shell; StringView gecos; StringView username; + Vector extra_gids; auto args_parser = Core::ArgsParser(); args_parser.set_general_help("Modify a user account"); @@ -74,6 +75,21 @@ ErrorOr serenity_main(Main::Arguments arguments) return gid.has_value(); }, }); + args_parser.add_option(Core::ArgsParser::Option { + .argument_mode = Core::ArgsParser::OptionArgumentMode::Required, + .help_string = "Set the user's supplementary groups. Groups are specified with a comma-separated list. Group names or numbers may be used", + .long_name = "groups", + .short_name = 'G', + .value_name = "groups", + .accept_value = [&extra_gids](StringView comma_separated_groups) { + auto groups = comma_separated_groups.split_view(','); + for (auto group : groups) { + if (auto gid = group_string_to_gid(group); gid.has_value()) + extra_gids.append(gid.value()); + } + return true; + }, + }); args_parser.add_option(lock, "Lock password", "lock", 'L'); args_parser.add_option(unlock, "Unlock password", "unlock", 'U'); args_parser.add_option(new_home_directory, "The user's new login directory", "home", 'd', "new-home"); @@ -162,6 +178,10 @@ ErrorOr serenity_main(Main::Arguments arguments) target_account.set_gecos(gecos); } + if (!extra_gids.is_empty()) { + target_account.set_extra_gids(extra_gids); + } + TRY(Core::System::pledge("stdio wpath rpath cpath fattr")); TRY(target_account.sync());