Skip to content

Commit 44f3924

Browse files
hurzelpurzelanjannath
authored andcommitted
update check for user in hyper-v admins group
this adds additional check to figure out if the user is a domained joined by looking at the value of env variables COMPUTERNAME and DOMAINJOINED since the values are equal for a local user
1 parent 1e8617d commit 44f3924

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/crc/preflight/preflight_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var userPartOfCrcUsersAndHypervAdminsGroupCheck = Check{
155155
var errReboot = errors.New("Please reboot your system and run 'crc setup' to complete the setup process")
156156

157157
func username() string {
158-
if ok, _ := win32.DomainJoined(); ok {
158+
if ok := win32.DomainJoined(); ok {
159159
return fmt.Sprintf(`%s\%s`, os.Getenv("USERDOMAIN"), os.Getenv("USERNAME"))
160160
}
161161
return os.Getenv("USERNAME")

pkg/os/windows/win32/domains_windows.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,28 @@ package win32
1818

1919
import (
2020
"errors"
21+
"os"
2122

2223
"github.com/yusufpapurcu/wmi"
2324
)
2425

25-
//nolint
26+
// nolint
2627
type Win32_ComputerSystem struct {
2728
Partofdomain bool
2829
}
2930

3031
// DomainJoined attempts to determine whether the machine is actively domain joined.
31-
func DomainJoined() (bool, error) {
32+
33+
func DomainJoined() bool {
34+
domainJoined, err := domainJoinedWmi()
35+
if err != nil {
36+
// simple additional domain check: a local User got the computername = domain
37+
return os.Getenv("USERDOMAIN") != os.Getenv("COMPUTERNAME")
38+
}
39+
return domainJoined
40+
}
41+
42+
func domainJoinedWmi() (bool, error) {
3243
var c []Win32_ComputerSystem
3344
q := wmi.CreateQuery(&c, "")
3445

0 commit comments

Comments
 (0)