dshoreman / servidor

A modern web application for managing servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[System] Can't add groups to a user

dshoreman opened this issue · comments

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);
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.

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
->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.

ezoic increase your site revenue