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)
9 /* INCLUDES *****************************************************************/
19 /* GLOBALS ******************************************************************/
21 POBJECT_TYPE WmipGuidObjectType
;
22 GENERIC_MAPPING WmipGenericMapping
=
31 /* FUNCTIONS *****************************************************************/
37 _In_ SECURITY_OPERATION_CODE OperationType
,
38 _In_ PSECURITY_INFORMATION SecurityInformation
,
39 _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
,
40 _Inout_ PULONG CapturedLength
,
41 _Inout_ PSECURITY_DESCRIPTOR
*ObjectSecurityDescriptor
,
42 _In_ POOL_TYPE PoolType
,
43 _In_ PGENERIC_MAPPING GenericMapping
)
47 ASSERT((PoolType
== PagedPool
) || (PoolType
== NonPagedPool
));
48 ASSERT((OperationType
== QuerySecurityDescriptor
) ||
49 (OperationType
== SetSecurityDescriptor
) ||
50 (OperationType
== AssignSecurityDescriptor
) ||
51 (OperationType
== DeleteSecurityDescriptor
));
53 if (OperationType
== QuerySecurityDescriptor
)
55 return ObQuerySecurityDescriptorInfo(Object
,
59 ObjectSecurityDescriptor
);
61 else if (OperationType
== SetSecurityDescriptor
)
63 return ObSetSecurityDescriptorInfo(Object
,
66 ObjectSecurityDescriptor
,
70 else if (OperationType
== AssignSecurityDescriptor
)
72 ObAssignObjectSecurityDescriptor(Object
, SecurityDescriptor
, PoolType
);
73 return STATUS_SUCCESS
;
75 else if (OperationType
== DeleteSecurityDescriptor
)
77 return ObDeassignSecurity(ObjectSecurityDescriptor
);
81 return STATUS_INVALID_PARAMETER
;
89 PWMIP_GUID_OBJECT GuidObject
= Object
;
91 /* Check if the object is attached to an IRP */
92 if (GuidObject
->Irp
!= NULL
)
94 /* This is not supported yet */
102 _In_opt_ PEPROCESS Process
,
104 _In_ ACCESS_MASK GrantedAccess
,
105 _In_ ULONG ProcessHandleCount
,
106 _In_ ULONG SystemHandleCount
)
108 /* For now nothing */
113 WmipInitializeGuidObjectType(
116 static UNICODE_STRING GuidObjectName
= RTL_CONSTANT_STRING(L
"WmiGuid");
117 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer
;
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
;
134 /* Create the object type */
135 Status
= ObCreateObjectType(&GuidObjectName
,
136 &ObjectTypeInitializer
,
138 &WmipGuidObjectType
);
139 if (!NT_SUCCESS(Status
))
141 DPRINT1("ObCreateObjectType failed: 0x%lx\n", Status
);
150 _In_ PUNICODE_STRING GuidString
,
153 WCHAR Buffer
[GUID_STRING_LENGTH
+ 2];
154 UNICODE_STRING String
;
156 /* Validate string length */
157 if (GuidString
->Length
!= GUID_STRING_LENGTH
* sizeof(WCHAR
))
159 return STATUS_INVALID_PARAMETER
;
162 /* Copy the string and wrap it in {} */
163 RtlCopyMemory(&Buffer
[1], GuidString
->Buffer
, GuidString
->Length
);
165 Buffer
[GUID_STRING_LENGTH
+ 1] = L
'}';
167 String
.Buffer
= Buffer
;
168 String
.Length
= String
.MaximumLength
= sizeof(Buffer
);
170 return RtlGUIDFromString(&String
, Guid
);
175 WmipCreateGuidObject(
176 _In_
const GUID
*Guid
,
177 _Out_ PWMIP_GUID_OBJECT
*OutGuidObject
)
179 OBJECT_ATTRIBUTES ObjectAttributes
;
180 PWMIP_GUID_OBJECT GuidObject
;
183 /* Initialize object attributes for an unnamed object */
184 InitializeObjectAttributes(&ObjectAttributes
,
188 NULL
); // FIXME: security descriptor!
190 /* Create the GUID object */
191 Status
= ObCreateObject(KernelMode
,
196 sizeof(WMIP_GUID_OBJECT
),
199 (PVOID
*)&GuidObject
);
200 if (!NT_SUCCESS(Status
))
202 DPRINT1("WMI: failed to create GUID object: 0x%lx\n", Status
);
206 RtlZeroMemory(GuidObject
, sizeof(*GuidObject
));
207 GuidObject
->Guid
= *Guid
;
209 *OutGuidObject
= GuidObject
;
211 return STATUS_SUCCESS
;
218 _In_ ACCESS_MASK DesiredAccess
,
219 _In_ KPROCESSOR_MODE AccessMode
,
220 _Out_ PHANDLE OutGuidObjectHandle
,
221 _Outptr_ PVOID
*OutGuidObject
)
223 PWMIP_GUID_OBJECT GuidObject
;
224 ULONG HandleAttributes
;
227 /* Create the GUID object */
228 Status
= WmipCreateGuidObject(Guid
, &GuidObject
);
229 if (!NT_SUCCESS(Status
))
231 DPRINT1("Failed to create GUID object: 0x%lx\n", Status
);
232 *OutGuidObject
= NULL
;
236 /* Set handle attributes */
237 HandleAttributes
= (AccessMode
== KernelMode
) ? OBJ_KERNEL_HANDLE
: 0;
239 /* Get a handle for the object */
240 Status
= ObOpenObjectByPointer(GuidObject
,
246 OutGuidObjectHandle
);
247 if (!NT_SUCCESS(Status
))
249 DPRINT1("ObOpenObjectByPointer failed: 0x%lx\n", Status
);
250 ObDereferenceObject(GuidObject
);
254 *OutGuidObject
= GuidObject
;
261 WmipOpenGuidObjectByName(
262 _In_ POBJECT_ATTRIBUTES ObjectAttributes
,
263 _In_ ACCESS_MASK DesiredAccess
,
264 _In_ KPROCESSOR_MODE AccessMode
,
265 _Out_ PHANDLE OutGuidObjectHandle
,
266 _Outptr_ PVOID
*OutGuidObject
)
268 static UNICODE_STRING Prefix
= RTL_CONSTANT_STRING(L
"\\WmiGuid\\");
269 UNICODE_STRING GuidString
;
274 /* Check if we have the expected prefix */
275 if (!RtlPrefixUnicodeString(&Prefix
, ObjectAttributes
->ObjectName
, FALSE
))
277 DPRINT1("WMI: Invalid prefix for guid object '%wZ'\n",
278 ObjectAttributes
->ObjectName
);
279 return STATUS_INVALID_PARAMETER
;
282 /* Extract the GUID string */
283 GuidString
= *ObjectAttributes
->ObjectName
;
284 GuidString
.Buffer
+= Prefix
.Length
/ sizeof(WCHAR
);
285 GuidString
.Length
-= Prefix
.Length
;
287 /* Convert the string into a GUID structure */
288 Status
= WmipGUIDFromString(&GuidString
, &Guid
);
289 if (!NT_SUCCESS(Status
))
291 DPRINT1("WMI: Invalid uuid format for guid '%wZ'\n", &GuidString
);
295 return WmipOpenGuidObject(&Guid
,