Skip to content

Commit

Permalink
fix(agent): set home fallback when user home does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybarreto authored and gustavosbarreto committed Nov 9, 2023
1 parent f3030a1 commit 5b7d9cb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/agent/server/command/command_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"syscall"

"github.com/shellhub-io/shellhub/pkg/agent/pkg/osauth"
log "github.com/sirupsen/logrus"
)

func NewCmd(u *osauth.User, shell, term, host string, command ...string) *exec.Cmd {
Expand All @@ -34,7 +35,14 @@ func NewCmd(u *osauth.User, shell, term, host string, command ...string) *exec.C
"SHELL=" + shell,
"SHELLHUB_HOST=" + host,
}
cmd.Dir = u.HomeDir

if _, err := os.Stat(u.HomeDir); err != nil {
log.WithError(err).WithField("dir", u.HomeDir).Warn("setting user's home directory to /")

cmd.Dir = "/"
} else {
cmd.Dir = u.HomeDir
}

if os.Geteuid() == 0 {
cmd.SysProcAttr = &syscall.SysProcAttr{}
Expand Down

0 comments on commit 5b7d9cb

Please sign in to comment.