mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 12:09:57 +00:00
AUTH-2105: Adds support for local forwarding. Refactor auditlogger creation.
AUTH-2088: Adds dynamic destination routing
This commit is contained in:
36
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
36
vendor/golang.org/x/sys/windows/svc/mgr/config.go
generated
vendored
@@ -42,6 +42,8 @@ type Config struct {
|
||||
DisplayName string
|
||||
Password string
|
||||
Description string
|
||||
SidType uint32 // one of SERVICE_SID_TYPE, the type of sid to use for the service
|
||||
DelayedAutoStart bool // the service is started after other auto-start services are started plus a short delay
|
||||
}
|
||||
|
||||
func toString(p *uint16) string {
|
||||
@@ -94,6 +96,16 @@ func (s *Service) Config() (Config, error) {
|
||||
}
|
||||
p2 := (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0]))
|
||||
|
||||
b, err = s.queryServiceConfig2(windows.SERVICE_CONFIG_DELAYED_AUTO_START_INFO)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
p3 := (*windows.SERVICE_DELAYED_AUTO_START_INFO)(unsafe.Pointer(&b[0]))
|
||||
delayedStart := false
|
||||
if p3.IsDelayedAutoStartUp != 0 {
|
||||
delayedStart = true
|
||||
}
|
||||
|
||||
return Config{
|
||||
ServiceType: p.ServiceType,
|
||||
StartType: p.StartType,
|
||||
@@ -105,6 +117,7 @@ func (s *Service) Config() (Config, error) {
|
||||
ServiceStartName: toString(p.ServiceStartName),
|
||||
DisplayName: toString(p.DisplayName),
|
||||
Description: toString(p2.Description),
|
||||
DelayedAutoStart: delayedStart,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -114,6 +127,19 @@ func updateDescription(handle windows.Handle, desc string) error {
|
||||
windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d)))
|
||||
}
|
||||
|
||||
func updateSidType(handle windows.Handle, sidType uint32) error {
|
||||
return windows.ChangeServiceConfig2(handle, windows.SERVICE_CONFIG_SERVICE_SID_INFO, (*byte)(unsafe.Pointer(&sidType)))
|
||||
}
|
||||
|
||||
func updateStartUp(handle windows.Handle, isDelayed bool) error {
|
||||
var d windows.SERVICE_DELAYED_AUTO_START_INFO
|
||||
if isDelayed {
|
||||
d.IsDelayedAutoStartUp = 1
|
||||
}
|
||||
return windows.ChangeServiceConfig2(handle,
|
||||
windows.SERVICE_CONFIG_DELAYED_AUTO_START_INFO, (*byte)(unsafe.Pointer(&d)))
|
||||
}
|
||||
|
||||
// UpdateConfig updates service s configuration parameters.
|
||||
func (s *Service) UpdateConfig(c Config) error {
|
||||
err := windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType,
|
||||
@@ -123,6 +149,16 @@ func (s *Service) UpdateConfig(c Config) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = updateSidType(s.Handle, c.SidType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = updateStartUp(s.Handle, c.DelayedAutoStart)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return updateDescription(s.Handle, c.Description)
|
||||
}
|
||||
|
||||
|
49
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
49
vendor/golang.org/x/sys/windows/svc/mgr/mgr.go
generated
vendored
@@ -13,6 +13,7 @@ package mgr
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
"unicode/utf16"
|
||||
"unsafe"
|
||||
|
||||
@@ -48,6 +49,36 @@ func (m *Mgr) Disconnect() error {
|
||||
return windows.CloseServiceHandle(m.Handle)
|
||||
}
|
||||
|
||||
type LockStatus struct {
|
||||
IsLocked bool // Whether the SCM has been locked.
|
||||
Age time.Duration // For how long the SCM has been locked.
|
||||
Owner string // The name of the user who has locked the SCM.
|
||||
}
|
||||
|
||||
// LockStatus returns whether the service control manager is locked by
|
||||
// the system, for how long, and by whom. A locked SCM indicates that
|
||||
// most service actions will block until the system unlocks the SCM.
|
||||
func (m *Mgr) LockStatus() (*LockStatus, error) {
|
||||
bytesNeeded := uint32(unsafe.Sizeof(windows.QUERY_SERVICE_LOCK_STATUS{}) + 1024)
|
||||
for {
|
||||
bytes := make([]byte, bytesNeeded)
|
||||
lockStatus := (*windows.QUERY_SERVICE_LOCK_STATUS)(unsafe.Pointer(&bytes[0]))
|
||||
err := windows.QueryServiceLockStatus(m.Handle, lockStatus, uint32(len(bytes)), &bytesNeeded)
|
||||
if err == windows.ERROR_INSUFFICIENT_BUFFER && bytesNeeded >= uint32(unsafe.Sizeof(windows.QUERY_SERVICE_LOCK_STATUS{})) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := &LockStatus{
|
||||
IsLocked: lockStatus.IsLocked != 0,
|
||||
Age: time.Duration(lockStatus.LockDuration) * time.Second,
|
||||
Owner: windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(lockStatus.LockOwner))[:]),
|
||||
}
|
||||
return status, nil
|
||||
}
|
||||
}
|
||||
|
||||
func toPtr(s string) *uint16 {
|
||||
if len(s) == 0 {
|
||||
return nil
|
||||
@@ -102,9 +133,27 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.SidType != windows.SERVICE_SID_TYPE_NONE {
|
||||
err = updateSidType(h, c.SidType)
|
||||
if err != nil {
|
||||
windows.DeleteService(h)
|
||||
windows.CloseServiceHandle(h)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.Description != "" {
|
||||
err = updateDescription(h, c.Description)
|
||||
if err != nil {
|
||||
windows.DeleteService(h)
|
||||
windows.CloseServiceHandle(h)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.DelayedAutoStart {
|
||||
err = updateStartUp(h, c.DelayedAutoStart)
|
||||
if err != nil {
|
||||
windows.DeleteService(h)
|
||||
windows.CloseServiceHandle(h)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
11
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
11
vendor/golang.org/x/sys/windows/svc/mgr/service.go
generated
vendored
@@ -8,6 +8,7 @@ package mgr
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
@@ -60,13 +61,15 @@ func (s *Service) Control(c svc.Cmd) (svc.Status, error) {
|
||||
|
||||
// Query returns current status of service s.
|
||||
func (s *Service) Query() (svc.Status, error) {
|
||||
var t windows.SERVICE_STATUS
|
||||
err := windows.QueryServiceStatus(s.Handle, &t)
|
||||
var t windows.SERVICE_STATUS_PROCESS
|
||||
var needed uint32
|
||||
err := windows.QueryServiceStatusEx(s.Handle, windows.SC_STATUS_PROCESS_INFO, (*byte)(unsafe.Pointer(&t)), uint32(unsafe.Sizeof(t)), &needed)
|
||||
if err != nil {
|
||||
return svc.Status{}, err
|
||||
}
|
||||
return svc.Status{
|
||||
State: svc.State(t.CurrentState),
|
||||
Accepts: svc.Accepted(t.ControlsAccepted),
|
||||
State: svc.State(t.CurrentState),
|
||||
Accepts: svc.Accepted(t.ControlsAccepted),
|
||||
ProcessId: t.ProcessId,
|
||||
}, nil
|
||||
}
|
||||
|
1
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
1
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
@@ -72,6 +72,7 @@ type Status struct {
|
||||
Accepts Accepted
|
||||
CheckPoint uint32 // used to report progress during a lengthy operation
|
||||
WaitHint uint32 // estimated time required for a pending operation, in milliseconds
|
||||
ProcessId uint32 // if the service is running, the process identifier of it, and otherwise zero
|
||||
}
|
||||
|
||||
// ChangeRequest is sent to the service Handler to request service status change.
|
||||
|
Reference in New Issue
Block a user