Transparent SSH jump host with auditing.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
733 B

package stronghold
import (
"io"
"os"
)
type writeCloser struct {
io.Writer
io.Closer
}
type safeFileWriter struct {
name string
mode os.FileMode
f *os.File
err error
}
func newSafeFileWriter(name string, mode os.FileMode) io.WriteCloser {
return &safeFileWriter{
name: name,
mode: mode,
}
}
func (sfw *safeFileWriter) Close() error {
if sfw.f == nil {
return nil
}
err := sfw.f.Close()
sfw.f = nil
return err
}
func (sfw *safeFileWriter) Write(p []byte) (int, error) {
if sfw.err == nil && sfw.f == nil {
sfw.f, sfw.err = os.OpenFile(sfw.name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, sfw.mode)
}
if sfw.err != nil {
return len(p), nil
}
var n int
n, sfw.err = sfw.f.Write(p)
return n, nil
}