From: Paul Durrant Date: Thu, 22 Oct 2015 14:50:58 +0000 (+0100) Subject: Add a registry override to veto driver installations X-Git-Tag: 8.2.0-rc1~46 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2a1afc35b9cc4b1feda4957d8654a87da7439019;p=pvdrivers%2Fwin%2Fxennet.git Add a registry override to veto driver installations There are certain cases where a local installer package may wish to prevent Windows Update installations of drivers. This can be achieved by having the co-installer check for a registry value and fail it's pre-install phase if the value is present. Signed-off-by: Paul Durrant --- diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c index d1222df..f60aa43 100644 --- a/src/coinst/coinst.c +++ b/src/coinst/coinst.c @@ -190,6 +190,132 @@ __FunctionName( #undef _NAME } +static BOOLEAN +AllowUpdate( + IN PTCHAR DriverName, + OUT PBOOLEAN Allow + ) +{ + TCHAR ServiceKeyName[MAX_PATH]; + HKEY ServiceKey; + HRESULT Result; + HRESULT Error; + DWORD ValueLength; + DWORD Value; + DWORD Type; + + Log("====> (%s)", DriverName); + + Result = StringCbPrintf(ServiceKeyName, + MAX_PATH, + SERVICES_KEY "\\%s", + DriverName); + assert(SUCCEEDED(Result)); + + Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + ServiceKeyName, + 0, + KEY_READ, + &ServiceKey); + if (Error != ERROR_SUCCESS) { + if (Error == ERROR_FILE_NOT_FOUND) { + Value = 1; + goto done; + } + + SetLastError(Error); + goto fail1; + } + + ValueLength = sizeof (Value); + + Error = RegQueryValueEx(ServiceKey, + "AllowUpdate", + NULL, + &Type, + (LPBYTE)&Value, + &ValueLength); + if (Error != ERROR_SUCCESS) { + if (Error == ERROR_FILE_NOT_FOUND) { + Type = REG_DWORD; + Value = 1; + } else { + SetLastError(Error); + goto fail2; + } + } + + if (Type != REG_DWORD) { + SetLastError(ERROR_BAD_FORMAT); + goto fail3; + } + +done: + if (Value == 0) { + Log("DISALLOWED"); + *Allow = FALSE; + } + + RegCloseKey(ServiceKey); + + Log("<===="); + + return TRUE; + +fail3: + Log("fail3"); + +fail2: + Log("fail2"); + + RegCloseKey(ServiceKey); + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = __GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + +static BOOLEAN +AllowInstall( + OUT PBOOLEAN Allow + ) +{ + BOOLEAN Success; + HRESULT Error; + + Log("====>"); + + *Allow = TRUE; + + Success = AllowUpdate("XENNET", Allow); + if (!Success) + goto fail1; + + Log("<===="); + + return TRUE; + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = __GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + static BOOLEAN CheckStatus( OUT PBOOLEAN NeedReboot @@ -315,13 +441,44 @@ __DifInstallPreProcess( IN PCOINSTALLER_CONTEXT_DATA Context ) { + HRESULT Error; + BOOLEAN Success; + BOOLEAN Allow; + UNREFERENCED_PARAMETER(DeviceInfoSet); UNREFERENCED_PARAMETER(DeviceInfoData); UNREFERENCED_PARAMETER(Context); - Log("<===>"); + Log("====>"); + + Success = AllowInstall(&Allow); + if (!Success) + goto fail1; + + if (!Allow) { + SetLastError(ERROR_ACCESS_DENIED); + goto fail2; + } + + Log("<===="); return NO_ERROR; + +fail2: + Log("fail2"); + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + + Message = __GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return Error; } static FORCEINLINE HRESULT