[NTOSKRNL] Implement SeGetLogonIdDeviceMap
[reactos.git] / ntoskrnl / include / internal / ob.h
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/internal/ob.h
5 * PURPOSE: Internal header for the Object Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 //
10 // Define this if you want debugging support
11 //
12 #define _OB_DEBUG_ 0x00
13
14 //
15 // These define the Debug Masks Supported
16 //
17 #define OB_HANDLE_DEBUG 0x01
18 #define OB_NAMESPACE_DEBUG 0x02
19 #define OB_SECURITY_DEBUG 0x04
20 #define OB_REFERENCE_DEBUG 0x08
21 #define OB_CALLBACK_DEBUG 0x10
22
23 //
24 // Debug/Tracing support
25 //
26 #if _OB_DEBUG_
27 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
28 #define OBTRACE DbgPrintEx
29 #else
30 #define OBTRACE(x, ...) \
31 if (x & ObpTraceLevel) DbgPrint(__VA_ARGS__)
32 #endif
33 #else
34 #define OBTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__)
35 #endif
36
37 //
38 // Mask to detect GENERIC_XXX access masks being used
39 //
40 #define GENERIC_ACCESS \
41 (GENERIC_READ | \
42 GENERIC_WRITE | \
43 GENERIC_EXECUTE | \
44 GENERIC_ALL)
45
46 //
47 // Handle Bit Flags
48 //
49 #define OBJ_PROTECT_CLOSE 0x01
50 //#define OBJ_INHERIT 0x02
51 #define OBJ_AUDIT_OBJECT_CLOSE 0x04
52 #define OBJ_HANDLE_ATTRIBUTES (OBJ_PROTECT_CLOSE |\
53 OBJ_INHERIT | \
54 OBJ_AUDIT_OBJECT_CLOSE)
55
56 //
57 // Identifies a Kernel Handle
58 //
59 #ifdef _WIN64
60 #define KERNEL_HANDLE_FLAG 0xFFFFFFFF80000000ULL
61 #else
62 #define KERNEL_HANDLE_FLAG 0x80000000
63 #endif
64 #define ObpIsKernelHandle(Handle, ProcessorMode) \
65 ((((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) == KERNEL_HANDLE_FLAG) && \
66 ((ProcessorMode) == KernelMode) && \
67 ((Handle) != NtCurrentProcess()) && \
68 ((Handle) != NtCurrentThread()))
69
70 //
71 // Converts to and from a Kernel Handle to a normal handle
72 //
73 #define ObKernelHandleToHandle(Handle) \
74 (HANDLE)((ULONG_PTR)(Handle) & ~KERNEL_HANDLE_FLAG)
75 #define ObMarkHandleAsKernelHandle(Handle) \
76 (HANDLE)((ULONG_PTR)(Handle) | KERNEL_HANDLE_FLAG)
77
78 //
79 // Converts from an EXHANDLE object to a POBJECT_HEADER
80 //
81 #define ObpGetHandleObject(x) \
82 ((POBJECT_HEADER)((ULONG_PTR)x->Object & ~OBJ_HANDLE_ATTRIBUTES))
83
84 //
85 // Recovers the security descriptor from a cached security descriptor header
86 //
87 #define ObpGetHeaderForSd(x) \
88 CONTAINING_RECORD((x), SECURITY_DESCRIPTOR_HEADER, SecurityDescriptor)
89
90 //
91 // Recovers the security descriptor from a cached security descriptor list entry
92 //
93 #define ObpGetHeaderForEntry(x) \
94 CONTAINING_RECORD((x), SECURITY_DESCRIPTOR_HEADER, Link)
95
96 //
97 // Context Structures for Ex*Handle Callbacks
98 //
99 typedef struct _OBP_SET_HANDLE_ATTRIBUTES_CONTEXT
100 {
101 KPROCESSOR_MODE PreviousMode;
102 OBJECT_HANDLE_ATTRIBUTE_INFORMATION Information;
103 } OBP_SET_HANDLE_ATTRIBUTES_CONTEXT, *POBP_SET_HANDLE_ATTRIBUTES_CONTEXT;
104
105 typedef struct _OBP_CLOSE_HANDLE_CONTEXT
106 {
107 PHANDLE_TABLE HandleTable;
108 KPROCESSOR_MODE AccessMode;
109 } OBP_CLOSE_HANDLE_CONTEXT, *POBP_CLOSE_HANDLE_CONTEXT;
110
111 typedef struct _OBP_FIND_HANDLE_DATA
112 {
113 POBJECT_HEADER ObjectHeader;
114 POBJECT_TYPE ObjectType;
115 POBJECT_HANDLE_INFORMATION HandleInformation;
116 } OBP_FIND_HANDLE_DATA, *POBP_FIND_HANDLE_DATA;
117
118 //
119 // Cached Security Descriptor Header
120 //
121 typedef struct _SECURITY_DESCRIPTOR_HEADER
122 {
123 LIST_ENTRY Link;
124 ULONG RefCount;
125 ULONG FullHash;
126 QUAD SecurityDescriptor;
127 } SECURITY_DESCRIPTOR_HEADER, *PSECURITY_DESCRIPTOR_HEADER;
128
129 //
130 // Cached Security Descriptor List
131 //
132 typedef struct _OB_SD_CACHE_LIST
133 {
134 EX_PUSH_LOCK PushLock;
135 LIST_ENTRY Head;
136 } OB_SD_CACHE_LIST, *POB_SD_CACHE_LIST;
137
138 //
139 // Structure for quick-compare of a DOS Device path
140 //
141 typedef union
142 {
143 WCHAR Name[sizeof(ULARGE_INTEGER) / sizeof(WCHAR)];
144 ULARGE_INTEGER Alignment;
145 } ALIGNEDNAME;
146
147 //
148 // Private Temporary Buffer for Lookup Routines
149 //
150 #define TAG_OB_TEMP_STORAGE 'tSbO'
151 typedef struct _OB_TEMP_BUFFER
152 {
153 ACCESS_STATE LocalAccessState;
154 OBJECT_CREATE_INFORMATION ObjectCreateInfo;
155 OBP_LOOKUP_CONTEXT LookupContext;
156 AUX_ACCESS_DATA AuxData;
157 } OB_TEMP_BUFFER, *POB_TEMP_BUFFER;
158
159 //
160 // Startup and Shutdown Functions
161 //
162 INIT_FUNCTION
163 BOOLEAN
164 NTAPI
165 ObInitSystem(
166 VOID
167 );
168
169 VOID
170 NTAPI
171 ObShutdownSystem(
172 VOID
173 );
174
175 //
176 // Directory Namespace Functions
177 //
178 BOOLEAN
179 NTAPI
180 ObpDeleteEntryDirectory(
181 IN POBP_LOOKUP_CONTEXT Context
182 );
183
184 BOOLEAN
185 NTAPI
186 ObpInsertEntryDirectory(
187 IN POBJECT_DIRECTORY Parent,
188 IN POBP_LOOKUP_CONTEXT Context,
189 IN POBJECT_HEADER ObjectHeader
190 );
191
192 PVOID
193 NTAPI
194 ObpLookupEntryDirectory(
195 IN POBJECT_DIRECTORY Directory,
196 IN PUNICODE_STRING Name,
197 IN ULONG Attributes,
198 IN UCHAR SearchShadow,
199 IN POBP_LOOKUP_CONTEXT Context
200 );
201
202 //
203 // Symbolic Link Functions
204 //
205 VOID
206 NTAPI
207 ObpDeleteSymbolicLink(
208 IN PVOID ObjectBody
209 );
210
211 NTSTATUS
212 NTAPI
213 ObpParseSymbolicLink(
214 IN PVOID ParsedObject,
215 IN PVOID ObjectType,
216 IN OUT PACCESS_STATE AccessState,
217 IN KPROCESSOR_MODE AccessMode,
218 IN ULONG Attributes,
219 IN OUT PUNICODE_STRING FullPath,
220 IN OUT PUNICODE_STRING RemainingName,
221 IN OUT PVOID Context OPTIONAL,
222 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
223 OUT PVOID *NextObject
224 );
225
226 VOID
227 NTAPI
228 ObpCreateSymbolicLinkName(
229 IN POBJECT_SYMBOLIC_LINK SymbolicLink
230 );
231
232 VOID
233 NTAPI
234 ObpDeleteSymbolicLinkName(
235 IN POBJECT_SYMBOLIC_LINK SymbolicLink
236 );
237
238 //
239 // Process/Handle Table Init/Rundown
240 //
241 NTSTATUS
242 NTAPI
243 ObInitProcess(
244 IN PEPROCESS Parent OPTIONAL,
245 IN PEPROCESS Process
246 );
247
248 PHANDLE_TABLE
249 NTAPI
250 ObReferenceProcessHandleTable(
251 IN PEPROCESS Process
252 );
253
254 VOID
255 NTAPI
256 ObDereferenceProcessHandleTable(
257 IN PEPROCESS Process
258 );
259
260 VOID
261 NTAPI
262 ObKillProcess(
263 IN PEPROCESS Process
264 );
265
266 //
267 // Object Lookup Functions
268 //
269 NTSTATUS
270 NTAPI
271 ObpLookupObjectName(
272 IN HANDLE RootHandle OPTIONAL,
273 IN OUT PUNICODE_STRING ObjectName,
274 IN ULONG Attributes,
275 IN POBJECT_TYPE ObjectType,
276 IN KPROCESSOR_MODE AccessMode,
277 IN OUT PVOID ParseContext,
278 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
279 IN PVOID InsertObject OPTIONAL,
280 IN OUT PACCESS_STATE AccessState,
281 OUT POBP_LOOKUP_CONTEXT LookupContext,
282 OUT PVOID *FoundObject
283 );
284
285 //
286 // Object Attribute Functions
287 //
288 BOOLEAN
289 NTAPI
290 ObpSetHandleAttributes(
291 IN OUT PHANDLE_TABLE_ENTRY HandleTableEntry,
292 IN ULONG_PTR Context
293 );
294
295 NTSTATUS
296 NTAPI
297 ObQueryDeviceMapInformation(
298 IN PEPROCESS Process,
299 OUT PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo,
300 IN ULONG Flags
301 );
302
303 //
304 // Object Lifetime Functions
305 //
306 VOID
307 NTAPI
308 ObpDeleteObject(
309 IN PVOID Object,
310 IN BOOLEAN CalledFromWorkerThread
311 );
312
313 LONG
314 FASTCALL
315 ObDereferenceObjectEx(
316 IN PVOID Object,
317 IN LONG Count
318 );
319
320 LONG
321 FASTCALL
322 ObReferenceObjectEx(
323 IN PVOID Object,
324 IN LONG Count
325 );
326
327 BOOLEAN
328 FASTCALL
329 ObReferenceObjectSafe(
330 IN PVOID Object
331 );
332
333 VOID
334 NTAPI
335 ObpReapObject(
336 IN PVOID Unused
337 );
338
339 VOID
340 FASTCALL
341 ObpSetPermanentObject(
342 IN PVOID ObjectBody,
343 IN BOOLEAN Permanent
344 );
345
346 VOID
347 NTAPI
348 ObpDeleteNameCheck(
349 IN PVOID Object
350 );
351
352 VOID
353 NTAPI
354 ObClearProcessHandleTable(
355 IN PEPROCESS Process
356 );
357
358 NTSTATUS
359 NTAPI
360 ObDuplicateObject(
361 IN PEPROCESS SourceProcess,
362 IN HANDLE SourceHandle,
363 IN PEPROCESS TargetProcess OPTIONAL,
364 IN PHANDLE TargetHandle OPTIONAL,
365 IN ACCESS_MASK DesiredAccess,
366 IN ULONG HandleAttributes,
367 IN ULONG Options,
368 IN KPROCESSOR_MODE PreviousMode
369 );
370
371 VOID
372 NTAPI
373 ObFreeObjectCreateInfoBuffer(
374 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
375 );
376
377 VOID
378 NTAPI
379 ObpFreeObjectNameBuffer(
380 IN PUNICODE_STRING Name
381 );
382
383 VOID
384 NTAPI
385 ObpDeleteObjectType(
386 IN PVOID Object
387 );
388
389 NTSTATUS
390 NTAPI
391 ObReferenceFileObjectForWrite(
392 IN HANDLE Handle,
393 IN KPROCESSOR_MODE AccessMode,
394 OUT PFILE_OBJECT *FileObject,
395 OUT POBJECT_HANDLE_INFORMATION HandleInformation
396 );
397
398 //
399 // DOS Devices Functions
400 //
401 NTSTATUS
402 NTAPI
403 ObSetDeviceMap(
404 IN PEPROCESS Process,
405 IN HANDLE DirectoryHandle
406 );
407
408 NTSTATUS
409 NTAPI
410 ObSetDirectoryDeviceMap(OUT PDEVICE_MAP * DeviceMap,
411 IN HANDLE DirectoryHandle
412 );
413
414 VOID
415 NTAPI
416 ObDereferenceDeviceMap(
417 IN PEPROCESS Process
418 );
419
420 VOID
421 FASTCALL
422 ObfDereferenceDeviceMap(
423 IN PDEVICE_MAP DeviceMap
424 );
425
426 VOID
427 NTAPI
428 ObInheritDeviceMap(
429 IN PEPROCESS Parent,
430 IN PEPROCESS Process
431 );
432
433 INIT_FUNCTION
434 NTSTATUS
435 NTAPI
436 ObpCreateDosDevicesDirectory(
437 VOID
438 );
439
440 ULONG
441 NTAPI
442 ObIsLUIDDeviceMapsEnabled(
443 VOID
444 );
445
446 //
447 // Security descriptor cache functions
448 //
449 INIT_FUNCTION
450 NTSTATUS
451 NTAPI
452 ObpInitSdCache(
453 VOID
454 );
455
456 PSECURITY_DESCRIPTOR
457 NTAPI
458 ObpReferenceSecurityDescriptor(
459 IN POBJECT_HEADER ObjectHeader
460 );
461
462 //
463 // Object Security Routines
464 //
465 BOOLEAN
466 NTAPI
467 ObCheckObjectAccess(
468 IN PVOID Object,
469 IN OUT PACCESS_STATE AccessState,
470 IN BOOLEAN LockHeld,
471 IN KPROCESSOR_MODE AccessMode,
472 OUT PNTSTATUS ReturnedStatus
473 );
474
475 BOOLEAN
476 NTAPI
477 ObCheckCreateObjectAccess(
478 IN PVOID Object,
479 IN ACCESS_MASK CreateAccess,
480 IN PACCESS_STATE AccessState,
481 IN PUNICODE_STRING ComponentName,
482 IN BOOLEAN LockHeld,
483 IN KPROCESSOR_MODE AccessMode,
484 OUT PNTSTATUS AccessStatus
485 );
486
487 BOOLEAN
488 NTAPI
489 ObpCheckTraverseAccess(
490 IN PVOID Object,
491 IN ACCESS_MASK TraverseAccess,
492 IN PACCESS_STATE AccessState OPTIONAL,
493 IN BOOLEAN LockHeld,
494 IN KPROCESSOR_MODE AccessMode,
495 OUT PNTSTATUS AccessStatus
496 );
497
498 BOOLEAN
499 NTAPI
500 ObpCheckObjectReference(
501 IN PVOID Object,
502 IN OUT PACCESS_STATE AccessState,
503 IN BOOLEAN LockHeld,
504 IN KPROCESSOR_MODE AccessMode,
505 OUT PNTSTATUS AccessStatus
506 );
507
508 //
509 // Default Object Security Callback Routines
510 //
511 NTSTATUS
512 NTAPI
513 ObAssignObjectSecurityDescriptor(
514 IN PVOID Object,
515 IN PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
516 IN POOL_TYPE PoolType
517 );
518
519 NTSTATUS
520 NTAPI
521 ObDeassignSecurity(
522 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
523 );
524
525 NTSTATUS
526 NTAPI
527 ObQuerySecurityDescriptorInfo(
528 IN PVOID Object,
529 IN PSECURITY_INFORMATION SecurityInformation,
530 OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
531 IN OUT PULONG Length,
532 IN PSECURITY_DESCRIPTOR *OutputSecurityDescriptor
533 );
534
535 NTSTATUS
536 NTAPI
537 ObSetSecurityDescriptorInfo(
538 IN PVOID Object,
539 IN PSECURITY_INFORMATION SecurityInformation,
540 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
541 IN OUT PSECURITY_DESCRIPTOR *OutputSecurityDescriptor,
542 IN POOL_TYPE PoolType,
543 IN PGENERIC_MAPPING GenericMapping
544 );
545
546 //
547 // Executive Fast Referencing Functions
548 //
549 VOID
550 FASTCALL
551 ObInitializeFastReference(
552 IN PEX_FAST_REF FastRef,
553 IN PVOID Object
554 );
555
556 PVOID
557 FASTCALL
558 ObFastReplaceObject(
559 IN PEX_FAST_REF FastRef,
560 IN PVOID Object
561 );
562
563 PVOID
564 FASTCALL
565 ObFastReferenceObject(
566 IN PEX_FAST_REF FastRef
567 );
568
569 PVOID
570 FASTCALL
571 ObFastReferenceObjectLocked(
572 IN PEX_FAST_REF FastRef
573 );
574
575 VOID
576 FASTCALL
577 ObFastDereferenceObject(
578 IN PEX_FAST_REF FastRef,
579 IN PVOID Object
580 );
581
582 //
583 // Object Create and Object Name Capture Functions
584 //
585 NTSTATUS
586 NTAPI
587 ObpCaptureObjectName(
588 IN PUNICODE_STRING CapturedName,
589 IN PUNICODE_STRING ObjectName,
590 IN KPROCESSOR_MODE AccessMode,
591 IN BOOLEAN AllocateFromLookaside
592 );
593
594 NTSTATUS
595 NTAPI
596 ObpCaptureObjectCreateInformation(
597 IN POBJECT_ATTRIBUTES ObjectAttributes,
598 IN KPROCESSOR_MODE AccessMode,
599 IN KPROCESSOR_MODE CreatorMode,
600 IN BOOLEAN AllocateFromLookaside,
601 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
602 OUT PUNICODE_STRING ObjectName
603 );
604
605 //
606 // Miscellanea
607 //
608 ULONG
609 NTAPI
610 ObGetProcessHandleCount(
611 IN PEPROCESS Process
612 );
613
614 //
615 // Global data inside the Object Manager
616 //
617 extern ULONG ObpTraceLevel;
618 extern KEVENT ObpDefaultObject;
619 extern KGUARDED_MUTEX ObpDeviceMapLock;
620 extern POBJECT_TYPE ObpTypeObjectType;
621 extern POBJECT_TYPE ObpDirectoryObjectType;
622 extern POBJECT_TYPE ObpSymbolicLinkObjectType;
623 extern POBJECT_DIRECTORY ObpRootDirectoryObject;
624 extern POBJECT_DIRECTORY ObpTypeDirectoryObject;
625 extern PHANDLE_TABLE ObpKernelHandleTable;
626 extern WORK_QUEUE_ITEM ObpReaperWorkItem;
627 extern volatile PVOID ObpReaperList;
628 extern GENERAL_LOOKASIDE ObpNameBufferLookasideList, ObpCreateInfoLookasideList;
629 extern BOOLEAN IoCountOperations;
630 extern ALIGNEDNAME ObpDosDevicesShortNamePrefix;
631 extern ALIGNEDNAME ObpDosDevicesShortNameRoot;
632 extern UNICODE_STRING ObpDosDevicesShortName;
633 extern WCHAR ObpUnsecureGlobalNamesBuffer[128];
634 extern ULONG ObpUnsecureGlobalNamesLength;
635 extern ULONG ObpObjectSecurityMode;
636 extern ULONG ObpProtectionMode;
637 extern ULONG ObpLUIDDeviceMapsDisabled;
638 extern ULONG ObpLUIDDeviceMapsEnabled;
639
640 //
641 // Inlined Functions
642 //
643 #include "ob_x.h"