Windows NT 4.0 source code leak
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.

391 lines
8.8 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. svccdevq.c
  5. Abstract:
  6. This module contains routines for supporting the character device
  7. APIs in the server service, SrvNetCharDevQEnum, SrvNetCharDevQGetInfo,
  8. SrvNetCharDevQPurge and SrvNetCharDevQSetInfo.
  9. Author:
  10. David Treadwell (davidtr) 31-Jan-1991
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text( PAGE, SrvNetCharDevQEnum )
  17. #pragma alloc_text( PAGE, SrvNetCharDevQPurge )
  18. #pragma alloc_text( PAGE, SrvNetCharDevQSetInfo )
  19. #if SRV_COMM_DEVICES
  20. #pragma alloc_text( PAGE, FillCharDevQInfoBuffer )
  21. #pragma alloc_text( PAGE, FilterCharDevQs )
  22. #pragma alloc_text( PAGE, SizeCharDevQs )
  23. #endif
  24. #endif
  25. //
  26. // Forward declarations.
  27. //
  28. VOID
  29. FillCharDevQInfoBuffer (
  30. IN PSERVER_REQUEST_PACKET Srp,
  31. IN PVOID Block,
  32. IN OUT PVOID *FixedStructure,
  33. IN LPTSTR *EndOfVariableData
  34. );
  35. BOOLEAN
  36. FilterCharDevQs (
  37. IN PSERVER_REQUEST_PACKET Srp,
  38. IN PVOID Block
  39. );
  40. ULONG
  41. SizeCharDevQs (
  42. IN PSERVER_REQUEST_PACKET Srp,
  43. IN PVOID Block
  44. );
  45. //
  46. // Macros to determine the size a character device would take up at one of the
  47. // levels of chardev information.
  48. //
  49. #define TOTAL_SIZE_OF_CHARDEVQ(level,share) \
  50. ( (level) == 0 ? sizeof(CHARDEVQ_INFO_0) + \
  51. SrvLengthOfStringInApiBuffer(&(share)->ShareName) : \
  52. sizeof(CHARDEVQ_INFO_1) + \
  53. SrvLengthOfStringInApiBuffer(&(share)->ShareName) + \
  54. SrvLengthOfStringInApiBuffer( \
  55. &(share)->Type.CommDevice->DosPathName) )
  56. #define FIXED_SIZE_OF_CHARDEVQ(level) \
  57. ( (level) == 0 ? sizeof(CHARDEVQ_INFO_0) : \
  58. sizeof(CHARDEVQ_INFO_1) )
  59. NTSTATUS
  60. SrvNetCharDevQEnum (
  61. IN PSERVER_REQUEST_PACKET Srp,
  62. IN PVOID Buffer,
  63. IN ULONG BufferLength
  64. )
  65. /*++
  66. Routine Description:
  67. This routine processes the NetCharDevQEnum API in the server.
  68. Arguments:
  69. Srp - a pointer to the server request packet that contains all
  70. the information necessary to satisfy the request. This includes:
  71. INPUT:
  72. Level - level of information to return, 0, or 1.
  73. Name1 - a username; the number of requests ahead of a specified
  74. user is written to cq1_numahead in lm2.x; since NT doesn't
  75. support queueing or pooling of comm devices, we only use
  76. the existence of a username to know to set the field to
  77. CHARDEVQ_NO_REQUESTS.
  78. OUTPUT:
  79. Parameters.Get.EntriesRead - the number of entries that fit in
  80. the output buffer.
  81. Parameters.Get.TotalEntries - the total number of entries that
  82. would be returned with a large enough buffer.
  83. Parameters.Get.TotalBytesNeeded - the buffer size that would be
  84. required to hold all the entries.
  85. Buffer - a pointer to the buffer for results.
  86. BufferLength - the length of this buffer.
  87. Return Value:
  88. NTSTATUS - result of operation to return to the server service.
  89. --*/
  90. {
  91. PAGED_CODE( );
  92. #if SRV_COMM_DEVICES
  93. return SrvShareEnumApiHandler(
  94. Srp,
  95. Buffer,
  96. BufferLength,
  97. FilterCharDevQs,
  98. SizeCharDevQs,
  99. FillCharDevQInfoBuffer
  100. );
  101. #else
  102. Srp->Parameters.Get.EntriesRead = 0;
  103. Srp->Parameters.Get.TotalEntries = 0;
  104. Srp->Parameters.Get.TotalBytesNeeded = 0;
  105. Srp->ErrorCode = NO_ERROR;
  106. return STATUS_SUCCESS;
  107. #endif
  108. } // SrvNetCharDevQEnum
  109. NTSTATUS
  110. SrvNetCharDevQPurge (
  111. IN PSERVER_REQUEST_PACKET Srp,
  112. IN PVOID Buffer,
  113. IN ULONG BufferLength
  114. )
  115. {
  116. PAGED_CODE( );
  117. Srp, Buffer, BufferLength;
  118. return STATUS_NOT_IMPLEMENTED;
  119. } // SrvNetCharDevQPurge
  120. NTSTATUS
  121. SrvNetCharDevQSetInfo (
  122. IN PSERVER_REQUEST_PACKET Srp,
  123. IN PVOID Buffer,
  124. IN ULONG BufferLength
  125. )
  126. {
  127. PAGED_CODE( );
  128. Srp, Buffer, BufferLength;
  129. return STATUS_NOT_IMPLEMENTED;
  130. } // SrvNetCharDevQSetInfo
  131. #if SRV_COMM_DEVICES
  132. VOID
  133. FillCharDevQInfoBuffer (
  134. IN PSERVER_REQUEST_PACKET Srp,
  135. IN PVOID Block,
  136. IN OUT PVOID *FixedStructure,
  137. IN LPTSTR *EndOfVariableData
  138. )
  139. /*++
  140. Routine Description:
  141. This routine puts a single fixed file structure and associated
  142. variable data, into a buffer. Fixed data goes at the beginning of
  143. the buffer, variable data at the end.
  144. *** This routine assumes that ALL the data, both fixed and variable,
  145. will fit.
  146. Arguments:
  147. Srp - a pointer to the SRP for the operation. Only the Level
  148. field is used.
  149. Block - the comm share from which to get information.
  150. FixedStructure - where the in the buffer to place the fixed structure.
  151. This pointer is updated to point to the next available
  152. position for a fixed structure.
  153. EndOfVariableData - the last position on the buffer that variable
  154. data for this structure can occupy. The actual variable data
  155. is written before this position as long as it won't overwrite
  156. fixed structures. It is would overwrite fixed structures, it
  157. is not written.
  158. Return Value:
  159. None.
  160. --*/
  161. {
  162. PCHARDEVQ_INFO_1 cq1 = *FixedStructure;
  163. PSHARE share = Block;
  164. PAGED_CODE( );
  165. //
  166. // Update FixedStructure to point to the next structure location.
  167. //
  168. *FixedStructure = (PCHAR)*FixedStructure +
  169. FIXED_SIZE_OF_CHARDEVQ( Srp->Level );
  170. ASSERT( (ULONG)*EndOfVariableData >= (ULONG)*FixedStructure );
  171. //
  172. // Case on the level to fill in the fixed structure appropriately.
  173. // We fill in actual pointers in the output structure. This is
  174. // possible because we are in the server FSD, hence the server
  175. // service's process and address space.
  176. //
  177. // *** Using the switch statement in this fashion relies on the fact
  178. // that the first fields on the different chardev structures are
  179. // identical (with the exception of level 10, which is handled
  180. // separately).
  181. //
  182. switch( Srp->Level ) {
  183. case 1:
  184. //
  185. // Fill in level-1 fields of char dev Q structure.
  186. //
  187. // !!! we could store the priority in the share block and
  188. // return it here, even though it has no impact on the way
  189. // things operate. Does this make sense? Would it be
  190. // confusing?
  191. cq1->cq1_priority = 0;
  192. SrvCopyUnicodeStringToBuffer(
  193. &share->Type.CommDevice->DosPathName,
  194. *FixedStructure,
  195. EndOfVariableData,
  196. &cq1->cq1_devs
  197. );
  198. cq1->cq1_numusers = 0;
  199. if ( Srp->Name1.Buffer == NULL ) {
  200. cq1->cq1_numahead = 0;
  201. } else {
  202. cq1->cq1_numahead = (ULONG)CHARDEVQ_NO_REQUESTS;
  203. }
  204. // *** lack of break is intentional!
  205. case 0:
  206. //
  207. // Set up the share name in the output buffer.
  208. //
  209. SrvCopyUnicodeStringToBuffer(
  210. &share->ShareName,
  211. *FixedStructure,
  212. EndOfVariableData,
  213. &cq1->cq1_dev
  214. );
  215. break;
  216. default:
  217. //
  218. // This should never happen. The server service should have
  219. // checked for an invalid level.
  220. //
  221. INTERNAL_ERROR(
  222. ERROR_LEVEL_UNEXPECTED,
  223. "FillCharDevInfoBuffer: invalid level number: %ld",
  224. Srp->Level,
  225. NULL
  226. );
  227. SrvLogInvalidSmb( NULL );
  228. }
  229. return;
  230. } // FillCharDevQInfoBuffer
  231. BOOLEAN
  232. FilterCharDevQs (
  233. IN PSERVER_REQUEST_PACKET Srp,
  234. IN PVOID Block
  235. )
  236. /*++
  237. Routine Description:
  238. This routine is intended to be called by SrvEnumApiHandler to check
  239. whether a particular share is a comm queue.
  240. Arguments:
  241. Srp - a pointer to the SRP for the operation.
  242. Block - a pointer to the share to check.
  243. Return Value:
  244. TRUE if the block should be placed in the output buffer, FALSE
  245. if it should be passed over.
  246. --*/
  247. {
  248. PSHARE share = Block;
  249. PAGED_CODE( );
  250. return (BOOLEAN)( share->ShareType == ShareTypeComm );
  251. } // FilterCharDevQs
  252. ULONG
  253. SizeCharDevQs (
  254. IN PSERVER_REQUEST_PACKET Srp,
  255. IN PVOID Block
  256. )
  257. /*++
  258. Routine Description:
  259. This routine returns the size the passed-in comm share would take
  260. up in an API output buffer.
  261. Arguments:
  262. Srp - a pointer to the SRP for the operation. Only the level
  263. parameter is used.
  264. Block - a pointer to the comm device to size.
  265. Return Value:
  266. ULONG - The number of bytes the comm device would take up in the
  267. output buffer.
  268. --*/
  269. {
  270. PSHARE share = Block;
  271. PAGED_CODE( );
  272. return TOTAL_SIZE_OF_CHARDEVQ( Srp->Level, share );
  273. } // SizeCharDevQs
  274. #endif // SRV_COMM_DEVICES