13 | 13 |
// ErrServerClosed is returned by the Server's Serve, ListenAndServe,
|
14 | 14 |
// and ListenAndServeTLS methods after a call to Shutdown or Close.
|
15 | 15 |
var ErrServerClosed = errors.New("ssh: Server closed")
|
|
16 |
|
|
17 |
type RequestHandler func(ctx Context, srv *Server, req *gossh.Request) (ok bool, payload []byte)
|
|
18 |
|
|
19 |
var DefaultRequestHandlers = map[string]RequestHandler{}
|
|
20 |
|
|
21 |
type ChannelHandler func(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context)
|
|
22 |
|
|
23 |
var DefaultChannelHandlers = map[string]ChannelHandler{
|
|
24 |
"session": DefaultSessionHandler,
|
|
25 |
}
|
16 | 26 |
|
17 | 27 |
// Server defines parameters for running an SSH server. The zero value for
|
18 | 28 |
// Server is a valid configuration. When both PasswordHandler and
|
|
52 | 62 |
conns map[*gossh.ServerConn]struct{}
|
53 | 63 |
connWg sync.WaitGroup
|
54 | 64 |
doneChan chan struct{}
|
55 | |
}
|
56 | |
|
57 | |
type RequestHandler interface {
|
58 | |
HandleSSHRequest(ctx Context, srv *Server, req *gossh.Request) (ok bool, payload []byte)
|
59 | |
}
|
60 | |
|
61 | |
type RequestHandlerFunc func(ctx Context, srv *Server, req *gossh.Request) (ok bool, payload []byte)
|
62 | |
|
63 | |
func (f RequestHandlerFunc) HandleSSHRequest(ctx Context, srv *Server, req *gossh.Request) (ok bool, payload []byte) {
|
64 | |
return f(ctx, srv, req)
|
65 | |
}
|
66 | |
|
67 | |
var DefaultRequestHandlers = map[string]RequestHandler{}
|
68 | |
|
69 | |
type ChannelHandler interface {
|
70 | |
HandleSSHChannel(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context)
|
71 | |
}
|
72 | |
|
73 | |
type ChannelHandlerFunc func(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context)
|
74 | |
|
75 | |
func (f ChannelHandlerFunc) HandleSSHChannel(srv *Server, conn *gossh.ServerConn, newChan gossh.NewChannel, ctx Context) {
|
76 | |
f(srv, conn, newChan, ctx)
|
77 | |
}
|
78 | |
|
79 | |
var DefaultChannelHandlers = map[string]ChannelHandler{
|
80 | |
"session": ChannelHandlerFunc(DefaultSessionHandler),
|
81 | 65 |
}
|
82 | 66 |
|
83 | 67 |
func (srv *Server) ensureHostSigner() error {
|
|
287 | 271 |
ch.Reject(gossh.UnknownChannelType, "unsupported channel type")
|
288 | 272 |
continue
|
289 | 273 |
}
|
290 | |
go handler.HandleSSHChannel(srv, sshConn, ch, ctx)
|
|
274 |
go handler(srv, sshConn, ch, ctx)
|
291 | 275 |
}
|
292 | 276 |
}
|
293 | 277 |
|
|
303 | 287 |
}
|
304 | 288 |
/*reqCtx, cancel := context.WithCancel(ctx)
|
305 | 289 |
defer cancel() */
|
306 | |
ret, payload := handler.HandleSSHRequest(ctx, srv, req)
|
|
290 |
ret, payload := handler(ctx, srv, req)
|
307 | 291 |
req.Reply(ret, payload)
|
308 | 292 |
}
|
309 | 293 |
}
|