Skip to content

Commit

Permalink
Merge pull request #110 from gliderlabs/belak/raw-cmd
Browse files Browse the repository at this point in the history
Add Session.RawCommand()
  • Loading branch information
belak authored Jun 20, 2019
2 parents ac34fea + 4427459 commit 5b6cc70
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit 5b6cc70

Please sign in to comment.