ReactOS 0.4.16-dev-340-g0540c21
registry.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/registry.cpp
5 * PURPOSE: Registry access object
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "private.hpp"
10
11#define NDEBUG
12#include <debug.h>
13
14class CRegistryKey : public CUnknownImpl<IRegistryKey>
15{
16public:
18
20 CRegistryKey(IUnknown * OuterUnknown, HANDLE hKey, BOOL CanDelete) :
21 m_hKey(hKey),
23 m_CanDelete(CanDelete)
24 {
25 }
26 virtual ~CRegistryKey();
27
28protected:
29
33};
34
36{
37 if (!m_Deleted)
38 {
39 // close key only when has not been deleted yet
41 }
42}
43
47 IN REFIID refiid,
49{
51
52 DPRINT("CRegistryKey::QueryInterface entered\n");
53 if (IsEqualGUIDAligned(refiid, IID_IRegistryKey) ||
55 {
56 *Output = PVOID(PREGISTRYKEY(this));
57 PUNKNOWN(*Output)->AddRef();
58 return STATUS_SUCCESS;
59 }
60
62 {
63 DPRINT1("CRegistryKey::QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
65 }
66
68}
69
72CRegistryKey::DeleteKey()
73{
76
77 if (m_Deleted)
78 {
79 // key already deleted
81 }
82
83 if (!m_CanDelete)
84 {
85 // only general keys can be deleted
87 }
88
89 // delete key
90 Status = ZwDeleteKey(m_hKey);
91 if (NT_SUCCESS(Status))
92 {
94 m_hKey = NULL;
95 }
96 return Status;
97}
98
100NTAPI
101CRegistryKey::EnumerateKey(
102 IN ULONG Index,
104 OUT PVOID KeyInformation,
107{
109
110 if (m_Deleted)
111 {
113 }
114
115 return ZwEnumerateKey(m_hKey, Index, KeyInformationClass, KeyInformation, Length, ResultLength);
116}
117
119NTAPI
120CRegistryKey::EnumerateValueKey(
121 IN ULONG Index,
123 OUT PVOID KeyValueInformation,
126{
128
129 if (m_Deleted)
130 {
132 }
133
134 return ZwEnumerateValueKey(m_hKey, Index, KeyValueInformationClass, KeyValueInformation, Length, ResultLength);
135}
136
138NTAPI
139CRegistryKey::NewSubKey(
140 OUT PREGISTRYKEY *RegistrySubKey,
141 IN PUNKNOWN OuterUnknown,
146{
149 HANDLE hKey;
150 CRegistryKey * RegistryKey;
151
153
154 DPRINT("CRegistryKey::NewSubKey entered %S\n", SubKeyName->Buffer);
155
156 if (m_Deleted)
157 {
159 }
160
163 if (!NT_SUCCESS(Status))
164 {
165 DPRINT("CRegistryKey::NewSubKey failed with %x\n", Status);
166 return Status;
167 }
168
169 RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hKey, TRUE);
170 if (!RegistryKey)
172
173 Status = RegistryKey->QueryInterface(IID_IRegistryKey, (PVOID*)RegistrySubKey);
174
175 if (!NT_SUCCESS(Status))
176 {
177 delete RegistryKey;
178 return Status;
179 }
180
181 DPRINT("CRegistryKey::NewSubKey RESULT %p\n", *RegistrySubKey);
182 return STATUS_SUCCESS;
183}
184
186NTAPI
187CRegistryKey::QueryKey(
189 OUT PVOID KeyInformation,
192{
194
195 if (m_Deleted)
196 {
198 }
199
200 return ZwQueryKey(m_hKey, KeyInformationClass, KeyInformation, Length, ResultLength);
201}
202
204NTAPI
205CRegistryKey::QueryRegistryValues(
208{
210
211 if (m_Deleted)
212 {
214 }
215
217}
218
220NTAPI
221CRegistryKey::QueryValueKey(
224 OUT PVOID KeyValueInformation,
227{
229
231
232 if (m_Deleted)
233 {
235 }
236
237 Status = ZwQueryValueKey(m_hKey, ValueName, KeyValueInformationClass, KeyValueInformation, Length, ResultLength);
238 DPRINT("CRegistryKey::QueryValueKey entered %p value %wZ Status %x\n", this, ValueName, Status);
239 return Status;
240}
241
243NTAPI
244CRegistryKey::SetValueKey(
246 IN ULONG Type,
247 IN PVOID Data,
249 )
250{
251 DPRINT("CRegistryKey::SetValueKey entered %S\n", ValueName->Buffer);
253
254 if (m_Deleted)
255 {
257 }
258
259 return ZwSetValueKey(m_hKey, ValueName, 0, Type, Data, DataSize);
260}
261
263NTAPI
265 OUT PREGISTRYKEY* OutRegistryKey,
266 IN PUNKNOWN OuterUnknown OPTIONAL,
267 IN ULONG RegistryKeyType,
270 IN PVOID SubDevice OPTIONAL,
274{
275 HANDLE hHandle;
277 CRegistryKey * RegistryKey;
278 PPCLASS_DEVICE_EXTENSION DeviceExt;
279 PSUBDEVICE_DESCRIPTOR SubDeviceDescriptor;
280 ISubdevice * Device;
281 PSYMBOLICLINK_ENTRY SymEntry;
282 BOOL CanDelete = FALSE;
283
284 DPRINT("PcNewRegistryKey entered\n");
285
286 if (!OutRegistryKey)
288
289 if (RegistryKeyType != GeneralRegistryKey &&
290 RegistryKeyType != DeviceRegistryKey &&
291 RegistryKeyType != DriverRegistryKey &&
292 RegistryKeyType != HwProfileRegistryKey &&
293 RegistryKeyType != DeviceInterfaceRegistryKey)
294 {
296 }
297
298 // check for the key type
299 if (RegistryKeyType == GeneralRegistryKey)
300 {
301 // do we have the required object attributes
302 if (!ObjectAttributes)
303 {
304 // object attributes is mandatory
306 }
307 // try to create the key
308 Status = ZwCreateKey(&hHandle, DesiredAccess, ObjectAttributes, 0, NULL, CreateOptions, Disposition);
309
310 // key can be deleted
311 CanDelete = TRUE;
312 }
313 else if (RegistryKeyType == DeviceRegistryKey ||
314 RegistryKeyType == DriverRegistryKey ||
315 RegistryKeyType == HwProfileRegistryKey)
316 {
317 // check for HwProfileRegistryKey case
318 if (RegistryKeyType == HwProfileRegistryKey)
319 {
320 // IoOpenDeviceRegistryKey used different constant
322 }
323
324 // obtain the new device extension
325 DeviceExt = (PPCLASS_DEVICE_EXTENSION) ((PDEVICE_OBJECT)DeviceObject)->DeviceExtension;
326
327 Status = IoOpenDeviceRegistryKey(DeviceExt->PhysicalDeviceObject, RegistryKeyType, DesiredAccess, &hHandle);
328 }
329 else if (RegistryKeyType == DeviceInterfaceRegistryKey)
330 {
331 if (SubDevice == NULL)
332 {
333 // invalid parameter
335 }
336
337 // look up our undocumented interface
338 Status = ((PUNKNOWN)SubDevice)->QueryInterface(IID_ISubdevice, (LPVOID*)&Device);
339
340 if (!NT_SUCCESS(Status))
341 {
342 DPRINT("No ISubdevice interface\n");
343 // invalid parameter
345 }
346
347 // get the subdevice descriptor
348 Status = Device->GetDescriptor(&SubDeviceDescriptor);
349 if (!NT_SUCCESS(Status))
350 {
351 DPRINT("Failed to get subdevice descriptor %x\n", Status);
352 ((PUNKNOWN)SubDevice)->Release();
353 return STATUS_UNSUCCESSFUL;
354 }
355
356 // is there an registered device interface
357 if (IsListEmpty(&SubDeviceDescriptor->SymbolicLinkList))
358 {
359 DPRINT("No device interface registered\n");
360 ((PUNKNOWN)SubDevice)->Release();
361 return STATUS_UNSUCCESSFUL;
362 }
363
364 // get the first symbolic link
366
367 // open device interface
369
370 // release subdevice interface
371 ((PUNKNOWN)SubDevice)->Release();
372 }
373
374 // check for success
375 if (!NT_SUCCESS(Status))
376 {
377 DPRINT1("PcNewRegistryKey failed with %lx\n", Status);
378 return Status;
379 }
380
381 // allocate new registry key object
382 RegistryKey = new(NonPagedPool, TAG_PORTCLASS)CRegistryKey(OuterUnknown, hHandle, CanDelete);
383 if (!RegistryKey)
384 {
385 // not enough memory
386 ZwClose(hHandle);
388 }
389
390 // query for interface
391 Status = RegistryKey->QueryInterface(IID_IRegistryKey, (PVOID*)OutRegistryKey);
392
393 if (!NT_SUCCESS(Status))
394 {
395 // out of memory
396 delete RegistryKey;
397 }
398
399 DPRINT("PcNewRegistryKey result %p\n", *OutRegistryKey);
400 return STATUS_SUCCESS;
401}
Type
Definition: Type.h:7
struct SYMBOLICLINK_ENTRY * PSYMBOLICLINK_ENTRY
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define STDMETHODIMP
Definition: basetyps.h:43
const GUID IID_IUnknown
STDMETHODIMP QueryInterface(REFIID InterfaceId, PVOID *Interface)
Definition: registry.cpp:46
BOOL m_Deleted
Definition: registry.cpp:31
CRegistryKey(IUnknown *OuterUnknown, HANDLE hKey, BOOL CanDelete)
Definition: registry.cpp:20
virtual ~CRegistryKey()
Definition: registry.cpp:35
BOOL m_CanDelete
Definition: registry.cpp:32
HANDLE m_hKey
Definition: registry.cpp:30
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI PcNewRegistryKey(OUT PREGISTRYKEY *OutRegistryKey, IN PUNKNOWN OuterUnknown OPTIONAL, IN ULONG RegistryKeyType, IN ACCESS_MASK DesiredAccess, IN PVOID DeviceObject OPTIONAL, IN PVOID SubDevice OPTIONAL, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN ULONG CreateOptions OPTIONAL, OUT PULONG Disposition OPTIONAL)
Definition: registry.cpp:264
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NonPagedPool
Definition: env_spec_w32.h:307
unsigned int BOOL
Definition: ntddk_ex.h:94
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_INHERIT
Definition: winternl.h:225
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
ULONG AddRef()
static PWSTR GuidString
Definition: apphelp.c:93
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING SubKeyName
Definition: ndis.h:4725
_In_ ULONG _In_ KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass
Definition: cmfuncs.h:94
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
ULONG ACCESS_MASK
Definition: nt_native.h:40
enum _KEY_VALUE_INFORMATION_CLASS KEY_VALUE_INFORMATION_CLASS
Definition: reg.c:135
enum _KEY_INFORMATION_CLASS KEY_INFORMATION_CLASS
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define RTL_REGISTRY_HANDLE
Definition: nt_native.h:168
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI IoOpenDeviceInterfaceRegistryKey(IN PUNICODE_STRING SymbolicLinkName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DeviceInterfaceKey)
Definition: deviface.c:241
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
IRegistryKey * PREGISTRYKEY
Definition: portcls.h:1009
@ DriverRegistryKey
Definition: portcls.h:902
@ GeneralRegistryKey
Definition: portcls.h:900
@ DeviceInterfaceRegistryKey
Definition: portcls.h:904
@ DeviceRegistryKey
Definition: portcls.h:901
@ HwProfileRegistryKey
Definition: portcls.h:903
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
struct PCLASS_DEVICE_EXTENSION * PPCLASS_DEVICE_EXTENSION
#define TAG_PORTCLASS
Definition: private.hpp:24
#define REFIID
Definition: guiddef.h:118
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
base of all file and directory entries
Definition: entries.h:83
PDEVICE_OBJECT PhysicalDeviceObject
Definition: private.hpp:402
LIST_ENTRY SymbolicLinkList
Definition: interfaces.hpp:219
Definition: interfaces.hpp:174
UNICODE_STRING SymbolicLink
Definition: interfaces.hpp:176
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
#define PLUGPLAY_REGKEY_CURRENT_HWPROFILE
Definition: iofuncs.h:2788
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786
_In_ ULONG _In_ KEY_INFORMATION_CLASS KeyInformationClass
Definition: zwfuncs.h:167