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.

355 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. SeInfo.c
  5. Abstract:
  6. This module implements the Security Information routines for MSFS
  7. There are two entry points MsFsdQueryInformation and
  8. MsFsdSetInformation.
  9. Author:
  10. Manny Weiser [mannyw] 19-Feb-1992
  11. Revision History:
  12. --*/
  13. #include "mailslot.h"
  14. //
  15. // The debug trace level
  16. //
  17. #define Dbg (DEBUG_TRACE_SEINFO)
  18. //
  19. // local procedure prototypes
  20. //
  21. NTSTATUS
  22. MsCommonQuerySecurityInfo (
  23. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  24. IN PIRP Irp
  25. );
  26. NTSTATUS
  27. MsCommonSetSecurityInfo (
  28. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  29. IN PIRP Irp
  30. );
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( PAGE, MsCommonQuerySecurityInfo )
  33. #pragma alloc_text( PAGE, MsCommonSetSecurityInfo )
  34. #pragma alloc_text( PAGE, MsFsdQuerySecurityInfo )
  35. #pragma alloc_text( PAGE, MsFsdSetSecurityInfo )
  36. #endif
  37. NTSTATUS
  38. MsFsdQuerySecurityInfo (
  39. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  40. IN PIRP Irp
  41. )
  42. /*++
  43. Routine Description:
  44. This routine implements the FSD part of the Query Security Information API
  45. calls.
  46. Arguments:
  47. MsfsDeviceObject - Supplies the device object to use.
  48. Irp - Supplies the Irp being processed
  49. Return Value:
  50. NTSTATUS - The Fsd status for the Irp
  51. --*/
  52. {
  53. NTSTATUS status;
  54. PAGED_CODE();
  55. DebugTrace(+1, Dbg, "MsFsdQuerySecurityInfo\n", 0);
  56. //
  57. // Call the common Query Information routine.
  58. //
  59. FsRtlEnterFileSystem();
  60. status = MsCommonQuerySecurityInfo( MsfsDeviceObject, Irp );
  61. FsRtlExitFileSystem();
  62. //
  63. // And return to our caller
  64. //
  65. DebugTrace(-1, Dbg, "MsFsdQuerySecurityInfo -> %08lx\n", status );
  66. return status;
  67. }
  68. NTSTATUS
  69. MsFsdSetSecurityInfo (
  70. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  71. IN PIRP Irp
  72. )
  73. /*++
  74. Routine Description:
  75. This routine implements the FSD part of the Set Security Information API
  76. calls.
  77. Arguments:
  78. MsfsDeviceObject - Supplies the device object to use.
  79. Irp - Supplies the Irp being processed
  80. Return Value:
  81. NTSTATUS - The Fsd status for the Irp
  82. --*/
  83. {
  84. NTSTATUS status;
  85. PAGED_CODE();
  86. DebugTrace(+1, Dbg, "MsFsdSetSecurityInfo\n", 0);
  87. //
  88. // Call the common Set Information routine.
  89. //
  90. FsRtlEnterFileSystem();
  91. status = MsCommonSetSecurityInfo( MsfsDeviceObject, Irp );
  92. FsRtlExitFileSystem();
  93. //
  94. // And return to our caller
  95. //
  96. DebugTrace(-1, Dbg, "MsFsdSetSecurityInfo -> %08lx\n", status );
  97. return status;
  98. }
  99. //
  100. // Internal support routine
  101. //
  102. NTSTATUS
  103. MsCommonQuerySecurityInfo (
  104. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  105. IN PIRP Irp
  106. )
  107. /*++
  108. Routine Description:
  109. This is the common routine for querying security information.
  110. Arguments:
  111. Irp - Supplies the Irp to process
  112. Return Value:
  113. NTSTATUS - the return status for the operation
  114. --*/
  115. {
  116. PIO_STACK_LOCATION irpSp;
  117. NTSTATUS status;
  118. NODE_TYPE_CODE nodeTypeCode;
  119. PFCB fcb;
  120. PVOID fsContext2;
  121. PAGED_CODE();
  122. //
  123. // Get the current stack location
  124. //
  125. irpSp = IoGetCurrentIrpStackLocation( Irp );
  126. DebugTrace(+1, Dbg, "MsCommonQuerySecurityInfo...\n", 0);
  127. DebugTrace( 0, Dbg, " Irp = %08lx\n", Irp);
  128. DebugTrace( 0, Dbg, " ->SecurityInformation = %08lx\n", irpSp->Parameters.QuerySecurity.SecurityInformation);
  129. DebugTrace( 0, Dbg, " ->Length = %08lx\n", irpSp->Parameters.QuerySecurity.Length);
  130. DebugTrace( 0, Dbg, " ->UserBuffer = %08lx\n", Irp->UserBuffer);
  131. //
  132. // Get the Fcb and figure out who we are, and make sure we're not
  133. // disconnected.
  134. //
  135. if ((nodeTypeCode = MsDecodeFileObject( irpSp->FileObject,
  136. &fcb,
  137. &fsContext2 )) != MSFS_NTC_FCB) {
  138. DebugTrace(0, Dbg, "Mailslot is disconnected from us\n", 0);
  139. if (nodeTypeCode != NTC_UNDEFINED) {
  140. MsDereferenceNode( &fcb->Header );
  141. }
  142. MsCompleteRequest( Irp, STATUS_FILE_FORCED_CLOSED );
  143. status = STATUS_FILE_FORCED_CLOSED;
  144. DebugTrace(-1, Dbg, "MsCommonQueryInformation -> %08lx\n", status );
  145. return status;
  146. }
  147. //
  148. // Acquire exclusive access to the FCB.
  149. //
  150. MsAcquireSharedFcb( fcb );
  151. //
  152. // Call the security routine to do the actual query
  153. //
  154. status = SeQuerySecurityDescriptorInfo( &irpSp->Parameters.QuerySecurity.SecurityInformation,
  155. Irp->UserBuffer,
  156. &irpSp->Parameters.QuerySecurity.Length,
  157. &fcb->SecurityDescriptor );
  158. MsReleaseFcb( fcb );
  159. MsDereferenceFcb( fcb );
  160. //
  161. // Finish up the IRP.
  162. //
  163. MsCompleteRequest( Irp, status );
  164. DebugTrace(-1, Dbg, "MsCommonQuerySecurityInfo -> %08lx\n", status );
  165. return status;
  166. }
  167. NTSTATUS
  168. MsCommonSetSecurityInfo (
  169. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  170. IN PIRP Irp
  171. )
  172. /*++
  173. Routine Description:
  174. This is the common routine for Setting security information.
  175. Arguments:
  176. Irp - Supplies the Irp to process
  177. Return Value:
  178. NTSTATUS - the return status for the operation
  179. --*/
  180. {
  181. PIO_STACK_LOCATION irpSp;
  182. NTSTATUS status;
  183. NODE_TYPE_CODE nodeTypeCode;
  184. PFCB fcb;
  185. PVOID fsContext2;
  186. PSECURITY_DESCRIPTOR OldSecurityDescriptor;
  187. PAGED_CODE();
  188. //
  189. // Get the current stack location
  190. //
  191. irpSp = IoGetCurrentIrpStackLocation( Irp );
  192. DebugTrace(+1, Dbg, "MsCommonSetSecurityInfo...\n", 0);
  193. DebugTrace( 0, Dbg, " Irp = %08lx\n", Irp);
  194. DebugTrace( 0, Dbg, " ->SecurityInformation = %08lx\n", irpSp->Parameters.SetSecurity.SecurityInformation);
  195. DebugTrace( 0, Dbg, " ->SecurityDescriptor = %08lx\n", irpSp->Parameters.SetSecurity.SecurityDescriptor);
  196. //
  197. // Get the FCB and figure out who we are, and make sure we're not
  198. // disconnected.
  199. //
  200. if ((nodeTypeCode = MsDecodeFileObject( irpSp->FileObject,
  201. &fcb,
  202. &fsContext2 )) != MSFS_NTC_FCB) {
  203. DebugTrace(0, Dbg, "Invalid handle\n", 0);
  204. if (nodeTypeCode != NTC_UNDEFINED) {
  205. MsDereferenceNode( &fcb->Header );
  206. }
  207. MsCompleteRequest( Irp, STATUS_INVALID_HANDLE );
  208. status = STATUS_INVALID_HANDLE;
  209. DebugTrace(-1, Dbg, "MsCommonQueryInformation -> %08lx\n", status );
  210. return status;
  211. }
  212. //
  213. // Acquire exclusive access to the FCB
  214. //
  215. MsAcquireExclusiveFcb( fcb );
  216. //
  217. // Call the security routine to do the actual set
  218. //
  219. OldSecurityDescriptor = fcb->SecurityDescriptor;
  220. status = SeSetSecurityDescriptorInfo( NULL,
  221. &irpSp->Parameters.SetSecurity.SecurityInformation,
  222. irpSp->Parameters.SetSecurity.SecurityDescriptor,
  223. &fcb->SecurityDescriptor,
  224. PagedPool,
  225. IoGetFileObjectGenericMapping() );
  226. if (NT_SUCCESS(status)) {
  227. ExFreePool( OldSecurityDescriptor );
  228. }
  229. MsReleaseFcb( fcb );
  230. MsDereferenceFcb( fcb );
  231. //
  232. // Finish up the IRP.
  233. //
  234. MsCompleteRequest( Irp, status );
  235. DebugTrace(-1, Dbg, "MsCommonSetSecurityInfo -> %08lx\n", status );
  236. return status;
  237. }