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/registry: ReadSubKeyNames will only work if QUERY_VALUE is passed #23869

Closed
FluorescentTouch opened this issue Feb 16, 2018 · 11 comments

Comments

@FluorescentTouch
Copy link
Contributor

What version of Go are you using (go version)?

1.9

What is wrong (for my opinion)?

package registry
func (Key) ReadSubKeyNames() requires both registry.QUERY_VALUE and registry.ENUMERATE_SUB_KEYS permissions (key.Stat() inside RedSubKeyNames() requires registry.QUERY_VALUE permission).

What did you expect to see?

Because windows has divided rights for QUERY_VALUE and ENUMERATE_SUB_KEYS and possibility to set up one without other, it would be impossible to enum sub keys without QUERY_VALUE permission, even if ENUMERATE_SUB_KEYS permission will be set.

What did you see instead?

Even if i had ENUMERATE_SUB_KEYS permission, but don't have QUERY_VALUE i can't enumerate subkeys of registry key with go registry package.

@FluorescentTouch FluorescentTouch changed the title windows registry package ReadSubKeyNames() does not wors properly windows registry package function ReadSubKeyNames() does not work properly Feb 16, 2018
@alexbrainman
Copy link
Member

@FluorescentTouch I do not understand your explanation of why ReadSubKeyNames does not work properly. Sorry. Please, provide small program to demonstrate the problem. Run your program, show us its output and tell us what your program should output instead.

Thank you

@FluorescentTouch
Copy link
Contributor Author

FluorescentTouch commented Feb 17, 2018

@alexbrainman here the code is!

package main

import (
	"fmt"
	"syscall"

	"golang.org/x/sys/windows/registry"
)

func main() {
	newKey, _, err := registry.CreateKey(registry.Key(syscall.HKEY_CURRENT_USER), "testKey", registry.ENUMERATE_SUB_KEYS)
	if err != nil {
		fmt.Println("Possible error 1")
		panic(err)
	}

	subKeyNames, err := newKey.ReadSubKeyNames(-1)
	if err != nil {
		fmt.Println("Possible error 2")
		panic(err)
	}
	fmt.Println(subKeyNames)
}

Possible error 2
panic: Access is denied.
goroutine 1 [running]:
panic(0x4a4c20, 0xc04200a300)
C:/Go/src/runtime/panic.go:500 +0x1af
main.main()
D:/data/go_test/src/registry/main.go:22 +0x20c

Even with ENUMERATE_SUB_KEYS permission i can't enumerate sub keys without more permissions added to this one. This is because first line of ReadSubKeysNames() func:

ki, err := k.Stat()

Stat() function requires QUERY_VALUE permission, and ENUMERATE_SUB_KEYS permission is not enough. Compared to windows registry logic, where u can enumerate subkeys even if read and query_value is not permitted for user.

I believe there has to be some different syscall for just enumerating subkeys without reading key value and tehre has to be different function, that doesn not require QUERY_VALUE permission.

@alexbrainman
Copy link
Member

@alexbrainman here the code is!

Thank you for explaining. I understand your report now, and I agree that newKey.ReadSubKeyNames could and should work with just ENUMERATE_SUB_KEYS. Would you like to try and fix this yourself? The change would needs to include new test. And also it should adjust all calls to ReadSubKeyNames to have only ENUMERATE_SUB_KEYS if needed. We also need to adjust internal/syscall/windows/registry package in standard library.

https://golang.org/doc/contribute.html explains how to contribute. Or you could send PR via Github. If not I will fix this when I have time.

Thank you.

Alex

@alexbrainman alexbrainman changed the title windows registry package function ReadSubKeyNames() does not work properly x/sys/windows/registry: ReadSubKeyNames will only work if QUERY_VALUE is passed Feb 17, 2018
@gopherbot gopherbot added this to the Unreleased milestone Feb 17, 2018
@FluorescentTouch
Copy link
Contributor Author

@alexbrainman I'll try to find a fix, and report here in a week if i can do such work. If not, i would notify you. Thank you!

@alexbrainman
Copy link
Member

Sounds like a plan.

Alex

@FluorescentTouch
Copy link
Contributor Author

@gopherbot
Copy link

Change https://golang.org/cl/95655 mentions this issue: windows/registry: improve ReadSubKeyNames permissions

@FluorescentTouch
Copy link
Contributor Author

@alexbrainman I dont know how to comment on googlesource.com, so i'll put it there. I'll send another PR to change $GOROOT/src/internal/syscall/windows/registry after this one would be accepted.

@alexbrainman
Copy link
Member

Reopening so we do not forget to do similar changes in $GOROOT/src/internal/syscall/windows/registry.

Alex

@alexbrainman alexbrainman reopened this Feb 24, 2018
@gopherbot
Copy link

Change https://golang.org/cl/97435 mentions this issue: windows/registry: improve ReadSubKeys permissions

@FluorescentTouch
Copy link
Contributor Author

FluorescentTouch commented Feb 27, 2018

@alexbrainman , https://go-review.googlesource.com/c/go/+/97435 PL created for $GOROOT/src/internal/syscall/windows/registry

@golang golang locked and limited conversation to collaborators Mar 2, 2019
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

3 participants