Skip to content

Commit

Permalink
better custom shell support
Browse files Browse the repository at this point in the history
  • Loading branch information
ferama committed Feb 19, 2023
1 parent 9099f9b commit 7e8ae41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/configs/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ sshd:
# OPTIONAL: if true, the sftp subsystem will be disabled server side
disable_sftp_subsystem: false
# OPTIONAL: if empty a shell will be auto inferred. You can
# set a custom value here. Example: /usr/bin/python3
shell_executable: "your/custom/shell/fullpath"
# set a custom value here.
# Example1: /usr/bin/python3
# Example2: sh -c your command here
shell_executable: "your/custom/shell"

# enables and configures rest endpoints and web ui
# Be WARNED: the endpoint is not authenticated and through the apis
Expand Down
7 changes: 0 additions & 7 deletions pkg/sshd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -74,12 +73,6 @@ func NewSshServer(conf *SshDConf) *sshServer {
panic(err)
}

if conf.ShellExecutable != "" {
if _, err := os.Stat(conf.ShellExecutable); err != nil {
log.Fatalf("invalid shell executable '%s'", conf.ShellExecutable)
}
}

ss := &sshServer{
authorizedKeysURI: conf.AuthorizedKeysURI,
password: conf.AuthorizedPassword,
Expand Down
8 changes: 7 additions & 1 deletion pkg/sshd/session_chan_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"os/user"
"strings"
"sync"

"github.com/ferama/rospo/pkg/rpty"
Expand Down Expand Up @@ -81,7 +82,12 @@ func handleChannelSession(
var cmd *exec.Cmd

if req.Type == "shell" {
cmd = exec.Command(shell)
if customShell != "" {
parts := strings.Split(customShell, " ")
cmd = exec.Command(parts[0], parts[1:]...)
} else {
cmd = exec.Command(shell)
}
} else {
var payload = struct{ Value string }{}
ssh.Unmarshal(req.Payload, &payload)
Expand Down

0 comments on commit 7e8ae41

Please sign in to comment.