mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
util/winutil: publicize existing functions for opening read-only connections to the Windows Service Control Manager
We're going to need to access these from code outside winutil. Updates #10215 Signed-off-by: Aaron Klotz <aaron@tailscale.com>
This commit is contained in:
parent
cae6edf485
commit
5812093d31
@ -60,13 +60,13 @@ func LogSvcState(logf logger.Logf, rootSvcName string) {
|
||||
// walkServices opens the service named rootSvcName and walks its dependency
|
||||
// graph, invoking callback for each service (including the root itself).
|
||||
func walkServices(rootSvcName string, callback walkSvcFunc) error {
|
||||
scm, err := connectToLocalSCMForRead()
|
||||
scm, err := ConnectToLocalSCMForRead()
|
||||
if err != nil {
|
||||
return fmt.Errorf("connecting to Service Control Manager: %w", err)
|
||||
}
|
||||
defer scm.Disconnect()
|
||||
|
||||
rootSvc, err := openServiceForRead(scm, rootSvcName)
|
||||
rootSvc, err := OpenServiceForRead(scm, rootSvcName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening service %q: %w", rootSvcName, err)
|
||||
}
|
||||
@ -102,7 +102,7 @@ func walkServices(rootSvcName string, callback walkSvcFunc) error {
|
||||
continue
|
||||
}
|
||||
|
||||
depSvc, err := openServiceForRead(scm, depName)
|
||||
depSvc, err := OpenServiceForRead(scm, depName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening service %q: %w", depName, err)
|
||||
}
|
||||
@ -276,10 +276,10 @@ func makeLogEntry(svc *mgr.Service, status svc.Status, cfg mgr.Config) (entry sv
|
||||
return entry
|
||||
}
|
||||
|
||||
// connectToLocalSCMForRead connects to the Windows Service Control Manager with
|
||||
// ConnectToLocalSCMForRead connects to the Windows Service Control Manager with
|
||||
// read-only access. x/sys/windows/svc/mgr/Connect requests read+write access,
|
||||
// which requires higher privileges than we want.
|
||||
func connectToLocalSCMForRead() (*mgr.Mgr, error) {
|
||||
// which requires Administrative access rights.
|
||||
func ConnectToLocalSCMForRead() (*mgr.Mgr, error) {
|
||||
h, err := windows.OpenSCManager(nil, nil, windows.GENERIC_READ)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -287,10 +287,10 @@ func connectToLocalSCMForRead() (*mgr.Mgr, error) {
|
||||
return &mgr.Mgr{Handle: h}, nil
|
||||
}
|
||||
|
||||
// openServiceForRead opens a service with read-only access.
|
||||
// OpenServiceForRead opens a service with read-only access.
|
||||
// x/sys/windows/svc/mgr/(*Mgr).OpenService requests read+write access,
|
||||
// which requires higher privileges than we want.
|
||||
func openServiceForRead(scm *mgr.Mgr, svcName string) (*mgr.Service, error) {
|
||||
// which requires Administrative access rights.
|
||||
func OpenServiceForRead(scm *mgr.Mgr, svcName string) (*mgr.Service, error) {
|
||||
svcNamePtr, err := windows.UTF16PtrFromString(svcName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user