Leaked source code of windows server 2003
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.

2918 lines
84 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. network.c
  5. Abstract:
  6. This module contains routines for interfacing the LAN Manager server
  7. to the network.
  8. Author:
  9. Chuck Lenzmeier (chuckl) 7-Oct-1989
  10. Environment:
  11. File System Process, kernel mode only
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #include "network.tmh"
  16. #pragma hdrstop
  17. #include <ntddip.h>
  18. #include <ntddtcp.h>
  19. #include <ipfltdrv.h>
  20. #include <tcpinfo.h>
  21. #include <tdiinfo.h>
  22. #include <nbtioctl.h>
  23. // WinSock definitions
  24. #define AF_INET 2
  25. struct sockaddr_in {
  26. short sin_family;
  27. USHORT sin_port;
  28. struct in_addr sin_addr;
  29. char sin_zero[8];
  30. };
  31. #define AF_INET6 23
  32. /* IPv6 socket address structure, RFC 2553 */
  33. struct sockaddr_in6 {
  34. short sin6_family; /* AF_INET6 */
  35. USHORT sin6_port; /* Transport level port number */
  36. ULONG sin6_flowinfo; /* IPv6 flow information */
  37. union {
  38. UCHAR Byte[16];
  39. USHORT Word[8];
  40. } sin6_addr;
  41. ULONG sin6_scope_id; /* set of interfaces for a scope */
  42. };
  43. #define BugCheckFileId SRV_FILE_NETWORK
  44. //
  45. // Local declarations
  46. //
  47. NTSTATUS
  48. GetNetworkAddress (
  49. IN PENDPOINT Endpoint
  50. );
  51. NTSTATUS
  52. OpenEndpoint (
  53. OUT PENDPOINT *Endpoint,
  54. IN PUNICODE_STRING NetworkName,
  55. IN PUNICODE_STRING TransportName,
  56. IN PANSI_STRING TransportAddress,
  57. IN PUNICODE_STRING DomainName,
  58. IN ULONG TransportAddFlags,
  59. IN BOOLEAN AlternateEndpoint
  60. );
  61. NTSTATUS
  62. OpenNetbiosAddress (
  63. IN OUT PENDPOINT Endpoint,
  64. IN PVOID DeviceName,
  65. IN PVOID NetbiosName
  66. );
  67. NTSTATUS
  68. OpenNetbiosExAddress (
  69. IN OUT PENDPOINT Endpoint,
  70. IN PVOID DeviceName,
  71. IN PVOID NetbiosName
  72. );
  73. NTSTATUS
  74. OpenNonNetbiosAddress (
  75. IN OUT PENDPOINT Endpoint,
  76. IN PVOID DeviceName,
  77. IN PVOID NetbiosName
  78. );
  79. NTSTATUS
  80. OpenIpxSocket (
  81. OUT PHANDLE Handle,
  82. OUT PFILE_OBJECT *FileObject,
  83. OUT PDEVICE_OBJECT *DeviceObject,
  84. IN PVOID DeviceName,
  85. IN USHORT Socket
  86. );
  87. #ifdef ALLOC_PRAGMA
  88. #pragma alloc_text( PAGE, SrvAddServedNet )
  89. #pragma alloc_text( PAGE, SrvDeleteServedNet )
  90. #pragma alloc_text( PAGE, SrvDoDisconnect )
  91. #pragma alloc_text( PAGE, GetNetworkAddress )
  92. #pragma alloc_text( PAGE, OpenEndpoint )
  93. #pragma alloc_text( PAGE, OpenNetbiosAddress )
  94. #pragma alloc_text( PAGE, OpenNonNetbiosAddress )
  95. #pragma alloc_text( PAGE, OpenIpxSocket )
  96. #pragma alloc_text( PAGE, SrvRestartAccept )
  97. #pragma alloc_text( PAGE, GetIpxMaxBufferSize )
  98. #endif
  99. #if 0
  100. NOT PAGEABLE -- SrvOpenConnection
  101. NOT PAGEABLE -- SrvPrepareReceiveWorkItem
  102. NOT PAGEABLE -- SrvStartSend
  103. NOT PAGEABLE -- SrvStartSend2
  104. #endif
  105. NTSTATUS
  106. SrvAddServedNet(
  107. IN PUNICODE_STRING NetworkName,
  108. IN PUNICODE_STRING TransportName,
  109. IN PANSI_STRING TransportAddress,
  110. IN PUNICODE_STRING DomainName,
  111. IN ULONG TransportAddFlags,
  112. IN DWORD PasswordLength,
  113. IN PBYTE Password
  114. )
  115. /*++
  116. Routine Description:
  117. This function initializes the server on a network. This
  118. involves making the server known by creating a transport endpoint,
  119. posting a Listen request, and setting up event handlers.
  120. Arguments:
  121. NetworkName - The administrative name of the network (e.g., NET1)
  122. TransportName - The fully qualified name of the transport device.
  123. For example, "\Device\Nbf".
  124. TransportAddress - The fully qualified address (or name ) of the
  125. server's endpoint. This name is used exactly as specified. For
  126. NETBIOS-compatible networks, the caller must upcase and
  127. blank-fill the name. For example, "NTSERVERbbbbbbbb".
  128. DomainName - The name of the domain to service
  129. Password/PasswordLength - used for mutual authentication (optional)
  130. Return Value:
  131. NTSTATUS - Indicates whether the network was successfully started.
  132. --*/
  133. {
  134. NTSTATUS status;
  135. PENDPOINT endpoint;
  136. PAGED_CODE( );
  137. IF_DEBUG(TRACE1) KdPrint(( "SrvAddServedNet entered\n" ));
  138. //
  139. // Call OpenEndpoint to open the transport provider, bind to the
  140. // server address, and register the FSD receive event handler.
  141. //
  142. status = OpenEndpoint(
  143. &endpoint,
  144. NetworkName,
  145. TransportName,
  146. TransportAddress,
  147. DomainName,
  148. TransportAddFlags,
  149. FALSE); // primary endpoint
  150. if ( !NT_SUCCESS(status) ) {
  151. IF_DEBUG(ERRORS) {
  152. KdPrint(( "SrvAddServedNet: unable to open endpoint %wZ for addr %z, status %X\n", TransportName, (PCSTRING)TransportAddress, status ));
  153. }
  154. return status;
  155. }
  156. //
  157. // Dereference the endpoint. (When it was created, the reference
  158. // count was incremented to account for our pointer.)
  159. //
  160. SrvDereferenceEndpoint( endpoint );
  161. //
  162. // Call OpenEndpoint to open the transport provider, bind to the
  163. // server address, and register the FSD receive event handler. This is
  164. // the auxillary endpoint registration in the new TDI address format. Since
  165. // this is not supported by all the transports it cannot be deemed an error.
  166. //
  167. //
  168. status = OpenEndpoint(
  169. &endpoint,
  170. NetworkName,
  171. TransportName,
  172. TransportAddress,
  173. DomainName,
  174. TransportAddFlags,
  175. TRUE); // Alternate endpoint
  176. if ( NT_SUCCESS( status ) ) {
  177. SrvDereferenceEndpoint( endpoint );
  178. }
  179. if( PasswordLength ) {
  180. SrvAddSecurityCredentials( TransportAddress, DomainName, PasswordLength, Password );
  181. }
  182. return STATUS_SUCCESS;
  183. } // SrvAddServedNet
  184. NTSTATUS
  185. SrvDeleteServedNet(
  186. IN PUNICODE_STRING TransportName,
  187. IN PANSI_STRING TransportAddress
  188. )
  189. /*++
  190. Routine Description:
  191. This function causes the server to stop listening to a network.
  192. Arguments:
  193. TransportAddress - the transport address (e.g. \Device\Nbf\POPCORN
  194. of the endpoint to delete.
  195. Return Value:
  196. NTSTATUS - Indicates whether the network was successfully stopped.
  197. --*/
  198. {
  199. PLIST_ENTRY listEntry;
  200. PENDPOINT endpoint;
  201. BOOLEAN match;
  202. NTSTATUS status = STATUS_NONEXISTENT_NET_NAME;
  203. PAGED_CODE( );
  204. IF_DEBUG(TRACE1) KdPrint(( "SrvDeleteServedNet entered\n" ));
  205. //
  206. // Find the endpoint block with the specified name.
  207. //
  208. top:
  209. ACQUIRE_LOCK( &SrvEndpointLock );
  210. listEntry = SrvEndpointList.ListHead.Flink;
  211. while ( listEntry != &SrvEndpointList.ListHead ) {
  212. endpoint = CONTAINING_RECORD(
  213. listEntry,
  214. ENDPOINT,
  215. GlobalEndpointListEntry
  216. );
  217. if( GET_BLOCK_STATE(endpoint) == BlockStateActive ) {
  218. //
  219. // We have a match if the transport name is correct and we either
  220. // haven't specified a transport address, or if the transport
  221. // address matches
  222. //
  223. match = (BOOLEAN)(
  224. RtlEqualUnicodeString(
  225. TransportName,
  226. &endpoint->TransportName,
  227. TRUE // case insensitive compare
  228. )
  229. &&
  230. (
  231. TransportAddress->Length == 0 ||
  232. RtlEqualString(
  233. (PSTRING)TransportAddress,
  234. (PSTRING)&endpoint->TransportAddress,
  235. TRUE // case insensitive compare
  236. )
  237. )
  238. );
  239. if ( match ) {
  240. //
  241. // The specified network name (endpoint) exists. Close the
  242. // endpoint. This releases the endpoint lock.
  243. //
  244. SrvCloseEndpoint( endpoint );
  245. status = STATUS_SUCCESS;
  246. //
  247. // Restart this loop, since this endpoint may have vaporized and
  248. // the list might have changed because we dropped SrvEndpointLock.
  249. //
  250. // SrvCloseEndpoint will have marked this endpoint as BlockStateClosing,
  251. // so we will not be in an infinite loop!
  252. //
  253. goto top;
  254. }
  255. }
  256. //
  257. // Go to the next one.
  258. //
  259. listEntry = listEntry->Flink;
  260. }
  261. //
  262. // We are done. If we successfully matched an endpoint, we return STATUS_SUCCESS
  263. //
  264. RELEASE_LOCK( &SrvEndpointLock );
  265. return status;
  266. } // SrvDeleteServedNet
  267. NTSTATUS
  268. SrvDoDisconnect (
  269. IN OUT PCONNECTION Connection
  270. )
  271. /*++
  272. Routine Description:
  273. This function issues a Disconnect request on a network. The request
  274. is performed synchronously -- control is not returned to the caller
  275. until the request completes.
  276. Arguments:
  277. Connection - Supplies a pointer to an Connection Block
  278. Return Value:
  279. NTSTATUS - Indicates whether the disconnect was successful.
  280. --*/
  281. {
  282. NTSTATUS status;
  283. PAGED_CODE( );
  284. IF_DEBUG(TRACE2) KdPrint(( "SrvDoDisconnect entered\n" ));
  285. #if SRVDBG29
  286. UpdateConnectionHistory( "SDSC", Connection->Endpoint, Connection );
  287. #endif
  288. ASSERT( !Connection->Endpoint->IsConnectionless );
  289. //
  290. // Issue the disconnect request.
  291. //
  292. status = SrvIssueDisconnectRequest(
  293. Connection->FileObject,
  294. &Connection->DeviceObject,
  295. TDI_DISCONNECT_ABORT
  296. );
  297. if ( !NT_SUCCESS(status) ) {
  298. INTERNAL_ERROR(
  299. ERROR_LEVEL_EXPECTED,
  300. "SrvDoDisconnect: NtDeviceIoControlFile failed: %X",
  301. status,
  302. NULL
  303. );
  304. #if SRVDBG29
  305. if (status != STATUS_LINK_FAILED && status != STATUS_REMOTE_DISCONNECT) {
  306. KdPrint(( "SRV: SrvDoDisconnect: SrvIssueDisconnectRequest failed\n" ));
  307. DbgBreakPoint();
  308. }
  309. #endif
  310. //
  311. // Mark the connection as not reusable, because the transport
  312. // probably still thinks it's active.
  313. //
  314. Connection->NotReusable = TRUE;
  315. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  316. }
  317. //
  318. // Return the status of the I/O operation.
  319. //
  320. return status;
  321. } // SrvDoDisconnect
  322. NTSTATUS
  323. SrvOpenConnection (
  324. IN PENDPOINT Endpoint
  325. )
  326. /*++
  327. Routine Description:
  328. This function opens a connection for an endpoint and queues it to
  329. the endpoint's free connection list.
  330. Arguments:
  331. Endpoint - Supplies a pointer to an Endpoint Block
  332. Return Value:
  333. NTSTATUS - Indicates whether the connection was successfully opened.
  334. --*/
  335. {
  336. NTSTATUS status;
  337. PCONNECTION connection;
  338. PPAGED_CONNECTION pagedConnection;
  339. CHAR eaBuffer[sizeof(FILE_FULL_EA_INFORMATION) - 1 +
  340. TDI_CONNECTION_CONTEXT_LENGTH + 1 +
  341. sizeof(CONNECTION_CONTEXT)];
  342. PFILE_FULL_EA_INFORMATION ea;
  343. CONNECTION_CONTEXT UNALIGNED *ctx;
  344. OBJECT_ATTRIBUTES objectAttributes;
  345. IO_STATUS_BLOCK iosb;
  346. KIRQL oldIrql;
  347. PTABLE_HEADER tableHeader;
  348. SHORT sidIndex;
  349. USHORT i;
  350. PTABLE_ENTRY entry = NULL;
  351. TDI_PROVIDER_INFO providerInfo;
  352. //
  353. // Allocate a connection block.
  354. //
  355. SrvAllocateConnection( &connection );
  356. if ( connection == NULL ) {
  357. return STATUS_INSUFF_SERVER_RESOURCES;
  358. }
  359. pagedConnection = connection->PagedConnection;
  360. //
  361. // Allocate an entry in the endpoint's connection table.
  362. //
  363. ACQUIRE_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(0), &oldIrql );
  364. for ( i = 1; i < ENDPOINT_LOCK_COUNT ; i++ ) {
  365. ACQUIRE_DPC_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(i) );
  366. }
  367. tableHeader = &Endpoint->ConnectionTable;
  368. if ( tableHeader->FirstFreeEntry == -1 &&
  369. SrvGrowTable(
  370. tableHeader,
  371. 8,
  372. 0x7fff,
  373. NULL ) == FALSE ) {
  374. for ( i = ENDPOINT_LOCK_COUNT-1 ; i > 0 ; i-- ) {
  375. RELEASE_DPC_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(i) );
  376. }
  377. RELEASE_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(0), oldIrql );
  378. status = STATUS_INSUFF_SERVER_RESOURCES;
  379. goto cleanup;
  380. }
  381. sidIndex = tableHeader->FirstFreeEntry;
  382. entry = &tableHeader->Table[sidIndex];
  383. tableHeader->FirstFreeEntry = entry->NextFreeEntry;
  384. DEBUG entry->NextFreeEntry = -2;
  385. if ( tableHeader->LastFreeEntry == sidIndex ) {
  386. tableHeader->LastFreeEntry = -1;
  387. }
  388. for ( i = ENDPOINT_LOCK_COUNT-1 ; i > 0 ; i-- ) {
  389. RELEASE_DPC_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(i) );
  390. }
  391. RELEASE_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(0), oldIrql );
  392. if ( !Endpoint->IsConnectionless ) {
  393. //
  394. // Create the EA for the connection context.
  395. //
  396. ea = (PFILE_FULL_EA_INFORMATION)eaBuffer;
  397. ea->NextEntryOffset = 0;
  398. ea->Flags = 0;
  399. ea->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
  400. ea->EaValueLength = sizeof(CONNECTION_CONTEXT);
  401. RtlCopyMemory( ea->EaName, StrConnectionContext, ea->EaNameLength + 1 );
  402. ctx = (CONNECTION_CONTEXT UNALIGNED *)&ea->EaName[ea->EaNameLength + 1];
  403. *ctx = connection;
  404. //
  405. // Create the connection file object.
  406. //
  407. SrvInitializeObjectAttributes_U(
  408. &objectAttributes,
  409. &Endpoint->TransportName,
  410. OBJ_CASE_INSENSITIVE,
  411. NULL,
  412. NULL
  413. );
  414. status = NtCreateFile(
  415. &pagedConnection->ConnectionHandle,
  416. 0,
  417. &objectAttributes,
  418. &iosb,
  419. NULL,
  420. 0,
  421. 0,
  422. 0,
  423. 0,
  424. eaBuffer,
  425. FIELD_OFFSET( FILE_FULL_EA_INFORMATION, EaName[0] ) +
  426. ea->EaNameLength + 1 + ea->EaValueLength
  427. );
  428. if ( !NT_SUCCESS(status) ) {
  429. IF_DEBUG(ERRORS) {
  430. KdPrint(( "SrvOpenConnection: NtCreateFile failed: %X\n", status ));
  431. }
  432. goto cleanup;
  433. }
  434. SRVDBG_CLAIM_HANDLE( pagedConnection->ConnectionHandle, "CON", 7, connection );
  435. //
  436. // Obtain a referenced pointer to the file object.
  437. //
  438. status = ObReferenceObjectByHandle(
  439. pagedConnection->ConnectionHandle,
  440. 0,
  441. (POBJECT_TYPE) NULL,
  442. KernelMode,
  443. (PVOID *)&connection->FileObject,
  444. NULL
  445. );
  446. if ( !NT_SUCCESS(status) ) {
  447. SrvLogServiceFailure( SRV_SVC_OB_REF_BY_HANDLE, status );
  448. //
  449. // This internal error bugchecks the system.
  450. //
  451. INTERNAL_ERROR(
  452. ERROR_LEVEL_IMPOSSIBLE,
  453. "SrvOpenConnection: ObReferenceObjectByHandle failed: %X",
  454. status,
  455. NULL
  456. );
  457. goto cleanup;
  458. }
  459. //
  460. // Get the address of the device object for the endpoint.
  461. //
  462. connection->DeviceObject = IoGetRelatedDeviceObject(
  463. connection->FileObject
  464. );
  465. //
  466. // Associate the connection with the endpoint's address.
  467. //
  468. status = SrvIssueAssociateRequest(
  469. connection->FileObject,
  470. &connection->DeviceObject,
  471. Endpoint->EndpointHandle
  472. );
  473. if ( !NT_SUCCESS(status) ) {
  474. INTERNAL_ERROR(
  475. ERROR_LEVEL_UNEXPECTED,
  476. "SrvOpenConnection: SrvIssueAssociateRequest failed: %X",
  477. status,
  478. NULL
  479. );
  480. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  481. goto cleanup;
  482. }
  483. IF_DEBUG(NET1) {
  484. KdPrint(( "SrvOpenConnection: Connection on %p %z opened; handle %p, pointer %p\n", Endpoint,
  485. (PCSTRING)&Endpoint->TransportAddress,
  486. connection->PagedConnection->ConnectionHandle,
  487. connection->FileObject ));
  488. }
  489. //
  490. // Initialize the MaximumSendSize for the transport that we're using
  491. //
  492. status = SrvIssueTdiQuery(
  493. connection->FileObject,
  494. &connection->DeviceObject,
  495. (PCHAR)&providerInfo,
  496. sizeof(providerInfo),
  497. TDI_QUERY_PROVIDER_INFO
  498. );
  499. //
  500. // If we got the provider info, make sure the maximum send size is at
  501. // least 1K-1. If we have no provider info, then maximum send size is 64KB.
  502. //
  503. if ( NT_SUCCESS(status) ) {
  504. connection->MaximumSendSize = providerInfo.MaxSendSize;
  505. if ( connection->MaximumSendSize < MIN_SEND_SIZE ) {
  506. connection->MaximumSendSize = MIN_SEND_SIZE;
  507. }
  508. } else {
  509. connection->MaximumSendSize = MAX_PARTIAL_BUFFER_SIZE;
  510. }
  511. } else { // if ( Endpoint->IsConnectionless )
  512. if (sidIndex > 0xfff) {
  513. // The IPXSID index can only span 12 bits
  514. // Code needs to be added to ensure that we can try to locate
  515. // an index less than 0xfff
  516. status = STATUS_INSUFF_SERVER_RESOURCES;
  517. goto cleanup;
  518. }
  519. // Give this the default initialization
  520. connection->MaximumSendSize = MAX_PARTIAL_BUFFER_SIZE;
  521. }
  522. //
  523. // Set the reference count on the connection to zero, in order to
  524. // put it on the free list. (SrvAllocateConnection initialized the
  525. // count to two.)
  526. //
  527. connection->BlockHeader.ReferenceCount = 0;
  528. UPDATE_REFERENCE_HISTORY( connection, TRUE );
  529. UPDATE_REFERENCE_HISTORY( connection, TRUE );
  530. //
  531. // Reference the endpoint and link the connection into the
  532. // endpoint's free connection list.
  533. //
  534. connection->Endpoint = Endpoint;
  535. connection->EndpointSpinLock =
  536. &ENDPOINT_SPIN_LOCK(sidIndex & ENDPOINT_LOCK_MASK);
  537. ACQUIRE_LOCK( &SrvEndpointLock );
  538. SrvReferenceEndpoint( Endpoint );
  539. ACQUIRE_SPIN_LOCK( connection->EndpointSpinLock, &oldIrql );
  540. INCREMENT_IPXSID_SEQUENCE( entry->SequenceNumber );
  541. if ( sidIndex == 0 && entry->SequenceNumber == 0 ) {
  542. INCREMENT_IPXSID_SEQUENCE( entry->SequenceNumber );
  543. }
  544. connection->Sid = MAKE_IPXSID( sidIndex, entry->SequenceNumber );
  545. connection->SidIndex = sidIndex;
  546. entry->Owner = connection;
  547. RELEASE_SPIN_LOCK( connection->EndpointSpinLock, oldIrql );
  548. ACQUIRE_GLOBAL_SPIN_LOCK( Fsd, &oldIrql );
  549. SrvInsertTailList(
  550. &Endpoint->FreeConnectionList,
  551. &connection->EndpointFreeListEntry
  552. );
  553. #if SRVDBG29
  554. UpdateConnectionHistory( "OPEN", Endpoint, connection );
  555. #endif
  556. Endpoint->FreeConnectionCount++;
  557. Endpoint->TotalConnectionCount++;
  558. RELEASE_GLOBAL_SPIN_LOCK( Fsd, oldIrql );
  559. IF_DEBUG(TDI) {
  560. KdPrint(( "SrvOpenConnection created connection %p for endpoint %p; free %ld, total %ld\n", connection, Endpoint,
  561. Endpoint->FreeConnectionCount,
  562. Endpoint->TotalConnectionCount ));
  563. }
  564. RELEASE_LOCK( &SrvEndpointLock );
  565. //
  566. // The connection open was successful.
  567. //
  568. IF_DEBUG(TRACE1) {
  569. KdPrint(( "SrvOpenConnection complete: %X\n", STATUS_SUCCESS ));
  570. }
  571. return STATUS_SUCCESS;
  572. //
  573. // Out-of-line error cleanup.
  574. //
  575. cleanup:
  576. //
  577. // Something failed. Clean up as appropriate.
  578. //
  579. if ( !Endpoint->IsConnectionless ) {
  580. if ( connection->FileObject != NULL ) {
  581. ObDereferenceObject( connection->FileObject );
  582. }
  583. if ( pagedConnection->ConnectionHandle != NULL ) {
  584. SRVDBG_RELEASE_HANDLE( pagedConnection->ConnectionHandle, "CON", 12, connection );
  585. SrvNtClose( pagedConnection->ConnectionHandle, FALSE );
  586. }
  587. }
  588. if ( entry != NULL ) {
  589. SrvRemoveEntryTable( tableHeader, sidIndex );
  590. }
  591. SrvFreeConnection( connection );
  592. return status;
  593. } // SrvOpenConnection
  594. NTSTATUS
  595. GetNetworkAddress (
  596. IN PENDPOINT Endpoint
  597. )
  598. {
  599. NTSTATUS status;
  600. PCHAR adapterStatus;
  601. PCHAR adapterAddress;
  602. ANSI_STRING ansiString;
  603. CHAR addressData[12+1];
  604. ULONG i;
  605. struct {
  606. ULONG ActivityCount;
  607. TA_IPX_ADDRESS LocalAddress;
  608. } addressInfo;
  609. PAGED_CODE( );
  610. if ( !Endpoint->IsConnectionless ) {
  611. //
  612. // Allocate a buffer to receive adapter information.
  613. //
  614. // *** We want to get the ADAPTER_STATUS structure, but it is
  615. // defined in the windows header file sdk\inc\nb30.h.
  616. // Rather than including all the windows header files, just
  617. // allocate about a page, which should always be enough for
  618. // that structure.
  619. //
  620. adapterStatus = ALLOCATE_NONPAGED_POOL( 4080, BlockTypeAdapterStatus );
  621. if ( adapterStatus == NULL ) {
  622. return STATUS_INSUFF_SERVER_RESOURCES;
  623. }
  624. status = SrvIssueTdiQuery(
  625. Endpoint->FileObject,
  626. &Endpoint->DeviceObject,
  627. adapterStatus,
  628. 4080,
  629. TDI_QUERY_ADAPTER_STATUS
  630. );
  631. if ( !NT_SUCCESS(status) ) {
  632. INTERNAL_ERROR(
  633. ERROR_LEVEL_UNEXPECTED,
  634. "GetNetworkAddress: SrvIssueTdiQuery failed: %X\n",
  635. status,
  636. NULL
  637. );
  638. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  639. DEALLOCATE_NONPAGED_POOL( adapterStatus );
  640. return status;
  641. }
  642. adapterAddress = adapterStatus;
  643. } else {
  644. status = SrvIssueTdiQuery(
  645. Endpoint->NameSocketFileObject,
  646. &Endpoint->NameSocketDeviceObject,
  647. (PCHAR)&addressInfo,
  648. sizeof(addressInfo),
  649. TDI_QUERY_ADDRESS_INFO
  650. );
  651. if ( !NT_SUCCESS(status) ) {
  652. INTERNAL_ERROR(
  653. ERROR_LEVEL_UNEXPECTED,
  654. "GetNetworkAddress: SrvIssueTdiQuery failed: %X\n",
  655. status,
  656. NULL
  657. );
  658. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  659. return status;
  660. }
  661. Endpoint->LocalAddress = addressInfo.LocalAddress.Address[0].Address[0];
  662. adapterAddress = addressInfo.LocalAddress.Address[0].Address[0].NodeAddress;
  663. }
  664. //
  665. // Get an ANSI string that contains the adapter address.
  666. //
  667. ansiString.Buffer = addressData;
  668. ansiString.Length = 12;
  669. ansiString.MaximumLength = 13;
  670. #define tohexdigit(a) ((CHAR)( (a) > 9 ? ((a) + 'a' - 0xA) : ((a) + '0') ))
  671. for ( i = 0; i < 6; i++ ) {
  672. addressData[2*i] = tohexdigit( (adapterAddress[i] >> 4) & 0x0F );
  673. addressData[2*i+1] = tohexdigit( adapterAddress[i] & 0x0F );
  674. }
  675. addressData[12] = '\0';
  676. //
  677. // Convert the address string to Unicode.
  678. //
  679. status = RtlAnsiStringToUnicodeString(
  680. &Endpoint->NetworkAddress,
  681. &ansiString,
  682. FALSE
  683. );
  684. ASSERT( NT_SUCCESS(status) );
  685. if ( !Endpoint->IsConnectionless ) {
  686. DEALLOCATE_NONPAGED_POOL( adapterStatus );
  687. }
  688. return STATUS_SUCCESS;
  689. } // GetNetworkAddress
  690. NTSTATUS
  691. OpenEndpoint (
  692. OUT PENDPOINT *Endpoint,
  693. IN PUNICODE_STRING NetworkName,
  694. IN PUNICODE_STRING TransportName,
  695. IN PANSI_STRING TransportAddress,
  696. IN PUNICODE_STRING DomainName,
  697. IN DWORD TransportAddFlags,
  698. IN BOOLEAN AlternateEndpoint
  699. )
  700. /*++
  701. Routine Description:
  702. This function opens a transport provider, simultaneously binding the
  703. server's address to the transport endpoint, and registers a Receive
  704. event handler for the endpoint.
  705. Arguments:
  706. Endpoint - Returns a pointer to an Endpoint Block
  707. NetworkName - Supplies the administrative name of the network (e.g.,
  708. NET1).
  709. TransportName - The fully qualified name of the transport device.
  710. For example, "\Device\Nbf".
  711. TransportAddress - The exact name of the server to be used on the
  712. specified transport. For NETBIOS-compatible networks, the
  713. caller must upcase and blank-fill the name. For example,
  714. "NTSERVERbbbbbbbb".
  715. DomainName - name of domain to serve
  716. Return Value:
  717. NTSTATUS - Indicates whether the network was successfully opened.
  718. --*/
  719. {
  720. NTSTATUS status = STATUS_SUCCESS;
  721. PENDPOINT endpoint = NULL; // local copy of Endpoint
  722. PAGED_CODE( );
  723. IF_DEBUG(TRACE1) KdPrint(( "OpenEndpoint %wZ entered\n", TransportName ));
  724. //
  725. // Allocate an endpoint block.
  726. //
  727. SrvAllocateEndpoint(
  728. &endpoint,
  729. NetworkName,
  730. TransportName,
  731. TransportAddress,
  732. DomainName
  733. );
  734. if ( endpoint == NULL ) {
  735. IF_DEBUG(ERRORS) {
  736. KdPrint(( "OpenEndpoint complete: %X\n",
  737. STATUS_INSUFF_SERVER_RESOURCES ));
  738. }
  739. return STATUS_INSUFF_SERVER_RESOURCES;
  740. }
  741. if( TransportAddFlags & SRP_XADD_PRIMARY_MACHINE ) {
  742. endpoint->IsPrimaryName = 1;
  743. if( SrvComputerName.Buffer == NULL ) {
  744. status = RtlAnsiStringToUnicodeString( &SrvComputerName, TransportAddress, TRUE );
  745. if( NT_SUCCESS( status ) ) {
  746. //
  747. // Trim off the trailing spaces
  748. //
  749. while( SrvComputerName.Buffer[(SrvComputerName.Length-sizeof(WCHAR))/sizeof(WCHAR)]
  750. == L' ' ) {
  751. SrvComputerName.Length -= sizeof(WCHAR);
  752. }
  753. }
  754. }
  755. }
  756. if( NT_SUCCESS( status ) ) {
  757. if( TransportAddFlags & SRP_XADD_REMAP_PIPE_NAMES ) {
  758. endpoint->RemapPipeNames = 1;
  759. }
  760. if (AlternateEndpoint) {
  761. status = OpenNetbiosExAddress(
  762. endpoint,
  763. TransportName,
  764. TransportAddress->Buffer);
  765. endpoint->AlternateAddressFormat = TRUE;
  766. } else {
  767. endpoint->AlternateAddressFormat = FALSE;
  768. //
  769. // Assume that the transport is a NetBIOS provider, and try to
  770. // open the server's address using the NetBIOS name.
  771. //
  772. status = OpenNetbiosAddress(
  773. endpoint,
  774. TransportName,
  775. TransportAddress->Buffer
  776. );
  777. //
  778. // We could not open the transport as a NetBIOS provider. We will now try
  779. // to see if it is a direct host IPX provider. However, if we have been
  780. // configured to use Security Signatures, do not attempt direct host IPX since
  781. // security signatures are not supported for direct host IPX transports
  782. //
  783. if ( !NT_SUCCESS(status) && SrvSmbSecuritySignaturesRequired == FALSE ) {
  784. BOOLEAN isDuplicate = FALSE;
  785. PLIST_ENTRY listEntry;
  786. //
  787. // Apparently the transport is not a NetBIOS provider. We can
  788. // not open multiple connectionless providers through the same
  789. // TransportName.
  790. //
  791. ACQUIRE_LOCK( &SrvEndpointLock );
  792. for( listEntry = SrvEndpointList.ListHead.Flink;
  793. listEntry != &SrvEndpointList.ListHead;
  794. listEntry = listEntry->Flink ) {
  795. PENDPOINT tmpEndpoint;
  796. tmpEndpoint = CONTAINING_RECORD( listEntry, ENDPOINT, GlobalEndpointListEntry );
  797. if( GET_BLOCK_STATE( tmpEndpoint ) == BlockStateActive &&
  798. tmpEndpoint->IsConnectionless &&
  799. RtlCompareUnicodeString( &tmpEndpoint->TransportName, TransportName, TRUE ) == 0 ) {
  800. IF_DEBUG(ERRORS) {
  801. KdPrint(( "OpenEndpoint: Only one connectionless endpoint on %wZ allowed!\n",
  802. TransportName ));
  803. }
  804. isDuplicate = TRUE;
  805. status = STATUS_TOO_MANY_NODES;
  806. break;
  807. }
  808. }
  809. RELEASE_LOCK( &SrvEndpointLock );
  810. //
  811. // Try to open it as a connectionless provider.
  812. //
  813. if( isDuplicate == FALSE ) {
  814. NTSTATUS status2;
  815. status2 = OpenNonNetbiosAddress(
  816. endpoint,
  817. TransportName,
  818. TransportAddress->Buffer
  819. );
  820. if( NT_SUCCESS( status2 ) ) {
  821. status = status2;
  822. }
  823. }
  824. }
  825. }
  826. }
  827. if ( !NT_SUCCESS(status) ) {
  828. //
  829. // We couldn't open the provider as either a NetBIOS provider
  830. // or as a connectionless provider.
  831. //
  832. IF_DEBUG(ERRORS) {
  833. KdPrint(( "OpenEndpoint: OpenAddress failed: %X\n", status ));
  834. }
  835. //
  836. // Close all free connections.
  837. //
  838. EmptyFreeConnectionList( endpoint );
  839. SrvFreeEndpoint( endpoint );
  840. ACQUIRE_LOCK( &SrvEndpointLock );
  841. SrvEndpointCount--;
  842. if( SrvEndpointCount == 0 )
  843. {
  844. KeSetEvent( &SrvEndpointEvent, 0, FALSE );
  845. }
  846. RELEASE_LOCK( &SrvEndpointLock );
  847. return status;
  848. }
  849. //
  850. // Query the provider for the send entry point
  851. //
  852. SrvQuerySendEntryPoint(
  853. endpoint->FileObject,
  854. &endpoint->DeviceObject,
  855. IOCTL_TDI_QUERY_DIRECT_SEND_HANDLER,
  856. (PVOID*)&endpoint->FastTdiSend
  857. );
  858. //
  859. // Query the provider for the send entry point
  860. //
  861. SrvQuerySendEntryPoint(
  862. endpoint->FileObject,
  863. &endpoint->DeviceObject,
  864. IOCTL_TDI_QUERY_DIRECT_SENDDG_HANDLER,
  865. (PVOID*)&endpoint->FastTdiSendDatagram
  866. );
  867. //
  868. // The network open was successful. Link the new endpoint into the
  869. // list of active endpoints. Return with a success status. (We
  870. // don't dereference the endpoint because we're returning a pointer
  871. // to the endpoint.)
  872. //
  873. SrvInsertEntryOrderedList( &SrvEndpointList, endpoint );
  874. *Endpoint = endpoint;
  875. IF_DEBUG(TRACE1) {
  876. KdPrint(( "OpenEndpoint complete: %wZ %X\n", TransportName, STATUS_SUCCESS ));
  877. }
  878. return STATUS_SUCCESS;
  879. } // OpenEndpoint
  880. NTSTATUS
  881. SetupConnectionEndpointHandlers(
  882. IN OUT PENDPOINT Endpoint)
  883. {
  884. NTSTATUS status;
  885. ULONG i;
  886. Endpoint->IsConnectionless = FALSE;
  887. status = SrvVerifyDeviceStackSize(
  888. Endpoint->EndpointHandle,
  889. TRUE,
  890. &Endpoint->FileObject,
  891. &Endpoint->DeviceObject,
  892. NULL
  893. );
  894. if ( !NT_SUCCESS( status ) ) {
  895. INTERNAL_ERROR(
  896. ERROR_LEVEL_EXPECTED,
  897. "OpenNetbiosAddress: Verify Device Stack Size failed: %X\n",
  898. status,
  899. NULL
  900. );
  901. goto cleanup;
  902. }
  903. //
  904. // Find the network address of the adapter used by corresponding to
  905. // this endpoint.
  906. //
  907. GetNetworkAddress( Endpoint );
  908. //
  909. // Register the server's Receive event handler.
  910. //
  911. status = SrvIssueSetEventHandlerRequest(
  912. Endpoint->FileObject,
  913. &Endpoint->DeviceObject,
  914. TDI_EVENT_RECEIVE,
  915. (PVOID)SrvFsdTdiReceiveHandler,
  916. Endpoint
  917. );
  918. if ( !NT_SUCCESS(status) ) {
  919. INTERNAL_ERROR(
  920. ERROR_LEVEL_EXPECTED,
  921. "OpenNetbiosAddress: set receive event handler failed: %X",
  922. status,
  923. NULL
  924. );
  925. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  926. goto cleanup;
  927. }
  928. //
  929. // Register the server's Disconnect event handler.
  930. //
  931. status = SrvIssueSetEventHandlerRequest(
  932. Endpoint->FileObject,
  933. &Endpoint->DeviceObject,
  934. TDI_EVENT_DISCONNECT,
  935. (PVOID)SrvFsdTdiDisconnectHandler,
  936. Endpoint
  937. );
  938. if ( !NT_SUCCESS(status) ) {
  939. INTERNAL_ERROR(
  940. ERROR_LEVEL_UNEXPECTED,
  941. "OpenNetbiosAddress: set disconnect event handler failed: %X",
  942. status,
  943. NULL
  944. );
  945. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  946. goto cleanup;
  947. }
  948. //
  949. // Create a number of free connections for the endpoint. These
  950. // connections will be used to service Connect events.
  951. //
  952. // *** If we fail in an attempt to create a connection, but we can
  953. // successfully create at least one, we keep the endpoint. The
  954. // cleanup code below depends on this behavior.
  955. //
  956. for ( i = 0; i < SrvFreeConnectionMinimum; i++ ) {
  957. status = SrvOpenConnection( Endpoint );
  958. if ( !NT_SUCCESS(status) ) {
  959. INTERNAL_ERROR(
  960. ERROR_LEVEL_EXPECTED,
  961. "OpenNetbiosAddress: SrvOpenConnection failed: %X",
  962. status,
  963. NULL
  964. );
  965. if ( i == 0 ) {
  966. goto cleanup;
  967. } else {
  968. break;
  969. }
  970. }
  971. }
  972. //
  973. // Register the server's Connect event handler.
  974. //
  975. // *** Note that Connect events can be delivered IMMEDIATELY upon
  976. // completion of this request!
  977. //
  978. status = SrvIssueSetEventHandlerRequest(
  979. Endpoint->FileObject,
  980. &Endpoint->DeviceObject,
  981. TDI_EVENT_CONNECT,
  982. (PVOID)SrvFsdTdiConnectHandler,
  983. Endpoint
  984. );
  985. if ( !NT_SUCCESS(status) ) {
  986. INTERNAL_ERROR(
  987. ERROR_LEVEL_UNEXPECTED,
  988. "OpenNetbiosAddress: set connect event handler failed: %X",
  989. status,
  990. NULL
  991. );
  992. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  993. goto cleanup;
  994. }
  995. return STATUS_SUCCESS;
  996. //
  997. // Out-of-line error cleanup.
  998. //
  999. cleanup:
  1000. //
  1001. // Something failed. Clean up as appropriate.
  1002. //
  1003. if ( Endpoint->FileObject != NULL ) {
  1004. ObDereferenceObject( Endpoint->FileObject );
  1005. Endpoint->FileObject = NULL;
  1006. }
  1007. if ( Endpoint->EndpointHandle != NULL ) {
  1008. SRVDBG_RELEASE_HANDLE( Endpoint->EndpointHandle, "END", 14, Endpoint );
  1009. SrvNtClose( Endpoint->EndpointHandle, FALSE );
  1010. Endpoint->EndpointHandle = NULL;
  1011. }
  1012. return status;
  1013. }
  1014. NTSTATUS
  1015. OpenNetbiosAddress (
  1016. IN OUT PENDPOINT Endpoint,
  1017. IN PVOID DeviceName,
  1018. IN PVOID NetbiosName
  1019. )
  1020. {
  1021. NTSTATUS status;
  1022. ULONG i;
  1023. CHAR eaBuffer[sizeof(FILE_FULL_EA_INFORMATION) +
  1024. TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
  1025. sizeof(TA_NETBIOS_ADDRESS)];
  1026. PAGED_CODE( );
  1027. status = TdiOpenNetbiosAddress(
  1028. &Endpoint->EndpointHandle,
  1029. eaBuffer,
  1030. DeviceName,
  1031. NetbiosName
  1032. );
  1033. if ( !NT_SUCCESS(status) ) {
  1034. IF_DEBUG( ERRORS ) {
  1035. KdPrint(( "TdiOpenNetbiosAddress( %wZ ) status %X\n", DeviceName, status ));
  1036. }
  1037. return status;
  1038. }
  1039. status = SetupConnectionEndpointHandlers(Endpoint);
  1040. return status;
  1041. } // OpenNetbiosAddress
  1042. NTSTATUS
  1043. OpenNetbiosExAddress(
  1044. IN OUT PENDPOINT Endpoint,
  1045. IN PVOID DeviceName,
  1046. IN PVOID NetbiosName
  1047. )
  1048. {
  1049. NTSTATUS status;
  1050. PFILE_FULL_EA_INFORMATION ea;
  1051. OBJECT_ATTRIBUTES objectAttributes;
  1052. IO_STATUS_BLOCK iosb;
  1053. ULONG length;
  1054. CHAR buffer[sizeof(FILE_FULL_EA_INFORMATION) +
  1055. TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
  1056. sizeof(TA_NETBIOS_EX_ADDRESS)];
  1057. TA_NETBIOS_EX_ADDRESS NetbiosExAddress;
  1058. PTDI_ADDRESS_NETBIOS_EX pTdiNetbiosExAddress;
  1059. PTDI_ADDRESS_NETBIOS pNetbiosAddress;
  1060. ULONG NetbiosExAddressLength;
  1061. PAGED_CODE( );
  1062. //
  1063. // Build the NETBIOS Extended address.
  1064. //
  1065. NetbiosExAddress.TAAddressCount = 1;
  1066. NetbiosExAddress.Address[0].AddressLength = TDI_ADDRESS_LENGTH_NETBIOS_EX;
  1067. NetbiosExAddress.Address[0].AddressType = TDI_ADDRESS_TYPE_NETBIOS_EX;
  1068. pTdiNetbiosExAddress = NetbiosExAddress.Address[0].Address;
  1069. pNetbiosAddress = &pTdiNetbiosExAddress->NetbiosAddress;
  1070. pNetbiosAddress->NetbiosNameType = TDI_ADDRESS_NETBIOS_TYPE_UNIQUE;
  1071. NetbiosExAddressLength = FIELD_OFFSET(TRANSPORT_ADDRESS,Address)
  1072. + FIELD_OFFSET(TA_ADDRESS,Address)
  1073. + FIELD_OFFSET(TDI_ADDRESS_NETBIOS_EX,NetbiosAddress)
  1074. + TDI_ADDRESS_LENGTH_NETBIOS;
  1075. RtlCopyMemory(
  1076. pNetbiosAddress->NetbiosName,
  1077. NetbiosName,
  1078. NETBIOS_NAME_LEN);
  1079. // Copy the default endpoint name onto the NETBIOS Extended address.
  1080. RtlCopyMemory(
  1081. pTdiNetbiosExAddress->EndpointName,
  1082. SMBSERVER_LOCAL_ENDPOINT_NAME,
  1083. NETBIOS_NAME_LEN);
  1084. length = FIELD_OFFSET( FILE_FULL_EA_INFORMATION, EaName[0] ) +
  1085. TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
  1086. NetbiosExAddressLength;
  1087. ea = (PFILE_FULL_EA_INFORMATION)buffer;
  1088. ea->NextEntryOffset = 0;
  1089. ea->Flags = 0;
  1090. ea->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
  1091. ea->EaValueLength = (USHORT)NetbiosExAddressLength;
  1092. RtlCopyMemory( ea->EaName, StrTransportAddress, ea->EaNameLength + 1 );
  1093. RtlCopyMemory(
  1094. &ea->EaName[ea->EaNameLength + 1],
  1095. &NetbiosExAddress,
  1096. NetbiosExAddressLength
  1097. );
  1098. InitializeObjectAttributes( &objectAttributes, DeviceName, OBJ_CASE_INSENSITIVE, NULL, NULL );
  1099. status = NtCreateFile (
  1100. &Endpoint->EndpointHandle,
  1101. FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, // desired access
  1102. &objectAttributes, // object attributes
  1103. &iosb, // returned status information
  1104. NULL, // block size (unused)
  1105. 0, // file attributes
  1106. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access
  1107. FILE_CREATE, // create disposition
  1108. 0, // create options
  1109. buffer, // EA buffer
  1110. length // EA length
  1111. );
  1112. if ( !NT_SUCCESS(status) ) {
  1113. IF_DEBUG( ERRORS ) {
  1114. KdPrint(("NtCreateFile %wZ NETBIOS_EX address status %X\n", DeviceName, status ));
  1115. }
  1116. return status;
  1117. }
  1118. Endpoint->IsNoNetBios = TRUE;
  1119. status = SetupConnectionEndpointHandlers(Endpoint);
  1120. IF_DEBUG( ERRORS ) {
  1121. if( !NT_SUCCESS( status ) ) {
  1122. KdPrint(("SetupConnectionEndpointHandlers failed, status %X\n", status ));
  1123. }
  1124. }
  1125. return status;
  1126. }
  1127. NTSTATUS
  1128. OpenNonNetbiosAddress (
  1129. IN OUT PENDPOINT Endpoint,
  1130. IN PVOID DeviceName,
  1131. IN PVOID NetbiosName
  1132. )
  1133. {
  1134. NTSTATUS status;
  1135. ULONG i;
  1136. ULONG numAdapters;
  1137. PULONG maxPktArray = NULL;
  1138. UCHAR buffer[sizeof(NWLINK_ACTION) + sizeof(IPX_ADDRESS_DATA) - 1];
  1139. PNWLINK_ACTION action;
  1140. PIPX_ADDRESS_DATA ipxAddressData;
  1141. PAGED_CODE( );
  1142. //
  1143. // Open the NetBIOS name socket.
  1144. //
  1145. status = OpenIpxSocket(
  1146. &Endpoint->NameSocketHandle,
  1147. &Endpoint->NameSocketFileObject,
  1148. &Endpoint->NameSocketDeviceObject,
  1149. DeviceName,
  1150. SMB_IPX_NAME_SOCKET
  1151. );
  1152. if ( !NT_SUCCESS(status) ) {
  1153. goto cleanup;
  1154. }
  1155. Endpoint->IsConnectionless = TRUE;
  1156. action = (PNWLINK_ACTION)buffer;
  1157. //
  1158. // Put the endpoint in broadcast reception mode.
  1159. //
  1160. action->Header.TransportId = 'XPIM'; // "MIPX"
  1161. action->Header.ActionCode = 0;
  1162. action->Header.Reserved = 0;
  1163. action->OptionType = NWLINK_OPTION_ADDRESS;
  1164. action->BufferLength = sizeof(action->Option);
  1165. action->Option = MIPX_RCVBCAST;
  1166. status = SrvIssueTdiAction(
  1167. Endpoint->NameSocketFileObject,
  1168. &Endpoint->NameSocketDeviceObject,
  1169. (PCHAR)action,
  1170. sizeof(NWLINK_ACTION)
  1171. );
  1172. if ( !NT_SUCCESS(status) ) {
  1173. goto cleanup;
  1174. }
  1175. //
  1176. // Tell the transport to give you the extended receive info
  1177. //
  1178. action->Header.TransportId = 'XPIM'; // "MIPX"
  1179. action->Header.ActionCode = 0;
  1180. action->Header.Reserved = 0;
  1181. action->OptionType = NWLINK_OPTION_ADDRESS;
  1182. action->BufferLength = sizeof(action->Option);
  1183. action->Option = MIPX_SETRCVFLAGS;
  1184. status = SrvIssueTdiAction(
  1185. Endpoint->NameSocketFileObject,
  1186. &Endpoint->NameSocketDeviceObject,
  1187. (PCHAR)action,
  1188. sizeof(NWLINK_ACTION)
  1189. );
  1190. if ( !NT_SUCCESS(status) ) {
  1191. goto cleanup;
  1192. }
  1193. //
  1194. // Get the max adapter number
  1195. //
  1196. action->Header.TransportId = 'XPIM'; // "MIPX"
  1197. action->Header.ActionCode = 0;
  1198. action->Header.Reserved = 0;
  1199. action->OptionType = NWLINK_OPTION_ADDRESS;
  1200. action->BufferLength = sizeof(action->Option) + sizeof(ULONG);
  1201. action->Option = MIPX_ADAPTERNUM2;
  1202. status = SrvIssueTdiAction(
  1203. Endpoint->NameSocketFileObject,
  1204. &Endpoint->NameSocketDeviceObject,
  1205. (PCHAR)action,
  1206. sizeof(NWLINK_ACTION) + sizeof(ULONG) - 1
  1207. );
  1208. if ( !NT_SUCCESS(status) ) {
  1209. goto cleanup;
  1210. }
  1211. numAdapters = *((PULONG)action->Data);
  1212. //
  1213. // Allocate an array to store the max pkt size for each adapter
  1214. //
  1215. maxPktArray = ALLOCATE_HEAP( numAdapters * sizeof(ULONG), BlockTypeBuffer );
  1216. if ( maxPktArray == NULL ) {
  1217. status = STATUS_INSUFF_SERVER_RESOURCES;
  1218. goto cleanup;
  1219. }
  1220. Endpoint->IpxMaxPacketSizeArray = maxPktArray;
  1221. Endpoint->MaxAdapters = numAdapters;
  1222. //
  1223. // Query the max pkt size for each adapter
  1224. //
  1225. action->Header.TransportId = 'XPIM'; // "MIPX"
  1226. action->Header.ActionCode = 0;
  1227. action->Header.Reserved = 0;
  1228. action->OptionType = NWLINK_OPTION_ADDRESS;
  1229. action->BufferLength = sizeof(action->Option) + sizeof(IPX_ADDRESS_DATA);
  1230. action->Option = MIPX_GETCARDINFO2;
  1231. ipxAddressData = (PIPX_ADDRESS_DATA)action->Data;
  1232. for ( i = 0; i < numAdapters; i++ ) {
  1233. ipxAddressData->adapternum = i;
  1234. status = SrvIssueTdiAction(
  1235. Endpoint->NameSocketFileObject,
  1236. &Endpoint->NameSocketDeviceObject,
  1237. (PCHAR)action,
  1238. sizeof(NWLINK_ACTION) + sizeof(IPX_ADDRESS_DATA) - 1
  1239. );
  1240. if ( !NT_SUCCESS(status) ) {
  1241. goto cleanup;
  1242. }
  1243. //
  1244. // If this is a wan link, then we need to query the length each
  1245. // time we get a connection.
  1246. //
  1247. if ( ipxAddressData->wan ) {
  1248. maxPktArray[i] = 0;
  1249. } else {
  1250. maxPktArray[i] = ipxAddressData->maxpkt;
  1251. }
  1252. }
  1253. //
  1254. // Find the network address of the adapter used by corresponding to
  1255. // this endpoint.
  1256. //
  1257. GetNetworkAddress( Endpoint );
  1258. //
  1259. // Register the name claim Receive Datagram event handler.
  1260. //
  1261. status = SrvIssueSetEventHandlerRequest(
  1262. Endpoint->NameSocketFileObject,
  1263. &Endpoint->NameSocketDeviceObject,
  1264. TDI_EVENT_RECEIVE_DATAGRAM,
  1265. (PVOID)SrvIpxNameDatagramHandler,
  1266. Endpoint
  1267. );
  1268. if ( !NT_SUCCESS(status) ) {
  1269. INTERNAL_ERROR(
  1270. ERROR_LEVEL_EXPECTED,
  1271. "OpenNonNetbiosAddress: set receive datagram event handler failed: %X",
  1272. status,
  1273. NULL
  1274. );
  1275. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  1276. goto cleanup;
  1277. }
  1278. //
  1279. // Claim the server name.
  1280. //
  1281. status = SrvIpxClaimServerName( Endpoint, NetbiosName );
  1282. if ( !NT_SUCCESS(status) ) {
  1283. goto cleanup;
  1284. }
  1285. //
  1286. // Open the server socket.
  1287. //
  1288. status = OpenIpxSocket(
  1289. &Endpoint->EndpointHandle,
  1290. &Endpoint->FileObject,
  1291. &Endpoint->DeviceObject,
  1292. DeviceName,
  1293. SMB_IPX_SERVER_SOCKET
  1294. );
  1295. if ( !NT_SUCCESS(status) ) {
  1296. goto cleanup;
  1297. }
  1298. //
  1299. // Create a number of free connections for the endpoint. These
  1300. // connections will be used to service Connect events.
  1301. //
  1302. // *** If we fail in an attempt to create a connection, but we can
  1303. // successfully create at least one, we keep the endpoint. The
  1304. // cleanup code below depends on this behavior.
  1305. //
  1306. for ( i = 0; i < SrvFreeConnectionMinimum; i++ ) {
  1307. status = SrvOpenConnection( Endpoint );
  1308. if ( !NT_SUCCESS(status) ) {
  1309. INTERNAL_ERROR(
  1310. ERROR_LEVEL_EXPECTED,
  1311. "OpenNonNetbiosAddress: SrvOpenConnection failed: %X",
  1312. status,
  1313. NULL
  1314. );
  1315. if ( i == 0 ) {
  1316. goto cleanup;
  1317. } else {
  1318. break;
  1319. }
  1320. }
  1321. }
  1322. //
  1323. // Register the server Receive Datagram event handler.
  1324. //
  1325. status = SrvIssueSetEventHandlerRequest(
  1326. Endpoint->FileObject,
  1327. &Endpoint->DeviceObject,
  1328. TDI_EVENT_RECEIVE_DATAGRAM,
  1329. (PVOID)SrvIpxServerDatagramHandler,
  1330. Endpoint
  1331. );
  1332. if ( !NT_SUCCESS(status) ) {
  1333. INTERNAL_ERROR(
  1334. ERROR_LEVEL_EXPECTED,
  1335. "OpenNonNetbiosAddress: set receive datagram event handler failed: %X",
  1336. status,
  1337. NULL
  1338. );
  1339. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  1340. goto cleanup;
  1341. }
  1342. //
  1343. // Register the server Chained Receive Datagram event handler.
  1344. //
  1345. status = SrvIssueSetEventHandlerRequest(
  1346. Endpoint->FileObject,
  1347. &Endpoint->DeviceObject,
  1348. TDI_EVENT_CHAINED_RECEIVE_DATAGRAM,
  1349. (PVOID)SrvIpxServerChainedDatagramHandler,
  1350. Endpoint
  1351. );
  1352. if ( !NT_SUCCESS(status) ) {
  1353. INTERNAL_ERROR(
  1354. ERROR_LEVEL_EXPECTED,
  1355. "OpenNonNetbiosAddress: set chained receive datagram event handler failed: %X",
  1356. status,
  1357. NULL
  1358. );
  1359. SrvLogServiceFailure( SRV_SVC_NT_IOCTL_FILE, status );
  1360. goto cleanup;
  1361. }
  1362. return STATUS_SUCCESS;
  1363. //
  1364. // Out-of-line error cleanup.
  1365. //
  1366. cleanup:
  1367. //
  1368. // Something failed. Clean up as appropriate.
  1369. //
  1370. if ( maxPktArray != NULL ) {
  1371. Endpoint->IpxMaxPacketSizeArray = NULL;
  1372. FREE_HEAP( maxPktArray );
  1373. }
  1374. if ( Endpoint->FileObject != NULL ) {
  1375. ObDereferenceObject( Endpoint->FileObject );
  1376. Endpoint->FileObject = NULL;
  1377. }
  1378. if ( Endpoint->EndpointHandle != NULL ) {
  1379. SRVDBG_RELEASE_HANDLE( Endpoint->EndpointHandle, "END", 14, Endpoint );
  1380. SrvNtClose( Endpoint->EndpointHandle, FALSE );
  1381. Endpoint->FileObject = NULL;
  1382. }
  1383. if ( Endpoint->NameSocketFileObject != NULL ) {
  1384. ObDereferenceObject( Endpoint->NameSocketFileObject );
  1385. Endpoint->NameSocketFileObject = NULL;
  1386. }
  1387. if ( Endpoint->NameSocketHandle != NULL ) {
  1388. SRVDBG_RELEASE_HANDLE( Endpoint->NameSocketHandle, "END", 14, Endpoint );
  1389. SrvNtClose( Endpoint->NameSocketHandle, FALSE );
  1390. Endpoint->NameSocketHandle = NULL;
  1391. }
  1392. return status;
  1393. } // OpenNonNetbiosAddress
  1394. NTSTATUS
  1395. OpenIpxSocket (
  1396. OUT PHANDLE Handle,
  1397. OUT PFILE_OBJECT *FileObject,
  1398. OUT PDEVICE_OBJECT *DeviceObject,
  1399. IN PVOID DeviceName,
  1400. IN USHORT Socket
  1401. )
  1402. {
  1403. NTSTATUS status;
  1404. ULONG length;
  1405. PFILE_FULL_EA_INFORMATION ea;
  1406. TA_IPX_ADDRESS ipxAddress;
  1407. OBJECT_ATTRIBUTES objectAttributes;
  1408. IO_STATUS_BLOCK iosb;
  1409. CHAR buffer[sizeof(FILE_FULL_EA_INFORMATION) +
  1410. TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
  1411. sizeof(TA_IPX_ADDRESS)];
  1412. PAGED_CODE( );
  1413. //
  1414. // Build the IPX socket address.
  1415. //
  1416. length = FIELD_OFFSET( FILE_FULL_EA_INFORMATION, EaName[0] ) +
  1417. TDI_TRANSPORT_ADDRESS_LENGTH + 1 +
  1418. sizeof(TA_IPX_ADDRESS);
  1419. ea = (PFILE_FULL_EA_INFORMATION)buffer;
  1420. ea->NextEntryOffset = 0;
  1421. ea->Flags = 0;
  1422. ea->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
  1423. ea->EaValueLength = sizeof (TA_IPX_ADDRESS);
  1424. RtlCopyMemory( ea->EaName, StrTransportAddress, ea->EaNameLength + 1 );
  1425. //
  1426. // Create a copy of the NETBIOS address descriptor in a local
  1427. // first, in order to avoid alignment problems.
  1428. //
  1429. ipxAddress.TAAddressCount = 1;
  1430. ipxAddress.Address[0].AddressType = TDI_ADDRESS_TYPE_IPX;
  1431. ipxAddress.Address[0].AddressLength = sizeof (TDI_ADDRESS_IPX);
  1432. ipxAddress.Address[0].Address[0].Socket = Socket;
  1433. RtlCopyMemory(
  1434. &ea->EaName[ea->EaNameLength + 1],
  1435. &ipxAddress,
  1436. sizeof(TA_IPX_ADDRESS)
  1437. );
  1438. InitializeObjectAttributes( &objectAttributes, DeviceName, 0, NULL, NULL );
  1439. status = NtCreateFile (
  1440. Handle,
  1441. FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, // desired access
  1442. &objectAttributes, // object attributes
  1443. &iosb, // returned status information
  1444. NULL, // block size (unused)
  1445. 0, // file attributes
  1446. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access
  1447. FILE_CREATE, // create disposition
  1448. 0, // create options
  1449. buffer, // EA buffer
  1450. length // EA length
  1451. );
  1452. if ( !NT_SUCCESS(status) ) {
  1453. return status;
  1454. }
  1455. status = SrvVerifyDeviceStackSize(
  1456. *Handle,
  1457. TRUE,
  1458. FileObject,
  1459. DeviceObject,
  1460. NULL
  1461. );
  1462. if ( !NT_SUCCESS( status ) ) {
  1463. INTERNAL_ERROR(
  1464. ERROR_LEVEL_EXPECTED,
  1465. "OpenIpxSocket: Verify Device Stack Size failed: %X\n",
  1466. status,
  1467. NULL
  1468. );
  1469. return status;
  1470. }
  1471. return STATUS_SUCCESS;
  1472. } // OpenIpxSocket
  1473. VOID
  1474. SrvPrepareReceiveWorkItem (
  1475. IN OUT PWORK_CONTEXT WorkContext,
  1476. IN BOOLEAN QueueItemToFreeList
  1477. )
  1478. /*++
  1479. Routine Description:
  1480. This routine initializes a Receive work item and optionally queues
  1481. it to a list anchored in the server FSD device object. The
  1482. transport receive event handler in the FSD dequeues work items from
  1483. this list and passes their associated IRPS to the transport
  1484. provider.
  1485. Arguments:
  1486. WorkContext - Supplies a pointer to the preallocated work context
  1487. block that represents the work item.
  1488. QueueItemToFreeList - If TRUE queue this work item on the receive
  1489. free queue.
  1490. Return Value:
  1491. None.
  1492. --*/
  1493. {
  1494. PSMB_HEADER header;
  1495. IF_DEBUG(TRACE2) KdPrint(( "SrvPrepareReceiveWorkItem entered\n" ));
  1496. //
  1497. // Set up pointers to the SMB header and parameters for the request
  1498. // and the response. Note that we currently write the response over
  1499. // the request. SMB processors must be able to handle this. We
  1500. // maintain separate request and response pointers so that we can
  1501. // use a separate buffer if necessary. Maintaining separate request
  1502. // and response parameter pointers also allows us to process AndX
  1503. // SMBs without having to pack the AndX commands as we go.
  1504. //
  1505. WorkContext->ResponseBuffer = WorkContext->RequestBuffer;
  1506. header = (PSMB_HEADER)WorkContext->RequestBuffer->Buffer;
  1507. WorkContext->RequestHeader = header;
  1508. WorkContext->RequestParameters = (PVOID)(header + 1);
  1509. WorkContext->ResponseHeader = header;
  1510. WorkContext->ResponseParameters = (PVOID)(header + 1);
  1511. //
  1512. // Set up the restart routine in the work context.
  1513. //
  1514. WorkContext->FsdRestartRoutine = SrvQueueWorkToFspAtDpcLevel;
  1515. WorkContext->FspRestartRoutine = SrvRestartReceive;
  1516. if ( QueueItemToFreeList ) {
  1517. //
  1518. // Queue the prepared receive work item to the FSD list.
  1519. //
  1520. GET_SERVER_TIME( WorkContext->CurrentWorkQueue, &WorkContext->Timestamp );
  1521. RETURN_FREE_WORKITEM( WorkContext );
  1522. } else {
  1523. //
  1524. // Make the work item look like it's in use by setting its
  1525. // reference count to 1.
  1526. //
  1527. ASSERT( WorkContext->BlockHeader.ReferenceCount == 0 );
  1528. WorkContext->BlockHeader.ReferenceCount = 1;
  1529. }
  1530. return;
  1531. } // SrvPrepareReceiveWorkItem
  1532. VOID SRVFASTCALL
  1533. SrvRestartAccept (
  1534. IN OUT PWORK_CONTEXT WorkContext
  1535. )
  1536. /*++
  1537. Routine Description:
  1538. This function is the worker thread restart routine for Accept
  1539. requests. If the endpoint on which the connection was established
  1540. is no longer active, this routine disconnects the connection. This
  1541. is necessary because the connect indication handler cannot
  1542. atomically verify that the endpoint is active and install the active
  1543. connection. (This is because the handler runs at DPC level.)
  1544. This routine also checks the status of the TdiAccept. In case of
  1545. an error, it frees the connection.
  1546. If all is well, but the endpoint is short of free connections, a new
  1547. one is created.
  1548. Arguments:
  1549. WorkContext - Supplies a pointer to the work context block describing
  1550. server-specific context for the request.
  1551. Return Value:
  1552. None.
  1553. --*/
  1554. {
  1555. PCONNECTION connection;
  1556. PENDPOINT endpoint;
  1557. PIRP irp;
  1558. NTSTATUS status;
  1559. PAGED_CODE( );
  1560. IF_DEBUG(WORKER1) KdPrint(( " - SrvRestartAccept\n" ));
  1561. connection = WorkContext->Connection;
  1562. endpoint = WorkContext->Endpoint;
  1563. irp = WorkContext->Irp;
  1564. IF_DEBUG(TRACE2) {
  1565. KdPrint(( " connection %p, endpoint %p, IRP %p\n",
  1566. connection, endpoint, irp ));
  1567. }
  1568. //
  1569. // If the I/O request failed or was canceled, or if the endpoint
  1570. // block is closing, clean up.
  1571. //
  1572. ACQUIRE_LOCK( &SrvEndpointLock );
  1573. if ( irp->Cancel ||
  1574. !NT_SUCCESS(irp->IoStatus.Status) ||
  1575. (GET_BLOCK_STATE(endpoint) != BlockStateActive) ) {
  1576. RELEASE_LOCK( &SrvEndpointLock );
  1577. DEBUG {
  1578. KdPrint(( "SrvRestartAccept: Accept failed!" ));
  1579. if ( irp->Cancel ) {
  1580. KdPrint(( " I/O canceled\n" ));
  1581. } else if ( !NT_SUCCESS(irp->IoStatus.Status) ) {
  1582. KdPrint(( " I/O failed: %X\n", irp->IoStatus.Status ));
  1583. } else {
  1584. KdPrint(( " Endpoint no longer active\n" ));
  1585. }
  1586. }
  1587. //
  1588. // Close the connection. If the Accept succeeded, we need to
  1589. // issue a Disconnect.
  1590. //
  1591. #if SRVDBG29
  1592. if (irp->Cancel) {
  1593. UpdateConnectionHistory( "ACC1", endpoint, connection );
  1594. } else if (!NT_SUCCESS(irp->IoStatus.Status)) {
  1595. UpdateConnectionHistory( "ACC2", endpoint, connection );
  1596. } else {
  1597. UpdateConnectionHistory( "ACC3", endpoint, connection );
  1598. }
  1599. #endif
  1600. connection->DisconnectReason = DisconnectAcceptFailedOrCancelled;
  1601. SrvCloseConnection(
  1602. connection,
  1603. (BOOLEAN)(irp->Cancel || !NT_SUCCESS(irp->IoStatus.Status) ?
  1604. TRUE : FALSE) // RemoteDisconnect
  1605. );
  1606. } else {
  1607. PNBT_ADDRESS_PAIR_INFO AddressPairInfo;
  1608. UNICODE_STRING clientMachineName;
  1609. //
  1610. // The Accept worked, and the endpoint is still active. Create
  1611. // a new free connection, if necessary.
  1612. //
  1613. if ( endpoint->FreeConnectionCount < SrvFreeConnectionMinimum ) {
  1614. (VOID)SrvOpenConnection( endpoint );
  1615. (VOID)SrvOpenConnection( endpoint );
  1616. }
  1617. RELEASE_LOCK( &SrvEndpointLock );
  1618. //
  1619. // Get the IP address of the client (if it has one)
  1620. //
  1621. AddressPairInfo = WorkContext->RequestBuffer->Buffer;
  1622. AddressPairInfo = (PNBT_ADDRESS_PAIR_INFO)(((ULONG_PTR)AddressPairInfo + 7) & ~7);
  1623. //
  1624. // Get the IP address of the client, if appropriate
  1625. //
  1626. status = SrvIssueTdiQuery( connection->FileObject,
  1627. &connection->DeviceObject,
  1628. (PCHAR)AddressPairInfo, sizeof( *AddressPairInfo ),
  1629. TDI_QUERY_ADDRESS_INFO
  1630. );
  1631. if( NT_SUCCESS( status ) &&
  1632. AddressPairInfo->AddressPair.TAAddressCount == 2 ) {
  1633. // Copy out the SockAddr info
  1634. if( AddressPairInfo->AddressPair.AddressIP.AddressType == TDI_ADDRESS_TYPE_IP )
  1635. {
  1636. PTDI_ADDRESS_IP Address = &AddressPairInfo->AddressPair.AddressIP.Address;
  1637. struct sockaddr_in* sockaddr = (struct sockaddr_in*)connection->SockAddr;
  1638. sockaddr->sin_family = AF_INET;
  1639. sockaddr->sin_port = Address->sin_port;
  1640. sockaddr->sin_addr.S_un.S_addr = Address->in_addr;
  1641. }
  1642. else if( AddressPairInfo->AddressPair.AddressIP.AddressType == TDI_ADDRESS_TYPE_IP6 )
  1643. {
  1644. PTDI_ADDRESS_IP6 Address = &AddressPairInfo->AddressPair.AddressIP.AddressIp6;
  1645. struct sockaddr_in6* sockaddr = (struct sockaddr_in6*)connection->SockAddr;
  1646. ASSERT(sizeof(TDI_ADDRESS_IP6)==sizeof(struct sockaddr_in6)-sizeof(USHORT));
  1647. sockaddr->sin6_family = AF_INET6;
  1648. RtlCopyMemory( &sockaddr->sin6_port, Address, sizeof(TDI_ADDRESS_IP6) );
  1649. }
  1650. // Setup the ClientIPAddress and the Keep-alives
  1651. if( AddressPairInfo->AddressPair.AddressIP.AddressType == TDI_ADDRESS_TYPE_IP )
  1652. {
  1653. PTCP_REQUEST_SET_INFORMATION_EX tcpSetInfo;
  1654. struct TCPKeepalive *keepAlive;
  1655. IO_STATUS_BLOCK iosb;
  1656. connection->ClientIPAddress = AddressPairInfo->AddressPair.AddressIP.Address.in_addr;
  1657. //
  1658. // We have an IP client. Set a reasonable keepalive interval.
  1659. //
  1660. tcpSetInfo = ALLOCATE_HEAP( sizeof(*tcpSetInfo) + sizeof( *keepAlive ), BlockTypeMisc );
  1661. if( tcpSetInfo != NULL ) {
  1662. RtlZeroMemory( tcpSetInfo, sizeof( *tcpSetInfo ) + sizeof( *keepAlive ) );
  1663. tcpSetInfo->ID.toi_entity.tei_entity = CO_TL_ENTITY;
  1664. tcpSetInfo->ID.toi_class = INFO_CLASS_PROTOCOL;
  1665. tcpSetInfo->ID.toi_type = INFO_TYPE_CONNECTION;
  1666. tcpSetInfo->ID.toi_id = TCP_SOCKET_KEEPALIVE_VALS;
  1667. tcpSetInfo->BufferSize = sizeof( *keepAlive );
  1668. keepAlive = (TCPKeepalive *)(&tcpSetInfo->Buffer[0]);
  1669. keepAlive->onoff = TRUE; // turn on keepalives
  1670. //
  1671. // keepalive time is the time to first keepalive transmission, by default it
  1672. // is 2 hours (7,200,000 milliseconds) for TCP. If there is no data transfer between
  1673. // client and server for keepalive time, the server will send first keepalive
  1674. // probe. Successive probes are determined by keepalive interval. If there is any
  1675. // data transfer, timer is reset to keepalive time.
  1676. //
  1677. // keepalive interval is the interval in milliseconds between keepalive transmissions
  1678. // until a response is received, by default it is 1000. Server sends a total of 10
  1679. // keepalive probes, keepalive interval apart, and if there is no response from the
  1680. // client, the connection is terminated.
  1681. //
  1682. keepAlive->keepalivetime = 2 * (60 * 1000); // 2 minutes
  1683. keepAlive->keepaliveinterval = 2 * 1000; // 2 seconds
  1684. //
  1685. // Set the keepalive values
  1686. //
  1687. (VOID)NtDeviceIoControlFile(
  1688. connection->PagedConnection->ConnectionHandle,
  1689. 0,
  1690. NULL,
  1691. NULL,
  1692. &iosb,
  1693. IOCTL_NETBT_SET_TCP_CONNECTION_INFO,
  1694. tcpSetInfo, sizeof( *tcpSetInfo ) + sizeof( *keepAlive ),
  1695. NULL, 0
  1696. );
  1697. FREE_HEAP( tcpSetInfo );
  1698. }
  1699. }
  1700. } else {
  1701. connection->ClientIPAddress = 0;
  1702. RtlZeroMemory( connection->SockAddr, SRV_CONNECTION_SOCKADDR_SIZE );
  1703. }
  1704. //
  1705. // Convert the client machine name to unicode
  1706. //
  1707. clientMachineName.Buffer = connection->ClientMachineName;
  1708. clientMachineName.MaximumLength =
  1709. (USHORT)(COMPUTER_NAME_LENGTH+1)*sizeof(WCHAR);
  1710. (VOID)RtlOemStringToUnicodeString(
  1711. &clientMachineName,
  1712. &connection->OemClientMachineNameString,
  1713. FALSE
  1714. );
  1715. //
  1716. // Add the double backslashes to the length
  1717. //
  1718. connection->ClientMachineNameString.Length =
  1719. (USHORT)(clientMachineName.Length + 2*sizeof(WCHAR));
  1720. }
  1721. SrvDereferenceWorkItem( WorkContext );
  1722. IF_DEBUG(TRACE2) KdPrint(( "SrvRestartAccept complete\n" ));
  1723. return;
  1724. } // SrvRestartAccept
  1725. VOID
  1726. SrvStartSend (
  1727. IN OUT PWORK_CONTEXT WorkContext,
  1728. IN PIO_COMPLETION_ROUTINE SendCompletionRoutine,
  1729. IN PMDL Mdl OPTIONAL,
  1730. IN ULONG SendOptions
  1731. )
  1732. /*++
  1733. Routine Description:
  1734. This function starts a Send request. It is started as an
  1735. asynchronous I/O request. When the Send completes, it is delivered
  1736. via the I/O completion routine to the server FSD, which routes it to
  1737. the specified FsdRestartRoutine. (This may be
  1738. SrvQueueWorkToFspAtDpcLevel, which queues the work item to the FSP
  1739. at the FspRestartRoutine.)
  1740. Partial sends and chained sends are supported. A partial send is one
  1741. that is not the last segment of a "message" or "record". A chained
  1742. send is one made up of multiple virtually discontiguous buffers.
  1743. Arguments:
  1744. WorkContext - Supplies a pointer to a Work Context block. The
  1745. following fields of this structure must be valid:
  1746. TdiRequest
  1747. Irp (optional; actual address copied here)
  1748. Endpoint
  1749. Endpoint->FileObject
  1750. Endpoint->DeviceObject
  1751. Connection
  1752. Connection->ConnectionId
  1753. Mdl - Supplies a pointer to the first (or only) MDL describing the
  1754. data that is to be sent. To effect a chained send, the Next
  1755. pointer of each MDL in the chain must point to the next MDL;
  1756. the end of the chain is indicated by the NULL Next pointer.
  1757. The total length of the send is calculated by summing the
  1758. ByteCount fields of each MDL in the chain.
  1759. This parameter is optional. If it is omitted, a zero-length
  1760. message is sent.
  1761. SendOptions - Supplied TDI send options, which indicate whether this
  1762. send is the last (or only) in a "chain" of partial sends.
  1763. Return Value:
  1764. None.
  1765. --*/
  1766. {
  1767. PTDI_REQUEST_KERNEL_SEND parameters;
  1768. PIO_STACK_LOCATION irpSp;
  1769. PIRP irp;
  1770. ULONG sendLength;
  1771. PDEVICE_OBJECT deviceObject;
  1772. PFILE_OBJECT fileObject;
  1773. IF_DEBUG(TRACE2) KdPrint(( "SrvStartSend entered\n" ));
  1774. ASSERT( !WorkContext->Endpoint->IsConnectionless );
  1775. //
  1776. // Set ProcessingCount to zero so this send cannot be cancelled.
  1777. // This is used together with setting the cancel flag to false below.
  1778. //
  1779. // WARNING: This still presents us with a tiny window where this
  1780. // send could be cancelled.
  1781. //
  1782. WorkContext->ProcessingCount = 0;
  1783. //
  1784. // Get the irp, device, and file objects
  1785. //
  1786. irp = WorkContext->Irp;
  1787. deviceObject = WorkContext->Connection->DeviceObject;
  1788. fileObject = WorkContext->Connection->FileObject;
  1789. CHECKIRP( irp );
  1790. if( irp->AssociatedIrp.SystemBuffer &&
  1791. (irp->Flags & IRP_DEALLOCATE_BUFFER) ) {
  1792. ExFreePool( irp->AssociatedIrp.SystemBuffer );
  1793. irp->Flags &= ~IRP_DEALLOCATE_BUFFER;
  1794. }
  1795. sendLength = WorkContext->ResponseBuffer->DataLength;
  1796. //
  1797. // Build the I/O request packet.
  1798. //
  1799. // *** Note that the connection block is not referenced to account
  1800. // for this I/O request. The WorkContext block already has a
  1801. // referenced pointer to the connection, and this pointer is not
  1802. // dereferenced until after the I/O completes.
  1803. //
  1804. ASSERT( irp->StackCount >= deviceObject->StackSize );
  1805. irp->Tail.Overlay.OriginalFileObject = fileObject;
  1806. irp->Tail.Overlay.Thread = WorkContext->CurrentWorkQueue->IrpThread;
  1807. irp->RequestorMode = KernelMode;
  1808. //
  1809. // Get a pointer to the next stack location. This one is used to
  1810. // hold the parameters for the device I/O control request.
  1811. //
  1812. irpSp = IoGetNextIrpStackLocation( irp );
  1813. //
  1814. // Set up the completion routine.
  1815. //
  1816. IoSetCompletionRoutine(
  1817. irp,
  1818. SendCompletionRoutine,
  1819. (PVOID)WorkContext,
  1820. TRUE,
  1821. TRUE,
  1822. TRUE
  1823. );
  1824. irpSp->FileObject = fileObject;
  1825. irpSp->DeviceObject = deviceObject;
  1826. parameters = (PTDI_REQUEST_KERNEL_SEND)&irpSp->Parameters;
  1827. parameters->SendFlags = SendOptions;
  1828. parameters->SendLength = sendLength;
  1829. //
  1830. // For these two cases, InputBuffer is the buffered I/O "system
  1831. // buffer". Build an MDL for either read or write access,
  1832. // depending on the method, for the output buffer.
  1833. //
  1834. irp->MdlAddress = Mdl;
  1835. //
  1836. // If statistics are to be gathered for this work item, do so now.
  1837. //
  1838. UPDATE_STATISTICS(
  1839. WorkContext,
  1840. sendLength,
  1841. WorkContext->ResponseHeader->Command
  1842. );
  1843. #if DBG
  1844. if( sendLength >= sizeof( SMB_HEADER ) && sendLength <= 0xffff && Mdl ) {
  1845. PSMB_HEADER Smb = MmGetSystemAddressForMdl( Mdl );
  1846. if ( SmbGetAlignedUlong( (PULONG)Smb->Protocol ) == SMB_HEADER_PROTOCOL ) {
  1847. ULONG len;
  1848. PMDL tmpMdl;
  1849. //
  1850. // For debugging purposes, put extra data in the response smb. This will help us figure
  1851. // out what went wrong if the client detects an SMB format error
  1852. //
  1853. //
  1854. // Put the send length in PidHigh
  1855. //
  1856. SmbPutUshort( &Smb->PidHigh, (USHORT)sendLength );
  1857. //
  1858. // Put the overall MDL length in Pid. The transport is only supposed to transmit SendLength -- so
  1859. // this will help us figure out if the transport is sending too much data.
  1860. //
  1861. for( len = 0, tmpMdl = Mdl; tmpMdl != NULL; tmpMdl = tmpMdl->Next ) {
  1862. len += MmGetMdlByteCount( tmpMdl );
  1863. }
  1864. SmbPutUshort( &Smb->Pid, (USHORT)len );
  1865. }
  1866. }
  1867. #endif
  1868. //
  1869. // If we are doing security signatures, we need to sign this packet
  1870. //
  1871. if( sendLength &&
  1872. WorkContext->Connection &&
  1873. WorkContext->Connection->SmbSecuritySignatureActive == TRUE &&
  1874. WorkContext->NoResponseSmbSecuritySignature == FALSE ) {
  1875. SrvAddSmbSecuritySignature( WorkContext, Mdl, sendLength );
  1876. }
  1877. //
  1878. // Pass the request to the transport provider.
  1879. //
  1880. IF_DEBUG(TRACE2) {
  1881. KdPrint(( "SrvStartSend posting Send IRP %p\n", irp ));
  1882. }
  1883. WorkContext->Irp->Cancel = FALSE;
  1884. //
  1885. // Increment the pending operation count
  1886. //
  1887. InterlockedIncrement( &WorkContext->Connection->OperationsPendingOnTransport );
  1888. //
  1889. // Set the cancel flag to FALSE in case this was cancelled by
  1890. // the SrvSmbNtCancel routine.
  1891. //
  1892. if ( WorkContext->Endpoint->FastTdiSend ) {
  1893. INCREMENT_DEBUG_STAT2( SrvDbgStatistics.DirectSendsAttempted );
  1894. irpSp->MinorFunction = TDI_DIRECT_SEND;
  1895. IoSetNextIrpStackLocation( irp );
  1896. WorkContext->Endpoint->FastTdiSend( deviceObject, irp );
  1897. } else {
  1898. irpSp->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
  1899. irpSp->MinorFunction = TDI_SEND;
  1900. irp->AssociatedIrp.SystemBuffer = NULL;
  1901. irp->Flags = (ULONG)IRP_BUFFERED_IO;
  1902. (VOID)IoCallDriver( deviceObject, irp );
  1903. }
  1904. IF_DEBUG(TRACE2) KdPrint(( "SrvStartSend complete\n" ));
  1905. return;
  1906. } // SrvStartSend
  1907. VOID
  1908. SrvStartSend2 (
  1909. IN OUT PWORK_CONTEXT WorkContext,
  1910. IN PIO_COMPLETION_ROUTINE SendCompletionRoutine
  1911. )
  1912. /*++
  1913. Routine Description:
  1914. This function starts a Send request. It is started as an
  1915. asynchronous I/O request. When the Send completes, it is delivered
  1916. via the I/O completion routine to the server FSD, which routes it to
  1917. the specified FsdRestartRoutine. (This may be
  1918. SrvQueueWorkToFspAtDpcLevel, which queues the work item to the FSP
  1919. at the FspRestartRoutine.)
  1920. Partial sends and chained sends are supported. A partial send is one
  1921. that is not the last segment of a "message" or "record". A chained
  1922. send is one made up of multiple virtually discontiguous buffers.
  1923. ** This is identical to SrvStartSend except that the parameter mdl
  1924. is assumed to be ResponseBuffer->Mdl and sendOptions is assumed to be
  1925. 0 **
  1926. Arguments:
  1927. WorkContext - Supplies a pointer to a Work Context block. The
  1928. following fields of this structure must be valid:
  1929. TdiRequest
  1930. Irp (optional; actual address copied here)
  1931. Endpoint
  1932. Endpoint->FileObject
  1933. Endpoint->DeviceObject
  1934. Connection
  1935. Connection->ConnectionId
  1936. Return Value:
  1937. None.
  1938. --*/
  1939. {
  1940. PTDI_REQUEST_KERNEL_SEND parameters;
  1941. PIO_STACK_LOCATION irpSp;
  1942. PIRP irp;
  1943. PDEVICE_OBJECT deviceObject;
  1944. PFILE_OBJECT fileObject;
  1945. PMDL mdl = WorkContext->ResponseBuffer->Mdl;
  1946. ULONG sendLength = WorkContext->ResponseBuffer->DataLength;
  1947. IF_DEBUG(TRACE2) KdPrint(( "SrvStartSend2 entered\n" ));
  1948. ASSERT( !WorkContext->Endpoint->IsConnectionless );
  1949. //
  1950. // Set ProcessingCount to zero so this send cannot be cancelled.
  1951. // This is used together with setting the cancel flag to false below.
  1952. //
  1953. // WARNING: This still presents us with a tiny window where this
  1954. // send could be cancelled.
  1955. //
  1956. WorkContext->ProcessingCount = 0;
  1957. //
  1958. // Get the irp, device, and file objects
  1959. //
  1960. irp = WorkContext->Irp;
  1961. deviceObject = WorkContext->Connection->DeviceObject;
  1962. fileObject = WorkContext->Connection->FileObject;
  1963. CHECKIRP( irp );
  1964. if( irp->AssociatedIrp.SystemBuffer &&
  1965. (irp->Flags & IRP_DEALLOCATE_BUFFER) ) {
  1966. ExFreePool( irp->AssociatedIrp.SystemBuffer );
  1967. irp->Flags &= ~IRP_DEALLOCATE_BUFFER;
  1968. }
  1969. //
  1970. // Build the I/O request packet.
  1971. //
  1972. // *** Note that the connection block is not referenced to account
  1973. // for this I/O request. The WorkContext block already has a
  1974. // referenced pointer to the connection, and this pointer is not
  1975. // dereferenced until after the I/O completes.
  1976. //
  1977. ASSERT( irp->StackCount >= deviceObject->StackSize );
  1978. irp->Tail.Overlay.OriginalFileObject = fileObject;
  1979. irp->Tail.Overlay.Thread = WorkContext->CurrentWorkQueue->IrpThread;
  1980. DEBUG irp->RequestorMode = KernelMode;
  1981. //
  1982. // Get a pointer to the next stack location. This one is used to
  1983. // hold the parameters for the device I/O control request.
  1984. //
  1985. irpSp = IoGetNextIrpStackLocation( irp );
  1986. //
  1987. // Set up the completion routine.
  1988. //
  1989. IoSetCompletionRoutine(
  1990. irp,
  1991. SendCompletionRoutine,
  1992. (PVOID)WorkContext,
  1993. TRUE,
  1994. TRUE,
  1995. TRUE
  1996. );
  1997. irpSp->FileObject = fileObject;
  1998. irpSp->DeviceObject = deviceObject;
  1999. parameters = (PTDI_REQUEST_KERNEL_SEND)&irpSp->Parameters;
  2000. parameters->SendFlags = 0;
  2001. parameters->SendLength = sendLength;
  2002. //
  2003. // For these two cases, InputBuffer is the buffered I/O "system
  2004. // buffer". Build an MDL for either read or write access,
  2005. // depending on the method, for the output buffer.
  2006. //
  2007. irp->MdlAddress = mdl;
  2008. //
  2009. // If statistics are to be gathered for this work item, do so now.
  2010. //
  2011. UPDATE_STATISTICS(
  2012. WorkContext,
  2013. sendLength,
  2014. WorkContext->ResponseHeader->Command
  2015. );
  2016. #if DBG
  2017. if( sendLength >= sizeof( SMB_HEADER ) && sendLength <= 0xffff && mdl ) {
  2018. PSMB_HEADER Smb = MmGetSystemAddressForMdl( mdl );
  2019. if ( SmbGetAlignedUlong( (PULONG)Smb->Protocol ) == SMB_HEADER_PROTOCOL ) {
  2020. ULONG len;
  2021. PMDL tmpMdl;
  2022. //
  2023. // For debugging purposes, put extra data in the response smb. This
  2024. // will help us figure out what went wrong if the client detects an
  2025. // SMB format error
  2026. //
  2027. //
  2028. // Put the send length in PidHigh
  2029. //
  2030. SmbPutUshort( &Smb->PidHigh, (USHORT)sendLength );
  2031. //
  2032. // Put the overall MDL length in Pid. The transport is only supposed
  2033. // to transmit SendLength -- so this will help us figure out if the
  2034. // transport is sending too much data.
  2035. //
  2036. for( len = 0, tmpMdl = mdl; tmpMdl != NULL; tmpMdl = tmpMdl->Next ) {
  2037. len += MmGetMdlByteCount( tmpMdl );
  2038. }
  2039. SmbPutUshort( &Smb->Pid, (USHORT)len );
  2040. }
  2041. }
  2042. #endif
  2043. //
  2044. // If we are doing security signatures, we need to sign this packet
  2045. //
  2046. if( sendLength &&
  2047. WorkContext->Connection &&
  2048. WorkContext->Connection->SmbSecuritySignatureActive == TRUE &&
  2049. WorkContext->NoResponseSmbSecuritySignature == FALSE ) {
  2050. SrvAddSmbSecuritySignature( WorkContext, mdl, sendLength );
  2051. }
  2052. //
  2053. // Pass the request to the transport provider.
  2054. //
  2055. IF_DEBUG(TRACE2) {
  2056. KdPrint(( "SrvStartSend2 posting Send IRP %p\n", irp ));
  2057. }
  2058. WorkContext->Irp->Cancel = FALSE;
  2059. //
  2060. // Increment the pending operation count
  2061. //
  2062. InterlockedIncrement( &WorkContext->Connection->OperationsPendingOnTransport );
  2063. //
  2064. // Set the cancel flag to FALSE in case this was cancelled by
  2065. // the SrvSmbNtCancel routine.
  2066. //
  2067. if ( WorkContext->Endpoint->FastTdiSend ) {
  2068. INCREMENT_DEBUG_STAT2( SrvDbgStatistics.DirectSendsAttempted );
  2069. irpSp->MinorFunction = TDI_DIRECT_SEND;
  2070. IoSetNextIrpStackLocation( irp );
  2071. WorkContext->Endpoint->FastTdiSend( deviceObject, irp );
  2072. } else {
  2073. irpSp->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
  2074. irpSp->MinorFunction = TDI_SEND;
  2075. irp->AssociatedIrp.SystemBuffer = NULL;
  2076. irp->Flags = (ULONG)IRP_BUFFERED_IO;
  2077. (VOID)IoCallDriver( deviceObject, irp );
  2078. }
  2079. IF_DEBUG(TRACE2) KdPrint(( "SrvStartSend2 complete\n" ));
  2080. return;
  2081. } // SrvStartSend2
  2082. ULONG
  2083. GetIpxMaxBufferSize(
  2084. PENDPOINT Endpoint,
  2085. ULONG AdapterNumber,
  2086. ULONG DefaultMaxBufferSize
  2087. )
  2088. /*++
  2089. Routine Description:
  2090. This routine computes the max buffer size the server negotiates
  2091. with the client. It takes the smaller of DefaultMaxBufferSize
  2092. and the max packet length returned by the ipx transport.
  2093. Arguments:
  2094. Endpoint - pointer to the endpoint corresponding to the ipx transport
  2095. AdapterNumber - the adapter number for which the max buffer size is to
  2096. be computed for.
  2097. DefaultMaxBufferSize - the maximum size that can be returned by this
  2098. routine.
  2099. Return Value:
  2100. The max buffer size to be negotiated by the server.
  2101. --*/
  2102. {
  2103. NTSTATUS status;
  2104. ULONG maxBufferSize;
  2105. PNWLINK_ACTION action;
  2106. PIPX_ADDRESS_DATA ipxAddressData;
  2107. UCHAR buffer[sizeof(NWLINK_ACTION) + sizeof(IPX_ADDRESS_DATA) - 1];
  2108. PAGED_CODE( );
  2109. action = (PNWLINK_ACTION)buffer;
  2110. //
  2111. // Verify that the adapter number is within bounds
  2112. //
  2113. if ( AdapterNumber > Endpoint->MaxAdapters ) {
  2114. return DefaultMaxBufferSize;
  2115. }
  2116. //
  2117. // If value in array is non-zero, then this is not a wan link.
  2118. // Use that value.
  2119. //
  2120. if ( Endpoint->IpxMaxPacketSizeArray[AdapterNumber-1] != 0 ) {
  2121. maxBufferSize = MIN(
  2122. Endpoint->IpxMaxPacketSizeArray[AdapterNumber-1],
  2123. DefaultMaxBufferSize
  2124. );
  2125. return (maxBufferSize & ~3);
  2126. }
  2127. //
  2128. // This is a wan link, query the max packet size.
  2129. //
  2130. action->Header.TransportId = 'XPIM'; // "MIPX"
  2131. action->Header.ActionCode = 0;
  2132. action->Header.Reserved = 0;
  2133. action->OptionType = NWLINK_OPTION_ADDRESS;
  2134. action->BufferLength = sizeof(action->Option) + sizeof(IPX_ADDRESS_DATA);
  2135. action->Option = MIPX_GETCARDINFO2;
  2136. ipxAddressData = (PIPX_ADDRESS_DATA)action->Data;
  2137. ipxAddressData->adapternum = AdapterNumber - 1;
  2138. status = SrvIssueTdiAction(
  2139. Endpoint->NameSocketFileObject,
  2140. &Endpoint->NameSocketDeviceObject,
  2141. (PCHAR)action,
  2142. sizeof(NWLINK_ACTION) + sizeof(IPX_ADDRESS_DATA) - 1
  2143. );
  2144. if ( !NT_SUCCESS(status) ) {
  2145. return DefaultMaxBufferSize;
  2146. }
  2147. ASSERT( ipxAddressData->wan );
  2148. maxBufferSize = MIN(
  2149. (ULONG)ipxAddressData->maxpkt,
  2150. DefaultMaxBufferSize
  2151. );
  2152. return (maxBufferSize & ~3);
  2153. } // GetMaxIpxPacketSize
  2154. VOID
  2155. SrvpNotifyChangesToNetBt(
  2156. IN TDI_PNP_OPCODE PnPOpcode,
  2157. IN PUNICODE_STRING DeviceName,
  2158. IN PWSTR MultiSZBindList)
  2159. /*++
  2160. Routine Description:
  2161. This routine should not be part of srv. It has been introduced into this
  2162. component to overcome current limitations in NetBt. The NetBt transport
  2163. exposes two kinds of devices -- the traditional NetBt device and the
  2164. new non Netbios device which make use of the NetBt framing code without the
  2165. name resolution aspects of it. The current implementation in NetBt exposes
  2166. the former devices on a per adapter basis while the second category of device
  2167. is exposed on a global basis ( one for all the adapters ). This poses
  2168. problems in disabling/enabling srv on a given adapter.
  2169. The correct solution is to expose the second category of devices on a per
  2170. adapter basis. Till it is done this workaround is reqd. With this workaround
  2171. whenever the server is notified of any changes to the binding string it turns
  2172. around and notifies the NetBt transport about these changes.
  2173. This routine is based upon the following assumptions ...
  2174. 1) The notification from TDI is not done at raised IRQL.
  2175. 2) The thread on which this notification occurs has enough access rights.
  2176. 3) The notification to NetBt is done asynchronously with srv's reaction
  2177. to the change. The srv handles the PNP notification by passing it off to
  2178. user mode and have it come through the server service.
  2179. Arguments:
  2180. PNPOpcode - the PNP opcode
  2181. DeviceName - the transport for which this opcode is intended
  2182. MultiSZBindList - the binding list
  2183. Return Value:
  2184. None.
  2185. --*/
  2186. {
  2187. NTSTATUS Status;
  2188. OBJECT_ATTRIBUTES ObjectAttributes;
  2189. HANDLE NetbioslessSmbHandle;
  2190. IO_STATUS_BLOCK IoStatusBlock;
  2191. UNICODE_STRING NetbioslessSmbName = {36,36, L"\\device\\NetbiosSmb"};
  2192. InitializeObjectAttributes(
  2193. &ObjectAttributes,
  2194. &NetbioslessSmbName,
  2195. OBJ_CASE_INSENSITIVE,
  2196. NULL,
  2197. NULL );
  2198. Status = ZwCreateFile (
  2199. &NetbioslessSmbHandle,
  2200. FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES, // desired access
  2201. &ObjectAttributes, // object attributes
  2202. &IoStatusBlock, // returned status information
  2203. NULL, // block size (unused)
  2204. 0, // file attributes
  2205. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access
  2206. FILE_CREATE, // create disposition
  2207. 0, // create options
  2208. NULL, // EA buffer
  2209. 0 // EA length
  2210. );
  2211. if ( NT_SUCCESS(Status) ) {
  2212. NETBT_SMB_BIND_REQUEST NetBtNotificationParameters;
  2213. NetBtNotificationParameters.RequestType = SMB_SERVER;
  2214. NetBtNotificationParameters.PnPOpCode = PnPOpcode;
  2215. NetBtNotificationParameters.pDeviceName = DeviceName;
  2216. NetBtNotificationParameters.MultiSZBindList = MultiSZBindList;
  2217. Status = ZwDeviceIoControlFile(
  2218. NetbioslessSmbHandle,
  2219. NULL,
  2220. NULL,
  2221. NULL,
  2222. &IoStatusBlock,
  2223. IOCTL_NETBT_SET_SMBDEVICE_BIND_INFO,
  2224. &NetBtNotificationParameters,
  2225. sizeof(NetBtNotificationParameters),
  2226. NULL,
  2227. 0);
  2228. IF_DEBUG( ERRORS ) {
  2229. KdPrint(("NtFsControlFile %wZ in SrvpNotifyChangesToNetBt status %X\n", &NetbioslessSmbName, Status ));
  2230. }
  2231. Status = ZwClose(NetbioslessSmbHandle);
  2232. IF_DEBUG( ERRORS ) {
  2233. KdPrint(("NtCloseFile %wZ in SrvpNotifyChangesToNetBt status %X\n", &NetbioslessSmbName, Status ));
  2234. }
  2235. } else {
  2236. IF_DEBUG( ERRORS ) {
  2237. KdPrint(("NtCreateFile %wZ in SrvpNotifyChangesToNetBt status %X\n", &NetbioslessSmbName, Status ));
  2238. }
  2239. }
  2240. }