mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
usermod: Add -G
option to modify supplementary groups
This commit is contained in:
parent
d7fccfc237
commit
caf55c0b2d
2 changed files with 22 additions and 1 deletions
|
@ -5,7 +5,7 @@ usermod - modify a user account
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```sh
|
```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
|
## Description
|
||||||
|
@ -19,6 +19,7 @@ This program must be run as root.
|
||||||
* `--version`: Print version
|
* `--version`: Print version
|
||||||
* `-u uid`, `--uid uid`: The new numerical value of the user's ID
|
* `-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 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
|
* `-L`, `--lock`: Lock password
|
||||||
* `-U`, `--unlock`: Unlock password
|
* `-U`, `--unlock`: Unlock password
|
||||||
* `-d new-home`, `--home new-home`: The user's new login directory
|
* `-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 shell;
|
||||||
StringView gecos;
|
StringView gecos;
|
||||||
StringView username;
|
StringView username;
|
||||||
|
Vector<gid_t> extra_gids;
|
||||||
|
|
||||||
auto args_parser = Core::ArgsParser();
|
auto args_parser = Core::ArgsParser();
|
||||||
args_parser.set_general_help("Modify a user account");
|
args_parser.set_general_help("Modify a user account");
|
||||||
|
@ -74,6 +75,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return gid.has_value();
|
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(lock, "Lock password", "lock", 'L');
|
||||||
args_parser.add_option(unlock, "Unlock password", "unlock", 'U');
|
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");
|
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);
|
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(Core::System::pledge("stdio wpath rpath cpath fattr"));
|
||||||
|
|
||||||
TRY(target_account.sync());
|
TRY(target_account.sync());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue