Repository: go
Issue: proposal: x/sys/windows: indicate when ERROR_NOT_ALL_ASSIGNED occurs in AdjustTokenPrivileges
Labels: OS-Windows,Proposal,NeedsInvestigation,compiler/runtime

<!--
Please answer these questions before submitting your issue. Thanks!
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.21.4 windows/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes, it reproduces with the latest release as of 15 Nov 2023.

### What operating system and processor architecture are you using (`go env`)?
Windows 11 Pro Version 22H2 (OS Build 22621.2715)

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\--OMITED--\AppData\Local\go-build
set GOENV=C:\Users\--OMITED--\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=--OMITED--
set GONOPROXY=--OMITED--
set GONOSUMDB=--OMITED--
set GOOS=windows
set GOPATH=D:\packages\go
set GOPRIVATE=--OMITED--
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.4
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on go.dev/play is best.
-->
Here is link to Go Playground (but note that this will not run on the Go Playground because it requires Windows environment). I also provided a full listing below.
https://go.dev/play/p/G2J2te4l-4q

The program is attempting to call `AdjustTokenPrivileges` to enable the `SeSecurityPrivilege`. When I run the program elevated (as Administrator), the program runs as expected without an issue. The issue occurs when running as a normal user (non elevated privilege) where it also completes without any error, where it was supposed to panic at line 32.

```golang
package main

import (
	"golang.org/x/sys/windows"
	"unsafe"
)

func main() {
	var token windows.Token
	err := windows.OpenProcessToken(windows.CurrentProcess(), windows.TOKEN_ADJUST_PRIVILEGES|windows.TOKEN_QUERY, &token)
	if err != nil {
		panic(err)
	}

	var luid windows.LUID

	privilegeName := "SeSecurityPrivilege"
	err = windows.LookupPrivilegeValue(nil, windows.StringToUTF16Ptr(privilegeName), &luid)
	if err != nil {
		panic(err)
	}

	newStateBuffer := make([]byte, 4+unsafe.Sizeof(windows.LUIDAndAttributes{}))
	newState := (*windows.Tokenprivileges)(unsafe.Pointer(&newStateBuffer[0]))
	newState.PrivilegeCount = 1
	newState.Privileges[0].Luid = luid
	newState.Privileges[0].Attributes = windows.SE_PRIVILEGE_ENABLED

	err = windows.AdjustTokenPrivileges(token, false, newState, uint32(len(newStateBuffer)), nil, nil)
	// When elevated this should succeed, but when not elevated ERROR_NOT_ALL_ASSIGNED should be returned, but it succeeds instead.
	if err != nil {
		panic(err)
	}
}
```


### What did you expect to see?
When I run the program as a normal user (not administrator), I expect the `windows.AdjustTokenPrivileges` call at line 29 to fail with and return error `ERROR_NOT_ALL_ASSIGNED` error, since the privilege that was requested to be enable was not enabled.

### What did you see instead?
`windows.AdjustTokenPrivileges` returns null instead of returning an error.