2015-02-13 14:46:14 -05:00
|
|
|
// +build windows
|
2015-04-17 06:05:30 -04:00
|
|
|
|
2015-02-13 14:46:14 -05:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-03-31 16:37:49 -04:00
|
|
|
"errors"
|
2016-01-30 21:45:49 -05:00
|
|
|
"fmt"
|
|
|
|
"github.com/Microsoft/go-winio"
|
2015-03-31 16:37:49 -04:00
|
|
|
"net"
|
2015-04-17 17:32:18 -04:00
|
|
|
"net/http"
|
2016-01-30 21:45:49 -05:00
|
|
|
"strings"
|
2015-02-13 14:46:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewServer sets up the required Server and does protocol specific checking.
|
2015-10-05 12:32:08 -04:00
|
|
|
func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) {
|
2015-03-31 16:37:49 -04:00
|
|
|
var (
|
2015-05-30 00:25:27 -04:00
|
|
|
ls []net.Listener
|
2015-03-31 16:37:49 -04:00
|
|
|
)
|
2015-02-13 14:46:14 -05:00
|
|
|
switch proto {
|
|
|
|
case "tcp":
|
2015-07-29 23:08:51 -04:00
|
|
|
l, err := s.initTCPSocket(addr)
|
2015-05-20 19:48:39 -04:00
|
|
|
if err != nil {
|
2015-03-31 16:37:49 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-05-30 00:25:27 -04:00
|
|
|
ls = append(ls, l)
|
2015-05-15 16:05:35 -04:00
|
|
|
|
2016-01-30 21:45:49 -05:00
|
|
|
case "npipe":
|
|
|
|
// allow Administrators and SYSTEM, plus whatever additional users or groups were specified
|
|
|
|
sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)"
|
|
|
|
if s.cfg.SocketGroup != "" {
|
|
|
|
for _, g := range strings.Split(s.cfg.SocketGroup, ",") {
|
|
|
|
sid, err := winio.LookupSidByName(g)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sddl += fmt.Sprintf("(A;;GRGW;;;%s)", sid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l, err := winio.ListenPipe(addr, sddl)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ls = append(ls, l)
|
|
|
|
|
2015-02-13 14:46:14 -05:00
|
|
|
default:
|
2016-01-30 21:45:49 -05:00
|
|
|
return nil, errors.New("Invalid protocol format. Windows only supports tcp and npipe.")
|
2015-02-13 14:46:14 -05:00
|
|
|
}
|
2015-05-30 00:25:27 -04:00
|
|
|
|
2015-10-05 12:32:08 -04:00
|
|
|
var res []*HTTPServer
|
2015-05-30 00:25:27 -04:00
|
|
|
for _, l := range ls {
|
2015-07-29 23:08:51 -04:00
|
|
|
res = append(res, &HTTPServer{
|
2015-05-30 00:25:27 -04:00
|
|
|
&http.Server{
|
2015-10-05 12:32:08 -04:00
|
|
|
Addr: addr,
|
2015-05-30 00:25:27 -04:00
|
|
|
},
|
|
|
|
l,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
|
2015-02-13 14:46:14 -05:00
|
|
|
}
|
2015-02-13 18:08:42 -05:00
|
|
|
|
2015-05-15 16:05:35 -04:00
|
|
|
func allocateDaemonPort(addr string) error {
|
|
|
|
return nil
|
|
|
|
}
|