Skip to content

Commit

Permalink
execute the command without shell (#25)
Browse files Browse the repository at this point in the history
* execute the command without shell

Signed-off-by: Ramiro Berrelleza <rberrelleza@gmail.com>

* remove extra logs

Signed-off-by: Ramiro Berrelleza <rberrelleza@gmail.com>
  • Loading branch information
rberrelleza authored Oct 28, 2020
1 parent c75fb26 commit 2428e8c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,13 @@ func sftpHandler(sess ssh.Session) {
func (srv Server) buildCmd(s ssh.Session) *exec.Cmd {
var cmd *exec.Cmd

if len(s.RawCommand()) == 0 {
switch len(s.Command()) {
case 0:
cmd = exec.Command(srv.Shell)
} else {
args := []string{"-c", s.RawCommand()}
cmd = exec.Command(srv.Shell, args...)
case 1:
cmd = exec.Command(s.Command()[0])
default:
cmd = exec.Command(s.Command()[0], s.Command()[1:]...)
}

cmd.Env = append(cmd.Env, os.Environ()...)
Expand Down

0 comments on commit 2428e8c

Please sign in to comment.