ReactOS  0.4.13-dev-1148-g9b75b67
Registry.c
Go to the documentation of this file.
1 /*
2  * PROJECT: Filesystem Filter Manager
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: drivers/filters/fltmgr/Misc.c
5  * PURPOSE: Uncataloged functions
6  * PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include "fltmgr.h"
12 #include "fltmgrint.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 
18 /* DATA *********************************************************************/
19 
20 #define REG_SERVICES_KEY L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"
21 #define REG_PATH_LENGTH 512
22 
23 
24 /* INTERNAL FUNCTIONS ******************************************************/
25 
26 
33 {
35  UNICODE_STRING ServicesKey;
38 
39  /* Setup a local buffer to hold the services key path */
40  Path.Length = 0;
41  Path.MaximumLength = REG_PATH_LENGTH;
42  Path.Buffer = Buffer;
43 
44  /* Build up the serices key name */
46  RtlCopyUnicodeString(&Path, &ServicesKey);
48 
49  if (SubKey)
50  {
51  /* Tag on any child key */
54  }
55 
57  &Path,
59  NULL,
60  NULL);
61 
62  /* Open and return the key handle param*/
63  return ZwOpenKey(Handle, DesiredAccess, &ObjectAttributes);
64 }
65 
72  _Out_opt_ PULONG BytesRequired)
73 {
75  ULONG ValueLength = 0;
77 
78  PAGED_CODE();
79 
80  /* Get the size of the buffer required to hold the string */
81  Status = ZwQueryValueKey(KeyHandle,
82  ValueName,
84  NULL,
85  0,
86  &ValueLength);
88  {
89  return Status;
90  }
91 
92  /* Allocate the buffer */
96  if (Value == NULL)
97  {
99  goto Quit;
100  }
101 
102  /* Now read in the value */
103  Status = ZwQueryValueKey(KeyHandle,
104  ValueName,
106  Value,
107  ValueLength,
108  &ValueLength);
109  if (!NT_SUCCESS(Status))
110  {
111  goto Quit;
112  }
113 
114  /* Make sure we got the type expected */
115  if (Value->Type != Type)
116  {
118  goto Quit;
119  }
120 
121  if (BytesRequired)
122  {
123  *BytesRequired = Value->DataLength;
124  }
125 
126  /* Make sure the caller buffer is big enough to hold the data */
127  if (!BufferSize || BufferSize < Value->DataLength)
128  {
130  goto Quit;
131  }
132 
133  /* Copy the data into the caller buffer */
134  RtlCopyMemory(Buffer, Value->Data, Value->DataLength);
135 
136 Quit:
137 
138  if (Value)
140 
141  return Status;
142 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Type
Definition: Type.h:6
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
#define _In_opt_
Definition: no_sal2.h:213
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define FM_TAG_TEMP_REGISTRY
Definition: fltmgr.h:22
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1802
smooth NULL
Definition: ftsmooth.c:416
#define _Out_writes_bytes_(size)
Definition: no_sal2.h:370
#define _Out_
Definition: no_sal2.h:323
Definition: bufpool.h:45
NTSTATUS FltpReadRegistryValue(_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _In_opt_ ULONG Type, _Out_writes_bytes_(BufferSize) PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG BytesRequired)
Definition: Registry.c:67
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define _Out_opt_
Definition: no_sal2.h:339
_In_ HANDLE Handle
Definition: extypes.h:390
NTSTATUS FltpOpenFilterServicesKey(_In_ PFLT_FILTER Filter, _In_ ACCESS_MASK DesiredAccess, _In_opt_ PUNICODE_STRING SubKey, _Out_ PHANDLE Handle)
Definition: Registry.c:28
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define BufferSize
Definition: classpnp.h:419
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
UNICODE_STRING Name
Definition: fltmgrint.h:100
PRTL_UNICODE_STRING_BUFFER Path
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define REG_SERVICES_KEY
Definition: Registry.c:20
#define REG_PATH_LENGTH
Definition: Registry.c:21