server_windows.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // +build windows
  2. package server
  3. import (
  4. "errors"
  5. "fmt"
  6. "github.com/Microsoft/go-winio"
  7. "net"
  8. "net/http"
  9. "strings"
  10. )
  11. // NewServer sets up the required Server and does protocol specific checking.
  12. func (s *Server) newServer(proto, addr string) ([]*HTTPServer, error) {
  13. var (
  14. ls []net.Listener
  15. )
  16. switch proto {
  17. case "tcp":
  18. l, err := s.initTCPSocket(addr)
  19. if err != nil {
  20. return nil, err
  21. }
  22. ls = append(ls, l)
  23. case "npipe":
  24. // allow Administrators and SYSTEM, plus whatever additional users or groups were specified
  25. sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)"
  26. if s.cfg.SocketGroup != "" {
  27. for _, g := range strings.Split(s.cfg.SocketGroup, ",") {
  28. sid, err := winio.LookupSidByName(g)
  29. if err != nil {
  30. return nil, err
  31. }
  32. sddl += fmt.Sprintf("(A;;GRGW;;;%s)", sid)
  33. }
  34. }
  35. l, err := winio.ListenPipe(addr, sddl)
  36. if err != nil {
  37. return nil, err
  38. }
  39. ls = append(ls, l)
  40. default:
  41. return nil, errors.New("Invalid protocol format. Windows only supports tcp and npipe.")
  42. }
  43. var res []*HTTPServer
  44. for _, l := range ls {
  45. res = append(res, &HTTPServer{
  46. &http.Server{
  47. Addr: addr,
  48. },
  49. l,
  50. })
  51. }
  52. return res, nil
  53. }
  54. func allocateDaemonPort(addr string) error {
  55. return nil
  56. }