ssh/tailssh: use root / as cmd.Dir when users HomeDir doesn't exist

Fixes #5224

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali 2022-11-01 16:15:16 +05:00 committed by Maisem Ali
parent 2be951a582
commit 1440742a1c
1 changed files with 10 additions and 1 deletions

View File

@ -283,7 +283,16 @@ func (ss *sshSession) launchProcess() error {
ss.cmd = ss.newIncubatorCommand()
cmd := ss.cmd
cmd.Dir = ss.conn.localUser.HomeDir
homeDir := ss.conn.localUser.HomeDir
if _, err := os.Stat(homeDir); err == nil {
cmd.Dir = homeDir
} else if os.IsNotExist(err) {
// If the home directory doesn't exist, we can't chdir to it.
// Instead, we'll chdir to the root directory.
cmd.Dir = "/"
} else {
return err
}
cmd.Env = append(cmd.Env, envForUser(ss.conn.localUser)...)
for _, kv := range ss.Environ() {
if acceptEnvPair(kv) {