@@ -44,6 +44,9 @@ type Session interface {
4444 // which considers quoting not just whitespace.
4545 Command () []string
4646
47+ // RawCommand returns the exact command that was provided by the user.
48+ RawCommand () string
49+
4750 // PublicKey returns the PublicKey used to authenticate. If a public key was not
4851 // used it will return nil.
4952 PublicKey () PublicKey
@@ -106,7 +109,7 @@ type session struct {
106109 env []string
107110 ptyCb PtyCallback
108111 sessReqCb SessionRequestCallback
109- cmd [] string
112+ rawCmd string
110113 ctx Context
111114 sigCh chan <- Signal
112115 sigBuf []Signal
@@ -179,8 +182,13 @@ func (sess *session) Environ() []string {
179182 return append ([]string (nil ), sess .env ... )
180183}
181184
185+ func (sess * session ) RawCommand () string {
186+ return sess .rawCmd
187+ }
188+
182189func (sess * session ) Command () []string {
183- return append ([]string (nil ), sess .cmd ... )
190+ cmd , _ := shlex .Split (sess .rawCmd , true )
191+ return append ([]string (nil ), cmd ... )
184192}
185193
186194func (sess * session ) Pty () (Pty , <- chan Window , bool ) {
@@ -214,12 +222,12 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
214222
215223 var payload = struct { Value string }{}
216224 gossh .Unmarshal (req .Payload , & payload )
217- sess .cmd , _ = shlex . Split ( payload .Value , true )
225+ sess .rawCmd = payload .Value
218226
219227 // If there's a session policy callback, we need to confirm before
220228 // accepting the session.
221229 if sess .sessReqCb != nil && ! sess .sessReqCb (sess , req .Type ) {
222- sess .cmd = nil
230+ sess .rawCmd = ""
223231 req .Reply (false , nil )
224232 continue
225233 }
0 commit comments