Пример #1
0
static BOOLEAN
SupportChildDrivers(
    VOID
    )
{
    BOOLEAN     Success;
    HKEY        XenbusKey;
    HRESULT     Error;
    DWORD       SubKeys;
    DWORD       MaxSubKeyLength;
    DWORD       SubKeyLength;
    PTCHAR      SubKeyName;
    HKEY        DeviceKey;
    PTCHAR      DriverKeyName;
    HKEY        DriverKey;
    PTCHAR      MatchingDeviceID;
    DWORD       Index;

    Log("====>");

    Success = OpenBusKey("XENHID", &XenbusKey);
    if (!Success) {
        // If there is no key then this must be a fresh installation
        if (GetLastError() == ERROR_FILE_NOT_FOUND)
            goto done;

        goto fail1;
    }

    Error = RegQueryInfoKey(XenbusKey,
                            NULL,
                            NULL,
                            NULL,
                            &SubKeys,
                            &MaxSubKeyLength,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL);
    if (Error != ERROR_SUCCESS) {
        SetLastError(Error);
        goto fail2;
    }

    SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);

    SubKeyName = malloc(SubKeyLength);
    if (SubKeyName == NULL)
        goto fail3;

    for (Index = 0; Index < SubKeys; Index++) {
        SubKeyLength = MaxSubKeyLength + sizeof (TCHAR);
        memset(SubKeyName, 0, SubKeyLength);

        Error = RegEnumKeyEx(XenbusKey,
                             Index,
                             (LPTSTR)SubKeyName,
                             &SubKeyLength,
                             NULL,
                             NULL,
                             NULL,
                             NULL);
        if (Error != ERROR_SUCCESS) {
            SetLastError(Error);
            goto fail4;
        }

        Success = OpenDeviceKey("XENHID", SubKeyName, &DeviceKey);
        if (!Success)
            goto fail5;

        Success = GetDriverKeyName(DeviceKey, &DriverKeyName);
        if (!Success)
            goto fail6;

        if (DriverKeyName == NULL)
            goto loop;

        Success = OpenDriverKey(DriverKeyName, &DriverKey);
        if (!Success)
            goto loop;

        Success = GetMatchingDeviceID(DriverKey, &MatchingDeviceID);
        if (!Success)
            goto fail7;

        Success = SupportDeviceID(MatchingDeviceID);
        if (!Success)
            goto fail8;

        free(MatchingDeviceID);

        RegCloseKey(DriverKey);

    loop:
        if (DriverKeyName != NULL)
            free(DriverKeyName);

        RegCloseKey(DeviceKey);
    }

    free(SubKeyName);

    RegCloseKey(XenbusKey);

done:
    Log("<====");

    return TRUE;

fail8:
    Log("fail8");

    free(MatchingDeviceID);

fail7:
    Log("fail7");

    RegCloseKey(DriverKey);

    free(DriverKeyName);

fail6:
    Log("fail6");

    RegCloseKey(DeviceKey);

fail5:
    Log("fail5");

fail4:
    Log("fail4");

    free(SubKeyName);

fail3:
    Log("fail3");

fail2:
    Log("fail2");

    RegCloseKey(XenbusKey);

fail1:
    Error = GetLastError();

    {
        PTCHAR  Message;

        Message = GetErrorMessage(Error);
        Log("fail1 (%s)", Message);
        LocalFree(Message);
    }

    return FALSE;
}
Пример #2
0
static BOOLEAN
AllowInstall(
    VOID
    )
{
    BOOLEAN Success;
    PTCHAR  DeviceKeyName = NULL;
    HKEY    DeviceKey = NULL;
    PTCHAR  DriverKeyName = NULL;
    HKEY    DriverKey = NULL;
    HRESULT Error;
    DWORD   MaxValueLength;
    DWORD   DriverDescLength;
    PTCHAR  DriverDesc = NULL;
    DWORD   Type;

    // Look for a legacy platform device
    Success = GetDeviceKeyName(PLATFORM_DEVICE_0001_NAME,
                               &DeviceKeyName);
    if (!Success)
        goto fail1;

    if (DeviceKeyName != NULL)
        goto found;

    Success = GetDeviceKeyName(PLATFORM_DEVICE_0002_NAME,
                               &DeviceKeyName);
    if (!Success)
        goto fail2;

    if (DeviceKeyName != NULL)
        goto found;

    // No legacy platform device
    goto done;

found:
    Success = OpenDeviceKey(DeviceKeyName, &DeviceKey);
    if (!Success)
        goto fail3;

    // Check for a bound driver
    Success = GetDriverKeyName(DeviceKey, &DriverKeyName);
    if (!Success)
        goto fail4;

    if (DriverKeyName == NULL)
        goto done;

    Success = OpenDriverKey(DriverKeyName, &DriverKey);
    if (!Success)
        goto fail5;

    Error = RegQueryInfoKey(DriverKey,
                            NULL,
                            NULL,
                            NULL,    
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            &MaxValueLength,
                            NULL,
                            NULL);
    if (Error != ERROR_SUCCESS) {
        SetLastError(Error);
        goto fail6;
    }

    DriverDescLength = MaxValueLength + sizeof (TCHAR);

    DriverDesc = malloc(DriverDescLength);
    if (DriverDesc == NULL)
        goto fail7;

    memset(DriverDesc, 0, DriverDescLength);

    Error = RegQueryValueEx(DriverKey,
                            "DriverDesc",
                            NULL,
                            &Type,
                            (LPBYTE)DriverDesc,
                            &DriverDescLength);
    if (Error != ERROR_SUCCESS) {
        if (Error == ERROR_FILE_NOT_FOUND)
            goto done;

        SetLastError(Error);
        goto fail8;
    }

    if (Type != REG_SZ) {
        SetLastError(ERROR_BAD_FORMAT);
        goto fail9;
    }

    if (strcmp(DriverDesc, "Xen Platform") != 0) {
        SetLastError(ERROR_INSTALL_FAILURE);
        goto fail10;
    }

done:
    if (DriverDesc != NULL) {
        free(DriverDesc);
        RegCloseKey(DriverKey);
    }

    if (DriverKeyName != NULL) {
        free(DriverKeyName);
        RegCloseKey(DeviceKey);
    }

    if (DeviceKeyName != NULL)
        free(DeviceKeyName);

    return TRUE;

fail10:
    Log("fail10");

fail9:
    Log("fail9");

fail8:
    Log("fail8");

    free(DriverDesc);

fail7:
    Log("fail7");

fail6:
    Log("fail6");

    RegCloseKey(DriverKey);

fail5:
    Log("fail5");

    free(DriverKeyName);

fail4:
    Log("fail4");

    RegCloseKey(DeviceKey);

fail3:
    Log("fail3");

    free(DeviceKeyName);

fail2:
    Log("fail2");

fail1:
    Error = GetLastError();

    {
        PTCHAR  Message;

        Message = GetErrorMessage(Error);
        Log("fail1 (%s)", Message);
        LocalFree(Message);
    }

    return FALSE;
}