Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/windows/svc/mgr: CreateService does not allow driver loading #14019

Closed
npetroni opened this issue Jan 19, 2016 · 5 comments
Closed

x/sys/windows/svc/mgr: CreateService does not allow driver loading #14019

npetroni opened this issue Jan 19, 2016 · 5 comments

Comments

@npetroni
Copy link

@npetroni npetroni commented Jan 19, 2016

Summary:

golang.org/x/sys/windows/svc/mgr.CreateService does not allow driver loading.

Details:

golang.org/x/sys/windows/svc/mgr.CreateService is a high-level interface for the Windows CreateService function. The former accepts a struct Config but ignores that structure's ServiceType field. Instead, it uses the constant windows.SERVICE_WIN32_OWN_PROCESS. This implementation precludes the creation of other service types, including drivers.

I propose modifying golang.org/x/sys/windows/svc/mgr.CreateService to honor the ServiceType field, but continue using windows.SERVICE_WIN32_OWN_PROCESS as the default when that field is unpopulated (i.e., equal to zero). This change is consistent with other Config members in that function, preserves the semantics for existing callers, and allows driver loading (more generally, other service types).

Something like this works for me:

diff --git a/windows/svc/mgr/mgr.go b/windows/svc/mgr/mgr.go
index 4d7e72e..da8ceb6 100644
--- a/windows/svc/mgr/mgr.go
+++ b/windows/svc/mgr/mgr.go
@@ -85,12 +85,15 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se
        if c.ErrorControl == 0 {
                c.ErrorControl = ErrorNormal
        }
+       if c.ServiceType == 0 {
+               c.ServiceType = windows.SERVICE_WIN32_OWN_PROCESS
+       }
        s := syscall.EscapeArg(exepath)
        for _, v := range args {
                s += " " + syscall.EscapeArg(v)
        }
        h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName),
-               windows.SERVICE_ALL_ACCESS, windows.SERVICE_WIN32_OWN_PROCESS,
+               windows.SERVICE_ALL_ACCESS, c.ServiceType,
                c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup),
                nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password))
        if err != nil {
@ianlancetaylor ianlancetaylor changed the title golang.org/x/sys/windows/svc/mgr.CreateService does not allow driver loading x/sys/windows/svc/mgr: CreateService does not allow driver loading Jan 19, 2016
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jan 19, 2016
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 19, 2016

CC @alexbrainman

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jan 20, 2016

@npetroni SGTM.

Would you like to send your change? Thank you.

Alex

@npetroni
Copy link
Author

@npetroni npetroni commented Jan 20, 2016

https://go-review.googlesource.com/18760

First time using the process, so please let me know if I did anything wrong. Thanks.

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 20, 2016

CL https://golang.org/cl/18760 mentions this issue.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Jan 21, 2016

let me know if I did anything wrong

I did just fine. Thank you.

Alex

@golang golang locked and limited conversation to collaborators Jan 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants