Initial import

This commit is contained in:
2025-10-10 10:05:13 +02:00
parent 3effc1597b
commit b96b6e7f8f
164 changed files with 5473 additions and 0 deletions

52
ssh/channel.go Normal file
View File

@@ -0,0 +1,52 @@
package ssh
import (
"errors"
"io"
"golang.org/x/crypto/ssh"
)
type DupeChannel struct {
ssh.Channel
// Reads writes read actions.
Reads io.WriteCloser
// Writer writes write actions.
Writes io.WriteCloser
}
func (c DupeChannel) Close() error {
var errs []error
for _, closer := range []io.Closer{
c.Channel,
c.Reads,
c.Writes,
} {
if closer == nil {
continue
}
if cerr := closer.Close(); cerr != nil {
errs = append(errs, cerr)
}
}
return errors.Join(errs...)
}
func (c DupeChannel) Read(p []byte) (n int, err error) {
if c.Reads == nil {
return c.Channel.Read(p)
}
return io.TeeReader(c.Channel, c.Reads).Read(p)
}
func (c DupeChannel) Write(p []byte) (n int, err error) {
if c.Writes == nil {
return c.Channel.Write(p)
}
if n, err = c.Channel.Write(p); n > 0 {
_, _ = c.Writes.Write(p[:])
}
return
}