sshpiper/cmd/sshpiperd/hook.go
Boshi Lian 2603cdfa8b
support handle ping@openssh packet (#582)
* chore: Update dependencies in go.mod and go.sum

* chore: Update submodule commit for crypto

* refactor: Update hook functions to return ssh.PipePackageHookMethod for better integration

* fix: Increase sleep duration in TestFixed to ensure proper execution

* fix: Increase sleep duration in TestFixed to ensure proper file flush

* fix: Update docker-compose service images and modify test to use host-password-old

* refactor: Simplify hook functions to return error instead of PipePackageHookMethod for better error handling

* feat: Add reply-ping flag to enable ping response for compatibility with older sshd

* fix: Update subproject commit reference in crypto
2025-05-08 11:53:40 -07:00

37 lines
671 B
Go

package main
import "golang.org/x/crypto/ssh"
type hookChain struct {
hooks []ssh.PipePacketHook
}
// chain stops if any of the hooks return ssh.PipePacketHookReply
func (h *hookChain) append(hook ssh.PipePacketHook) {
if hook != nil {
h.hooks = append(h.hooks, hook)
}
}
func (h *hookChain) hook() ssh.PipePacketHook {
if len(h.hooks) == 0 {
return nil
}
return func(packet []byte) (method ssh.PipePacketHookMethod, packetOut []byte, err error) {
packetOut = packet
for _, hk := range h.hooks {
method, packetOut, err = hk(packetOut)
if err != nil {
return
}
if method == ssh.PipePacketHookReply {
return
}
}
return
}
}