Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[System] Can't add groups to a user #313

Open
dshoreman opened this issue Dec 17, 2020 · 1 comment
Open

[System] Can't add groups to a user #313

dshoreman opened this issue Dec 17, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@dshoreman
Copy link
Owner

dshoreman commented Dec 17, 2020

After creating a new regular user in System > Users, attempts to add the sudo group to that user will fail.

It's this chunk of code that's throwing, reporting "exit code 2":

exec("sudo {$cmd} {$this->user->toArgs()} {$name}", $output, $retval);
unset($output);
if (0 !== $retval) {
throw new UserSaveException("Something went wrong (exit code: {$retval})");
}

Moving the full command to a variable (so it could be dumped in the exception) shows the generated command as being sudo usermod -G "sudo" -m newuser. It looks fine at first glance, but running that command in a shell reveals the error:

usermod: -m flag is only allowed with the -d flag

According to the options, -m in usermod is an alias of --move-home, which is likely not what we want! Where is that coming from?

It would also be worth capturing (or redirecting to stdout) the stderr output and logging it somewhere when there errors happen so we have a bit more info to go by in future.

@dshoreman dshoreman added the bug Something isn't working label Dec 17, 2020
@dshoreman dshoreman self-assigned this Dec 17, 2020
@dshoreman dshoreman added this to To do in System Users & Groups via automation Dec 17, 2020
@dshoreman
Copy link
Owner Author

Looks like the frontend is always (or perhaps only when a dir is set) sending move_home: true with the request, which causes -m to be added via setMoveHome() in System\User:

public function update(array $data): array
{
$this->user->setName($data['name'])
->setUid($data['uid'] ?? null)
->setGid($data['gid'] ?? null)
->setShell($data['shell'] ?? null)
->setGroups($data['groups'] ?? null)
->setMoveHome($data['move_home'] ?? false)
->setHomeDirectory($data['dir'] ?? '');

setHomeDirectory() will ensure the home directory has changed before adding the -d option, but this check is not applied in setMoveHome() which is why we end up with a bad command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

1 participant