ReactOS 0.4.15-dev-5666-gc548b97
devicemap.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for devicemap.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI ObSetDeviceMap (IN PEPROCESS Process, IN HANDLE DirectoryHandle)
 
NTSTATUS NTAPI ObSetDirectoryDeviceMap (OUT PDEVICE_MAP *DeviceMap, IN HANDLE DirectoryHandle)
 
NTSTATUS NTAPI ObpSetCurrentProcessDeviceMap (VOID)
 
PDEVICE_MAP NTAPI ObpReferenceDeviceMap (VOID)
 
VOID NTAPI ObDereferenceDeviceMap (IN PEPROCESS Process)
 
VOID FASTCALL ObfDereferenceDeviceMap (IN PDEVICE_MAP DeviceMap)
 
VOID NTAPI ObInheritDeviceMap (IN PEPROCESS Parent, IN PEPROCESS Process)
 
NTSTATUS NTAPI ObQueryDeviceMapInformation (_In_opt_ PEPROCESS Process, _Out_ PPROCESS_DEVICEMAP_INFORMATION DeviceMapInfo, _In_ ULONG Flags)
 
ULONG NTAPI ObIsLUIDDeviceMapsEnabled (VOID)
 

Variables

ULONG ObpLUIDDeviceMapsDisabled
 
ULONG ObpLUIDDeviceMapsEnabled
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file devicemap.c.

Function Documentation

◆ ObDereferenceDeviceMap()

VOID NTAPI ObDereferenceDeviceMap ( IN PEPROCESS  Process)

Definition at line 456 of file devicemap.c.

457{
458 PDEVICE_MAP DeviceMap;
459
460 DPRINT("ObDereferenceDeviceMap()\n");
461
462 /* Get the pointer to this process devicemap and reset it
463 holding the device map lock */
465 DeviceMap = Process->DeviceMap;
466 Process->DeviceMap = NULL;
468
469 /* Continue only if there is a device map */
470 if (DeviceMap != NULL)
471 ObfDereferenceDeviceMap(DeviceMap);
472}
VOID FASTCALL ObfDereferenceDeviceMap(IN PDEVICE_MAP DeviceMap)
Definition: devicemap.c:477
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
KGUARDED_MUTEX ObpDeviceMapLock
Definition: oblife.c:24
#define DPRINT
Definition: sndvol32.h:71

Referenced by PspDeleteProcess(), and PspSetPrimaryToken().

◆ ObfDereferenceDeviceMap()

VOID FASTCALL ObfDereferenceDeviceMap ( IN PDEVICE_MAP  DeviceMap)

Definition at line 477 of file devicemap.c.

478{
479 DPRINT("ObfDereferenceDeviceMap()\n");
480
481 /* Acquire the device map lock */
483
484 /* Decrement the reference counter */
485 DeviceMap->ReferenceCount--;
486 DPRINT("ReferenceCount: %lu\n", DeviceMap->ReferenceCount);
487
488 /* Leave, if there are still references to this device map */
489 if (DeviceMap->ReferenceCount != 0)
490 {
491 /* Release the device map lock and leave */
493 return;
494 }
495
496 /* Nobody is referencing it anymore, unlink the DOS directory */
497 DeviceMap->DosDevicesDirectory->DeviceMap = NULL;
498
499 /* Release the devicemap lock */
501
502 /* Dereference the DOS Devices Directory and free the Device Map */
503 ObMakeTemporaryObject(DeviceMap->DosDevicesDirectory);
504 ObDereferenceObject(DeviceMap->DosDevicesDirectory);
505 ExFreePoolWithTag(DeviceMap, 'mDbO');
506}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1361
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by ObDereferenceDeviceMap(), ObpLookupObjectName(), ObpSetCurrentProcessDeviceMap(), ObQueryDeviceMapInformation(), ObSetDeviceMap(), SeGetLogonIdDeviceMap(), SepRmDeleteLogonSession(), and SepRmDereferenceLogonSession().

◆ ObInheritDeviceMap()

VOID NTAPI ObInheritDeviceMap ( IN PEPROCESS  Parent,
IN PEPROCESS  Process 
)

Definition at line 511 of file devicemap.c.

513{
514 PDEVICE_MAP DeviceMap;
515
516 DPRINT("ObInheritDeviceMap()\n");
517
518 /* Acquire the device map lock */
520
521 /* Get the parent process device map or the system device map */
522 DeviceMap = (Parent != NULL) ? Parent->DeviceMap : ObSystemDeviceMap;
523 if (DeviceMap != NULL)
524 {
525 /* Reference the device map and attach it to the new process */
526 DeviceMap->ReferenceCount++;
527 DPRINT("ReferenceCount: %lu\n", DeviceMap->ReferenceCount);
528
529 Process->DeviceMap = DeviceMap;
530 }
531
532 /* Release the device map lock */
534}
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:732
if(dx< 0)
Definition: linetemp.h:194
PDEVICE_MAP ObSystemDeviceMap
Definition: obinit.c:46
ULONG ReferenceCount
Definition: obtypes.h:527

Referenced by PspCreateProcess().

◆ ObIsLUIDDeviceMapsEnabled()

ULONG NTAPI ObIsLUIDDeviceMapsEnabled ( VOID  )

Definition at line 662 of file devicemap.c.

663{
665}
ULONG ObpLUIDDeviceMapsEnabled
Definition: devicemap.c:18

Referenced by NtQueryInformationProcess(), and PspSetPrimaryToken().

◆ ObpReferenceDeviceMap()

PDEVICE_MAP NTAPI ObpReferenceDeviceMap ( VOID  )

Definition at line 325 of file devicemap.c.

326{
329 PTOKEN Token = NULL;
330 PDEVICE_MAP DeviceMap;
331 PETHREAD CurrentThread;
332 BOOLEAN LookingForSystem;
333 LUID SystemLuid = SYSTEM_LUID;
336
337 LookingForSystem = FALSE;
338
339 /* If LUID mapping is enable, try to get appropriate device map */
341 {
342 /* In case of impersonation, we've got a bit of work to do */
343 CurrentThread = PsGetCurrentThread();
344 if (CurrentThread->ActiveImpersonationInfo)
345 {
346 /* Get impersonation token */
347 Token = PsReferenceImpersonationToken(CurrentThread,
348 &CopyOnOpen,
351 /* Get logon LUID */
352 if (Token != NULL)
353 {
355 }
356 else
357 {
358 /* Force failure */
360 }
361
362 /* If we got logon LUID */
363 if (NT_SUCCESS(Status))
364 {
365 /*
366 * Check it's not system, system is easy to handle,
367 * we just need to return ObSystemDeviceMap
368 */
369 if (!RtlEqualLuid(&LogonId, &SystemLuid))
370 {
371 /* Ask Se for the device map */
372 Status = SeGetLogonIdDeviceMap(&LogonId, &DeviceMap);
373 if (NT_SUCCESS(Status))
374 {
375 /* Acquire the device map lock */
377
378 /* Reference the device map if any */
379 if (DeviceMap != NULL)
380 {
381 ++DeviceMap->ReferenceCount;
382 }
383
384 /* Release the device map lock */
386
387 /* If we got the device map, we're done! */
388 if (DeviceMap != NULL)
389 {
391
392 return DeviceMap;
393 }
394 }
395 }
396 else
397 {
398 LookingForSystem = TRUE;
399 }
400 }
401 }
402
403 /*
404 * Fall back case of the LUID mapping, make sure there's a
405 * a device map attached to the current process
406 */
407 if (PsGetCurrentProcess()->DeviceMap == NULL &&
409 {
410 /* We may have failed after we got impersonation token */
411 if (Token != NULL)
412 {
414 }
415
416 return NULL;
417 }
418 }
419
420 /* Acquire the device map lock */
422
423 /* If we're looking for system map, use it */
424 if (LookingForSystem)
425 {
426 DeviceMap = ObSystemDeviceMap;
427 }
428 /* Otherwise, use current process device map */
429 else
430 {
431 DeviceMap = PsGetCurrentProcess()->DeviceMap;
432 }
433
434 /* If we got one, reference it */
435 if (DeviceMap != NULL)
436 {
437 ++DeviceMap->ReferenceCount;
438 }
439
440 /* Release the device map lock */
442
443 /* We may have impersonation token (if we failed in impersonation branch) */
444 if (Token != NULL)
445 {
447 }
448
449 /* Return the potentially found device map */
450 return DeviceMap;
451}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI ObpSetCurrentProcessDeviceMap(VOID)
Definition: devicemap.c:248
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
Status
Definition: gdiplustypes.h:25
enum _SECURITY_IMPERSONATION_LEVEL SECURITY_IMPERSONATION_LEVEL
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ BOOLEAN EffectiveOnly
Definition: sefuncs.h:403
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
NTSTATUS NTAPI SeGetLogonIdDeviceMap(_In_ PLUID LogonId, _Out_ PDEVICE_MAP *DeviceMap)
Retrieves the DOS device map from a logon session.
Definition: srm.c:1347
PACCESS_TOKEN NTAPI PsReferenceImpersonationToken(IN PETHREAD Thread, OUT PBOOLEAN CopyOnOpen, OUT PBOOLEAN EffectiveOnly, OUT PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
Definition: security.c:849
NTSTATUS NTAPI SeQueryAuthenticationIdToken(_In_ PACCESS_TOKEN Token, _Out_ PLUID LogonId)
Queries the authentication ID of an access token.
Definition: token.c:1823
#define STATUS_NO_TOKEN
Definition: ntstatus.h:360
ULONG ActiveImpersonationInfo
Definition: pstypes.h:1181
_Out_ PBOOLEAN CopyOnOpen
Definition: psfuncs.h:154
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_Out_ PBOOLEAN _Out_ PBOOLEAN _Out_ PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
Definition: psfuncs.h:156
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
#define SYSTEM_LUID
Definition: setypes.h:700

Referenced by ObpLookupObjectName(), and ObQueryDeviceMapInformation().

◆ ObpSetCurrentProcessDeviceMap()

NTSTATUS NTAPI ObpSetCurrentProcessDeviceMap ( VOID  )

Definition at line 248 of file devicemap.c.

249{
254 LUID SystemLuid = SYSTEM_LUID;
255 PDEVICE_MAP DeviceMap, OldDeviceMap;
256
257 /* Get our impersonation token */
260 if (Token == NULL)
261 {
262 return STATUS_NO_TOKEN;
263 }
264
265 /* Query the Logon ID */
267 if (!NT_SUCCESS(Status))
268 {
269 goto done;
270 }
271
272 /* If that's system, then use system device map */
273 if (RtlEqualLuid(&LogonId, &SystemLuid))
274 {
275 DeviceMap = ObSystemDeviceMap;
276 }
277 /* Otherwise ask Se for the device map */
278 else
279 {
280 Status = SeGetLogonIdDeviceMap(&LogonId, &DeviceMap);
281 if (!NT_SUCCESS(Status))
282 {
283 /* Normalize failure status */
285 goto done;
286 }
287 }
288
289 /* Fail if no device map */
290 if (DeviceMap == NULL)
291 {
293 goto done;
294 }
295
296 /* Acquire the device map lock */
298
299 /* Save old device map attached to the process */
300 OldDeviceMap = CurrentProcess->DeviceMap;
301
302 /* Set new device map & reference it */
303 ++DeviceMap->ReferenceCount;
304 CurrentProcess->DeviceMap = DeviceMap;
305
306 /* Release the device map lock */
308
309 /* If we had a device map, dereference it */
310 if (OldDeviceMap != NULL)
311 {
312 ObfDereferenceDeviceMap(OldDeviceMap);
313 }
314
315done:
316 /* We're done with the token! */
318
319 return Status;
320}
ULONG CurrentProcess
Definition: shell.c:125
PACCESS_TOKEN NTAPI PsReferencePrimaryToken(PEPROCESS Process)
Definition: security.c:440
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:293

Referenced by ObpReferenceDeviceMap().

◆ ObQueryDeviceMapInformation()

NTSTATUS NTAPI ObQueryDeviceMapInformation ( _In_opt_ PEPROCESS  Process,
_Out_ PPROCESS_DEVICEMAP_INFORMATION  DeviceMapInfo,
_In_ ULONG  Flags 
)

Definition at line 539 of file devicemap.c.

543{
544 PDEVICE_MAP DeviceMap = NULL, GlobalDeviceMap;
545 BOOLEAN Dereference;
547 ULONG BitMask, i;
548 BOOLEAN ReturnAny;
550
551 /* Validate flags */
553 {
555 }
556
557 Dereference = FALSE;
558 /* Do we want to return anything? */
560
561 /* If LUID mappings are enabled... */
563 {
564 /* Check for process parameter validness */
566 {
568 }
569
570 /* And get the device map */
571 DeviceMap = ObpReferenceDeviceMap();
572 }
573
574 /* Acquire the device map lock */
576
577 /*
578 * If we had a device map, if because of LUID mappings,
579 * we'll have to dereference it afterwards
580 */
581 if (DeviceMap != NULL)
582 {
583 Dereference = TRUE;
584 }
585 else
586 {
587 /* Get the process device map or the system device map */
588 DeviceMap = (Process != NULL) ? Process->DeviceMap : ObSystemDeviceMap;
589 }
590
591 /* Fail if no device map */
592 if (DeviceMap == NULL)
593 {
595 return STATUS_END_OF_FILE;
596 }
597
598 /* At that point, assume success */
600
601 /* Try to get the global device map if any */
602 GlobalDeviceMap = DeviceMap;
603 if (DeviceMap->GlobalDosDevicesDirectory != NULL)
604 {
605 if (DeviceMap->GlobalDosDevicesDirectory->DeviceMap != NULL)
606 {
607 GlobalDeviceMap = DeviceMap->GlobalDosDevicesDirectory->DeviceMap;
608 }
609 }
610
611 /* Now, setup our device map info, especially drive types */
612 MapInfo.Query.DriveMap = DeviceMap->DriveMap;
613 /* Browse every device */
614 for (i = 0, BitMask = 1; i < 32; ++i, BitMask *= 2)
615 {
616 /* Set the type given current device map */
617 MapInfo.Query.DriveType[i] = DeviceMap->DriveType[i];
618
619 /*
620 * If device is not existing and we're asked to return
621 * more than just LUID mapped, get the entry
622 * from global device map if not remote
623 */
624 if (!(MapInfo.Query.DriveMap & BitMask) && ReturnAny)
625 {
626 if (ObpLUIDDeviceMapsEnabled != 0 ||
627 (GlobalDeviceMap->DriveType[i] != DOSDEVICE_DRIVE_REMOTE &&
628 GlobalDeviceMap->DriveType[i] != DOSDEVICE_DRIVE_CALCULATE))
629 {
630 MapInfo.Query.DriveType[i] = GlobalDeviceMap->DriveType[i];
631 MapInfo.Query.DriveMap |= BitMask & GlobalDeviceMap->DriveMap;
632 }
633 }
634 }
635
636 /* Release the device map lock */
638
639 /* Dereference LUID device map */
640 if (Dereference)
641 {
642 ObfDereferenceDeviceMap(DeviceMap);
643 }
644
645 /* Copy back data */
647 {
648 RtlCopyMemory(DeviceMapInfo, &MapInfo, sizeof(PROCESS_DEVICEMAP_INFORMATION));
649 }
651 {
653 }
654 _SEH2_END;
655
656 return Status;
657}
PDEVICE_MAP NTAPI ObpReferenceDeviceMap(VOID)
Definition: devicemap.c:325
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define PROCESS_LUID_DOSDEVICES_ONLY
Definition: pstypes.h:228
unsigned int ULONG
Definition: retypes.h:1
#define DOSDEVICE_DRIVE_CALCULATE
Definition: obtypes.h:164
#define DOSDEVICE_DRIVE_REMOTE
Definition: obtypes.h:167
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_SUCCESS
Definition: shellext.h:65
UCHAR DriveType[32]
Definition: obtypes.h:529
POBJECT_DIRECTORY GlobalDosDevicesDirectory
Definition: obtypes.h:526
ULONG DriveMap
Definition: obtypes.h:528
struct _DEVICE_MAP * DeviceMap
Definition: obtypes.h:418
struct _PROCESS_DEVICEMAP_INFORMATION::@3972::@3974 Query
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by NtQueryInformationProcess().

◆ ObSetDeviceMap()

NTSTATUS NTAPI ObSetDeviceMap ( IN PEPROCESS  Process,
IN HANDLE  DirectoryHandle 
)

Definition at line 24 of file devicemap.c.

26{
27 POBJECT_DIRECTORY DirectoryObject = NULL;
28 PDEVICE_MAP DeviceMap = NULL, NewDeviceMap = NULL, OldDeviceMap;
30 PEPROCESS WorkProcess;
31 BOOLEAN MakePermanant = FALSE;
32
37 (PVOID*)&DirectoryObject,
38 NULL);
39 if (!NT_SUCCESS(Status))
40 {
41 DPRINT("ObReferenceObjectByHandle() failed (Status 0x%08lx)\n", Status);
42 return Status;
43 }
44
45 /* Allocate and initialize a new device map */
47 sizeof(*DeviceMap),
48 'mDbO');
49 if (DeviceMap == NULL)
50 {
51 ObDereferenceObject(DirectoryObject);
53 }
54
55 /* Initialize the device map */
56 RtlZeroMemory(DeviceMap, sizeof(*DeviceMap));
57 DeviceMap->ReferenceCount = 1;
58 DeviceMap->DosDevicesDirectory = DirectoryObject;
59
60 /* Acquire the device map lock */
62
63 /* Attach the device map to the directory object */
64 if (DirectoryObject->DeviceMap == NULL)
65 {
66 DirectoryObject->DeviceMap = DeviceMap;
67 }
68 else
69 {
70 NewDeviceMap = DeviceMap;
71
72 /* There's already a device map,
73 so reuse it */
74 DeviceMap = DirectoryObject->DeviceMap;
75 ++DeviceMap->ReferenceCount;
76 }
77
78 /* Caller gave a process, use it */
79 if (Process != NULL)
80 {
81 WorkProcess = Process;
82 }
83 /* If no process given, use current and
84 * set system device map */
85 else
86 {
87 WorkProcess = PsGetCurrentProcess();
88 ObSystemDeviceMap = DeviceMap;
89 }
90
91 /* If current object isn't system one, save system one in current
92 * device map */
93 if (DirectoryObject != ObSystemDeviceMap->DosDevicesDirectory)
94 {
95 /* We also need to make the object permanant */
97 MakePermanant = TRUE;
98 }
99
100 /* Save old process device map */
101 OldDeviceMap = WorkProcess->DeviceMap;
102 /* Attach the device map to the process */
103 WorkProcess->DeviceMap = DeviceMap;
104
105 /* Release the device map lock */
107
108 /* If we have to make the object permamant, do it now */
109 if (MakePermanant)
110 {
111 POBJECT_HEADER ObjectHeader;
112 POBJECT_HEADER_NAME_INFO HeaderNameInfo;
113
114 ObjectHeader = OBJECT_TO_OBJECT_HEADER(DirectoryObject);
115 HeaderNameInfo = ObpReferenceNameInfo(ObjectHeader);
116
117 ObpEnterObjectTypeMutex(ObjectHeader->Type);
118 if (HeaderNameInfo != NULL && HeaderNameInfo->Directory != NULL)
119 {
120 ObjectHeader->Flags |= OB_FLAG_PERMANENT;
121 }
122 ObpLeaveObjectTypeMutex(ObjectHeader->Type);
123
124 if (HeaderNameInfo != NULL)
125 {
126 ObpDereferenceNameInfo(HeaderNameInfo);
127 }
128 }
129
130 /* Release useless device map if required */
131 if (NewDeviceMap != NULL)
132 {
133 ObDereferenceObject(DirectoryObject);
134 ExFreePoolWithTag(NewDeviceMap, 'mDbO');
135 }
136
137 /* And dereference previous process device map */
138 if (OldDeviceMap != NULL)
139 {
140 ObfDereferenceDeviceMap(OldDeviceMap);
141 }
142
143 return STATUS_SUCCESS;
144}
static HANDLE DirectoryHandle
Definition: ObType.c:48
#define ObpDirectoryObjectType
Definition: ObTypes.c:118
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define KeGetPreviousMode()
Definition: ketypes.h:1108
#define OB_FLAG_PERMANENT
Definition: obtypes.h:101
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
FORCEINLINE VOID ObpLeaveObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:352
FORCEINLINE VOID ObpDereferenceNameInfo(IN POBJECT_HEADER_NAME_INFO HeaderNameInfo)
Definition: ob_x.h:143
FORCEINLINE POBJECT_HEADER_NAME_INFO ObpReferenceNameInfo(IN POBJECT_HEADER ObjectHeader)
Definition: ob_x.h:102
FORCEINLINE VOID ObpEnterObjectTypeMutex(IN POBJECT_TYPE ObjectType)
Definition: ob_x.h:340
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
POBJECT_DIRECTORY DosDevicesDirectory
Definition: obtypes.h:525
PVOID DeviceMap
Definition: pstypes.h:1313
POBJECT_DIRECTORY Directory
Definition: obtypes.h:432
UCHAR Flags
Definition: obtypes.h:497
POBJECT_TYPE Type
Definition: obtypes.h:493
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by NtSetInformationProcess(), and ObpCreateDosDevicesDirectory().

◆ ObSetDirectoryDeviceMap()

NTSTATUS NTAPI ObSetDirectoryDeviceMap ( OUT PDEVICE_MAP DeviceMap,
IN HANDLE  DirectoryHandle 
)

Definition at line 149 of file devicemap.c.

151{
152 POBJECT_DIRECTORY DirectoryObject = NULL;
153 PDEVICE_MAP LocalMap = NULL, NewDeviceMap = NULL;
155 POBJECT_HEADER ObjectHeader;
156 POBJECT_HEADER_NAME_INFO HeaderNameInfo;
157
162 (PVOID*)&DirectoryObject,
163 NULL);
164 if (!NT_SUCCESS(Status))
165 {
166 DPRINT("ObReferenceObjectByHandle() failed (Status 0x%08lx)\n", Status);
167 return Status;
168 }
169
170 /* Allocate and initialize a new device map */
172 sizeof(*LocalMap),
173 'mDbO');
174 if (LocalMap == NULL)
175 {
176 ObDereferenceObject(DirectoryObject);
178 }
179
180 /* Initialize the device map */
181 RtlZeroMemory(LocalMap, sizeof(*LocalMap));
182 LocalMap->ReferenceCount = 1;
183 LocalMap->DosDevicesDirectory = DirectoryObject;
184
185 /* Acquire the device map lock */
187
188 /* Attach the device map to the directory object */
189 if (DirectoryObject->DeviceMap == NULL)
190 {
191 DirectoryObject->DeviceMap = LocalMap;
192 }
193 else
194 {
195 NewDeviceMap = LocalMap;
196
197 /* There's already a device map,
198 so reuse it */
199 LocalMap = DirectoryObject->DeviceMap;
200 ++LocalMap->ReferenceCount;
201 }
202
203 /* If current object isn't system one, save system one in current
204 * device map */
205 if (DirectoryObject != ObSystemDeviceMap->DosDevicesDirectory)
206 {
207 /* We also need to make the object permanant */
209 }
210
211 /* Release the device map lock */
213
214 if (DeviceMap != NULL)
215 {
216 *DeviceMap = LocalMap;
217 }
218
219 /* Caller expects us to make the object permanant, so do it! */
220 ObjectHeader = OBJECT_TO_OBJECT_HEADER(DirectoryObject);
221 HeaderNameInfo = ObpReferenceNameInfo(ObjectHeader);
222
223 ObpEnterObjectTypeMutex(ObjectHeader->Type);
224 if (HeaderNameInfo != NULL && HeaderNameInfo->Directory != NULL)
225 {
226 ObjectHeader->Flags |= OB_FLAG_PERMANENT;
227 }
228 ObpLeaveObjectTypeMutex(ObjectHeader->Type);
229
230 if (HeaderNameInfo != NULL)
231 {
232 ObpDereferenceNameInfo(HeaderNameInfo);
233 }
234
235 /* Release useless device map if required */
236 if (NewDeviceMap != NULL)
237 {
238 ObDereferenceObject(DirectoryObject);
239 ExFreePoolWithTag(NewDeviceMap, 'mDbO');
240 }
241
242 return Status;
243}
#define KernelMode
Definition: asm.h:34

Referenced by SeGetLogonIdDeviceMap().

Variable Documentation

◆ ObpLUIDDeviceMapsDisabled

ULONG ObpLUIDDeviceMapsDisabled

Definition at line 17 of file devicemap.c.

Referenced by ObpCreateDosDevicesDirectory().

◆ ObpLUIDDeviceMapsEnabled