From 44274595c24ea511f02809c37c0d048f4c7e1173 Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Wed, 19 Jun 2019 00:20:00 -0700 Subject: [PATCH] Add Session.RawCommand() --- session.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/session.go b/session.go index 19ddda6..8ad49cc 100644 --- a/session.go +++ b/session.go @@ -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 @@ -106,7 +109,7 @@ type session struct { env []string ptyCb PtyCallback sessReqCb SessionRequestCallback - cmd []string + rawCmd string ctx Context sigCh chan<- Signal sigBuf []Signal @@ -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) { @@ -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 }