[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Remove code that copies network settings from the co-installer



This functionality is now implemented by XENVIF.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/coinst/coinst.c | 1640 +++------------------------------------------------
 1 file changed, 70 insertions(+), 1570 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index 0905205..fce8abd 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -210,1452 +210,57 @@ __FunctionName(
 #undef  _NAME
 }
 
-static HKEY
-OpenSoftwareKey(
-    IN  HDEVINFO            DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA    DeviceInfoData
-    )
-{
-    HKEY                    Key;
-    HRESULT                 Error;
-
-    Key = SetupDiOpenDevRegKey(DeviceInfoSet,
-                               DeviceInfoData,
-                               DICS_FLAG_GLOBAL,
-                               0,
-                               DIREG_DRV,
-                               KEY_ALL_ACCESS);
-    if (Key == INVALID_HANDLE_VALUE) {
-        SetLastError(ERROR_PATH_NOT_FOUND);
-        goto fail1;
-    }
-
-    return Key;
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return NULL;
-}
-
-static PTCHAR
-GetProperty(
-    IN  HDEVINFO            DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA    DeviceInfoData,
-    IN  DWORD               Index
-    )
-{
-    DWORD                   Type;
-    DWORD                   PropertyLength;
-    PTCHAR                  Property;
-    HRESULT                 Error;
-
-    if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
-                                          DeviceInfoData,
-                                          Index,
-                                          &Type,
-                                          NULL,
-                                          0,
-                                          &PropertyLength)) {
-        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
-            goto fail1;
-    }
-
-    if (Type != REG_SZ) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail2;
-    }
-
-    PropertyLength += sizeof (TCHAR);
-
-    Property = calloc(1, PropertyLength);
-    if (Property == NULL)
-        goto fail3;
-
-    if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
-                                          DeviceInfoData,
-                                          Index,
-                                          NULL,
-                                          (PBYTE)Property,
-                                          PropertyLength,
-                                          NULL))
-        goto fail4;
-
-    return Property;
-
-fail4:
-    free(Property);
-
-fail3:
-    Log("fail3");
-
-fail2:
-    Log("fail2");
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return NULL;
-}
-
-static BOOLEAN
-SetFriendlyName(
-    IN  HDEVINFO            DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA    DeviceInfoData
-    )
-{
-    PTCHAR                  Description;
-    PTCHAR                  Location;
-    TCHAR                   FriendlyName[MAX_PATH];
-    DWORD                   FriendlyNameLength;
-    HRESULT                 Result;
-    HRESULT                 Error;
-
-    Description = GetProperty(DeviceInfoSet,
-                              DeviceInfoData,
-                              SPDRP_DEVICEDESC);
-    if (Description == NULL)
-        goto fail1;
-
-    Location = GetProperty(DeviceInfoSet,
-                           DeviceInfoData,
-                           SPDRP_LOCATION_INFORMATION);
-    if (Location == NULL)
-        goto fail2;
-
-    Result = StringCbPrintf(FriendlyName,
-                            MAX_PATH,
-                            "%s #%s",
-                            Description,
-                            Location);
-    if (!SUCCEEDED(Result))
-        goto fail3;
-
-    FriendlyNameLength = (DWORD)(strlen(FriendlyName) + sizeof (TCHAR));
-
-    if (!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
-                                          DeviceInfoData,
-                                          SPDRP_FRIENDLYNAME,
-                                          (PBYTE)FriendlyName,
-                                          FriendlyNameLength))
-        goto fail4;
-
-    Log("%s", FriendlyName);
-
-    free(Location);
-
-    free(Description);
-
-    return TRUE;
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    free(Location);
-
-fail2:
-    Log("fail2");
-
-    free(Description);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-ParseMacAddress(
-    IN  PCHAR               Buffer,
-    OUT PETHERNET_ADDRESS   Address
-    )
-{
-    ULONG                   Length;
-    HRESULT                 Error;
-
-    Length = 0;
-    for (;;) {
-        CHAR    Character;
-        UCHAR   Byte;
-
-        Character = *Buffer++;
-        if (Character == '\0')
-            break;
-
-        if (Character >= '0' && Character <= '9')
-            Byte = Character - '0';
-        else if (Character >= 'A' && Character <= 'F')
-            Byte = 0x0A + Character - 'A';
-        else if (Character >= 'a' && Character <= 'f')
-            Byte = 0x0A + Character - 'a';
-        else
-            break;
-
-        Byte <<= 4;
-
-        Character = *Buffer++;
-        if (Character == '\0')
-            break;
-
-        if (Character >= '0' && Character <= '9')
-            Byte += Character - '0';
-        else if (Character >= 'A' && Character <= 'F')
-            Byte += 0x0A + Character - 'A';
-        else if (Character >= 'a' && Character <= 'f')
-            Byte += 0x0A + Character - 'a';
-        else
-            break;
-
-        Address->Byte[Length++] = Byte;
-
-        // Skip over any separator
-        if (*Buffer == ':' || *Buffer == '-')
-            Buffer++;
-    }
-
-    if (Length != ETHERNET_ADDRESS_LENGTH) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail1;
-    }
-
-    return TRUE;
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-
-static BOOLEAN
-GetPermanentAddress(
-    IN  HDEVINFO            DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA    DeviceInfoData,
-    OUT PETHERNET_ADDRESS   Address
-    )
-{
-    PTCHAR                  Location;
-    HRESULT                 Error;
-    HKEY                    AddressesKey;
-    DWORD                   MaxValueLength;
-    DWORD                   BufferLength;
-    PTCHAR                  Buffer;
-    DWORD                   Type;
-    BOOLEAN                 Success;
-
-    Location = GetProperty(DeviceInfoSet,
-                           DeviceInfoData,
-                           SPDRP_LOCATION_INFORMATION);
-    if (Location == NULL)
-        goto fail1;
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         ADDRESSES_KEY,
-                         0,
-                         KEY_READ,
-                         &AddressesKey);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    Error = RegQueryInfoKey(AddressesKey,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &MaxValueLength,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    BufferLength = MaxValueLength + sizeof (TCHAR);
-
-    Buffer = calloc(1, BufferLength);
-    if (Buffer == NULL)
-        goto fail4;
-
-    Error = RegQueryValueEx(AddressesKey,
-                            Location,
-                            NULL,
-                            &Type,
-                            (LPBYTE)Buffer,
-                            &BufferLength);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail5;
-    }
-
-    if (Type != REG_SZ) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail6;
-    }
-
-    Success = ParseMacAddress(Buffer, Address);
-    if (!Success)
-        goto fail7;
-
-    free(Buffer);
-
-    RegCloseKey(AddressesKey);
-
-    free(Location);
-
-    Log("%02X:%02X:%02X:%02X:%02X:%02X",
-        Address->Byte[0],
-        Address->Byte[1],
-        Address->Byte[2],
-        Address->Byte[3],
-        Address->Byte[4],
-        Address->Byte[5]);
-
-    return TRUE;
-
-fail7:
-    Log("fail7");
-
-fail6:
-    Log("fail6");
-
-fail5:
-    Log("fail5");
-
-    free(Buffer);
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    RegCloseKey(AddressesKey);
-
-fail2:
-    Log("fail2");
-
-    free(Location);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-GetNetLuid(
-    IN  PETHERNET_ADDRESS   Address,
-    OUT PNET_LUID           *NetLuid
-    )
-{
-    PMIB_IF_TABLE2          Table;
-    DWORD                   Index;
-    PMIB_IF_ROW2            Row;
-    HRESULT                 Error;
-
-    Error = GetIfTable2(&Table);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    for (Index = 0; Index < Table->NumEntries; Index++) {
-        Row = &Table->Table[Index];
-
-        if (!(Row->InterfaceAndOperStatusFlags.HardwareInterface) ||
-            !(Row->InterfaceAndOperStatusFlags.ConnectorPresent))
-            continue;
-
-        if (Row->OperStatus != IfOperStatusUp)
-            continue;
-
-        if (Row->PhysicalAddressLength != sizeof (ETHERNET_ADDRESS))
-            continue;
-
-        if (memcmp(Row->PhysicalAddress,
-                   Address,
-                   sizeof (ETHERNET_ADDRESS)) == 0)
-            goto found;
-    }
-
-    *NetLuid = NULL;
-    goto done;
-
-found:
-    *NetLuid = calloc(1, sizeof (NET_LUID));
-    if (*NetLuid == NULL)
-        goto fail2;
-
-    (*NetLuid)->Value = Row->InterfaceLuid.Value;
-
-done:
-    FreeMibTable(Table);
-
-    return TRUE;
-
-fail2:
-    Log("fail2");
-
-    FreeMibTable(Table);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-OpenClassKey(
-    IN  const GUID  *Guid,
-    OUT PHKEY       Key
-    )
-{   
-    TCHAR           KeyName[MAX_PATH];
-    HRESULT         Result;
-    HRESULT         Error;
-
-    Result = StringCbPrintf(KeyName,
-                            MAX_PATH,
-                            
"%s\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
-                            CLASS_KEY,
-                            Guid->Data1,
-                            Guid->Data2,
-                            Guid->Data3,
-                            Guid->Data4[0],
-                            Guid->Data4[1],
-                            Guid->Data4[2],
-                            Guid->Data4[3],
-                            Guid->Data4[4],
-                            Guid->Data4[5],
-                            Guid->Data4[6],
-                            Guid->Data4[7]);
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail1;
-    }
-
-    Log("%s", KeyName);
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         KeyName,
-                         0,
-                         KEY_READ,
-                         Key);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    return TRUE;
-
-fail2:
-    Log("fail2");
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-FindAliasSoftwareKeyName(
-    IN  PETHERNET_ADDRESS   Address,
-    OUT PTCHAR              *Name
-    )
-{
-    const GUID              *Guid = &GUID_DEVCLASS_NET;
-    BOOLEAN                 Success;
-    PNET_LUID               NetLuid;
-    HKEY                    NetKey;
-    HRESULT                 Error;
-    DWORD                   SubKeys;
-    DWORD                   MaxSubKeyLength;
-    DWORD                   SubKeyLength;
-    PTCHAR                  SubKeyName;
-    DWORD                   Index;
-    HKEY                    SubKey;
-    DWORD                   NameLength;
-    HRESULT                 Result;
-
-    Log("====>");
-
-    Success = GetNetLuid(Address, &NetLuid);
-    if (!Success)
-        goto fail1;
-
-    *Name = NULL;
-
-    if (NetLuid == NULL)
-        goto done;
-
-    Log("%08x.%08x",
-        NetLuid->Info.IfType,
-        NetLuid->Info.NetLuidIndex);
-
-    Success = OpenClassKey(Guid, &NetKey);
-    if (!Success)
-        goto fail2;
-
-    Error = RegQueryInfoKey(NetKey,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &SubKeys,
-                            &MaxSubKeyLength,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
-
-    SubKeyName = malloc(SubKeyLength);
-    if (SubKeyName == NULL)
-        goto fail4;
-
-    for (Index = 0; Index < SubKeys; Index++) {
-        DWORD   Length;
-        DWORD   Type;
-        DWORD   IfType;
-        DWORD   NetLuidIndex;
-
-        SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
-        memset(SubKeyName, 0, SubKeyLength);
-
-        Error = RegEnumKeyEx(NetKey,
-                             Index,
-                             (LPTSTR)SubKeyName,
-                             &SubKeyLength,
-                             NULL,
-                             NULL,
-                             NULL,
-                             NULL);
-        if (Error != ERROR_SUCCESS) {
-            SetLastError(Error);
-            goto fail5;
-        }
-
-        Error = RegOpenKeyEx(NetKey,
-                             SubKeyName,
-                             0,
-                             KEY_READ,
-                             &SubKey);
-        if (Error != ERROR_SUCCESS)
-            continue;
-
-        Length = sizeof (DWORD);
-        Error = RegQueryValueEx(SubKey,
-                                "*IfType",
-                                NULL,
-                                &Type,
-                                (LPBYTE)&IfType,
-                                &Length);
-        if (Error != ERROR_SUCCESS ||
-            Type != REG_DWORD)
-            goto loop;
-
-        Length = sizeof (DWORD);
-        Error = RegQueryValueEx(SubKey,
-                                "NetLuidIndex",
-                                NULL,
-                                &Type,
-                                (LPBYTE)&NetLuidIndex,
-                                &Length);
-        if (Error != ERROR_SUCCESS ||
-            Type != REG_DWORD)
-            goto loop;
-
-        if (NetLuid->Info.IfType == IfType &&
-            NetLuid->Info.NetLuidIndex == NetLuidIndex)
-            goto found;
-
-loop:
-        RegCloseKey(SubKey);
-    }
-
-    SetLastError(ERROR_FILE_NOT_FOUND);
-    goto fail6;
-
-found:
-    RegCloseKey(SubKey);
-
-    RegCloseKey(NetKey);
-
-    free(NetLuid);
-
-    NameLength = (DWORD)(sizeof ("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\\") +
-                         ((strlen(SubKeyName) + 1) * sizeof (TCHAR)));
-
-    *Name = calloc(1, NameLength);
-    if (*Name == NULL)
-        goto fail7;
-
-    Result = StringCbPrintf(*Name,
-                            NameLength,
-                            
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\%s",
-                            Guid->Data1,
-                            Guid->Data2,
-                            Guid->Data3,
-                            Guid->Data4[0],
-                            Guid->Data4[1],
-                            Guid->Data4[2],
-                            Guid->Data4[3],
-                            Guid->Data4[4],
-                            Guid->Data4[5],
-                            Guid->Data4[6],
-                            Guid->Data4[7],
-                            SubKeyName);
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail8;
-    }
-
-done:
-    Log("%s", (*Name == NULL) ? "[NONE]" : *Name);
-
-    Log("<====");
-
-    return TRUE;
-
-fail8:
-    Log("fail8");
-
-    free(*Name);
-
-fail7:
-    Log("fail7");
-
-fail6:
-    Log("fail6");
-
-fail5:
-    Log("fail5");
-
-    free(SubKeyName);
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    RegCloseKey(NetKey);
-
-fail2:
-    Log("fail2");
-
-    free(NetLuid);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static HKEY
-OpenAliasSoftwareKey(
-    IN  PTCHAR  Name
-    )
-{
-    HRESULT     Result;
-    TCHAR       KeyName[MAX_PATH];
-    HKEY        Key;
-    HRESULT     Error;
-
-    Result = StringCbPrintf(KeyName,
-                            MAX_PATH,
-                            "%s\\%s",
-                            CLASS_KEY,
-                            Name);
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail1;
-    }
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         KeyName,
-                         0,
-                         KEY_READ,
-                         &Key);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    return Key;
-
-fail2:
-    Log("fail2");
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return NULL;
-}
-
-static PTCHAR
-GetInterfaceName(
-    IN  HKEY    SoftwareKey
-    )
-{
-    HRESULT     Error;
-    HKEY        LinkageKey;
-    DWORD       MaxValueLength;
-    DWORD       RootDeviceLength;
-    PTCHAR      RootDevice;
-    DWORD       Type;
-
-    Error = RegOpenKeyEx(SoftwareKey,
-                         "Linkage",
-                         0,
-                         KEY_READ,
-                         &LinkageKey);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    Error = RegQueryInfoKey(LinkageKey,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &MaxValueLength,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    RootDeviceLength = MaxValueLength + sizeof (TCHAR);
-
-    RootDevice = calloc(1, RootDeviceLength);
-    if (RootDevice == NULL)
-        goto fail2;
-
-    Error = RegQueryValueEx(LinkageKey,
-                            "RootDevice",
-                            NULL,
-                            &Type,
-                            (LPBYTE)RootDevice,
-                            &RootDeviceLength);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    Error = RegQueryValueEx(LinkageKey,
-                            "RootDevice",
-                            NULL,
-                            &Type,
-                            (LPBYTE)RootDevice,
-                            &RootDeviceLength);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    if (Type != REG_MULTI_SZ) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail4;
-    }
-
-    Log("%s", RootDevice);
-
-    RegCloseKey(LinkageKey);
-
-    return RootDevice;
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    free(RootDevice);
-
-fail2:
-    Log("fail2");
-
-    RegCloseKey(LinkageKey);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return NULL;
-}
-
-static BOOLEAN
-CopyKeyValues(
-    IN  HKEY    DestinationKey,
-    IN  HKEY    SourceKey
-    )
-{
-    HRESULT     Error;
-    DWORD       Values;
-    DWORD       MaxNameLength;
-    PTCHAR      Name;
-    DWORD       MaxValueLength;
-    LPBYTE      Value;
-    DWORD       Index;
-
-    Log("====>");
-
-    Error = RegQueryInfoKey(SourceKey,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &Values,
-                            &MaxNameLength,
-                            &MaxValueLength,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    Log("%d VALUES", Values);
-
-    if (Values == 0)
-        goto done;
-
-    MaxNameLength += sizeof (TCHAR);
-
-    Name = malloc(MaxNameLength);
-    if (Name == NULL)
-        goto fail2;
-
-    Value = malloc(MaxValueLength);
-    if (Value == NULL)
-        goto fail3;
-
-    for (Index = 0; Index < Values; Index++) {
-        DWORD   NameLength;
-        DWORD   ValueLength;
-        DWORD   Type;
-
-        NameLength = MaxNameLength;
-        memset(Name, 0, NameLength);
-
-        ValueLength = MaxValueLength;
-        memset(Value, 0, ValueLength);
-
-        Error = RegEnumValue(SourceKey,
-                             Index,
-                             (LPTSTR)Name,
-                             &NameLength,
-                             NULL,
-                             &Type,
-                             Value,
-                             &ValueLength);
-        if (Error != ERROR_SUCCESS) {
-            SetLastError(Error);
-            goto fail4;
-        }
-
-        Error = RegSetValueEx(DestinationKey,
-                              Name,
-                              0,
-                              Type,
-                              Value,
-                              ValueLength);
-        if (Error != ERROR_SUCCESS) {
-            SetLastError(Error);
-            goto fail5;
-        }
-
-        Log("COPIED %s", Name);
-    }
-
-    free(Value);
-    free(Name);
-
-done:
-    Log("<====");
-
-    return TRUE;
-
-fail5:
-    Log("fail5");
-
-fail4:
-    Log("fail4");
-
-    free(Value);
-
-fail3:
-    Log("fail3");
-
-    free(Name);
-
-fail2:
-    Log("fail2");
-
-fail1:
-    Log("fail1");
-
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-
-}
-
-static BOOLEAN
-CopyValues(
-    IN  PTCHAR  DestinationKeyName,
-    IN  PTCHAR  SourceKeyName
-    )
-{
-    HRESULT     Error;
-    HKEY        DestinationKey;
-    HKEY        SourceKey;
-
-    Log("====>");
-
-    Log("DESTINATION: %s", DestinationKeyName);
-    Log("SOURCE: %s", SourceKeyName);
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         SourceKeyName,
-                         0,
-                         KEY_ALL_ACCESS,
-                         &SourceKey);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-    
-    Error = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
-                           DestinationKeyName,
-                           0,
-                           NULL,
-                           REG_OPTION_NON_VOLATILE,
-                           KEY_ALL_ACCESS,
-                           NULL,
-                           &DestinationKey,
-                           NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    CopyKeyValues(DestinationKey, SourceKey);
-
-    RegCloseKey(DestinationKey);
-    RegCloseKey(SourceKey);
-
-    Log("<====");
-
-    return TRUE;
-
-fail2:
-    Log("fail2");
-
-    RegCloseKey(SourceKey);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-CopyParameters(
-    IN  PTCHAR  Prefix,
-    IN  PTCHAR  DestinationName,
-    IN  PTCHAR  SourceName
-    )
-{
-    DWORD       Length;
-    PTCHAR      SourceKeyName;
-    PTCHAR      DestinationKeyName;
-    HRESULT     Result;
-    HRESULT     Error;
-    BOOLEAN     Success;
-
-    Log("====>");
-
-    Length = (DWORD)((strlen(Prefix) +
-                      strlen(DestinationName) +
-                      1) * sizeof (TCHAR));
-
-    DestinationKeyName = calloc(1, Length);
-    if (DestinationKeyName == NULL)
-        goto fail1;
-
-    Result = StringCbPrintf(DestinationKeyName,
-                            Length,
-                            "%s%s",
-                            Prefix,
-                            DestinationName);
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail2;
-    }
-
-    Length = (DWORD)((strlen(Prefix) +
-                      strlen(SourceName) +
-                      1) * sizeof (TCHAR));
-
-    SourceKeyName = calloc(1, Length);
-    if (SourceKeyName == NULL)
-        goto fail3;
-
-    Result = StringCbPrintf(SourceKeyName,
-                            Length,
-                            "%s%s",
-                            Prefix,
-                            SourceName);
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail4;
-    }
-
-    Success = CopyValues(DestinationKeyName, SourceKeyName);
-
-    free(SourceKeyName);
-    free(DestinationKeyName);
-
-    Log("<====");
-
-    return Success;
-
-fail4:
-    Log("fail4");
-
-    free(SourceKeyName);
-
-fail3:
-    Log("fail3");
-
-fail2:
-    Log("fail2");
-
-    free(DestinationKeyName);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-CopyIpVersion6Addresses(
-    IN  PTCHAR  DestinationKeyName,
-    IN  PTCHAR  SourceKeyName,
-    IN  PTCHAR  DestinationValueName,
-    IN  PTCHAR  SourceValueName
-    )
-{
-    HKEY        DestinationKey;
-    HKEY        SourceKey;
-    HRESULT     Error;
-    DWORD       Values;
-    DWORD       MaxNameLength;
-    PTCHAR      Name;
-    DWORD       MaxValueLength;
-    LPBYTE      Value;
-    DWORD       Index;
-
-    Log("DESTINATION: %s\\%s", DestinationKeyName, DestinationValueName);
-    Log("SOURCE: %s\\%s", SourceKeyName, SourceValueName);
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         SourceKeyName,
-                         0,
-                         KEY_ALL_ACCESS,
-                         &SourceKey);
-    if (Error != ERROR_SUCCESS) {
-        if (Error == ERROR_FILE_NOT_FOUND)
-            goto done;
-
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    Error = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
-                           DestinationKeyName,
-                           0,
-                           NULL,
-                           REG_OPTION_NON_VOLATILE,
-                           KEY_ALL_ACCESS,
-                           NULL,
-                           &DestinationKey,
-                           NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail2;
-    }
-
-    Error = RegQueryInfoKey(SourceKey,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &Values,
-                            &MaxNameLength,
-                            &MaxValueLength,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    if (Values == 0)
-        goto done;
-
-    MaxNameLength += sizeof (TCHAR);
-
-    Name = malloc(MaxNameLength);
-    if (Name == NULL)
-        goto fail4;
-
-    Value = malloc(MaxValueLength);
-    if (Value == NULL)
-        goto fail5;
-
-    for (Index = 0; Index < Values; Index++) {
-        DWORD   NameLength;
-        DWORD   ValueLength;
-        DWORD   Type;
-
-        NameLength = MaxNameLength;
-        memset(Name, 0, NameLength);
-
-        ValueLength = MaxValueLength;
-        memset(Value, 0, ValueLength);
-
-        Error = RegEnumValue(SourceKey,
-                             Index,
-                             (LPTSTR)Name,
-                             &NameLength,
-                             NULL,
-                             &Type,
-                             Value,
-                             &ValueLength);
-        if (Error != ERROR_SUCCESS) {
-            SetLastError(Error);
-            goto fail6;
-        }
-
-        if (strncmp(Name, SourceValueName, sizeof (ULONG64) * 2) != 0){
-            Log("Ignoring %s ( %s )", Name, SourceValueName);
-            continue;
-        }
-
-        Log("READ: %s", Name);
-
-        memcpy(Name, DestinationValueName, sizeof (ULONG64) * 2);
-
-        Log("WRITE: %s", Name);
-
-        Error = RegSetValueEx(DestinationKey,
-                              Name,
-                              0,
-                              Type,
-                              Value,
-                              ValueLength);
-        if (Error != ERROR_SUCCESS) {
-            SetLastError(Error);
-            goto fail7;
-        }
-    }
-
-    free(Value);
-    free(Name);
-
-    RegCloseKey(DestinationKey);
-    RegCloseKey(SourceKey);
-
-done:
-
-    return TRUE;
-
-fail7:
-    Log("fail7");
-
-fail6:
-    Log("fail6");
-
-    free(Value);
-
-fail5:
-    Log("fail5");
-
-    free(Name);
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    RegCloseKey(DestinationKey);
-
-fail2:
-    Log("fail2");
-
-    RegCloseKey(SourceKey);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
 static PTCHAR
-GetIpVersion6AddressValueName(
-    IN  HKEY    Key
+GetProperty(
+    IN  HDEVINFO            DeviceInfoSet,
+    IN  PSP_DEVINFO_DATA    DeviceInfoData,
+    IN  DWORD               Index
     )
 {
-    HRESULT     Error;
-    DWORD       MaxValueLength;
-    DWORD       ValueLength;
-    LPDWORD     Value;
-    DWORD       Type;
-    NET_LUID    NetLuid;
-    DWORD       BufferLength;
-    PTCHAR      Buffer;
-    HRESULT     Result;
-
-    memset(&NetLuid, 0, sizeof (NetLuid));
-
-    Error = RegQueryInfoKey(Key,
-                            NULL,
-                            NULL,
-                            NULL,    
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            NULL,
-                            &MaxValueLength,
-                            NULL,
-                            NULL);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    ValueLength = MaxValueLength;
-
-    Value = calloc(1, ValueLength);
-    if (Value == NULL)
-        goto fail2;
-
-    Error = RegQueryValueEx(Key,
-                            "NetLuidIndex",
-                            NULL,
-                            &Type,
-                            (LPBYTE)Value,
-                            &ValueLength);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail3;
-    }
-
-    if (Type != REG_DWORD) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail4;
-    }
-
-    NetLuid.Info.NetLuidIndex = *Value;
+    DWORD                   Type;
+    DWORD                   PropertyLength;
+    PTCHAR                  Property;
+    HRESULT                 Error;
 
-    Error = RegQueryValueEx(Key,
-                            "*IfType",
-                            NULL,
-                            &Type,
-                            (LPBYTE)Value,
-                            &ValueLength);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail5;
+    if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
+                                          DeviceInfoData,
+                                          Index,
+                                          &Type,
+                                          NULL,
+                                          0,
+                                          &PropertyLength)) {
+        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+            goto fail1;
     }
 
-    if (Type != REG_DWORD) {
+    if (Type != REG_SZ) {
         SetLastError(ERROR_BAD_FORMAT);
-        goto fail6;
-    }
-
-    NetLuid.Info.IfType = *Value;
-
-    BufferLength = ((sizeof (ULONG64) * 2) + 1) * sizeof (TCHAR);
-
-    Buffer = calloc(1, BufferLength);
-    if (Buffer == NULL)
-        goto fail7;
-
-    Result = StringCbPrintf(Buffer,
-                            BufferLength,
-                            "%016llx",
-                            _byteswap_uint64(NetLuid.Value));
-    if (!SUCCEEDED(Result)) {
-        SetLastError(ERROR_BUFFER_OVERFLOW);
-        goto fail8;
+        goto fail2;
     }
 
-    free(Value);
-
-    return Buffer;
-
-fail8:
-    Log("fail8");
-
-    free(Buffer);
+    PropertyLength += sizeof (TCHAR);
 
-fail7:
-    Log("fail7");
+    Property = calloc(1, PropertyLength);
+    if (Property == NULL)
+        goto fail3;
 
-fail6:
-    Log("fail6");
+    if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
+                                          DeviceInfoData,
+                                          Index,
+                                          NULL,
+                                          (PBYTE)Property,
+                                          PropertyLength,
+                                          NULL))
+        goto fail4;
 
-fail5:
-    Log("fail5");
+    return Property;
 
 fail4:
-    Log("fail4");
+    free(Property);
 
 fail3:
     Log("fail3");
 
-    free(Value);
-
 fail2:
     Log("fail2");
 
@@ -1674,140 +279,67 @@ fail1:
 }
 
 static BOOLEAN
-CopySettings(
-    IN  HKEY    DestinationKey,
-    IN  HKEY    SourceKey
+SetFriendlyName(
+    IN  HDEVINFO            DeviceInfoSet,
+    IN  PSP_DEVINFO_DATA    DeviceInfoData
     )
 {
-    PTCHAR      DestinationName;
-    PTCHAR      SourceName;
-    BOOLEAN     Success;
-    HRESULT     Error;
-
-    Log("====>");
-
-    Success = TRUE;
-
-    SourceName = GetInterfaceName(SourceKey);
+    PTCHAR                  Description;
+    PTCHAR                  Location;
+    TCHAR                   FriendlyName[MAX_PATH];
+    DWORD                   FriendlyNameLength;
+    HRESULT                 Result;
+    HRESULT                 Error;
 
-    if (SourceName == NULL)
+    Description = GetProperty(DeviceInfoSet,
+                              DeviceInfoData,
+                              SPDRP_DEVICEDESC);
+    if (Description == NULL)
         goto fail1;
 
-    DestinationName = GetInterfaceName(DestinationKey);
-
-    if (DestinationName == NULL)
+    Location = GetProperty(DeviceInfoSet,
+                           DeviceInfoData,
+                           SPDRP_LOCATION_INFORMATION);
+    if (Location == NULL)
         goto fail2;
 
-    if (_stricmp(SourceName, DestinationName) == 0)
-        goto done;
-
-    Success &= CopyParameters(PARAMETERS_KEY(NetBT) "\\Interfaces\\Tcpip_",
-                              DestinationName,
-                              SourceName);
-    Success &= CopyParameters(PARAMETERS_KEY(Tcpip) "\\Interfaces\\",
-                              DestinationName,
-                              SourceName);
-    Success &= CopyParameters(PARAMETERS_KEY(Tcpip6) "\\Interfaces\\",
-                              DestinationName,
-                              SourceName);
-
-    free(DestinationName);
-    free(SourceName);
-
-    SourceName = GetIpVersion6AddressValueName(SourceKey);
-
-    if (SourceName == NULL)
+    Result = StringCbPrintf(FriendlyName,
+                            MAX_PATH,
+                            "%s #%s",
+                            Description,
+                            Location);
+    if (!SUCCEEDED(Result))
         goto fail3;
 
-    DestinationName = GetIpVersion6AddressValueName(DestinationKey);
+    FriendlyNameLength = (DWORD)(strlen(FriendlyName) + sizeof (TCHAR));
 
-    if (DestinationName == NULL)
+    if (!SetupDiSetDeviceRegistryProperty(DeviceInfoSet,
+                                          DeviceInfoData,
+                                          SPDRP_FRIENDLYNAME,
+                                          (PBYTE)FriendlyName,
+                                          FriendlyNameLength))
         goto fail4;
 
-    Success &= CopyIpVersion6Addresses(NSI_KEY 
"\\{eb004a01-9b1a-11d4-9123-0050047759bc}\\10\\",
-                                       NSI_KEY 
"\\{eb004a01-9b1a-11d4-9123-0050047759bc}\\10\\",
-                                       DestinationName,
-                                       SourceName);
+    Log("%s", FriendlyName);
 
-done:
-    free(DestinationName);
-    free(SourceName);
+    free(Location);
 
-    Log("<====");
+    free(Description);
 
-    return Success;
+    return TRUE;
 
 fail4:
     Log("fail4");
 
-    free(SourceName);
-    goto fail1;
-
-fail3:
-    Log("fail3");
-
-fail2:
-    Log("fail2");
-
-    free(SourceName);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = __GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-CopySettingsFromAlias(
-    IN  HDEVINFO                    DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA            DeviceInfoData,
-    IN  PTCHAR                      Name
-    )
-{
-    HKEY                            Source;
-    HKEY                            Destination;
-    BOOLEAN                         Success;
-    HRESULT                         Error;
-
-    Log("====> (%s)", Name);
-
-    Source = OpenAliasSoftwareKey(Name);
-    if (Source == NULL)
-        goto fail1;
-
-    Destination = OpenSoftwareKey(DeviceInfoSet, DeviceInfoData);
-    if (Destination == NULL)
-        goto fail2;
-
-    Success = CopySettings(Destination, Source);
-    if (!Success)
-        goto fail3;
-
-    RegCloseKey(Destination);
-
-    RegCloseKey(Source);
-
-    Log("<====");
-
-    return TRUE;
-
 fail3:
     Log("fail3");
 
-    RegCloseKey(Destination);
+    free(Location);
 
 fail2:
     Log("fail2");
 
-    RegCloseKey(Source);
+    free(Description);
 
 fail1:
     Error = GetLastError();
@@ -2447,8 +979,6 @@ __DifInstallPostProcess(
     )
 {
     BOOLEAN                         Success;
-    ETHERNET_ADDRESS                Address;
-    PTCHAR                          SoftwareKeyName;
     BOOLEAN                         NeedReboot;
     HRESULT                         Error;
 
@@ -2456,32 +986,14 @@ __DifInstallPostProcess(
 
     Log("====>");
 
-    Success = GetPermanentAddress(DeviceInfoSet,
-                                  DeviceInfoData,
-                                  &Address);
-    if (!Success)
-        goto fail1;
-
-    Success = FindAliasSoftwareKeyName(&Address, &SoftwareKeyName);
-    if (!Success)
-        goto fail2;
-
-    if (SoftwareKeyName != NULL) {
-        Success = CopySettingsFromAlias(DeviceInfoSet,
-                                        DeviceInfoData,
-                                        SoftwareKeyName);
-        if (!Success)
-            goto fail3;
-    }
-
     Success = SetFriendlyName(DeviceInfoSet,
                               DeviceInfoData);
     if (!Success)
-        goto fail4;
+        goto fail1;
 
     Success = InstallUnplugService("NICS", "XENNET");
     if (!Success)
-        goto fail5;
+        goto fail2;
 
     RegisterInterface("XENVIF", "VIF", XENVIF_VIF_INTERFACE_VERSION_MAX);
     RegisterInterface("XENBUS", "CACHE", XENBUS_CACHE_INTERFACE_VERSION_MAX);
@@ -2496,18 +1008,6 @@ __DifInstallPostProcess(
 
     return NO_ERROR;
 
-fail5:
-    Log("fail5");
-
-fail4:
-    Log("fail4");
-
-fail3:
-    Log("fail3");
-
-    if (SoftwareKeyName != NULL)
-        free(SoftwareKeyName);
-
 fail2:
     Log("fail2");
 
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.