2017-09-11 13:48:07 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/pkg/errors"
|
2018-02-17 01:08:15 +01:00
|
|
|
"github.com/problame/go-netssh"
|
2017-09-11 13:48:07 +02:00
|
|
|
"io"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StdinserverListenerFactory struct {
|
2017-09-11 15:45:10 +02:00
|
|
|
ClientIdentity string `mapstructure:"client_identity"`
|
2018-02-17 01:08:15 +01:00
|
|
|
sockpath string
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-17 18:20:05 +02:00
|
|
|
func parseStdinserverListenerFactory(c JobParsingContext, i map[string]interface{}) (f *StdinserverListenerFactory, err error) {
|
2017-09-11 13:48:07 +02:00
|
|
|
|
|
|
|
f = &StdinserverListenerFactory{}
|
|
|
|
|
|
|
|
if err = mapstructure.Decode(i, f); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "mapstructure error")
|
|
|
|
}
|
|
|
|
if !(len(f.ClientIdentity) > 0) {
|
|
|
|
err = errors.Errorf("must specify 'client_identity'")
|
|
|
|
return
|
|
|
|
}
|
2017-09-17 18:20:05 +02:00
|
|
|
|
2018-02-17 01:08:15 +01:00
|
|
|
f.sockpath = path.Join(c.Global.Serve.Stdinserver.SockDir, f.ClientIdentity)
|
2017-09-17 18:20:05 +02:00
|
|
|
|
2017-09-11 13:48:07 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *StdinserverListenerFactory) Listen() (al AuthenticatedChannelListener, err error) {
|
|
|
|
|
2018-02-17 14:12:44 +01:00
|
|
|
if err = PreparePrivateSockpath(f.sockpath); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-02-17 01:08:15 +01:00
|
|
|
l, err := netssh.Listen(f.sockpath)
|
2017-09-11 13:48:07 +02:00
|
|
|
if err != nil {
|
2018-02-17 01:08:15 +01:00
|
|
|
return nil, err
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|
2018-02-17 01:08:15 +01:00
|
|
|
return StdinserverListener{l}, nil
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type StdinserverListener struct {
|
2018-02-17 01:08:15 +01:00
|
|
|
l *netssh.Listener
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|
|
|
|
|
2018-02-17 01:08:15 +01:00
|
|
|
func (l StdinserverListener) Accept() (ch io.ReadWriteCloser, err error) {
|
|
|
|
return l.l.Accept()
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|
|
|
|
|
2018-02-17 01:08:15 +01:00
|
|
|
func (l StdinserverListener) Close() (err error) {
|
|
|
|
return l.l.Close()
|
2017-09-11 13:48:07 +02:00
|
|
|
}
|