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.

541 lines
12 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. svcxport.c
  5. Abstract:
  6. This module contains routines for supporting the transport APIs in the
  7. server service, NetServerTransportAdd, NetServerTransportDel,
  8. and NetServerTransportEnum.
  9. Author:
  10. David Treadwell (davidtr) 6-Mar-1991
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. //
  16. // Forward declarations.
  17. //
  18. VOID
  19. FillTransportInfoBuffer (
  20. IN PSERVER_REQUEST_PACKET Srp,
  21. IN PVOID Block,
  22. IN OUT PVOID *FixedStructure,
  23. IN LPTSTR *EndOfVariableData
  24. );
  25. BOOLEAN
  26. FilterTransports (
  27. IN PSERVER_REQUEST_PACKET Srp,
  28. IN PVOID Block
  29. );
  30. ULONG
  31. SizeTransports (
  32. IN PSERVER_REQUEST_PACKET Srp,
  33. IN PVOID Block
  34. );
  35. #ifdef ALLOC_PRAGMA
  36. #pragma alloc_text( PAGE, SrvNetServerTransportAdd )
  37. #pragma alloc_text( PAGE, SrvNetServerTransportDel )
  38. #pragma alloc_text( PAGE, SrvNetServerTransportEnum )
  39. #pragma alloc_text( PAGE, FillTransportInfoBuffer )
  40. #pragma alloc_text( PAGE, FilterTransports )
  41. #pragma alloc_text( PAGE, SizeTransports )
  42. #endif
  43. NTSTATUS
  44. SrvNetServerTransportAdd (
  45. IN PSERVER_REQUEST_PACKET Srp,
  46. IN PVOID Buffer,
  47. IN ULONG BufferLength
  48. )
  49. /*++
  50. Routine Description:
  51. This routine processes the NetServerTransportAdd API in the server
  52. FSP. Because it opens an object (the transpot device object) it
  53. must be done in the server FSP, not the FSD.
  54. Arguments:
  55. Srp - a pointer to the server request packet that contains all
  56. the information necessary to satisfy the request. This includes:
  57. INPUT:
  58. None.
  59. OUTPUT:
  60. None.
  61. Buffer - a pointer to a TRANSPORT_INFO_0 structure for the new
  62. transport. All pointers should have been changed to offsets
  63. within the buffer.
  64. BufferLength - total length of this buffer.
  65. Return Value:
  66. NTSTATUS - result of operation to return to the server service.
  67. --*/
  68. {
  69. NTSTATUS status;
  70. PSERVER_TRANSPORT_INFO_1 svti1;
  71. UNICODE_STRING transportName;
  72. UNICODE_STRING domainName;
  73. ANSI_STRING transportAddress;
  74. UNICODE_STRING netName;
  75. PAGED_CODE( );
  76. //
  77. // Convert the offsets in the transport data structure to pointers.
  78. // Also make sure that all the pointers are within the specified
  79. // buffer.
  80. //
  81. svti1 = Buffer;
  82. OFFSET_TO_POINTER( svti1->svti1_transportname, svti1 );
  83. OFFSET_TO_POINTER( svti1->svti1_transportaddress, svti1 );
  84. OFFSET_TO_POINTER( svti1->svti1_domain, svti1 );
  85. if ( !POINTER_IS_VALID( svti1->svti1_transportname, svti1, BufferLength ) ||
  86. !POINTER_IS_VALID( svti1->svti1_transportaddress, svti1, BufferLength ) ||
  87. !POINTER_IS_VALID( svti1->svti1_domain, svti1, BufferLength ) ) {
  88. return STATUS_ACCESS_VIOLATION;
  89. }
  90. //
  91. // Set up the transport name, server name, domain name, and net name.
  92. //
  93. RtlInitUnicodeString( &transportName, (PWCH)svti1->svti1_transportname );
  94. netName.Buffer = NULL;
  95. netName.Length = 0;
  96. netName.MaximumLength = 0;
  97. RtlInitUnicodeString( &domainName, (PWCH)svti1->svti1_domain );
  98. transportAddress.Buffer = svti1->svti1_transportaddress;
  99. transportAddress.Length = (USHORT)svti1->svti1_transportaddresslength;
  100. transportAddress.MaximumLength = (USHORT)svti1->svti1_transportaddresslength;
  101. //
  102. // Attempt to add the new transport to the server.
  103. //
  104. status = SrvAddServedNet( &netName,
  105. &transportName,
  106. &transportAddress,
  107. &domainName,
  108. Srp->Flags & SRP_XADD_PRIMARY_MACHINE );
  109. return status;
  110. } // SrvNetServerTransportAdd
  111. NTSTATUS
  112. SrvNetServerTransportDel (
  113. IN PSERVER_REQUEST_PACKET Srp,
  114. IN PVOID Buffer,
  115. IN ULONG BufferLength
  116. )
  117. /*++
  118. Routine Description:
  119. This routine processes the NetServerTransportEnum API in the server
  120. FSD.
  121. Arguments:
  122. Srp - a pointer to the server request packet that contains all
  123. the information necessary to satisfy the request. This includes:
  124. INPUT:
  125. None.
  126. OUTPUT:
  127. None.
  128. Buffer - a pointer to a TRANSPORT_INFO_0 structure for the new
  129. transport. All pointers should have been changed to offsets
  130. within the buffer.
  131. BufferLength - total length of this buffer.
  132. Return Value:
  133. NTSTATUS - result of operation to return to the server service.
  134. --*/
  135. {
  136. NTSTATUS status;
  137. PSERVER_TRANSPORT_INFO_1 svti1;
  138. UNICODE_STRING transportName;
  139. UNICODE_STRING domainName;
  140. ANSI_STRING transportAddress;
  141. PAGED_CODE( );
  142. Srp;
  143. //
  144. // Convert the offsets in the transport data structure to pointers.
  145. // Also make sure that all the pointers are within the specified
  146. // buffer.
  147. //
  148. svti1 = Buffer;
  149. OFFSET_TO_POINTER( svti1->svti1_transportname, svti1 );
  150. OFFSET_TO_POINTER( svti1->svti1_transportaddress, svti1 );
  151. OFFSET_TO_POINTER( svti1->svti1_domain, svti1 );
  152. if ( !POINTER_IS_VALID( svti1->svti1_transportname, svti1, BufferLength ) ||
  153. !POINTER_IS_VALID( svti1->svti1_transportaddress, svti1, BufferLength ) ||
  154. !POINTER_IS_VALID( svti1->svti1_domain, svti1, BufferLength ) ) {
  155. return STATUS_ACCESS_VIOLATION;
  156. }
  157. //
  158. // Set up the transport name, server name, domain name, and net name.
  159. //
  160. RtlInitUnicodeString( &transportName, (PWCH)svti1->svti1_transportname );
  161. transportAddress.Buffer = svti1->svti1_transportaddress;
  162. transportAddress.Length = (USHORT)svti1->svti1_transportaddresslength;
  163. transportAddress.MaximumLength = (USHORT)svti1->svti1_transportaddresslength;
  164. //
  165. // Attempt to delete the transport endpoint from the server.
  166. //
  167. status = SrvDeleteServedNet( &transportName, &transportAddress );
  168. return status;
  169. } // SrvNetServerTransportDel
  170. NTSTATUS
  171. SrvNetServerTransportEnum (
  172. IN PSERVER_REQUEST_PACKET Srp,
  173. IN PVOID Buffer,
  174. IN ULONG BufferLength
  175. )
  176. /*++
  177. Routine Description:
  178. This routine processes the NetServerTransportEnum API in the server
  179. FSD.
  180. Arguments:
  181. Srp - a pointer to the server request packet that contains all
  182. the information necessary to satisfy the request. This includes:
  183. INPUT:
  184. None.
  185. OUTPUT:
  186. Parameters.Get.EntriesRead - the number of entries that fit in
  187. the output buffer.
  188. Parameters.Get.TotalEntries - the total number of entries that
  189. would be returned with a large enough buffer.
  190. Parameters.Get.TotalBytesNeeded - the buffer size that would be
  191. required to hold all the entries.
  192. Buffer - a pointer to a TRANSPORT_INFO_0 structure for the new
  193. transport. All pointers should have been changed to offsets
  194. within the buffer.
  195. BufferLength - total length of this buffer.
  196. Return Value:
  197. NTSTATUS - result of operation to return to the server service.
  198. --*/
  199. {
  200. PAGED_CODE( );
  201. return SrvEnumApiHandler(
  202. Srp,
  203. Buffer,
  204. BufferLength,
  205. &SrvEndpointList,
  206. FilterTransports,
  207. SizeTransports,
  208. FillTransportInfoBuffer
  209. );
  210. } // SrvNetServerTransportEnum
  211. VOID
  212. FillTransportInfoBuffer (
  213. IN PSERVER_REQUEST_PACKET Srp,
  214. IN PVOID Block,
  215. IN OUT PVOID *FixedStructure,
  216. IN LPTSTR *EndOfVariableData
  217. )
  218. /*++
  219. Routine Description:
  220. This routine puts a single fixed transport structure and, if it fits,
  221. associated variable data, into a buffer. Fixed data goes at the
  222. beginning of the buffer, variable data at the end.
  223. Arguments:
  224. Endpoint - the endpoint from which to get information.
  225. FixedStructure - where the ine buffer to place the fixed structure.
  226. This pointer is updated to point to the next available
  227. position for a fixed structure.
  228. EndOfVariableData - the last position on the buffer that variable
  229. data for this structure can occupy. The actual variable data
  230. is written before this position as long as it won't overwrite
  231. fixed structures. It is would overwrite fixed structures, it
  232. is not written.
  233. Return Value:
  234. None.
  235. --*/
  236. {
  237. PENDPOINT endpoint = Block;
  238. PSERVER_TRANSPORT_INFO_1 svti1 = *FixedStructure;
  239. ULONG TransportAddressLength;
  240. PAGED_CODE( );
  241. //
  242. // Update FixedStructure to point to the next structure location.
  243. //
  244. *FixedStructure = (PCHAR)*FixedStructure +
  245. (Srp->Level ? sizeof( SERVER_TRANSPORT_INFO_1 ) : sizeof( SERVER_TRANSPORT_INFO_0 ));
  246. ASSERT( (ULONG)*EndOfVariableData >= (ULONG)*FixedStructure );
  247. //
  248. // The number of VCs on the endpoint is equal to the total number
  249. // of connections on the endpoint less the free connections.
  250. //
  251. ACQUIRE_LOCK_SHARED( &SrvEndpointLock );
  252. svti1->svti1_numberofvcs =
  253. endpoint->TotalConnectionCount - endpoint->FreeConnectionCount;
  254. RELEASE_LOCK( &SrvEndpointLock );
  255. //
  256. // Copy over the transport name.
  257. //
  258. SrvCopyUnicodeStringToBuffer(
  259. &endpoint->TransportName,
  260. *FixedStructure,
  261. EndOfVariableData,
  262. &svti1->svti1_transportname
  263. );
  264. //
  265. // Copy over the network name.
  266. //
  267. SrvCopyUnicodeStringToBuffer(
  268. &endpoint->NetworkAddress,
  269. *FixedStructure,
  270. EndOfVariableData,
  271. &svti1->svti1_networkaddress
  272. );
  273. //
  274. // Copy over the domain name
  275. //
  276. if( Srp->Level > 0 ) {
  277. SrvCopyUnicodeStringToBuffer(
  278. &endpoint->DomainName,
  279. *FixedStructure,
  280. EndOfVariableData,
  281. &svti1->svti1_domain
  282. );
  283. }
  284. //
  285. // Copy over the transport address. We have to manually check here
  286. // whether it will fit in the output buffer.
  287. //
  288. //
  289. // Don't copy the trailing blanks of the transport address.
  290. //
  291. for ( TransportAddressLength = endpoint->TransportAddress.Length;
  292. TransportAddressLength > 0 && endpoint->TransportAddress.Buffer[TransportAddressLength-1] == ' ' ;
  293. TransportAddressLength-- ) ;
  294. *EndOfVariableData = (LPTSTR)( (PCHAR)*EndOfVariableData - TransportAddressLength );
  295. //
  296. // Ensure we remain byte aligned, so knock off the low bit if necessary. Remember, we
  297. // are filling backwards from the end of the buffer so we want to round the address down
  298. //
  299. *EndOfVariableData = (LPTSTR)( (ULONG)*EndOfVariableData & ~1 );
  300. if ( (ULONG)*EndOfVariableData > (ULONG)*FixedStructure ) {
  301. //
  302. // The address will fit. Copy it over to the output buffer.
  303. //
  304. RtlCopyMemory(
  305. *EndOfVariableData,
  306. endpoint->TransportAddress.Buffer,
  307. TransportAddressLength
  308. );
  309. svti1->svti1_transportaddress = (LPBYTE)*EndOfVariableData;
  310. svti1->svti1_transportaddresslength = TransportAddressLength;
  311. } else {
  312. svti1->svti1_transportaddress = NULL;
  313. svti1->svti1_transportaddresslength = 0;
  314. }
  315. return;
  316. } // FillTransportInfoBuffer
  317. BOOLEAN
  318. FilterTransports (
  319. IN PSERVER_REQUEST_PACKET Srp,
  320. IN PVOID Block
  321. )
  322. /*++
  323. Routine Description:
  324. This routine just returns TRUE since we always want to place
  325. information about all transports in the output buffer for a
  326. NetServerTransportEnum.
  327. Arguments:
  328. Srp - not used.
  329. Block - not used.
  330. Return Value:
  331. TRUE.
  332. --*/
  333. {
  334. PAGED_CODE( );
  335. Srp, Block;
  336. //
  337. // We always return information about all transports.
  338. //
  339. return TRUE;
  340. } // FilterFiles
  341. ULONG
  342. SizeTransports (
  343. IN PSERVER_REQUEST_PACKET Srp,
  344. IN PVOID Block
  345. )
  346. /*++
  347. Routine Description:
  348. This routine returns the size the passed-in endpoint would take up
  349. in an API output buffer.
  350. Arguments:
  351. Srp - not used.
  352. Block - a pointer to the endpoint to size.
  353. Return Value:
  354. ULONG - The number of bytes the endpoint would take up in the
  355. output buffer.
  356. --*/
  357. {
  358. PENDPOINT endpoint = Block;
  359. ULONG size;
  360. PAGED_CODE( );
  361. size = Srp->Level ? sizeof( SERVER_TRANSPORT_INFO_1 ) : sizeof( SERVER_TRANSPORT_INFO_0 );
  362. size += SrvLengthOfStringInApiBuffer(&(endpoint)->TransportName);
  363. size += (endpoint)->TransportAddress.Length + sizeof(TCHAR);
  364. size += SrvLengthOfStringInApiBuffer(&(endpoint)->NetworkAddress);
  365. if( Srp->Level ) {
  366. size += SrvLengthOfStringInApiBuffer( &(endpoint)->DomainName );
  367. }
  368. return size;
  369. } // SizeTransports