Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Session.RawCommand() #110

Merged
merged 1 commit into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Session interface {
// which considers quoting not just whitespace.
Command() []string

// RawCommand returns the exact command that was provided by the user.
RawCommand() string

// PublicKey returns the PublicKey used to authenticate. If a public key was not
// used it will return nil.
PublicKey() PublicKey
Expand Down Expand Up @@ -106,7 +109,7 @@ type session struct {
env []string
ptyCb PtyCallback
sessReqCb SessionRequestCallback
cmd []string
rawCmd string
ctx Context
sigCh chan<- Signal
sigBuf []Signal
Expand Down Expand Up @@ -179,8 +182,13 @@ func (sess *session) Environ() []string {
return append([]string(nil), sess.env...)
}

func (sess *session) RawCommand() string {
return sess.rawCmd
}

func (sess *session) Command() []string {
return append([]string(nil), sess.cmd...)
cmd, _ := shlex.Split(sess.rawCmd, true)
return append([]string(nil), cmd...)
}

func (sess *session) Pty() (Pty, <-chan Window, bool) {
Expand Down Expand Up @@ -214,12 +222,12 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {

var payload = struct{ Value string }{}
gossh.Unmarshal(req.Payload, &payload)
sess.cmd, _ = shlex.Split(payload.Value, true)
sess.rawCmd = payload.Value

// If there's a session policy callback, we need to confirm before
// accepting the session.
if sess.sessReqCb != nil && !sess.sessReqCb(sess, req.Type) {
sess.cmd = nil
sess.rawCmd = ""
req.Reply(false, nil)
continue
}
Expand Down