ReactOS  0.4.14-dev-376-gaedba84
guidobj.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/wmi/guidobj.c
5  * PURPOSE: I/O Windows Management Instrumentation (WMI) Support
6  * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <ntoskrnl.h>
12 #include <wmistr.h>
13 #include "wmip.h"
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 
19 /* GLOBALS ******************************************************************/
20 
23 {
28 };
29 
30 
31 /* FUNCTIONS *****************************************************************/
32 
34 NTAPI
37  _In_ SECURITY_OPERATION_CODE OperationType,
40  _Inout_ PULONG CapturedLength,
41  _Inout_ PSECURITY_DESCRIPTOR *ObjectSecurityDescriptor,
44 {
45  PAGED_CODE();
46 
48  ASSERT((OperationType == QuerySecurityDescriptor) ||
49  (OperationType == SetSecurityDescriptor) ||
50  (OperationType == AssignSecurityDescriptor) ||
51  (OperationType == DeleteSecurityDescriptor));
52 
53  if (OperationType == QuerySecurityDescriptor)
54  {
58  CapturedLength,
59  ObjectSecurityDescriptor);
60  }
61  else if (OperationType == SetSecurityDescriptor)
62  {
66  ObjectSecurityDescriptor,
67  PoolType,
69  }
70  else if (OperationType == AssignSecurityDescriptor)
71  {
73  return STATUS_SUCCESS;
74  }
75  else if (OperationType == DeleteSecurityDescriptor)
76  {
77  return ObDeassignSecurity(ObjectSecurityDescriptor);
78  }
79 
80  ASSERT(FALSE);
82 }
83 
84 VOID
85 NTAPI
88 {
89  PWMIP_GUID_OBJECT GuidObject = Object;
90 
91  /* Check if the object is attached to an IRP */
92  if (GuidObject->Irp != NULL)
93  {
94  /* This is not supported yet */
95  ASSERT(FALSE);
96  }
97 }
98 
99 VOID
100 NTAPI
103  _In_ PVOID Object,
106  _In_ ULONG SystemHandleCount)
107 {
108  /* For now nothing */
109 }
110 
111 NTSTATUS
112 NTAPI
114  VOID)
115 {
116  static UNICODE_STRING GuidObjectName = RTL_CONSTANT_STRING(L"WmiGuid");
117  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
119 
120  /* Setup the object type initializer */
121  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
122  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
123  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
124  ObjectTypeInitializer.GenericMapping = WmipGenericMapping;
125  ObjectTypeInitializer.PoolType = NonPagedPool;
126  ObjectTypeInitializer.MaintainHandleCount = FALSE;
127  ObjectTypeInitializer.ValidAccessMask = STANDARD_RIGHTS_ALL | 0xFFF;
128  ObjectTypeInitializer.SecurityRequired = TRUE;
129  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(WMIP_GUID_OBJECT);
130  ObjectTypeInitializer.SecurityProcedure = WmipSecurityMethod;
131  ObjectTypeInitializer.DeleteProcedure = WmipDeleteMethod;
132  ObjectTypeInitializer.CloseProcedure = WmipCloseMethod;
133 
134  /* Create the object type */
135  Status = ObCreateObjectType(&GuidObjectName,
136  &ObjectTypeInitializer,
137  0,
139  if (!NT_SUCCESS(Status))
140  {
141  DPRINT1("ObCreateObjectType failed: 0x%lx\n", Status);
142  }
143 
144  return Status;
145 }
146 
147 static
148 NTSTATUS
151  _Out_ PGUID Guid)
152 {
155 
156  /* Validate string length */
157  if (GuidString->Length != GUID_STRING_LENGTH * sizeof(WCHAR))
158  {
160  }
161 
162  /* Copy the string and wrap it in {} */
163  RtlCopyMemory(&Buffer[1], GuidString->Buffer, GuidString->Length);
164  Buffer[0] = L'{';
165  Buffer[GUID_STRING_LENGTH + 1] = L'}';
166 
167  String.Buffer = Buffer;
168  String.Length = String.MaximumLength = sizeof(Buffer);
169 
170  return RtlGUIDFromString(&String, Guid);
171 }
172 
173 static
174 NTSTATUS
176  _In_ const GUID *Guid,
177  _Out_ PWMIP_GUID_OBJECT *OutGuidObject)
178 {
180  PWMIP_GUID_OBJECT GuidObject;
182 
183  /* Initialize object attributes for an unnamed object */
185  NULL,
186  0,
187  NULL,
188  NULL); // FIXME: security descriptor!
189 
190  /* Create the GUID object */
194  KernelMode,
195  NULL,
196  sizeof(WMIP_GUID_OBJECT),
197  0,
198  0,
199  (PVOID*)&GuidObject);
200  if (!NT_SUCCESS(Status))
201  {
202  DPRINT1("WMI: failed to create GUID object: 0x%lx\n", Status);
203  return Status;
204  }
205 
206  RtlZeroMemory(GuidObject, sizeof(*GuidObject));
207  GuidObject->Guid = *Guid;
208 
209  *OutGuidObject = GuidObject;
210 
211  return STATUS_SUCCESS;
212 }
213 
214 NTSTATUS
215 NTAPI
217  _In_ LPCGUID Guid,
220  _Out_ PHANDLE OutGuidObjectHandle,
221  _Outptr_ PVOID *OutGuidObject)
222 {
223  PWMIP_GUID_OBJECT GuidObject;
226 
227  /* Create the GUID object */
228  Status = WmipCreateGuidObject(Guid, &GuidObject);
229  if (!NT_SUCCESS(Status))
230  {
231  DPRINT1("Failed to create GUID object: 0x%lx\n", Status);
232  *OutGuidObject = NULL;
233  return Status;
234  }
235 
236  /* Set handle attributes */
238 
239  /* Get a handle for the object */
240  Status = ObOpenObjectByPointer(GuidObject,
242  0,
245  AccessMode,
246  OutGuidObjectHandle);
247  if (!NT_SUCCESS(Status))
248  {
249  DPRINT1("ObOpenObjectByPointer failed: 0x%lx\n", Status);
250  ObDereferenceObject(GuidObject);
251  GuidObject = NULL;
252  }
253 
254  *OutGuidObject = GuidObject;
255 
256  return Status;
257 }
258 
259 NTSTATUS
260 NTAPI
265  _Out_ PHANDLE OutGuidObjectHandle,
266  _Outptr_ PVOID *OutGuidObject)
267 {
268  static UNICODE_STRING Prefix = RTL_CONSTANT_STRING(L"\\WmiGuid\\");
271  GUID Guid;
272  PAGED_CODE();
273 
274  /* Check if we have the expected prefix */
276  {
277  DPRINT1("WMI: Invalid prefix for guid object '%wZ'\n",
278  ObjectAttributes->ObjectName);
280  }
281 
282  /* Extract the GUID string */
283  GuidString = *ObjectAttributes->ObjectName;
284  GuidString.Buffer += Prefix.Length / sizeof(WCHAR);
285  GuidString.Length -= Prefix.Length;
286 
287  /* Convert the string into a GUID structure */
289  if (!NT_SUCCESS(Status))
290  {
291  DPRINT1("WMI: Invalid uuid format for guid '%wZ'\n", &GuidString);
292  return Status;
293  }
294 
295  return WmipOpenGuidObject(&Guid,
297  AccessMode,
298  OutGuidObjectHandle,
299  OutGuidObject);
300 }
301 
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static PWSTR GuidString
Definition: apphelp.c:91
_In_ HANDLE _In_opt_ HANDLE _Out_opt_ PHANDLE _In_ ACCESS_MASK _In_ ULONG HandleAttributes
Definition: obfuncs.h:429
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define TRUE
Definition: types.h:120
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define WMIGUID_SET
Definition: wmistr.h:160
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static NTSTATUS WmipCreateGuidObject(_In_ const GUID *Guid, _Out_ PWMIP_GUID_OBJECT *OutGuidObject)
Definition: guidobj.c:175
#define GUID_STRING_LENGTH
Definition: wmip.h:6
LONG NTSTATUS
Definition: precomp.h:26
#define _Outptr_
Definition: no_sal2.h:396
NTSTATUS NTAPI WmipSecurityMethod(_In_ PVOID Object, _In_ SECURITY_OPERATION_CODE OperationType, _In_ PSECURITY_INFORMATION SecurityInformation, _In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _Inout_ PULONG CapturedLength, _Inout_ PSECURITY_DESCRIPTOR *ObjectSecurityDescriptor, _In_ POOL_TYPE PoolType, _In_ PGENERIC_MAPPING GenericMapping)
Definition: guidobj.c:35
#define OBJ_OPENLINK
Definition: winternl.h:230
unsigned short Length
Definition: sprintf.c:451
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static WCHAR String[]
Definition: stringtable.c:55
#define WMIGUID_EXECUTE
Definition: wmistr.h:163
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2739
#define PAGED_CODE()
Definition: video.h:57
#define _In_opt_
Definition: no_sal2.h:213
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
BOOLEAN MaintainHandleCount
Definition: obtypes.h:361
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
struct _WMIP_GUID_OBJECT WMIP_GUID_OBJECT
NTSTATUS NTAPI ObSetSecurityDescriptorInfo(IN PVOID Object, IN PSECURITY_INFORMATION SecurityInformation, IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
Definition: obsecure.c:117
static GUID * Guid
Definition: apphelp.c:93
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
Definition: fltkernel.h:1339
Definition: bufpool.h:45
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
NTSTATUS NTAPI WmipInitializeGuidObjectType(VOID)
Definition: guidobj.c:113
NTSTATUS NTAPI WmipOpenGuidObjectByName(_In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE OutGuidObjectHandle, _Outptr_ PVOID *OutGuidObject)
Definition: guidobj.c:261
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD * PSECURITY_INFORMATION
Definition: ms-dtyp.idl:311
INT POOL_TYPE
Definition: typedefs.h:76
NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING, GUID *)
VOID NTAPI WmipDeleteMethod(_In_ PVOID Object)
Definition: guidobj.c:86
#define _Inout_
Definition: no_sal2.h:244
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI WmipCloseMethod(_In_opt_ PEPROCESS Process, _In_ PVOID Object, _In_ ACCESS_MASK GrantedAccess, _In_ ULONG ProcessHandleCount, _In_ ULONG SystemHandleCount)
Definition: guidobj.c:101
static NTSTATUS WmipGUIDFromString(_In_ PUNICODE_STRING GuidString, _Out_ PGUID Guid)
Definition: guidobj.c:149
static const WCHAR L[]
Definition: oid.c:1250
GENERIC_MAPPING WmipGenericMapping
Definition: guidobj.c:22
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
NTSTATUS NTAPI ObQuerySecurityDescriptorInfo(IN PVOID Object, IN PSECURITY_INFORMATION SecurityInformation, OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN OUT PULONG Length, IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor)
Definition: obsecure.c:85
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI ObDeassignSecurity(IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor)
Definition: obsecure.c:60
#define _In_
Definition: no_sal2.h:204
static GENERIC_MAPPING GenericMapping
Definition: SeInheritance.c:11
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define WMIGUID_QUERY
Definition: wmistr.h:159
OB_SECURITY_METHOD SecurityProcedure
Definition: obtypes.h:371
_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
unsigned int * PULONG
Definition: retypes.h:1
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
NTSTATUS NTAPI ObAssignObjectSecurityDescriptor(IN PVOID Object, IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL, IN POOL_TYPE PoolType)
Definition: obsecure.c:20
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
NTSTATUS NTAPI WmipOpenGuidObject(_In_ LPCGUID Guid, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE OutGuidObjectHandle, _Outptr_ PVOID *OutGuidObject)
Definition: guidobj.c:216
POBJECT_TYPE WmipGuidObjectType
Definition: guidobj.c:21
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
SECURITY_OPERATION_CODE
Definition: setypes.h:142
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define WMIGUID_ALL_ACCESS
Definition: wmistr.h:173
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14