usermod: Add -G
option to modify supplementary groups
This commit is contained in:
parent
d7fccfc237
commit
caf55c0b2d
Notes:
sideshowbarker
2024-07-17 08:35:21 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/caf55c0b2d Pull-request: https://github.com/SerenityOS/serenity/pull/19428
2 changed files with 22 additions and 1 deletions
|
@ -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] <username>
|
||||
$ usermod [--uid uid] [--gid group] [--groups groups] [--lock] [--unlock] [--home new-home] [--move] [--shell path-to-shell] [--gecos general-info] <username>
|
||||
```
|
||||
|
||||
## 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
|
||||
|
|
|
@ -57,6 +57,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringView shell;
|
||||
StringView gecos;
|
||||
StringView username;
|
||||
Vector<gid_t> extra_gids;
|
||||
|
||||
auto args_parser = Core::ArgsParser();
|
||||
args_parser.set_general_help("Modify a user account");
|
||||
|
@ -74,6 +75,21 @@ ErrorOr<int> 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<int> 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());
|
||||
|
|
Loading…
Add table
Reference in a new issue