From 48cdc51e9dde9e1c88d62e2a2469a0faf00c9bdd Mon Sep 17 00:00:00 2001 From: Kene Lin Date: Mon, 29 Jul 2024 03:22:51 +0800 Subject: [PATCH 1/2] windows: reduce permission requirement to query service status / config --- service_windows.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/service_windows.go b/service_windows.go index 2b854d77..862a845e 100644 --- a/service_windows.go +++ b/service_windows.go @@ -240,6 +240,16 @@ func lowPrivSvc(m *mgr.Mgr, name string) (*mgr.Service, error) { return &mgr.Service{Handle: h, Name: name}, nil } +func lowPrivSvcForStatus(m *mgr.Mgr, name string) (*mgr.Service, error) { + h, err := windows.OpenService( + m.Handle, syscall.StringToUTF16Ptr(name), + windows.SERVICE_QUERY_CONFIG|windows.SERVICE_QUERY_STATUS) + if err != nil { + return nil, err + } + return &mgr.Service{Handle: h, Name: name}, nil +} + func (ws *windowsService) setEnvironmentVariablesInRegistry() error { if len(ws.EnvVars) == 0 { return nil @@ -410,7 +420,7 @@ func (ws *windowsService) Status() (Status, error) { } defer m.Disconnect() - s, err := lowPrivSvc(m, ws.Name) + s, err := lowPrivSvcForStatus(m, ws.Name) if err != nil { if errno, ok := err.(syscall.Errno); ok && errno == errnoServiceDoesNotExist { return StatusUnknown, ErrNotInstalled From 2ced7916f553963d4b02f25bb4d7d97fb3591e47 Mon Sep 17 00:00:00 2001 From: Kene Lin Date: Mon, 29 Jul 2024 03:52:41 +0800 Subject: [PATCH 2/2] windows: rename lowPrivSvcForStatus to lowPrivSvcForQuery --- service_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service_windows.go b/service_windows.go index 862a845e..853f6109 100644 --- a/service_windows.go +++ b/service_windows.go @@ -240,7 +240,7 @@ func lowPrivSvc(m *mgr.Mgr, name string) (*mgr.Service, error) { return &mgr.Service{Handle: h, Name: name}, nil } -func lowPrivSvcForStatus(m *mgr.Mgr, name string) (*mgr.Service, error) { +func lowPrivSvcForQuery(m *mgr.Mgr, name string) (*mgr.Service, error) { h, err := windows.OpenService( m.Handle, syscall.StringToUTF16Ptr(name), windows.SERVICE_QUERY_CONFIG|windows.SERVICE_QUERY_STATUS) @@ -420,7 +420,7 @@ func (ws *windowsService) Status() (Status, error) { } defer m.Disconnect() - s, err := lowPrivSvcForStatus(m, ws.Name) + s, err := lowPrivSvcForQuery(m, ws.Name) if err != nil { if errno, ok := err.(syscall.Errno); ok && errno == errnoServiceDoesNotExist { return StatusUnknown, ErrNotInstalled