[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 2/6] Move interface registration to coinstaller
WHQL will fail when registry is accessed from NDIS drivers. Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx> --- src/coinst/coinst.c | 152 ++++++ src/xennet/main.c | 13 - src/xennet/miniport.c | 78 +-- src/xennet/registry.c | 1200 ------------------------------------------ src/xennet/registry.h | 168 ------ vs2012/xennet/xennet.vcxproj | 1 - vs2013/xennet/xennet.vcxproj | 1 - 7 files changed, 154 insertions(+), 1459 deletions(-) delete mode 100644 src/xennet/registry.c delete mode 100644 src/xennet/registry.h diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c index 532a382..265f348 100644 --- a/src/coinst/coinst.c +++ b/src/coinst/coinst.c @@ -44,6 +44,7 @@ #include <malloc.h> #include <stdarg.h> #include <assert.h> +#include <vif_interface.h> #include <tcpip.h> #include <version.h> @@ -2082,6 +2083,154 @@ fail1: return FALSE; } +static HKEY +OpenInterfacesKey( + IN PTCHAR ProviderName + ) +{ + HRESULT Result; + TCHAR KeyName[MAX_PATH]; + HKEY Key; + HRESULT Error; + + Result = StringCbPrintf(KeyName, + MAX_PATH, + "%s\\%s\\Interfaces", + SERVICES_KEY, + ProviderName); + if (!SUCCEEDED(Result)) { + SetLastError(ERROR_BUFFER_OVERFLOW); + goto fail1; + } + + Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + KeyName, + 0, + KEY_ALL_ACCESS, + &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 BOOLEAN +RegisterInterface( + IN PTCHAR ProviderName, + IN PTCHAR InterfaceName, + IN DWORD InterfaceVersion + ) +{ + HKEY Key; + HKEY InterfacesKey; + HRESULT Error; + + InterfacesKey = OpenInterfacesKey(ProviderName); + if (InterfacesKey == NULL) { + goto fail1; + } + + Error = RegCreateKeyEx(InterfacesKey, + "XENNET", + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &Key, + NULL); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail2; + } + + Error = RegSetValueEx(Key, + InterfaceName, + 0, + REG_DWORD, + (const BYTE *)InterfaceVersion, + sizeof(DWORD)); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail3; + } + + RegCloseKey(Key); + RegCloseKey(InterfacesKey); + return TRUE; + +fail3: + RegCloseKey(Key); +fail2: + RegCloseKey(InterfacesKey); +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = __GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + +static BOOLEAN +DeregisterAllInterfaces( + IN PTCHAR ProviderName + ) +{ + HKEY InterfacesKey; + HRESULT Error; + + InterfacesKey = OpenInterfacesKey(ProviderName); + if (InterfacesKey == NULL) { + goto fail1; + } + + Error = RegDeleteTree(InterfacesKey, + "XENNET"); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail2; + } + + RegCloseKey(InterfacesKey); + return TRUE; + +fail2: + RegCloseKey(InterfacesKey); +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = __GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + static BOOLEAN RequestReboot( IN HDEVINFO DeviceInfoSet, @@ -2185,6 +2334,8 @@ __DifInstallPostProcess( if (!Success) goto fail5; + RegisterInterface("XENVIF", "VIF", XENVIF_VIF_INTERFACE_VERSION_MAX); + if (SoftwareKeyName != NULL) { (VOID) RequestReboot(DeviceInfoSet, DeviceInfoData); @@ -2265,6 +2416,7 @@ __DifRemovePreProcess( Log("====>"); + (VOID) DeregisterAllInterfaces("XENVIF"); (VOID) RemoveUnplugService("NICS", "XENNET"); (VOID) RequestReboot(DeviceInfoSet, DeviceInfoData); diff --git a/src/xennet/main.c b/src/xennet/main.c index 6622e82..e193e0e 100644 --- a/src/xennet/main.c +++ b/src/xennet/main.c @@ -32,7 +32,6 @@ #include <version.h> #include "common.h" -#include "registry.h" #pragma NDIS_INIT_FUNCTION(DriverEntry) @@ -197,7 +196,6 @@ DriverEntry ( PNDIS_CONFIGURATION_PARAMETER ParameterValue; ULONG FailCreateClose; ULONG FailDeviceControl; - NTSTATUS status; ExInitializeDriverRuntime(DrvRtPoolNxOptIn); @@ -215,15 +213,6 @@ DriverEntry ( MONTH, YEAR); - status = RegistryInitialize(RegistryPath); - - ndisStatus = (NT_SUCCESS(status)) ? - NDIS_STATUS_SUCCESS : - NDIS_STATUS_FAILURE; - - if (ndisStatus != NDIS_STATUS_SUCCESS) - goto fail; - // // Register miniport with NDIS. // @@ -345,8 +334,6 @@ DriverUnload ( if (MiniportDriverHandle) NdisMDeregisterMiniportDriver(MiniportDriverHandle); - RegistryTeardown(); - Info("XENNET %d.%d.%d (%d) (%02d.%02d.%04d)\n", MAJOR_VERSION, MINOR_VERSION, diff --git a/src/xennet/miniport.c b/src/xennet/miniport.c index a1d605f..12d332f 100644 --- a/src/xennet/miniport.c +++ b/src/xennet/miniport.c @@ -32,19 +32,14 @@ #define INITGUID 1 #include "common.h" -#include "registry.h" #pragma warning( disable : 4098 ) extern NTSTATUS AllocAdapter(PADAPTER *Adapter); -#define SERVICES_KEY L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services" - static FORCEINLINE NTSTATUS __QueryInterface( IN PDEVICE_OBJECT DeviceObject, - IN const WCHAR *ProviderName, - IN const CHAR *InterfaceName, IN const GUID *Guid, IN ULONG Version, OUT PINTERFACE Interface, @@ -52,9 +47,6 @@ __QueryInterface( IN BOOLEAN Optional ) { - UNICODE_STRING Unicode; - HANDLE InterfacesKey; - HANDLE SubscriberKey; KEVENT Event; IO_STATUS_BLOCK StatusBlock; PIRP Irp; @@ -63,40 +55,6 @@ __QueryInterface( ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); - Unicode.MaximumLength = (USHORT)((wcslen(SERVICES_KEY) + - 1 + - wcslen(ProviderName) + - 1 + - wcslen(L"Interfaces") + - 1) * sizeof (WCHAR)); - - Unicode.Buffer = ExAllocatePoolWithTag(NonPagedPool, - Unicode.MaximumLength, - 'TEN'); - - status = STATUS_NO_MEMORY; - if (Unicode.Buffer == NULL) - goto fail1; - - status = RtlStringCbPrintfW(Unicode.Buffer, - Unicode.MaximumLength, - SERVICES_KEY L"\\%ws\\Interfaces", - ProviderName); - ASSERT(NT_SUCCESS(status)); - - Unicode.Length = (USHORT)(wcslen(Unicode.Buffer) * sizeof (WCHAR)); - - status = RegistryOpenKey(NULL, &Unicode, KEY_READ, &InterfacesKey); - if (!NT_SUCCESS(status)) - goto fail2; - - status = RegistryCreateSubKey(InterfacesKey, - "XENNET", - REG_OPTION_NON_VOLATILE, - &SubscriberKey); - if (!NT_SUCCESS(status)) - goto fail3; - KeInitializeEvent(&Event, NotificationEvent, FALSE); RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK)); @@ -110,7 +68,7 @@ __QueryInterface( status = STATUS_UNSUCCESSFUL; if (Irp == NULL) - goto fail4; + goto fail1; StackLocation = IoGetNextIrpStackLocation(Irp); StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE; @@ -136,45 +94,15 @@ __QueryInterface( if (status == STATUS_NOT_SUPPORTED && Optional) goto done; - goto fail5; + goto fail2; } - status = RegistryUpdateDwordValue(SubscriberKey, - (PCHAR)InterfaceName, - Version); - if (!NT_SUCCESS(status)) - goto fail6; - done: - RegistryCloseKey(SubscriberKey); - - RegistryCloseKey(InterfacesKey); - - ExFreePool(Unicode.Buffer); - return STATUS_SUCCESS; -fail6: - Error("fail6\n"); - -fail5: - Error("fail5\n"); - -fail4: - Error("fail4\n"); - - RegistryCloseKey(SubscriberKey); - -fail3: - Error("fail3\n"); - - RegistryCloseKey(InterfacesKey); - fail2: Error("fail2\n"); - ExFreePool(Unicode.Buffer); - fail1: Error("fail1 (%08x)\n", status); @@ -190,8 +118,6 @@ fail1: _Size, \ _Optional) \ __QueryInterface((_DeviceObject), \ - L ## #_ProviderName, \ - #_InterfaceName, \ &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ (_Version), \ (_Interface), \ diff --git a/src/xennet/registry.c b/src/xennet/registry.c deleted file mode 100644 index 5843ef5..0000000 --- a/src/xennet/registry.c +++ /dev/null @@ -1,1200 +0,0 @@ -/* Copyright (c) Citrix Systems Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <ntddk.h> -#include <util.h> - -#include "registry.h" -#include "assert.h" - -#define REGISTRY_POOL 'GERX' - -static UNICODE_STRING RegistryPath; - -static FORCEINLINE PVOID -__RegistryAllocate( - IN ULONG Length - ) -{ - return __AllocateNonPagedPoolWithTag(Length, REGISTRY_POOL); -} - -static FORCEINLINE VOID -__RegistryFree( - IN PVOID Buffer - ) -{ - __FreePoolWithTag(Buffer, REGISTRY_POOL); -} - -NTSTATUS -RegistryInitialize( - IN PUNICODE_STRING Path - ) -{ - NTSTATUS status; - - ASSERT3P(RegistryPath.Buffer, ==, NULL); - - status = RtlUpcaseUnicodeString(&RegistryPath, Path, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - return STATUS_SUCCESS; - -fail1: - Error("fail1 (%08x)\n", status); - - return status; -} - -VOID -RegistryTeardown( - VOID - ) -{ - RtlFreeUnicodeString(&RegistryPath); - RegistryPath.Buffer = NULL; - RegistryPath.MaximumLength = RegistryPath.Length = 0; -} - -NTSTATUS -RegistryOpenKey( - IN HANDLE Parent, - IN PUNICODE_STRING Path, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ) -{ - OBJECT_ATTRIBUTES Attributes; - NTSTATUS status; - - InitializeObjectAttributes(&Attributes, - Path, - OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, - Parent, - NULL); - - status = ZwOpenKey(Key, - DesiredAccess, - &Attributes); - if (!NT_SUCCESS(status)) - goto fail1; - - return STATUS_SUCCESS; - -fail1: - return status; -} - -NTSTATUS -RegistryOpenServiceKey( - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ) -{ - return RegistryOpenKey(NULL, &RegistryPath, DesiredAccess, Key); -} - -NTSTATUS -RegistryOpenSoftwareKey( - IN PDEVICE_OBJECT DeviceObject, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ) -{ - NTSTATUS status; - - status = IoOpenDeviceRegistryKey(DeviceObject, - PLUGPLAY_REGKEY_DRIVER, - DesiredAccess, - Key); - if (!NT_SUCCESS(status)) - goto fail1; - - return STATUS_SUCCESS; - -fail1: - return status; -} - -NTSTATUS -RegistryOpenHardwareKey( - IN PDEVICE_OBJECT DeviceObject, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ) -{ - HANDLE SubKey; - ULONG Length; - PKEY_NAME_INFORMATION Info; - PWCHAR Cursor; - UNICODE_STRING Unicode; - NTSTATUS status; - - status = IoOpenDeviceRegistryKey(DeviceObject, - PLUGPLAY_REGKEY_DEVICE, - KEY_READ, - &SubKey); - if (!NT_SUCCESS(status)) - goto fail1; - - Length = 0; - (VOID) ZwQueryKey(SubKey, - KeyNameInformation, - NULL, - 0, - &Length); - - status = STATUS_INVALID_PARAMETER; - if (Length == 0) - goto fail2; - - Info = __RegistryAllocate(Length + sizeof (WCHAR)); - - status = STATUS_NO_MEMORY; - if (Info == NULL) - goto fail3; - - status = ZwQueryKey(SubKey, - KeyNameInformation, - Info, - Length, - &Length); - if (!NT_SUCCESS(status)) - goto fail4; - - Info->Name[Info->NameLength / sizeof (WCHAR)] = '\0'; - - Cursor = wcsrchr(Info->Name, L'\\'); - ASSERT(Cursor != NULL); - - *Cursor = L'\0'; - - RtlInitUnicodeString(&Unicode, Info->Name); - - status = RegistryOpenKey(NULL, &Unicode, DesiredAccess, Key); - if (!NT_SUCCESS(status)) - goto fail5; - - __RegistryFree(Info); - - RegistryCloseKey(SubKey); - - return STATUS_SUCCESS; - -fail5: -fail4: - __RegistryFree(Info); - -fail3: -fail2: - RegistryCloseKey(SubKey); - -fail1: - return status; -} - -NTSTATUS -RegistryOpenSubKey( - IN PHANDLE Key, - IN PCHAR Name, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE SubKey - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - status = RegistryOpenKey(Key, &Unicode, DesiredAccess, SubKey); - if (!NT_SUCCESS(status)) - goto fail2; - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryCreateSubKey( - IN PHANDLE Key, - IN PCHAR Name, - IN ULONG Options, - OUT PHANDLE SubKey - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - OBJECT_ATTRIBUTES Attributes; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - InitializeObjectAttributes(&Attributes, - &Unicode, - OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, - Key, - NULL); - - status = ZwCreateKey(SubKey, - KEY_ALL_ACCESS, - &Attributes, - 0, - NULL, - Options, - NULL - ); - if (!NT_SUCCESS(status)) - goto fail2; - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryDeleteSubKey( - IN PHANDLE Key, - IN PCHAR Name - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - HANDLE SubKey; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - status = RegistryOpenKey(Key, &Unicode, KEY_ALL_ACCESS, &SubKey); - if (!NT_SUCCESS(status)) - goto fail2; - - status = ZwDeleteKey(SubKey); - if (!NT_SUCCESS(status)) - goto fail3; - - ZwClose(SubKey); - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail3: - ZwClose(SubKey); - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryEnumerateSubKeys( - IN HANDLE Key, - IN NTSTATUS (*Callback)(PVOID, HANDLE, PCHAR), - IN PVOID Context - ) -{ - ULONG Size; - NTSTATUS status; - PKEY_FULL_INFORMATION Full; - PKEY_BASIC_INFORMATION Basic; - ULONG Index; - - status = ZwQueryKey(Key, - KeyFullInformation, - NULL, - 0, - &Size); - if (status != STATUS_BUFFER_TOO_SMALL) - goto fail1; - - Full = __RegistryAllocate(Size); - - status = STATUS_NO_MEMORY; - if (Full == NULL) - goto fail2; - - status = ZwQueryKey(Key, - KeyFullInformation, - Full, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail3; - - Size = FIELD_OFFSET(KEY_BASIC_INFORMATION, Name) + - Full->MaxNameLen; - - Basic = __RegistryAllocate(Size); - status = STATUS_NO_MEMORY; - if (Basic == NULL) - goto fail4; - - for (Index = 0; Index < Full->SubKeys; Index++) { - UNICODE_STRING Unicode; - ANSI_STRING Ansi; - - status = ZwEnumerateKey(Key, - Index, - KeyBasicInformation, - Basic, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail5; - - Unicode.MaximumLength = (USHORT)Basic->NameLength; - Unicode.Buffer = Basic->Name; - Unicode.Length = (USHORT)Basic->NameLength; - - Ansi.MaximumLength = (USHORT)((Basic->NameLength / sizeof (WCHAR)) + sizeof (CHAR)); - Ansi.Buffer = __RegistryAllocate(Ansi.MaximumLength); - - status = STATUS_NO_MEMORY; - if (Ansi.Buffer == NULL) - goto fail6; - - status = RtlUnicodeStringToAnsiString(&Ansi, &Unicode, FALSE); - ASSERT(NT_SUCCESS(status)); - - Ansi.Length = (USHORT)(strlen(Ansi.Buffer) * sizeof (CHAR)); - - status = Callback(Context, Key, Ansi.Buffer); - - __RegistryFree(Ansi.Buffer); - Ansi.Buffer = NULL; - - if (!NT_SUCCESS(status)) - goto fail7; - } - - __RegistryFree(Basic); - - __RegistryFree(Full); - - return STATUS_SUCCESS; - -fail7: -fail6: -fail5: - __RegistryFree(Basic); - -fail4: -fail3: - __RegistryFree(Full); - -fail2: -fail1: - return status; -} - -NTSTATUS -RegistryEnumerateValues( - IN HANDLE Key, - IN NTSTATUS (*Callback)(PVOID, HANDLE, PCHAR), - IN PVOID Context - ) -{ - ULONG Size; - NTSTATUS status; - PKEY_FULL_INFORMATION Full; - PKEY_VALUE_BASIC_INFORMATION Basic; - ULONG Index; - - status = ZwQueryKey(Key, - KeyFullInformation, - NULL, - 0, - &Size); - if (status != STATUS_BUFFER_TOO_SMALL) - goto fail1; - - Full = __RegistryAllocate(Size); - - status = STATUS_NO_MEMORY; - if (Full == NULL) - goto fail2; - - status = ZwQueryKey(Key, - KeyFullInformation, - Full, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail3; - - Size = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + - Full->MaxValueNameLen; - - Basic = __RegistryAllocate(Size); - status = STATUS_NO_MEMORY; - if (Basic == NULL) - goto fail4; - - for (Index = 0; Index < Full->Values; Index++) { - UNICODE_STRING Unicode; - ANSI_STRING Ansi; - - status = ZwEnumerateValueKey(Key, - Index, - KeyValueBasicInformation, - Basic, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail5; - - Unicode.MaximumLength = (USHORT)Basic->NameLength; - Unicode.Buffer = Basic->Name; - Unicode.Length = (USHORT)Basic->NameLength; - - Ansi.MaximumLength = (USHORT)((Basic->NameLength / sizeof (WCHAR)) + sizeof (CHAR)); - Ansi.Buffer = __RegistryAllocate(Ansi.MaximumLength); - - status = RtlUnicodeStringToAnsiString(&Ansi, &Unicode, FALSE); - ASSERT(NT_SUCCESS(status)); - - Ansi.Length = (USHORT)(strlen(Ansi.Buffer) * sizeof (CHAR)); - - status = Callback(Context, Key, Ansi.Buffer); - - __RegistryFree(Ansi.Buffer); - - if (!NT_SUCCESS(status)) - goto fail6; - } - - __RegistryFree(Basic); - - __RegistryFree(Full); - - return STATUS_SUCCESS; - -fail6: -fail5: - __RegistryFree(Basic); - -fail4: -fail3: - __RegistryFree(Full); - -fail2: -fail1: - return status; -} - -NTSTATUS -RegistryDeleteValue( - IN PHANDLE Key, - IN PCHAR Name - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - status = ZwDeleteValueKey(Key, &Unicode); - if (!NT_SUCCESS(status)) - goto fail2; - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryQueryDwordValue( - IN HANDLE Key, - IN PCHAR Name, - OUT PULONG Value - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - PKEY_VALUE_PARTIAL_INFORMATION Partial; - ULONG Size; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - status = ZwQueryValueKey(Key, - &Unicode, - KeyValuePartialInformation, - NULL, - 0, - &Size); - if (status != STATUS_BUFFER_TOO_SMALL) - goto fail2; - - Partial = __RegistryAllocate(Size); - - status = STATUS_NO_MEMORY; - if (Partial == NULL) - goto fail3; - - status = ZwQueryValueKey(Key, - &Unicode, - KeyValuePartialInformation, - Partial, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail4; - - status = STATUS_INVALID_PARAMETER; - if (Partial->Type != REG_DWORD || - Partial->DataLength != sizeof (ULONG)) - goto fail5; - - *Value = *(PULONG)Partial->Data; - - __RegistryFree(Partial); - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail5: -fail4: - __RegistryFree(Partial); - -fail3: -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryUpdateDwordValue( - IN HANDLE Key, - IN PCHAR Name, - IN ULONG Value - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - PKEY_VALUE_PARTIAL_INFORMATION Partial; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + - sizeof (ULONG)); - - status = STATUS_NO_MEMORY; - if (Partial == NULL) - goto fail2; - - Partial->TitleIndex = 0; - Partial->Type = REG_DWORD; - Partial->DataLength = sizeof (ULONG); - *(PULONG)Partial->Data = Value; - - status = ZwSetValueKey(Key, - &Unicode, - Partial->TitleIndex, - Partial->Type, - Partial->Data, - Partial->DataLength); - if (!NT_SUCCESS(status)) - goto fail3; - - __RegistryFree(Partial); - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail3: - __RegistryFree(Partial); - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - - return status; -} - -static PANSI_STRING -RegistrySzToAnsi( - IN PWCHAR Buffer - ) -{ - PANSI_STRING Ansi; - ULONG Length; - UNICODE_STRING Unicode; - NTSTATUS status; - - Ansi = __RegistryAllocate(sizeof (ANSI_STRING) * 2); - - status = STATUS_NO_MEMORY; - if (Ansi == NULL) - goto fail1; - - Length = (ULONG)wcslen(Buffer); - Ansi[0].MaximumLength = (USHORT)(Length + 1) * sizeof (CHAR); - Ansi[0].Buffer = __RegistryAllocate(Ansi[0].MaximumLength); - - status = STATUS_NO_MEMORY; - if (Ansi[0].Buffer == NULL) - goto fail2; - - RtlInitUnicodeString(&Unicode, Buffer); - status = RtlUnicodeStringToAnsiString(&Ansi[0], &Unicode, FALSE); - ASSERT(NT_SUCCESS(status)); - - Ansi[0].Length = (USHORT)Length * sizeof (CHAR); - - return Ansi; - -fail2: - __RegistryFree(Ansi); - -fail1: - return NULL; -} - -static PANSI_STRING -RegistryMultiSzToAnsi( - IN PWCHAR Buffer - ) -{ - PANSI_STRING Ansi; - LONG Index; - LONG Count; - NTSTATUS status; - - Index = 0; - Count = 0; - for (;;) { - ULONG Length; - - Length = (ULONG)wcslen(&Buffer[Index]); - if (Length == 0) - break; - - Index += Length + 1; - Count++; - } - - Ansi = __RegistryAllocate(sizeof (ANSI_STRING) * (Count + 1)); - - status = STATUS_NO_MEMORY; - if (Ansi == NULL) - goto fail1; - - for (Index = 0; Index < Count; Index++) { - ULONG Length; - UNICODE_STRING Unicode; - - Length = (ULONG)wcslen(Buffer); - Ansi[Index].MaximumLength = (USHORT)(Length + 1) * sizeof (CHAR); - Ansi[Index].Buffer = __RegistryAllocate(Ansi[Index].MaximumLength); - - status = STATUS_NO_MEMORY; - if (Ansi[Index].Buffer == NULL) - goto fail2; - - RtlInitUnicodeString(&Unicode, Buffer); - - status = RtlUnicodeStringToAnsiString(&Ansi[Index], &Unicode, FALSE); - ASSERT(NT_SUCCESS(status)); - - Ansi[Index].Length = (USHORT)Length * sizeof (CHAR); - Buffer += Length + 1; - } - - return Ansi; - -fail2: - while (--Index >= 0) - __RegistryFree(Ansi[Index].Buffer); - - __RegistryFree(Ansi); - -fail1: - return NULL; -} - -NTSTATUS -RegistryQuerySzValue( - IN HANDLE Key, - IN PCHAR Name, - OUT PANSI_STRING *Array - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - PKEY_VALUE_PARTIAL_INFORMATION Value; - ULONG Size; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - status = ZwQueryValueKey(Key, - &Unicode, - KeyValuePartialInformation, - NULL, - 0, - &Size); - if (status != STATUS_BUFFER_TOO_SMALL) - goto fail2; - - Value = __RegistryAllocate(Size); - - status = STATUS_NO_MEMORY; - if (Value == NULL) - goto fail3; - - status = ZwQueryValueKey(Key, - &Unicode, - KeyValuePartialInformation, - Value, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail4; - - switch (Value->Type) { - case REG_SZ: - status = STATUS_NO_MEMORY; - *Array = RegistrySzToAnsi((PWCHAR)Value->Data); - break; - - case REG_MULTI_SZ: - status = STATUS_NO_MEMORY; - *Array = RegistryMultiSzToAnsi((PWCHAR)Value->Data); - break; - - default: - status = STATUS_INVALID_PARAMETER; - *Array = NULL; - break; - } - - if (*Array == NULL) - goto fail5; - - __RegistryFree(Value); - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail5: -fail4: - __RegistryFree(Value); - -fail3: -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -NTSTATUS -RegistryQueryKeyName( - IN HANDLE Key, - OUT PANSI_STRING *Array - ) -{ - PKEY_NAME_INFORMATION Value; - ULONG Size; - NTSTATUS status; - - status = ZwQueryKey(Key, - KeyNameInformation, - NULL, - 0, - &Size); - if (status != STATUS_BUFFER_TOO_SMALL) - goto fail1; - - // Name information is not intrinsically NULL terminated - Value = __RegistryAllocate(Size + sizeof (WCHAR)); - - status = STATUS_NO_MEMORY; - if (Value == NULL) - goto fail2; - - status = ZwQueryKey(Key, - KeyNameInformation, - Value, - Size, - &Size); - if (!NT_SUCCESS(status)) - goto fail3; - - Value->Name[Value->NameLength / sizeof (WCHAR)] = L'\0'; - *Array = RegistrySzToAnsi((PWCHAR)Value->Name); - - status = STATUS_NO_MEMORY; - if (*Array == NULL) - goto fail4; - - __RegistryFree(Value); - - return STATUS_SUCCESS; - -fail4: -fail3: - __RegistryFree(Value); - -fail2: -fail1: - return status; -} - -NTSTATUS -RegistryQuerySystemStartOption( - IN PCHAR Prefix, - OUT PANSI_STRING *Value - ) -{ - UNICODE_STRING Unicode; - HANDLE Key; - PANSI_STRING Ansi; - ULONG Length; - PCHAR Option; - PCHAR Context; - NTSTATUS status; - - RtlInitUnicodeString(&Unicode, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control"); - - status = RegistryOpenKey(NULL, &Unicode, KEY_READ, &Key); - if (!NT_SUCCESS(status)) - goto fail1; - - status = RegistryQuerySzValue(Key, "SystemStartOptions", &Ansi); - if (!NT_SUCCESS(status)) - goto fail2; - - // SystemStartOptions is a space separated list of options. - // Scan it looking for the one we want. - Length = (ULONG)strlen(Prefix); - - Option = __strtok_r(Ansi[0].Buffer, " ", &Context); - if (strncmp(Prefix, Option, Length) == 0) - goto found; - - while ((Option = __strtok_r(NULL, " ", &Context)) != NULL) - if (strncmp(Prefix, Option, Length) == 0) - goto found; - - status = STATUS_OBJECT_NAME_NOT_FOUND; - goto fail3; - -found: - *Value = __RegistryAllocate(sizeof (ANSI_STRING) * 2); - - status = STATUS_NO_MEMORY; - if (*Value == NULL) - goto fail4; - - Length = (ULONG)strlen(Option); - (*Value)[0].MaximumLength = (USHORT)(Length + 1) * sizeof (CHAR); - (*Value)[0].Buffer = __RegistryAllocate((*Value)[0].MaximumLength); - - status = STATUS_NO_MEMORY; - if ((*Value)[0].Buffer == NULL) - goto fail5; - - RtlCopyMemory((*Value)[0].Buffer, Option, Length * sizeof (CHAR)); - - (*Value)[0].Length = (USHORT)Length * sizeof (CHAR); - - RegistryFreeSzValue(Ansi); - - ZwClose(Key); - - return STATUS_SUCCESS; - -fail5: - __RegistryFree(*Value); - -fail4: -fail3: - RegistryFreeSzValue(Ansi); - -fail2: - ZwClose(Key); - -fail1: - return status; -} - -static PKEY_VALUE_PARTIAL_INFORMATION -RegistryAnsiToSz( - PANSI_STRING Ansi - ) -{ - ULONG Length; - PKEY_VALUE_PARTIAL_INFORMATION Partial; - UNICODE_STRING Unicode; - NTSTATUS status; - - Length = Ansi->Length + 1; - Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + - Length * sizeof (WCHAR)); - - status = STATUS_NO_MEMORY; - if (Partial == NULL) - goto fail1; - - Partial->TitleIndex = 0; - Partial->Type = REG_SZ; - Partial->DataLength = Length * sizeof (WCHAR); - - Unicode.MaximumLength = (UCHAR)Partial->DataLength; - Unicode.Buffer = (PWCHAR)Partial->Data; - Unicode.Length = 0; - - status = RtlAnsiStringToUnicodeString(&Unicode, Ansi, FALSE); - if (!NT_SUCCESS(status)) - goto fail2; - - return Partial; - -fail2: - __RegistryFree(Partial); - -fail1: - return NULL; -} - -static PKEY_VALUE_PARTIAL_INFORMATION -RegistryAnsiToMultiSz( - PANSI_STRING Ansi - ) -{ - ULONG Length; - ULONG Index; - PKEY_VALUE_PARTIAL_INFORMATION Partial; - UNICODE_STRING Unicode; - NTSTATUS status; - - Length = 1; - for (Index = 0; Ansi[Index].Buffer != NULL; Index++) - Length += Ansi[Index].Length + 1; - - Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) + - Length * sizeof (WCHAR)); - - status = STATUS_NO_MEMORY; - if (Partial == NULL) - goto fail1; - - Partial->TitleIndex = 0; - Partial->Type = REG_MULTI_SZ; - Partial->DataLength = Length * sizeof (WCHAR); - - Unicode.MaximumLength = (USHORT)Partial->DataLength; - Unicode.Buffer = (PWCHAR)Partial->Data; - Unicode.Length = 0; - - for (Index = 0; Ansi[Index].Buffer != NULL; Index++) { - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi[Index], FALSE); - if (!NT_SUCCESS(status)) - goto fail2; - - Length = Unicode.Length / sizeof (WCHAR); - - ASSERT3U(Unicode.MaximumLength, >=, (Length + 1) * sizeof (WCHAR)); - Unicode.MaximumLength -= (USHORT)((Length + 1) * sizeof (WCHAR)); - Unicode.Buffer += Length + 1; - Unicode.Length = 0; - } - *Unicode.Buffer = L'\0'; - - return Partial; - -fail2: - __RegistryFree(Partial); - -fail1: - return NULL; -} - -NTSTATUS -RegistryUpdateSzValue( - IN HANDLE Key, - IN PCHAR Name, - IN ULONG Type, - ... - ) -{ - ANSI_STRING Ansi; - UNICODE_STRING Unicode; - va_list Arguments; - PKEY_VALUE_PARTIAL_INFORMATION Partial; - NTSTATUS status; - - RtlInitAnsiString(&Ansi, Name); - - status = RtlAnsiStringToUnicodeString(&Unicode, &Ansi, TRUE); - if (!NT_SUCCESS(status)) - goto fail1; - - va_start(Arguments, Type); - switch (Type) { - case REG_SZ: { - PANSI_STRING Argument; - - Argument = va_arg(Arguments, PANSI_STRING); - - status = STATUS_NO_MEMORY; - Partial = RegistryAnsiToSz(Argument); - break; - } - case REG_MULTI_SZ: { - PANSI_STRING Argument; - - Argument = va_arg(Arguments, PANSI_STRING); - - status = STATUS_NO_MEMORY; - Partial = RegistryAnsiToMultiSz(Argument); - break; - } - default: - status = STATUS_INVALID_PARAMETER; - Partial = NULL; - break; - } - va_end(Arguments); - - if (Partial == NULL) - goto fail2; - - status = ZwSetValueKey(Key, - &Unicode, - Partial->TitleIndex, - Partial->Type, - Partial->Data, - Partial->DataLength); - if (!NT_SUCCESS(status)) - goto fail3; - - __RegistryFree(Partial); - - RtlFreeUnicodeString(&Unicode); - - return STATUS_SUCCESS; - -fail3: - __RegistryFree(Partial); - -fail2: - RtlFreeUnicodeString(&Unicode); - -fail1: - return status; -} - -VOID -RegistryFreeSzValue( - IN PANSI_STRING Array - ) -{ - ULONG Index; - - if (Array == NULL) - return; - - for (Index = 0; Array[Index].Buffer != NULL; Index++) - __RegistryFree(Array[Index].Buffer); - - __RegistryFree(Array); -} - -VOID -RegistryCloseKey( - IN HANDLE Key - ) -{ - ZwClose(Key); -} diff --git a/src/xennet/registry.h b/src/xennet/registry.h deleted file mode 100644 index 7d7dc01..0000000 --- a/src/xennet/registry.h +++ /dev/null @@ -1,168 +0,0 @@ -/* Copyright (c) Citrix Systems Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _XENNET_REGISTRY_H -#define _XENNET_REGISTRY_H - -#include <ntddk.h> - -extern NTSTATUS -RegistryInitialize( - IN PUNICODE_STRING Path - ); - -extern VOID -RegistryTeardown( - VOID - ); - -extern NTSTATUS -RegistryOpenKey( - IN HANDLE Parent, - IN PUNICODE_STRING Path, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ); - -extern NTSTATUS -RegistryOpenServiceKey( - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ); - -extern NTSTATUS -RegistryOpenSoftwareKey( - IN PDEVICE_OBJECT DeviceObject, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ); - -extern NTSTATUS -RegistryOpenHardwareKey( - IN PDEVICE_OBJECT DeviceObject, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE Key - ); - -extern NTSTATUS -RegistryOpenSubKey( - IN HANDLE Key, - IN PCHAR Name, - IN ACCESS_MASK DesiredAccess, - OUT PHANDLE SubKey - ); - -extern NTSTATUS -RegistryCreateSubKey( - IN HANDLE Key, - IN PCHAR Name, - IN ULONG Options, - OUT PHANDLE SubKey - ); - -extern NTSTATUS -RegistryDeleteSubKey( - IN HANDLE Key, - IN PCHAR Name - ); - -extern NTSTATUS -RegistryEnumerateSubKeys( - IN HANDLE Key, - IN NTSTATUS (*Callback)(PVOID, HANDLE, PCHAR), - IN PVOID Context - ); - -extern NTSTATUS -RegistryEnumerateValues( - IN HANDLE Key, - IN NTSTATUS (*Callback)(PVOID, HANDLE, PCHAR), - IN PVOID Context - ); - -extern NTSTATUS -RegistryDeleteValue( - IN HANDLE Key, - IN PCHAR Name - ); - -extern NTSTATUS -RegistryQueryDwordValue( - IN HANDLE Key, - IN PCHAR Name, - OUT PULONG Value - ); - -extern NTSTATUS -RegistryUpdateDwordValue( - IN HANDLE Key, - IN PCHAR Name, - IN ULONG Value - ); - -extern NTSTATUS -RegistryQuerySzValue( - IN HANDLE Key, - IN PCHAR Name, - OUT PANSI_STRING *Array - ); - -extern NTSTATUS -RegistryQueryKeyName( - IN HANDLE Key, - OUT PANSI_STRING *Array - ); - -extern NTSTATUS -RegistryQuerySystemStartOption( - IN PCHAR Name, - OUT PANSI_STRING *Option - ); - -extern VOID -RegistryFreeSzValue( - IN PANSI_STRING Array - ); - -extern NTSTATUS -RegistryUpdateSzValue( - IN HANDLE Key, - IN PCHAR Name, - IN ULONG Type, - ... - ); - -extern VOID -RegistryCloseKey( - IN HANDLE Key - ); - -#endif // _XENNET_REGISTRY_H diff --git a/vs2012/xennet/xennet.vcxproj b/vs2012/xennet/xennet.vcxproj index db07e9b..aab91d2 100644 --- a/vs2012/xennet/xennet.vcxproj +++ b/vs2012/xennet/xennet.vcxproj @@ -83,7 +83,6 @@ <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> - <ClCompile Include="../../src/xennet/registry.c" /> <ClCompile Include="../../src/xennet/adapter.c" /> <ClCompile Include="../../src/xennet/main.c" /> <ClCompile Include="../../src/xennet/miniport.c" /> diff --git a/vs2013/xennet/xennet.vcxproj b/vs2013/xennet/xennet.vcxproj index 0d98f3a..9401b99 100644 --- a/vs2013/xennet/xennet.vcxproj +++ b/vs2013/xennet/xennet.vcxproj @@ -114,7 +114,6 @@ <FilesToPackage Include="@(Inf->'%(CopyOutput)')" Condition="'@(Inf)'!=''" /> </ItemGroup> <ItemGroup> - <ClCompile Include="../../src/xennet/registry.c" /> <ClCompile Include="../../src/xennet/adapter.c" /> <ClCompile Include="../../src/xennet/main.c" /> <ClCompile Include="../../src/xennet/miniport.c" /> -- 1.9.4.msysgit.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |