in internal/sshd/session.go [55:108]
func (s *session) handle(ctx context.Context, requests <-chan *ssh.Request) (context.Context, error) {
ctxWithLogData := ctx
ctxlog := log.ContextLogger(ctx)
ctxlog.Debug("session: handle: entering request loop")
var err error
for req := range requests {
sessionLog := ctxlog.WithFields(log.Fields{
"bytesize": len(req.Payload),
"type": req.Type,
"want_reply": req.WantReply,
})
sessionLog.Debug("session: handle: request received")
var shouldContinue bool
switch req.Type {
case "env":
shouldContinue, err = s.handleEnv(ctx, req)
case "exec":
// The command has been executed as `ssh user@host command` or `exec` channel has been used
// in the app implementation
shouldContinue = false
ctxWithLogData, err = s.handleExec(ctx, req)
case "shell":
// The command has been entered into the shell or `shell` channel has been used
// in the app implementation
shouldContinue = false
var status uint32
ctxWithLogData, status, err = s.handleShell(ctx, req)
s.exit(ctx, status)
default:
// Ignore unknown requests but don't terminate the session
shouldContinue = true
if req.WantReply {
if err = req.Reply(false, []byte{}); err != nil {
sessionLog.WithError(err).Debug("session: handle: Failed to reply")
}
}
}
sessionLog.WithField("should_continue", shouldContinue).Debug("session: handle: request processed")
if !shouldContinue {
_ = s.channel.Close()
break
}
}
ctxlog.Debug("session: handle: exiting request loop")
return ctxWithLogData, err
}