Skip to content

proposal: x/sys/svc/mgr: Add "ConnectWithPermissions" and "OpenServiceWithPermissions" to allow for control on the windows permissions used #66694

@tomqwpl

Description

@tomqwpl

Proposal Details

Current the "Connect" method uses a fixed value of "windows.SC_MANAGER_ALL_ACCESS" when calling "windows.OpenSCManager". Similarly, the "OpenService" method uses a fixed value of "windows.SERVICE_ALL_ACCESS" when calling "windows.OpenService".

This proposal adds "ConnectWithPermissions" and "OpenServiceWithPermissions". These would both take an additional "uint32" value that is simply passed through to the underlying windows methods. The existing methods would delegate to these new methods passing the existing permissions values.

So you would have:

func Connect() (*Mgr, error) {
	return ConnectRemote("")
}

func ConnectWithPermissions(access uint32) (*Mgr, error) {
	return ConnectRemoteWithPermissions("", access)
}

func ConnectRemote(host string) (*Mgr, error) {
	return ConnectRemoteWithPermissions(host, windows.SC_MANAGER_ALL_ACCESS)
}

func ConnectRemoteWithPermissions(host string, access uint32) (*Mgr, error) {
...
h, err := windows.OpenSCManager(s, nil, access)
...

Then

func (m *Mgr) OpenService(name string) (*Service, error) {
	return m.OpenServiceWithPermissions(name, windows.SERVICE_ALL_ACCESS)
}

func (m *Mgr) OpenServiceWithPermissions(name string, access uint32) (*Service, error) {
	h, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), access)
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions