wintun: query for NetCfgInstanceId several times

This commit is contained in:
Jason A. Donenfeld 2019-03-22 16:48:40 -06:00
parent 52ec440d79
commit 2fa80c0cb7

View File

@ -45,14 +45,25 @@ func MakeWintun(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfo
} }
defer key.Close() defer key.Close()
// Read the NetCfgInstanceId value. var valueStr string
valueStr, valueType, err := key.GetStringValue("NetCfgInstanceId") var valueType uint32
//TODO: Figure out a way to not need to loop like this.
for i := 0; i < 30; i++ {
// Read the NetCfgInstanceId value.
valueStr, valueType, err = key.GetStringValue("NetCfgInstanceId")
if err != nil {
time.Sleep(time.Millisecond * 100)
continue
}
if valueType != registry.SZ {
return nil, fmt.Errorf("NetCfgInstanceId registry value is not REG_SZ (expected: %v, provided: %v)", registry.SZ, valueType)
}
break
}
if err != nil { if err != nil {
return nil, errors.New("RegQueryStringValue(\"NetCfgInstanceId\") failed: " + err.Error()) return nil, errors.New("RegQueryStringValue(\"NetCfgInstanceId\") failed: " + err.Error())
} }
if valueType != registry.SZ {
return nil, fmt.Errorf("NetCfgInstanceId registry value is not REG_SZ (expected: %v, provided: %v)", registry.SZ, valueType)
}
// Convert to windows.GUID. // Convert to windows.GUID.
ifid, err := guid.FromString(valueStr) ifid, err := guid.FromString(valueStr)