Revert "ssh/tailssh: change to user directory when running login/command"

This reverts commit dc5bc32d8f.

It broke tests. (sadly, ones which we have disabled on CI, but go test
./ssh/tailssh broke)
pull/8400/head
Brad Fitzpatrick 11 months ago committed by Brad Fitzpatrick
parent 6829caf6de
commit 32b8f25ed1

@ -113,7 +113,6 @@ func (ss *sshSession) newIncubatorCommand() (cmd *exec.Cmd) {
"--remote-ip=" + ci.src.Addr().String(),
"--has-tty=false", // updated in-place by startWithPTY
"--tty-name=", // updated in-place by startWithPTY
"--pwd=" + ss.conn.localUser.HomeDir,
}
if isSFTP {
@ -178,7 +177,6 @@ type incubatorArgs struct {
isShell bool
loginCmdPath string
cmdArgs []string
pwd string
}
func parseIncubatorArgs(args []string) (a incubatorArgs) {
@ -195,7 +193,6 @@ func parseIncubatorArgs(args []string) (a incubatorArgs) {
flags.BoolVar(&a.isShell, "shell", false, "is launching a shell (with no cmds)")
flags.BoolVar(&a.isSFTP, "sftp", false, "run sftp server (cmd is ignored)")
flags.StringVar(&a.loginCmdPath, "login-cmd", "", "the path to `login` cmd")
flags.StringVar(&a.pwd, "pwd", "/", "process initial working directory, if possible. else / is used")
flags.Parse(args)
a.cmdArgs = flags.Args()
return a
@ -282,12 +279,6 @@ func beIncubator(args []string) error {
cmd.Stderr = os.Stderr
cmd.Env = os.Environ()
if _, err := os.Stat(ia.pwd); err != nil && os.IsNotExist(err) {
cmd.Dir = "/"
} else {
cmd.Dir = ia.pwd
}
if ia.hasTTY {
// If we were launched with a tty then we should
// mark that as the ctty of the child. However,
@ -437,7 +428,16 @@ func (ss *sshSession) launchProcess() error {
ss.cmd = ss.newIncubatorCommand()
cmd := ss.cmd
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 = envForUser(ss.conn.localUser)
for _, kv := range ss.Environ() {
if acceptEnvPair(kv) {

Loading…
Cancel
Save