diff --git a/constraint/go.mod b/constraint/go.mod index 0682d9313..fc42c0668 100644 --- a/constraint/go.mod +++ b/constraint/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.5 require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc - github.com/golang/glog v1.2.1 + github.com/golang/glog v1.2.2 github.com/google/go-cmp v0.6.0 github.com/onsi/gomega v1.33.1 github.com/open-policy-agent/opa v0.67.0 diff --git a/constraint/go.sum b/constraint/go.sum index 7a1f47588..4b9efbe9b 100644 --- a/constraint/go.sum +++ b/constraint/go.sum @@ -74,8 +74,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= -github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY= +github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= diff --git a/constraint/vendor/github.com/golang/glog/glog_file.go b/constraint/vendor/github.com/golang/glog/glog_file.go index a1551dbc8..8eb8b08c6 100644 --- a/constraint/vendor/github.com/golang/glog/glog_file.go +++ b/constraint/vendor/github.com/golang/glog/glog_file.go @@ -26,7 +26,6 @@ import ( "fmt" "io" "os" - "os/user" "path/filepath" "runtime" "strings" @@ -68,9 +67,8 @@ func init() { host = shortHostname(h) } - current, err := user.Current() - if err == nil { - userName = current.Username + if u := lookupUser(); u != "" { + userName = u } // Sanitize userName since it is used to construct file paths. userName = strings.Map(func(r rune) rune { diff --git a/constraint/vendor/github.com/golang/glog/glog_file_nonwindows.go b/constraint/vendor/github.com/golang/glog/glog_file_nonwindows.go new file mode 100644 index 000000000..d5cdb793c --- /dev/null +++ b/constraint/vendor/github.com/golang/glog/glog_file_nonwindows.go @@ -0,0 +1,12 @@ +//go:build !windows + +package glog + +import "os/user" + +func lookupUser() string { + if current, err := user.Current(); err == nil { + return current.Username + } + return "" +} diff --git a/constraint/vendor/github.com/golang/glog/glog_file_windows.go b/constraint/vendor/github.com/golang/glog/glog_file_windows.go new file mode 100644 index 000000000..a9e4f609d --- /dev/null +++ b/constraint/vendor/github.com/golang/glog/glog_file_windows.go @@ -0,0 +1,30 @@ +//go:build windows + +package glog + +import ( + "syscall" +) + +// This follows the logic in the standard library's user.Current() function, except +// that it leaves out the potentially expensive calls required to look up the user's +// display name in Active Directory. +func lookupUser() string { + token, err := syscall.OpenCurrentProcessToken() + if err != nil { + return "" + } + defer token.Close() + tokenUser, err := token.GetTokenUser() + if err != nil { + return "" + } + username, _, accountType, err := tokenUser.User.Sid.LookupAccount("") + if err != nil { + return "" + } + if accountType != syscall.SidTypeUser { + return "" + } + return username +} diff --git a/constraint/vendor/modules.txt b/constraint/vendor/modules.txt index 2bc88e911..988ba34f4 100644 --- a/constraint/vendor/modules.txt +++ b/constraint/vendor/modules.txt @@ -76,7 +76,7 @@ github.com/gobwas/glob/util/strings ## explicit; go 1.15 github.com/gogo/protobuf/proto github.com/gogo/protobuf/sortkeys -# github.com/golang/glog v1.2.1 +# github.com/golang/glog v1.2.2 ## explicit; go 1.19 github.com/golang/glog github.com/golang/glog/internal/logsink