Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1742 lines
46 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. obquery.c
  5. Abstract:
  6. Query Object system service
  7. Author:
  8. Steve Wood (stevewo) 12-May-1989
  9. Revision History:
  10. --*/
  11. #include "obp.h"
  12. //
  13. // Local procedure prototypes
  14. //
  15. //
  16. // The following structure is used to pass the call back routine
  17. // "ObpSetHandleAttributes" the captured object information and
  18. // the processor mode of the caller.
  19. //
  20. typedef struct __OBP_SET_HANDLE_ATTRIBUTES {
  21. OBJECT_HANDLE_FLAG_INFORMATION ObjectInformation;
  22. KPROCESSOR_MODE PreviousMode;
  23. } OBP_SET_HANDLE_ATTRIBUTES, *POBP_SET_HANDLE_ATTRIBUTES;
  24. BOOLEAN
  25. ObpSetHandleAttributes (
  26. IN OUT PVOID TableEntry,
  27. IN ULONG_PTR Parameter
  28. );
  29. #if defined(ALLOC_PRAGMA)
  30. #pragma alloc_text(PAGE,NtQueryObject)
  31. #pragma alloc_text(PAGE,ObQueryNameString)
  32. #pragma alloc_text(PAGE,ObQueryTypeName)
  33. #pragma alloc_text(PAGE,ObQueryTypeInfo)
  34. #pragma alloc_text(PAGE,ObQueryObjectAuditingByHandle)
  35. #pragma alloc_text(PAGE,NtSetInformationObject)
  36. #pragma alloc_text(PAGE,ObpSetHandleAttributes)
  37. #pragma alloc_text(PAGE,ObSetHandleAttributes)
  38. #endif
  39. NTSTATUS
  40. NtQueryObject (
  41. IN HANDLE Handle,
  42. IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
  43. OUT PVOID ObjectInformation,
  44. IN ULONG ObjectInformationLength,
  45. OUT PULONG ReturnLength OPTIONAL
  46. )
  47. /*++
  48. Routine description:
  49. This routine is used to query information about a given object
  50. Arguments:
  51. Handle - Supplies a handle to the object being queried. This value
  52. is ignored if the requested information class is for type
  53. information.
  54. ObjectInformationClass - Specifies the type of information to return
  55. ObjectInformation - Supplies an output buffer for the information being
  56. returned
  57. ObjectInformationLength - Specifies, in bytes, the length of the
  58. preceding object information buffer
  59. ReturnLength - Optionally receives the length, in bytes, used to store
  60. the object information
  61. Return Value:
  62. An appropriate status value
  63. --*/
  64. {
  65. KPROCESSOR_MODE PreviousMode;
  66. NTSTATUS Status;
  67. PVOID Object;
  68. POBJECT_HEADER ObjectHeader;
  69. POBJECT_HEADER_QUOTA_INFO QuotaInfo;
  70. POBJECT_HEADER_NAME_INFO NameInfo;
  71. POBJECT_TYPE ObjectType;
  72. POBJECT_HEADER ObjectDirectoryHeader;
  73. POBJECT_DIRECTORY ObjectDirectory;
  74. ACCESS_MASK GrantedAccess;
  75. POBJECT_HANDLE_FLAG_INFORMATION HandleFlags;
  76. OBJECT_HANDLE_INFORMATION HandleInformation;
  77. ULONG NameInfoSize;
  78. ULONG SecurityDescriptorSize;
  79. ULONG TempReturnLength;
  80. OBJECT_BASIC_INFORMATION ObjectBasicInfo;
  81. POBJECT_TYPES_INFORMATION TypesInformation;
  82. POBJECT_TYPE_INFORMATION TypeInfo;
  83. ULONG i;
  84. PAGED_CODE();
  85. //
  86. // Initialize our local variables
  87. //
  88. TempReturnLength = 0;
  89. //
  90. // Get previous processor mode and probe output argument if necessary.
  91. //
  92. PreviousMode = KeGetPreviousMode();
  93. if (PreviousMode != KernelMode) {
  94. try {
  95. if (ObjectInformationClass != ObjectHandleFlagInformation) {
  96. ProbeForWrite( ObjectInformation,
  97. ObjectInformationLength,
  98. sizeof( ULONG ));
  99. } else {
  100. ProbeForWrite( ObjectInformation,
  101. ObjectInformationLength,
  102. 1 );
  103. }
  104. //
  105. // We'll use a local temp return length variable to pass
  106. // through to the later ob query calls which will increment
  107. // its value. We can't pass the users return length directly
  108. // because the user might also be altering its value behind
  109. // our back.
  110. //
  111. if (ARGUMENT_PRESENT( ReturnLength )) {
  112. ProbeForWriteUlong( ReturnLength );
  113. }
  114. } except( EXCEPTION_EXECUTE_HANDLER ) {
  115. return( GetExceptionCode() );
  116. }
  117. }
  118. //
  119. // If the query is not for types information then we
  120. // will have to get the object in question. Otherwise
  121. // for types information there really isn't an object
  122. // to grab.
  123. //
  124. if (ObjectInformationClass != ObjectTypesInformation) {
  125. Status = ObReferenceObjectByHandle( Handle,
  126. 0,
  127. NULL,
  128. PreviousMode,
  129. &Object,
  130. &HandleInformation );
  131. if (!NT_SUCCESS( Status )) {
  132. return( Status );
  133. }
  134. GrantedAccess = HandleInformation.GrantedAccess;
  135. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  136. ObjectType = ObjectHeader->Type;
  137. } else {
  138. GrantedAccess = 0;
  139. Object = NULL;
  140. ObjectHeader = NULL;
  141. ObjectType = NULL;
  142. }
  143. //
  144. // Now process the particular information class being
  145. // requested
  146. //
  147. switch( ObjectInformationClass ) {
  148. case ObjectBasicInformation:
  149. //
  150. // Make sure the output buffer is long enough and then
  151. // fill in the appropriate fields into our local copy
  152. // of basic information.
  153. //
  154. if (ObjectInformationLength != sizeof( OBJECT_BASIC_INFORMATION )) {
  155. ObDereferenceObject( Object );
  156. return( STATUS_INFO_LENGTH_MISMATCH );
  157. }
  158. ObjectBasicInfo.Attributes = HandleInformation.HandleAttributes;
  159. if (ObjectHeader->Flags & OB_FLAG_PERMANENT_OBJECT) {
  160. ObjectBasicInfo.Attributes |= OBJ_PERMANENT;
  161. }
  162. if (ObjectHeader->Flags & OB_FLAG_EXCLUSIVE_OBJECT) {
  163. ObjectBasicInfo.Attributes |= OBJ_EXCLUSIVE;
  164. }
  165. ObjectBasicInfo.GrantedAccess = GrantedAccess;
  166. ObjectBasicInfo.HandleCount = ObjectHeader->HandleCount;
  167. ObjectBasicInfo.PointerCount = ObjectHeader->PointerCount;
  168. QuotaInfo = OBJECT_HEADER_TO_QUOTA_INFO( ObjectHeader );
  169. if (QuotaInfo != NULL) {
  170. ObjectBasicInfo.PagedPoolCharge = QuotaInfo->PagedPoolCharge;
  171. ObjectBasicInfo.NonPagedPoolCharge = QuotaInfo->NonPagedPoolCharge;
  172. } else {
  173. ObjectBasicInfo.PagedPoolCharge = 0;
  174. ObjectBasicInfo.NonPagedPoolCharge = 0;
  175. }
  176. if (ObjectType == ObpSymbolicLinkObjectType) {
  177. ObjectBasicInfo.CreationTime = ((POBJECT_SYMBOLIC_LINK)Object)->CreationTime;
  178. } else {
  179. RtlZeroMemory( &ObjectBasicInfo.CreationTime,
  180. sizeof( ObjectBasicInfo.CreationTime ));
  181. }
  182. //
  183. // Compute the size of the object name string by taking its name plus
  184. // seperators and traversing up to the root adding each directories
  185. // name length plus seperators
  186. //
  187. NameInfo = ObpReferenceNameInfo( ObjectHeader );
  188. if ((NameInfo != NULL) && (NameInfo->Directory != NULL)) {
  189. PVOID ReferencedDirectory = NULL;
  190. //
  191. // We grab the root directory lock and test again the directory
  192. //
  193. ObjectDirectory = NameInfo->Directory;
  194. if (ObjectDirectory) {
  195. ObfReferenceObject( ObjectDirectory );
  196. ReferencedDirectory = ObjectDirectory;
  197. NameInfoSize = sizeof( OBJ_NAME_PATH_SEPARATOR ) + NameInfo->Name.Length;
  198. ObpDereferenceNameInfo( NameInfo );
  199. NameInfo = NULL;
  200. while (ObjectDirectory) {
  201. ObjectDirectoryHeader = OBJECT_TO_OBJECT_HEADER( ObjectDirectory );
  202. NameInfo = ObpReferenceNameInfo( ObjectDirectoryHeader );
  203. if ((NameInfo != NULL) && (NameInfo->Directory != NULL)) {
  204. NameInfoSize += sizeof( OBJ_NAME_PATH_SEPARATOR ) + NameInfo->Name.Length;
  205. ObjectDirectory = NameInfo->Directory;
  206. ObfReferenceObject( ObjectDirectory );
  207. ObpDereferenceNameInfo( NameInfo );
  208. NameInfo = NULL;
  209. ObDereferenceObject( ReferencedDirectory );
  210. ReferencedDirectory = ObjectDirectory;
  211. } else {
  212. break;
  213. }
  214. }
  215. if (ReferencedDirectory) {
  216. ObDereferenceObject( ReferencedDirectory );
  217. }
  218. NameInfoSize += sizeof( OBJECT_NAME_INFORMATION ) + sizeof( UNICODE_NULL );
  219. }
  220. } else {
  221. NameInfoSize = 0;
  222. }
  223. ObpDereferenceNameInfo( NameInfo );
  224. NameInfo = NULL;
  225. ObjectBasicInfo.NameInfoSize = NameInfoSize;
  226. ObjectBasicInfo.TypeInfoSize = ObjectType->Name.Length + sizeof( UNICODE_NULL ) +
  227. sizeof( OBJECT_TYPE_INFORMATION );
  228. if ((GrantedAccess & READ_CONTROL) &&
  229. ARGUMENT_PRESENT( ObjectHeader->SecurityDescriptor )) {
  230. SECURITY_INFORMATION SecurityInformation;
  231. //
  232. // Request a complete security descriptor
  233. //
  234. SecurityInformation = OWNER_SECURITY_INFORMATION |
  235. GROUP_SECURITY_INFORMATION |
  236. DACL_SECURITY_INFORMATION |
  237. SACL_SECURITY_INFORMATION;
  238. SecurityDescriptorSize = 0;
  239. (ObjectType->TypeInfo.SecurityProcedure)( Object,
  240. QuerySecurityDescriptor,
  241. &SecurityInformation,
  242. NULL,
  243. &SecurityDescriptorSize,
  244. &ObjectHeader->SecurityDescriptor,
  245. ObjectType->TypeInfo.PoolType,
  246. &ObjectType->TypeInfo.GenericMapping );
  247. } else {
  248. SecurityDescriptorSize = 0;
  249. }
  250. ObjectBasicInfo.SecurityDescriptorSize = SecurityDescriptorSize;
  251. //
  252. // Now that we've packaged up our local copy of basic info we need
  253. // to copy it into the output buffer and set the return
  254. // length
  255. //
  256. try {
  257. *(POBJECT_BASIC_INFORMATION) ObjectInformation = ObjectBasicInfo;
  258. TempReturnLength = ObjectInformationLength;
  259. } except( EXCEPTION_EXECUTE_HANDLER ) {
  260. //
  261. // Fall through, since we cannot undo what we have done.
  262. //
  263. }
  264. break;
  265. case ObjectNameInformation:
  266. //
  267. // Call a local worker routine
  268. //
  269. Status = ObQueryNameString( Object,
  270. (POBJECT_NAME_INFORMATION)ObjectInformation,
  271. ObjectInformationLength,
  272. &TempReturnLength );
  273. break;
  274. case ObjectTypeInformation:
  275. //
  276. // Call a local worker routine
  277. //
  278. Status = ObQueryTypeInfo( ObjectType,
  279. (POBJECT_TYPE_INFORMATION)ObjectInformation,
  280. ObjectInformationLength,
  281. &TempReturnLength );
  282. break;
  283. case ObjectTypesInformation:
  284. try {
  285. //
  286. // The first thing we do is set the return length to cover the
  287. // types info record. Later in each call to query type info
  288. // this value will be updated as necessary
  289. //
  290. TempReturnLength = sizeof( OBJECT_TYPES_INFORMATION );
  291. //
  292. // Make sure there is enough room to hold the types info record
  293. // and if so then compute the number of defined types there are
  294. //
  295. TypesInformation = (POBJECT_TYPES_INFORMATION)ObjectInformation;
  296. if (ObjectInformationLength < sizeof( OBJECT_TYPES_INFORMATION ) ) {
  297. Status = STATUS_INFO_LENGTH_MISMATCH;
  298. } else {
  299. TypesInformation->NumberOfTypes = 0;
  300. for (i=0; i<OBP_MAX_DEFINED_OBJECT_TYPES; i++) {
  301. ObjectType = ObpObjectTypes[ i ];
  302. if (ObjectType == NULL) {
  303. break;
  304. }
  305. TypesInformation->NumberOfTypes += 1;
  306. }
  307. }
  308. //
  309. // For each defined type we will query the type info for the
  310. // object type and adjust the TypeInfo pointer to the next
  311. // free spot
  312. //
  313. TypeInfo = (POBJECT_TYPE_INFORMATION)(((PUCHAR)TypesInformation) + ALIGN_UP( sizeof(*TypesInformation), ULONG_PTR ));
  314. for (i=0; i<OBP_MAX_DEFINED_OBJECT_TYPES; i++) {
  315. ObjectType = ObpObjectTypes[ i ];
  316. if (ObjectType == NULL) {
  317. break;
  318. }
  319. Status = ObQueryTypeInfo( ObjectType,
  320. TypeInfo,
  321. ObjectInformationLength,
  322. &TempReturnLength );
  323. if (NT_SUCCESS( Status )) {
  324. TypeInfo = (POBJECT_TYPE_INFORMATION)
  325. ((PCHAR)(TypeInfo+1) + ALIGN_UP( TypeInfo->TypeName.MaximumLength, ULONG_PTR ));
  326. }
  327. }
  328. } except( EXCEPTION_EXECUTE_HANDLER ) {
  329. Status = GetExceptionCode();
  330. }
  331. break;
  332. case ObjectHandleFlagInformation:
  333. try {
  334. //
  335. // Set the amount of data we are going to return
  336. //
  337. TempReturnLength = sizeof(OBJECT_HANDLE_FLAG_INFORMATION);
  338. HandleFlags = (POBJECT_HANDLE_FLAG_INFORMATION)ObjectInformation;
  339. //
  340. // Make sure we have enough room for the query, and if so we'll
  341. // set the output based on the flags stored in the handle
  342. //
  343. if (ObjectInformationLength < sizeof( OBJECT_HANDLE_FLAG_INFORMATION)) {
  344. Status = STATUS_INFO_LENGTH_MISMATCH;
  345. } else {
  346. HandleFlags->Inherit = FALSE;
  347. if (HandleInformation.HandleAttributes & OBJ_INHERIT) {
  348. HandleFlags->Inherit = TRUE;
  349. }
  350. HandleFlags->ProtectFromClose = FALSE;
  351. if (HandleInformation.HandleAttributes & OBJ_PROTECT_CLOSE) {
  352. HandleFlags->ProtectFromClose = TRUE;
  353. }
  354. }
  355. } except( EXCEPTION_EXECUTE_HANDLER ) {
  356. Status = GetExceptionCode();
  357. }
  358. break;
  359. default:
  360. //
  361. // To get to this point we must have had an object and the
  362. // information class is not defined, so we should dereference the
  363. // object and return to our user the bad status
  364. //
  365. ObDereferenceObject( Object );
  366. return( STATUS_INVALID_INFO_CLASS );
  367. }
  368. //
  369. // Now if the caller asked for a return length we'll set it from
  370. // our local copy
  371. //
  372. try {
  373. if (ARGUMENT_PRESENT( ReturnLength ) ) {
  374. *ReturnLength = TempReturnLength;
  375. }
  376. } except( EXCEPTION_EXECUTE_HANDLER ) {
  377. //
  378. // Fall through, since we cannot undo what we have done.
  379. //
  380. }
  381. //
  382. // In the end we can free the object if there was one and return
  383. // to our caller
  384. //
  385. if (Object != NULL) {
  386. ObDereferenceObject( Object );
  387. }
  388. return( Status );
  389. }
  390. NTSTATUS
  391. ObSetHandleAttributes (
  392. IN HANDLE Handle,
  393. IN POBJECT_HANDLE_FLAG_INFORMATION HandleFlags,
  394. IN KPROCESSOR_MODE PreviousMode
  395. )
  396. {
  397. BOOLEAN AttachedToProcess = FALSE;
  398. KAPC_STATE ApcState;
  399. OBP_SET_HANDLE_ATTRIBUTES CapturedInformation;
  400. PVOID ObjectTable;
  401. HANDLE ObjectHandle;
  402. NTSTATUS Status;
  403. PAGED_CODE();
  404. CapturedInformation.PreviousMode = PreviousMode;
  405. CapturedInformation.ObjectInformation = *HandleFlags;
  406. //
  407. // Get the address of the object table for the current process. Or
  408. // get the system handle table if this is a kernel handle and we are
  409. // in kernel mode
  410. //
  411. if (IsKernelHandle( Handle, PreviousMode )) {
  412. //
  413. // Make the handle look like a regular handle
  414. //
  415. ObjectHandle = DecodeKernelHandle( Handle );
  416. //
  417. // The global kernel handle table
  418. //
  419. ObjectTable = ObpKernelHandleTable;
  420. //
  421. // Go to the system process
  422. //
  423. if (PsGetCurrentProcess() != PsInitialSystemProcess) {
  424. KeStackAttachProcess (&PsInitialSystemProcess->Pcb, &ApcState);
  425. AttachedToProcess = TRUE;
  426. }
  427. } else {
  428. ObjectTable = ObpGetObjectTable();
  429. ObjectHandle = Handle;
  430. }
  431. //
  432. // Make the change to the handle table entry. The callback
  433. // routine will do the actual change
  434. //
  435. if (ExChangeHandle( ObjectTable,
  436. ObjectHandle,
  437. ObpSetHandleAttributes,
  438. (ULONG_PTR)&CapturedInformation) ) {
  439. Status = STATUS_SUCCESS;
  440. } else {
  441. Status = STATUS_ACCESS_DENIED;
  442. }
  443. //
  444. // If we are attached to the system process then return
  445. // back to our caller
  446. //
  447. if (AttachedToProcess) {
  448. KeUnstackDetachProcess(&ApcState);
  449. AttachedToProcess = FALSE;
  450. }
  451. return Status;
  452. }
  453. NTSTATUS
  454. NTAPI
  455. NtSetInformationObject (
  456. IN HANDLE Handle,
  457. IN OBJECT_INFORMATION_CLASS ObjectInformationClass,
  458. IN PVOID ObjectInformation,
  459. IN ULONG ObjectInformationLength
  460. )
  461. /*++
  462. Routine description:
  463. This routine is used to set handle information about a specified
  464. handle
  465. Arguments:
  466. Handle - Supplies the handle being modified
  467. ObjectInformationClass - Specifies the class of information being
  468. modified. The only accepted value is ObjectHandleFlagInformation
  469. ObjectInformation - Supplies the buffer containing the handle
  470. flag information structure
  471. ObjectInformationLength - Specifies the length, in bytes, of the
  472. object information buffer
  473. Return Value:
  474. An appropriate status value
  475. --*/
  476. {
  477. NTSTATUS Status;
  478. OBJECT_HANDLE_FLAG_INFORMATION CapturedFlags;
  479. KPROCESSOR_MODE PreviousMode;
  480. PAGED_CODE();
  481. //
  482. // Check if the information class and information length are correct.
  483. //
  484. if (ObjectInformationClass != ObjectHandleFlagInformation) {
  485. return STATUS_INVALID_INFO_CLASS;
  486. }
  487. if (ObjectInformationLength != sizeof(OBJECT_HANDLE_FLAG_INFORMATION)) {
  488. return STATUS_INFO_LENGTH_MISMATCH;
  489. }
  490. //
  491. // Get previous processor mode and probe and capture the input
  492. // buffer
  493. //
  494. PreviousMode = KeGetPreviousMode();
  495. try {
  496. if (PreviousMode != KernelMode) {
  497. ProbeForRead(ObjectInformation, ObjectInformationLength, 1);
  498. }
  499. CapturedFlags = *(POBJECT_HANDLE_FLAG_INFORMATION)ObjectInformation;
  500. } except(ExSystemExceptionFilter()) {
  501. return GetExceptionCode();
  502. }
  503. Status = ObSetHandleAttributes (Handle,
  504. &CapturedFlags,
  505. PreviousMode);
  506. //
  507. // And return to our caller
  508. //
  509. return Status;
  510. }
  511. #define OBP_MISSING_NAME_LITERAL L"..."
  512. #define OBP_MISSING_NAME_LITERAL_SIZE (sizeof( OBP_MISSING_NAME_LITERAL ) - sizeof( UNICODE_NULL ))
  513. NTSTATUS
  514. ObQueryNameString (
  515. IN PVOID Object,
  516. OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
  517. IN ULONG Length,
  518. OUT PULONG ReturnLength
  519. )
  520. /*++
  521. Routine description:
  522. This routine processes a query of an object's name information
  523. Arguments:
  524. Object - Supplies the object being queried
  525. ObjectNameInfo - Supplies the buffer to store the name string
  526. information
  527. Length - Specifies the length, in bytes, of the original object
  528. name info buffer.
  529. ReturnLength - Contains the number of bytes already used up
  530. in the object name info. On return this receives an updated
  531. byte count.
  532. (Length minus ReturnLength) is really now many bytes are left
  533. in the output buffer. The buffer supplied to this call may
  534. actually be offset within the original users buffer
  535. Return Value:
  536. An appropriate status value
  537. --*/
  538. {
  539. NTSTATUS Status;
  540. POBJECT_HEADER ObjectHeader;
  541. POBJECT_HEADER_NAME_INFO NameInfo;
  542. POBJECT_HEADER ObjectDirectoryHeader;
  543. POBJECT_DIRECTORY ObjectDirectory;
  544. ULONG NameInfoSize;
  545. PUNICODE_STRING String;
  546. PWCH StringBuffer;
  547. ULONG NameSize;
  548. PVOID ReferencedObject = NULL;
  549. BOOLEAN DoFullQuery = TRUE;
  550. ULONG BufferLength;
  551. PWCH OriginalBuffer;
  552. PAGED_CODE();
  553. //
  554. // Get the object header and name info record if it exists
  555. //
  556. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  557. NameInfo = ObpReferenceNameInfo( ObjectHeader );
  558. //
  559. // If the object type has a query name callback routine then
  560. // that is how we get the name
  561. //
  562. if (ObjectHeader->Type->TypeInfo.QueryNameProcedure != NULL) {
  563. try {
  564. KIRQL SaveIrql;
  565. ObpBeginTypeSpecificCallOut( SaveIrql );
  566. ObpEndTypeSpecificCallOut( SaveIrql, "Query", ObjectHeader->Type, Object );
  567. Status = (*ObjectHeader->Type->TypeInfo.QueryNameProcedure)( Object,
  568. (BOOLEAN)((NameInfo != NULL) && (NameInfo->Name.Length != 0)),
  569. ObjectNameInfo,
  570. Length,
  571. ReturnLength );
  572. } except( EXCEPTION_EXECUTE_HANDLER ) {
  573. Status = GetExceptionCode();
  574. }
  575. ObpDereferenceNameInfo( NameInfo );
  576. return( Status );
  577. }
  578. //
  579. // Otherwise, the object type does not specify a query name
  580. // procedure so we get to do the work. The first thing
  581. // to check is if the object doesn't even have a name. If
  582. // object doesn't have a name then we'll return an empty name
  583. // info structure.
  584. //
  585. RETRY:
  586. if ((NameInfo == NULL) || (NameInfo->Name.Buffer == NULL)) {
  587. //
  588. // Compute the length of our return buffer, set the output
  589. // if necessary and make sure the supplied buffer is large
  590. // enough
  591. //
  592. NameInfoSize = sizeof( OBJECT_NAME_INFORMATION );
  593. try {
  594. *ReturnLength = NameInfoSize;
  595. } except( EXCEPTION_EXECUTE_HANDLER ) {
  596. ObpDereferenceNameInfo( NameInfo );
  597. return( GetExceptionCode() );
  598. }
  599. if (Length < NameInfoSize) {
  600. ObpDereferenceNameInfo( NameInfo );
  601. return( STATUS_INFO_LENGTH_MISMATCH );
  602. }
  603. //
  604. // Initialize the output buffer to be an empty string
  605. // and then return to our caller
  606. //
  607. try {
  608. ObjectNameInfo->Name.Length = 0;
  609. ObjectNameInfo->Name.MaximumLength = 0;
  610. ObjectNameInfo->Name.Buffer = NULL;
  611. } except( EXCEPTION_EXECUTE_HANDLER ) {
  612. //
  613. // Fall through, since we cannot undo what we have done.
  614. //
  615. ObpDereferenceNameInfo(NameInfo);
  616. return( GetExceptionCode() );
  617. }
  618. ObpDereferenceNameInfo(NameInfo);
  619. return( STATUS_SUCCESS );
  620. }
  621. try {
  622. //
  623. // The object does have a name but now see if this is
  624. // just the root directory object in which case the name size
  625. // is only the "\" character
  626. //
  627. if (Object == ObpRootDirectoryObject) {
  628. NameSize = sizeof( OBJ_NAME_PATH_SEPARATOR );
  629. } else {
  630. //
  631. // The named object is not the root so for every directory
  632. // working out way up we'll add its size to the name keeping
  633. // track of "\" characters inbetween each component. We first
  634. // start with the object name itself and then move on to
  635. // the directories
  636. //
  637. ObjectDirectory = NameInfo->Directory;
  638. if (ObjectDirectory) {
  639. ObfReferenceObject( ObjectDirectory );
  640. ReferencedObject = ObjectDirectory;
  641. }
  642. NameSize = sizeof( OBJ_NAME_PATH_SEPARATOR ) + NameInfo->Name.Length;
  643. ObpDereferenceNameInfo( NameInfo );
  644. NameInfo = NULL;
  645. //
  646. // While we are not at the root we'll keep moving up
  647. //
  648. while ((ObjectDirectory != ObpRootDirectoryObject) && (ObjectDirectory)) {
  649. //
  650. // Get the name information for this directory
  651. //
  652. ObjectDirectoryHeader = OBJECT_TO_OBJECT_HEADER( ObjectDirectory );
  653. NameInfo = ObpReferenceNameInfo( ObjectDirectoryHeader );
  654. if ((NameInfo != NULL) && (NameInfo->Directory != NULL)) {
  655. //
  656. // This directory has a name so add it to the accumulated
  657. // size and move up the tree
  658. //
  659. NameSize += sizeof( OBJ_NAME_PATH_SEPARATOR ) + NameInfo->Name.Length;
  660. ObjectDirectory = NameInfo->Directory;
  661. if (ObjectDirectory) {
  662. ObfReferenceObject( ObjectDirectory );
  663. }
  664. ObpDereferenceNameInfo( NameInfo );
  665. NameInfo = NULL;
  666. ObDereferenceObject( ReferencedObject );
  667. ReferencedObject = ObjectDirectory;
  668. //
  669. // UNICODE_STRINGs can only hold MAXUSHORT bytes.
  670. //
  671. if (NameSize > MAXUSHORT) {
  672. break;
  673. }
  674. } else {
  675. //
  676. // This directory does not have a name so we'll give it
  677. // the "..." name and stop the loop
  678. //
  679. NameSize += sizeof( OBJ_NAME_PATH_SEPARATOR ) + OBP_MISSING_NAME_LITERAL_SIZE;
  680. break;
  681. }
  682. }
  683. }
  684. //
  685. // UNICODE_STRINGs can only hold MAXUSHORT bytes
  686. //
  687. if (NameSize > MAXUSHORT) {
  688. Status = STATUS_NAME_TOO_LONG;
  689. DoFullQuery = FALSE;
  690. leave;
  691. }
  692. //
  693. // At this point NameSize is the number of bytes we need to store the
  694. // name of the object from the root down. The total buffer size we are
  695. // going to need will include this size, plus object name information
  696. // structure, plus an ending null character
  697. //
  698. NameInfoSize = NameSize + sizeof( OBJECT_NAME_INFORMATION ) + sizeof( UNICODE_NULL );
  699. //
  700. // Set the output size and make sure the supplied buffer is large enough
  701. // to hold the information
  702. //
  703. try {
  704. *ReturnLength = NameInfoSize;
  705. } except( EXCEPTION_EXECUTE_HANDLER ) {
  706. Status = GetExceptionCode();
  707. DoFullQuery = FALSE;
  708. leave;
  709. }
  710. if (Length < NameInfoSize) {
  711. Status = STATUS_INFO_LENGTH_MISMATCH;
  712. DoFullQuery = FALSE;
  713. leave;
  714. }
  715. } finally {
  716. ObpDereferenceNameInfo( NameInfo );
  717. NameInfo = NULL;
  718. if (ReferencedObject) {
  719. ObDereferenceObject( ReferencedObject );
  720. ReferencedObject = NULL;
  721. }
  722. }
  723. if (!DoFullQuery) {
  724. return Status;
  725. }
  726. NameInfo = ObpReferenceNameInfo( ObjectHeader );
  727. //
  728. // Check whether someone else removed the name meanwhile
  729. //
  730. if (!NameInfo) {
  731. //
  732. // The name is gone, we need to jump to the code path that handles
  733. // empty object name
  734. //
  735. goto RETRY;
  736. }
  737. try{
  738. //
  739. // Set the String buffer to point to the byte right after the
  740. // last byte in the output string. This following logic actually
  741. // fills in the buffer backwards working from the name back to the
  742. // root
  743. //
  744. StringBuffer = (PWCH)ObjectNameInfo;
  745. StringBuffer = (PWCH)((PCH)StringBuffer + NameInfoSize);
  746. OriginalBuffer = (PWCH)((PCH)ObjectNameInfo + sizeof( OBJECT_NAME_INFORMATION ));
  747. try {
  748. //
  749. // Terminate the string with a null and backup one unicode
  750. // character
  751. //
  752. *--StringBuffer = UNICODE_NULL;
  753. //
  754. // If the object in question is not the root directory
  755. // then we are going to put its name in the string buffer
  756. // When we finally reach the root directory we'll append on
  757. // the final "\"
  758. //
  759. if (Object != ObpRootDirectoryObject) {
  760. //
  761. // Add in the objects name
  762. //
  763. String = &NameInfo->Name;
  764. StringBuffer = (PWCH)((PCH)StringBuffer - String->Length);
  765. RtlCopyMemory( StringBuffer, String->Buffer, String->Length );
  766. //
  767. // While we are not at the root directory we'll keep
  768. // moving up
  769. //
  770. ObjectDirectory = NameInfo->Directory;
  771. if (ObjectDirectory) {
  772. //
  773. // Reference the directory for this object to make sure it's
  774. // valid while looking up
  775. //
  776. ObfReferenceObject( ObjectDirectory );
  777. ReferencedObject = ObjectDirectory;
  778. }
  779. ObpDereferenceNameInfo( NameInfo );
  780. NameInfo = NULL;
  781. while ((ObjectDirectory != ObpRootDirectoryObject) && (ObjectDirectory)) {
  782. //
  783. // Get the name information for this directory
  784. //
  785. ObjectDirectoryHeader = OBJECT_TO_OBJECT_HEADER( ObjectDirectory );
  786. NameInfo = ObpReferenceNameInfo( ObjectDirectoryHeader );
  787. //
  788. // Tack on the "\" between the last name we added and
  789. // this new name
  790. //
  791. *--StringBuffer = OBJ_NAME_PATH_SEPARATOR;
  792. //
  793. // Preappend the directory name, if it has one, and
  794. // move up to the next directory.
  795. //
  796. if ((NameInfo != NULL) && (NameInfo->Directory != NULL)) {
  797. String = &NameInfo->Name;
  798. StringBuffer = (PWCH)((PCH)StringBuffer - String->Length);
  799. RtlCopyMemory( StringBuffer, String->Buffer, String->Length );
  800. ObjectDirectory = NameInfo->Directory;
  801. if (ObjectDirectory) {
  802. ObfReferenceObject( ObjectDirectory );
  803. }
  804. //
  805. // Dereference the name info (it must be done before dereferencing the object)
  806. //
  807. ObpDereferenceNameInfo( NameInfo );
  808. NameInfo = NULL;
  809. ObDereferenceObject( ReferencedObject );
  810. ReferencedObject = ObjectDirectory;
  811. } else {
  812. //
  813. // The directory is nameless so use the "..." for
  814. // its name and break out of the loop
  815. //
  816. StringBuffer = (PWCH)((PCH)StringBuffer - OBP_MISSING_NAME_LITERAL_SIZE);
  817. //
  818. // Because we don't hold the global lock any more, we can have a special case
  819. // where a directory of 1 or 2 letters name AND inserted into the root
  820. // can go away meanwhile and "..." will be too long to fit the remaining space
  821. // We already copied the buffer so we cannot rollback everything we done.
  822. // We'll return \.. if the original directory was 1 char length,
  823. // \..\ for 2 char length
  824. //
  825. if (StringBuffer < OriginalBuffer) {
  826. StringBuffer = OriginalBuffer;
  827. }
  828. RtlCopyMemory( StringBuffer,
  829. OBP_MISSING_NAME_LITERAL,
  830. OBP_MISSING_NAME_LITERAL_SIZE );
  831. //
  832. // Test if we are in the case commented above. If yes, we need to move the
  833. // current pointer to the next char, so the final assignment for \ a few lines
  834. // below will take effect on the start of the block.
  835. //
  836. if (StringBuffer == OriginalBuffer) {
  837. StringBuffer++;
  838. }
  839. break;
  840. }
  841. }
  842. }
  843. //
  844. // Tack on the "\" for the root directory and then set the
  845. // output unicode string variable to have the right size
  846. // and point to the right spot.
  847. //
  848. *--StringBuffer = OBJ_NAME_PATH_SEPARATOR;
  849. BufferLength = (USHORT)((ULONG_PTR)ObjectNameInfo + NameInfoSize - (ULONG_PTR)StringBuffer);
  850. ObjectNameInfo->Name.MaximumLength = (USHORT)BufferLength;
  851. ObjectNameInfo->Name.Length = (USHORT)(BufferLength - sizeof( UNICODE_NULL ));
  852. ObjectNameInfo->Name.Buffer = OriginalBuffer;
  853. //
  854. // If one of the parent directories disappeared, the final length
  855. // will be smaller than we estimated before. We need to move the string to
  856. // the beginning and adjust the returned size.
  857. //
  858. if (OriginalBuffer != StringBuffer) {
  859. RtlMoveMemory(OriginalBuffer, StringBuffer, BufferLength);
  860. *ReturnLength = BufferLength + sizeof( OBJECT_NAME_INFORMATION );
  861. }
  862. } except( EXCEPTION_EXECUTE_HANDLER ) {
  863. //
  864. // Fall through, since we cannot undo what we have done.
  865. //
  866. // This should probably get the exception code and return
  867. // that value. However, the caller we'll get an exception
  868. // at the first access of the ObjectNameInfo
  869. //
  870. }
  871. Status = STATUS_SUCCESS;
  872. } finally {
  873. ObpDereferenceNameInfo( NameInfo );
  874. if (ReferencedObject) {
  875. ObDereferenceObject( ReferencedObject );
  876. }
  877. }
  878. return Status;
  879. }
  880. NTSTATUS
  881. ObQueryTypeName (
  882. IN PVOID Object,
  883. PUNICODE_STRING ObjectTypeName,
  884. IN ULONG Length,
  885. OUT PULONG ReturnLength
  886. )
  887. /*++
  888. Routine description:
  889. This routine processes a query of an object's type name
  890. Arguments:
  891. Object - Supplies the object being queried
  892. ObjectTypeName - Supplies the buffer to store the type name
  893. string information
  894. Length - Specifies the length, in bytes, of the object type
  895. name buffer
  896. ReturnLength - Contains the number of bytes already used up
  897. in the object type name buffer. On return this receives
  898. an updated byte count
  899. (Length minus ReturnLength) is really now many bytes are left
  900. in the output buffer. The buffer supplied to this call may
  901. actually be offset within the original users buffer
  902. Return Value:
  903. An appropriate status value
  904. --*/
  905. {
  906. POBJECT_TYPE ObjectType;
  907. POBJECT_HEADER ObjectHeader;
  908. ULONG TypeNameSize;
  909. PUNICODE_STRING String;
  910. PWCH StringBuffer;
  911. ULONG NameSize;
  912. PAGED_CODE();
  913. //
  914. // From the object get its object type and from that get the size of
  915. // the object type name. The total size for we need for the output
  916. // buffer must fit the name, a terminating null, and a preceding
  917. // unicode string structure
  918. //
  919. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  920. ObjectType = ObjectHeader->Type;
  921. NameSize = ObjectType->Name.Length;
  922. TypeNameSize = NameSize + sizeof( UNICODE_NULL ) + sizeof( UNICODE_STRING );
  923. //
  924. // Update the number of bytes we need and make sure the output buffer is
  925. // large enough
  926. //
  927. try {
  928. *ReturnLength = TypeNameSize;
  929. } except( EXCEPTION_EXECUTE_HANDLER ) {
  930. return( GetExceptionCode() );
  931. }
  932. if (Length < TypeNameSize) {
  933. return( STATUS_INFO_LENGTH_MISMATCH );
  934. }
  935. //
  936. // Set string buffer to point to the one byte beyond the
  937. // buffer that we're going to fill in
  938. //
  939. StringBuffer = (PWCH)ObjectTypeName;
  940. StringBuffer = (PWCH)((PCH)StringBuffer + TypeNameSize);
  941. String = &ObjectType->Name;
  942. try {
  943. //
  944. // Tack on the terminating null character and copy over
  945. // the type name
  946. //
  947. *--StringBuffer = UNICODE_NULL;
  948. StringBuffer = (PWCH)((PCH)StringBuffer - String->Length);
  949. RtlCopyMemory( StringBuffer, String->Buffer, String->Length );
  950. //
  951. // Now set the preceding unicode string to have the right
  952. // lengths and to point to this buffer
  953. //
  954. ObjectTypeName->Length = (USHORT)NameSize;
  955. ObjectTypeName->MaximumLength = (USHORT)(NameSize+sizeof( UNICODE_NULL ));
  956. ObjectTypeName->Buffer = StringBuffer;
  957. } except( EXCEPTION_EXECUTE_HANDLER ) {
  958. //
  959. // Fall through, since we cannot undo what we have done.
  960. //
  961. }
  962. return( STATUS_SUCCESS );
  963. }
  964. NTSTATUS
  965. ObQueryTypeInfo (
  966. IN POBJECT_TYPE ObjectType,
  967. OUT POBJECT_TYPE_INFORMATION ObjectTypeInfo,
  968. IN ULONG Length,
  969. OUT PULONG ReturnLength
  970. )
  971. /*++
  972. Routine description:
  973. This routine processes the query for object type information
  974. Arguments:
  975. Object - Supplies a pointer to the object type being queried
  976. ObjectTypeInfo - Supplies the buffer to store the type information
  977. Length - Specifies the length, in bytes, of the object type
  978. information buffer
  979. ReturnLength - Contains the number of bytes already used up
  980. in the object type information buffer. On return this receives
  981. an updated byte count
  982. (Length minus ReturnLength) is really now many bytes are left
  983. in the output buffer. The buffer supplied to this call may
  984. actually be offset within the original users buffer
  985. Return Value:
  986. An appropriate status value
  987. --*/
  988. {
  989. NTSTATUS Status;
  990. try {
  991. //
  992. // The total number of bytes needed for this query includes the
  993. // object type information structure plus the name of the type
  994. // rounded up to a ulong boundary
  995. //
  996. *ReturnLength += sizeof( *ObjectTypeInfo ) + ALIGN_UP( ObjectType->Name.MaximumLength, ULONG );
  997. //
  998. // Make sure the buffer is large enough for this information and
  999. // then fill in the record
  1000. //
  1001. if (Length < *ReturnLength) {
  1002. Status = STATUS_INFO_LENGTH_MISMATCH;
  1003. } else {
  1004. ObjectTypeInfo->TotalNumberOfObjects = ObjectType->TotalNumberOfObjects;
  1005. ObjectTypeInfo->TotalNumberOfHandles = ObjectType->TotalNumberOfHandles;
  1006. ObjectTypeInfo->HighWaterNumberOfObjects = ObjectType->HighWaterNumberOfObjects;
  1007. ObjectTypeInfo->HighWaterNumberOfHandles = ObjectType->HighWaterNumberOfHandles;
  1008. ObjectTypeInfo->InvalidAttributes = ObjectType->TypeInfo.InvalidAttributes;
  1009. ObjectTypeInfo->GenericMapping = ObjectType->TypeInfo.GenericMapping;
  1010. ObjectTypeInfo->ValidAccessMask = ObjectType->TypeInfo.ValidAccessMask;
  1011. ObjectTypeInfo->SecurityRequired = ObjectType->TypeInfo.SecurityRequired;
  1012. ObjectTypeInfo->MaintainHandleCount = ObjectType->TypeInfo.MaintainHandleCount;
  1013. ObjectTypeInfo->PoolType = ObjectType->TypeInfo.PoolType;
  1014. ObjectTypeInfo->DefaultPagedPoolCharge = ObjectType->TypeInfo.DefaultPagedPoolCharge;
  1015. ObjectTypeInfo->DefaultNonPagedPoolCharge = ObjectType->TypeInfo.DefaultNonPagedPoolCharge;
  1016. //
  1017. // The type name goes right after this structure. We cannot use
  1018. // rtl routine like RtlCopyUnicodeString that might use the local
  1019. // memory to keep state, because this is the user buffer and it
  1020. // could be changing by user
  1021. //
  1022. ObjectTypeInfo->TypeName.Buffer = (PWSTR)(ObjectTypeInfo+1);
  1023. ObjectTypeInfo->TypeName.Length = ObjectType->Name.Length;
  1024. ObjectTypeInfo->TypeName.MaximumLength = ObjectType->Name.MaximumLength;
  1025. RtlCopyMemory( (PWSTR)(ObjectTypeInfo+1),
  1026. ObjectType->Name.Buffer,
  1027. ObjectType->Name.Length );
  1028. ((PWSTR)(ObjectTypeInfo+1))[ ObjectType->Name.Length/sizeof(WCHAR) ] = UNICODE_NULL;
  1029. Status = STATUS_SUCCESS;
  1030. }
  1031. } except( EXCEPTION_EXECUTE_HANDLER ) {
  1032. Status = GetExceptionCode();
  1033. }
  1034. return Status;
  1035. }
  1036. NTSTATUS
  1037. ObQueryObjectAuditingByHandle (
  1038. IN HANDLE Handle,
  1039. OUT PBOOLEAN GenerateOnClose
  1040. )
  1041. /*++
  1042. Routine description:
  1043. This routine tells the caller if the indicated handle will
  1044. generate an audit if it is closed
  1045. Arguments:
  1046. Handle - Supplies the handle being queried
  1047. GenerateOnClose - Receives TRUE if the handle will generate
  1048. an audit if closed and FALSE otherwise
  1049. Return Value:
  1050. An appropriate status value
  1051. --*/
  1052. {
  1053. PHANDLE_TABLE ObjectTable;
  1054. PHANDLE_TABLE_ENTRY ObjectTableEntry;
  1055. PVOID Object;
  1056. ULONG CapturedGrantedAccess;
  1057. ULONG CapturedAttributes;
  1058. NTSTATUS Status;
  1059. PETHREAD CurrentThread;
  1060. PAGED_CODE();
  1061. ObpValidateIrql( "ObQueryObjectAuditingByHandle" );
  1062. CurrentThread = PsGetCurrentThread ();
  1063. //
  1064. // For the current process we'll grab its object table and
  1065. // then get the object table entry
  1066. //
  1067. if (IsKernelHandle( Handle, KeGetPreviousMode() )) {
  1068. Handle = DecodeKernelHandle( Handle );
  1069. ObjectTable = ObpKernelHandleTable;
  1070. } else {
  1071. ObjectTable = PsGetCurrentProcessByThread (CurrentThread)->ObjectTable;
  1072. }
  1073. //
  1074. // Protect ourselves from being interrupted while we hold a handle table
  1075. // entry lock
  1076. //
  1077. KeEnterCriticalRegionThread(&CurrentThread->Tcb);
  1078. ObjectTableEntry = ExMapHandleToPointer( ObjectTable,
  1079. Handle );
  1080. //
  1081. // If we were given a valid handle we'll look at the attributes
  1082. // stored in the object table entry to decide if we generate
  1083. // an audit on close
  1084. //
  1085. if (ObjectTableEntry != NULL) {
  1086. CapturedAttributes = ObjectTableEntry->ObAttributes;
  1087. ExUnlockHandleTableEntry( ObjectTable, ObjectTableEntry );
  1088. if (CapturedAttributes & OBJ_AUDIT_OBJECT_CLOSE) {
  1089. *GenerateOnClose = TRUE;
  1090. } else {
  1091. *GenerateOnClose = FALSE;
  1092. }
  1093. Status = STATUS_SUCCESS;
  1094. } else {
  1095. Status = STATUS_INVALID_HANDLE;
  1096. }
  1097. KeLeaveCriticalRegionThread(&CurrentThread->Tcb);
  1098. return Status;
  1099. }
  1100. #if DBG
  1101. PUNICODE_STRING
  1102. ObGetObjectName (
  1103. IN PVOID Object
  1104. )
  1105. /*++
  1106. Routine description:
  1107. This routine returns a pointer to the name of object
  1108. Arguments:
  1109. Object - Supplies the object being queried
  1110. Return Value:
  1111. The address of the unicode string that stores the object
  1112. name if available and NULL otherwise
  1113. --*/
  1114. {
  1115. POBJECT_HEADER ObjectHeader;
  1116. POBJECT_HEADER_NAME_INFO NameInfo;
  1117. //
  1118. // Translate the input object to a name info structure
  1119. //
  1120. ObjectHeader = OBJECT_TO_OBJECT_HEADER( Object );
  1121. NameInfo = OBJECT_HEADER_TO_NAME_INFO( ObjectHeader );
  1122. //
  1123. // If the object has a name then return the address of
  1124. // the name otherwise return null
  1125. //
  1126. if ((NameInfo != NULL) && (NameInfo->Name.Length != 0)) {
  1127. return &NameInfo->Name;
  1128. } else {
  1129. return NULL;
  1130. }
  1131. }
  1132. #endif // DBG
  1133. //
  1134. // Local support routine
  1135. //
  1136. BOOLEAN
  1137. ObpSetHandleAttributes (
  1138. IN OUT PHANDLE_TABLE_ENTRY ObjectTableEntry,
  1139. IN ULONG_PTR Parameter
  1140. )
  1141. /*++
  1142. Routine description:
  1143. This is the call back routine for the ExChangeHandle from
  1144. NtSetInformationObject
  1145. Arguments:
  1146. ObjectTableEntry - Supplies a pointer to the object table entry being
  1147. modified
  1148. Parameter - Supplies a pointer to the OBJECT_HANDLE_FLAG_INFORMATION
  1149. structure to set into the table entry
  1150. Return Value:
  1151. Returns TRUE if the operation is successful otherwise FALSE
  1152. --*/
  1153. {
  1154. POBP_SET_HANDLE_ATTRIBUTES ObjectInformation;
  1155. POBJECT_HEADER ObjectHeader;
  1156. ObjectInformation = (POBP_SET_HANDLE_ATTRIBUTES)Parameter;
  1157. //
  1158. // Get a pointer to the object type via the object header and if the
  1159. // caller has asked for inherit but the object type says that inherit
  1160. // is an invalid flag then return false
  1161. //
  1162. ObjectHeader = (POBJECT_HEADER)(((ULONG_PTR)(ObjectTableEntry->Object)) & ~OBJ_HANDLE_ATTRIBUTES);
  1163. if ((ObjectInformation->ObjectInformation.Inherit) &&
  1164. ((ObjectHeader->Type->TypeInfo.InvalidAttributes & OBJ_INHERIT) != 0)) {
  1165. return FALSE;
  1166. }
  1167. //
  1168. // For each piece of information (inheriit and protect from close) that
  1169. // is in the object information buffer we'll set or clear the bits in
  1170. // the object table entry. The bits modified are the low order bits of
  1171. // used to store the pointer to the object header.
  1172. //
  1173. if (ObjectInformation->ObjectInformation.Inherit) {
  1174. ObjectTableEntry->ObAttributes |= OBJ_INHERIT;
  1175. } else {
  1176. ObjectTableEntry->ObAttributes &= ~OBJ_INHERIT;
  1177. }
  1178. if (ObjectInformation->ObjectInformation.ProtectFromClose) {
  1179. ObjectTableEntry->GrantedAccess |= ObpAccessProtectCloseBit;
  1180. } else {
  1181. ObjectTableEntry->GrantedAccess &= ~ObpAccessProtectCloseBit;
  1182. }
  1183. //
  1184. // And return to our caller
  1185. //
  1186. return TRUE;
  1187. }