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.

390 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. SeInfo.c
  5. Abstract:
  6. This module implements the Security Info routines for NPFS called by the
  7. dispatch driver. There are two entry points NpFsdQueryInformation
  8. and NpFsdSetInformation.
  9. Author:
  10. Gary Kimura [GaryKi] 21-Aug-1990
  11. Revision History:
  12. --*/
  13. #include "NpProcs.h"
  14. //
  15. // The debug trace level
  16. //
  17. #define Dbg (DEBUG_TRACE_SEINFO)
  18. //
  19. // local procedure prototypes
  20. //
  21. NTSTATUS
  22. NpCommonQuerySecurityInfo (
  23. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  24. IN PIRP Irp
  25. );
  26. NTSTATUS
  27. NpCommonSetSecurityInfo (
  28. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  29. IN PIRP Irp
  30. );
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text(PAGE, NpCommonQuerySecurityInfo)
  33. #pragma alloc_text(PAGE, NpCommonSetSecurityInfo)
  34. #pragma alloc_text(PAGE, NpFsdQuerySecurityInfo)
  35. #pragma alloc_text(PAGE, NpFsdSetSecurityInfo)
  36. #endif
  37. NTSTATUS
  38. NpFsdQuerySecurityInfo (
  39. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  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. NpfsDeviceObject - 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, "NpFsdQuerySecurityInfo\n", 0);
  56. //
  57. // Call the common Query Information routine.
  58. //
  59. FsRtlEnterFileSystem();
  60. NpAcquireExclusiveVcb();
  61. Status = NpCommonQuerySecurityInfo( NpfsDeviceObject, Irp );
  62. NpReleaseVcb();
  63. FsRtlExitFileSystem();
  64. if (Status != STATUS_PENDING) {
  65. NpCompleteRequest (Irp, Status);
  66. }
  67. //
  68. // And return to our caller
  69. //
  70. DebugTrace(-1, Dbg, "NpFsdQuerySecurityInfo -> %08lx\n", Status );
  71. return Status;
  72. }
  73. NTSTATUS
  74. NpFsdSetSecurityInfo (
  75. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  76. IN PIRP Irp
  77. )
  78. /*++
  79. Routine Description:
  80. This routine implements the FSD part of the Set Security Information API
  81. calls.
  82. Arguments:
  83. NpfsDeviceObject - Supplies the device object to use.
  84. Irp - Supplies the Irp being processed
  85. Return Value:
  86. NTSTATUS - The Fsd status for the Irp
  87. --*/
  88. {
  89. NTSTATUS Status;
  90. PAGED_CODE();
  91. DebugTrace(+1, Dbg, "NpFsdSetSecurityInfo\n", 0);
  92. //
  93. // Call the common Set Information routine.
  94. //
  95. FsRtlEnterFileSystem();
  96. NpAcquireExclusiveVcb();
  97. Status = NpCommonSetSecurityInfo( NpfsDeviceObject, Irp );
  98. NpReleaseVcb();
  99. FsRtlExitFileSystem();
  100. if (Status != STATUS_PENDING) {
  101. NpCompleteRequest (Irp, Status);
  102. }
  103. //
  104. // And return to our caller
  105. //
  106. DebugTrace(-1, Dbg, "NpFsdSetSecurityInfo -> %08lx\n", Status );
  107. return Status;
  108. }
  109. //
  110. // Internal support routine
  111. //
  112. NTSTATUS
  113. NpCommonQuerySecurityInfo (
  114. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  115. IN PIRP Irp
  116. )
  117. /*++
  118. Routine Description:
  119. This is the common routine for querying security information.
  120. Arguments:
  121. Irp - Supplies the Irp to process
  122. Return Value:
  123. NTSTATUS - the return status for the operation
  124. --*/
  125. {
  126. PIO_STACK_LOCATION IrpSp;
  127. NTSTATUS Status;
  128. NODE_TYPE_CODE NodeTypeCode;
  129. PFCB Fcb;
  130. PCCB Ccb;
  131. NAMED_PIPE_END NamedPipeEnd;
  132. PAGED_CODE();
  133. //
  134. // Get the current stack location
  135. //
  136. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  137. DebugTrace(+1, Dbg, "NpCommonQuerySecurityInfo...\n", 0);
  138. DebugTrace( 0, Dbg, " Irp = %08lx\n", Irp);
  139. DebugTrace( 0, Dbg, " ->SecurityInformation = %08lx\n", IrpSp->Parameters.QuerySecurity.SecurityInformation);
  140. DebugTrace( 0, Dbg, " ->Length = %08lx\n", IrpSp->Parameters.QuerySecurity.Length);
  141. DebugTrace( 0, Dbg, " ->UserBuffer = %08lx\n", Irp->UserBuffer);
  142. //
  143. // Get the ccb and figure out who we are, and make sure we're not
  144. // disconnected.
  145. //
  146. if ((NodeTypeCode = NpDecodeFileObject( IrpSp->FileObject,
  147. &Fcb,
  148. &Ccb,
  149. &NamedPipeEnd )) == NTC_UNDEFINED) {
  150. DebugTrace(0, Dbg, "Pipe is disconnected from us\n", 0);
  151. Status = STATUS_PIPE_DISCONNECTED;
  152. DebugTrace(-1, Dbg, "NpCommonQueryInformation -> %08lx\n", Status );
  153. return Status;
  154. }
  155. //
  156. // Now we only will allow write operations on the pipe and not a directory
  157. // or the device
  158. //
  159. if (NodeTypeCode != NPFS_NTC_CCB) {
  160. DebugTrace(0, Dbg, "FileObject is not for a named pipe\n", 0);
  161. Status = STATUS_INVALID_PARAMETER;
  162. DebugTrace(-1, Dbg, "NpCommonQueryInformation -> %08lx\n", Status );
  163. return Status;
  164. }
  165. //
  166. // Call the security routine to do the actual query
  167. //
  168. Status = SeQuerySecurityDescriptorInfo( &IrpSp->Parameters.QuerySecurity.SecurityInformation,
  169. Irp->UserBuffer,
  170. &IrpSp->Parameters.QuerySecurity.Length,
  171. &Fcb->SecurityDescriptor );
  172. if ( Status == STATUS_BUFFER_TOO_SMALL ) {
  173. Irp->IoStatus.Information = IrpSp->Parameters.QuerySecurity.Length;
  174. Status = STATUS_BUFFER_OVERFLOW;
  175. }
  176. DebugTrace(-1, Dbg, "NpCommonQuerySecurityInfo -> %08lx\n", Status );
  177. return Status;
  178. }
  179. //
  180. // Internal support routine
  181. //
  182. NTSTATUS
  183. NpCommonSetSecurityInfo (
  184. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  185. IN PIRP Irp
  186. )
  187. /*++
  188. Routine Description:
  189. This is the common routine for Setting security information.
  190. Arguments:
  191. Irp - Supplies the Irp to process
  192. Return Value:
  193. NTSTATUS - the return status for the operation
  194. --*/
  195. {
  196. PIO_STACK_LOCATION IrpSp;
  197. NTSTATUS Status;
  198. NODE_TYPE_CODE NodeTypeCode;
  199. PFCB Fcb;
  200. PCCB Ccb;
  201. NAMED_PIPE_END NamedPipeEnd;
  202. PSECURITY_DESCRIPTOR OldSecurityDescriptor, NewSecurityDescriptor, CachedSecurityDescriptor;
  203. PAGED_CODE();
  204. //
  205. // Get the current stack location
  206. //
  207. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  208. DebugTrace(+1, Dbg, "NpCommonSetSecurityInfo...\n", 0);
  209. DebugTrace( 0, Dbg, " Irp = %08lx\n", Irp);
  210. DebugTrace( 0, Dbg, " ->SecurityInformation = %08lx\n", IrpSp->Parameters.SetSecurity.SecurityInformation);
  211. DebugTrace( 0, Dbg, " ->SecurityDescriptor = %08lx\n", IrpSp->Parameters.SetSecurity.SecurityDescriptor);
  212. //
  213. // Get the ccb and figure out who we are, and make sure we're not
  214. // disconnected.
  215. //
  216. if ((NodeTypeCode = NpDecodeFileObject( IrpSp->FileObject,
  217. &Fcb,
  218. &Ccb,
  219. &NamedPipeEnd )) == NTC_UNDEFINED) {
  220. DebugTrace(0, Dbg, "Pipe is disconnected from us\n", 0);
  221. Status = STATUS_PIPE_DISCONNECTED;
  222. DebugTrace(-1, Dbg, "NpCommonQueryInformation -> %08lx\n", Status );
  223. return Status;
  224. }
  225. //
  226. // Now we only will allow write operations on the pipe and not a directory
  227. // or the device
  228. //
  229. if (NodeTypeCode != NPFS_NTC_CCB) {
  230. DebugTrace(0, Dbg, "FileObject is not for a named pipe\n", 0);
  231. Status = STATUS_INVALID_PARAMETER;
  232. DebugTrace(-1, Dbg, "NpCommonQueryInformation -> %08lx\n", Status );
  233. return Status;
  234. }
  235. //
  236. // Call the security routine to do the actual set
  237. //
  238. NewSecurityDescriptor = OldSecurityDescriptor = Fcb->SecurityDescriptor;
  239. Status = SeSetSecurityDescriptorInfo( NULL,
  240. &IrpSp->Parameters.SetSecurity.SecurityInformation,
  241. IrpSp->Parameters.SetSecurity.SecurityDescriptor,
  242. &NewSecurityDescriptor,
  243. PagedPool,
  244. IoGetFileObjectGenericMapping() );
  245. if (NT_SUCCESS(Status)) {
  246. Status = ObLogSecurityDescriptor (NewSecurityDescriptor,
  247. &CachedSecurityDescriptor,
  248. 1);
  249. NpFreePool (NewSecurityDescriptor);
  250. if (NT_SUCCESS(Status)) {
  251. Fcb->SecurityDescriptor = CachedSecurityDescriptor;
  252. ObDereferenceSecurityDescriptor( OldSecurityDescriptor, 1 );
  253. }
  254. }
  255. DebugTrace(-1, Dbg, "NpCommonSetSecurityInfo -> %08lx\n", Status );
  256. return Status;
  257. }