Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

852 lines
22 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. blkendp.c
  5. Abstract:
  6. This module implements routines for managing endpoint blocks.
  7. Author:
  8. Chuck Lenzmeier (chuckl) 4-Oct-1989
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #include "blkendp.tmh"
  13. #pragma hdrstop
  14. #define BugCheckFileId SRV_FILE_BLKENDP
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text( PAGE, SrvAllocateEndpoint )
  17. #pragma alloc_text( PAGE, SrvCheckAndReferenceEndpoint )
  18. #pragma alloc_text( PAGE, SrvCloseEndpoint )
  19. #pragma alloc_text( PAGE, SrvDereferenceEndpoint )
  20. #pragma alloc_text( PAGE, SrvFreeEndpoint )
  21. #pragma alloc_text( PAGE, SrvReferenceEndpoint )
  22. #pragma alloc_text( PAGE, SrvFindNamedEndpoint )
  23. #endif
  24. #if 0
  25. NOT PAGEABLE -- EmptyFreeConnectionList
  26. NOT PAGEABLE -- WalkConnectionTable
  27. #endif
  28. VOID
  29. SrvAllocateEndpoint (
  30. OUT PENDPOINT *Endpoint,
  31. IN PUNICODE_STRING NetworkName,
  32. IN PUNICODE_STRING TransportName,
  33. IN PANSI_STRING TransportAddress,
  34. IN PUNICODE_STRING DomainName
  35. )
  36. /*++
  37. Routine Description:
  38. This function allocates an Endpoint Block from the system nonpaged
  39. pool.
  40. Arguments:
  41. Endpoint - Returns a pointer to the endpoint block, or NULL if no
  42. pool was available.
  43. NetworkName - Supplies a pointer to the network name (e.g., NET1).
  44. TransportName - The fully qualified name of the transport device.
  45. For example, "\Device\Nbf".
  46. TransportAddress - The fully qualified address (or name ) of the
  47. server's endpoint. This name is used exactly as specified. For
  48. NETBIOS-compatible networks, the caller must upcase and
  49. blank-fill the name. E.g., "\Device\Nbf\NTSERVERbbbbbbbb".
  50. DomainName - the domain being serviced by this endpoint
  51. Return Value:
  52. None.
  53. --*/
  54. {
  55. CLONG length;
  56. PENDPOINT endpoint;
  57. NTSTATUS status;
  58. PAGED_CODE( );
  59. //
  60. // Attempt to allocate from nonpaged pool.
  61. //
  62. length = sizeof(ENDPOINT) +
  63. NetworkName->Length + sizeof(*NetworkName->Buffer) +
  64. TransportName->Length + sizeof(*TransportName->Buffer) +
  65. TransportAddress->Length + sizeof(*TransportAddress->Buffer) +
  66. RtlOemStringToUnicodeSize( TransportAddress ) +
  67. DNLEN * sizeof( *DomainName->Buffer ) +
  68. DNLEN + sizeof(CHAR);
  69. endpoint = ALLOCATE_NONPAGED_POOL( length, BlockTypeEndpoint );
  70. *Endpoint = endpoint;
  71. if ( endpoint == NULL ) {
  72. INTERNAL_ERROR (
  73. ERROR_LEVEL_EXPECTED,
  74. "SrvAllocateEndpoint: Unable to allocate %d bytes from nonpaged "
  75. "pool.",
  76. length,
  77. NULL
  78. );
  79. return;
  80. }
  81. IF_DEBUG(HEAP) {
  82. SrvPrint1( "SrvAllocateEndpoint: Allocated endpoint at %p\n",
  83. endpoint );
  84. }
  85. //
  86. // Initialize the endpoint block. Zero it first.
  87. //
  88. RtlZeroMemory( endpoint, length );
  89. SET_BLOCK_TYPE_STATE_SIZE( endpoint, BlockTypeEndpoint, BlockStateActive, length );
  90. endpoint->BlockHeader.ReferenceCount = 2; // allow for Active status
  91. // and caller's pointer
  92. //
  93. // Allocate connection table.
  94. //
  95. SrvAllocateTable(
  96. &endpoint->ConnectionTable,
  97. 6, // !!!
  98. TRUE
  99. );
  100. if ( endpoint->ConnectionTable.Table == NULL ) {
  101. DEALLOCATE_NONPAGED_POOL( endpoint );
  102. *Endpoint = NULL;
  103. return;
  104. }
  105. InitializeListHead( &endpoint->FreeConnectionList );
  106. #if SRVDBG29
  107. UpdateConnectionHistory( "INIT", endpoint, NULL );
  108. #endif
  109. //
  110. // Copy the network name, transport name, and server address, and domain
  111. // name into the block.
  112. //
  113. endpoint->NetworkName.Length = NetworkName->Length;
  114. endpoint->NetworkName.MaximumLength =
  115. (SHORT)(NetworkName->Length + sizeof(*NetworkName->Buffer));
  116. endpoint->NetworkName.Buffer = (PWCH)(endpoint + 1);
  117. RtlCopyMemory(
  118. endpoint->NetworkName.Buffer,
  119. NetworkName->Buffer,
  120. NetworkName->Length
  121. );
  122. endpoint->TransportName.Length = TransportName->Length;
  123. endpoint->TransportName.MaximumLength =
  124. (SHORT)(TransportName->Length + sizeof(*TransportName->Buffer));
  125. endpoint->TransportName.Buffer =
  126. (PWCH)((PCHAR)endpoint->NetworkName.Buffer +
  127. endpoint->NetworkName.MaximumLength);
  128. RtlCopyMemory(
  129. endpoint->TransportName.Buffer,
  130. TransportName->Buffer,
  131. TransportName->Length
  132. );
  133. endpoint->ServerName.MaximumLength = (USHORT)RtlOemStringToUnicodeSize( TransportAddress );
  134. endpoint->ServerName.Length = 0;
  135. endpoint->ServerName.Buffer = endpoint->TransportName.Buffer +
  136. endpoint->TransportName.MaximumLength / sizeof( WCHAR );
  137. endpoint->TransportAddress.Length = TransportAddress->Length;
  138. endpoint->TransportAddress.MaximumLength =
  139. (SHORT)(TransportAddress->Length + 1);
  140. endpoint->TransportAddress.Buffer =
  141. (PCHAR)endpoint->ServerName.Buffer +
  142. endpoint->ServerName.MaximumLength;
  143. RtlCopyMemory(
  144. endpoint->TransportAddress.Buffer,
  145. TransportAddress->Buffer,
  146. TransportAddress->Length
  147. );
  148. status = RtlOemStringToUnicodeString( &endpoint->ServerName, TransportAddress, FALSE );
  149. if (!NT_SUCCESS(status)) {
  150. DbgPrint("SRv ENDPOINT Name translation failed status %lx\n",status);
  151. KdPrint(("SRv ENDPOINT Name translation failed status %lx\n",status));
  152. }
  153. //
  154. // Trim the trailing blanks off the end of servername
  155. //
  156. while( endpoint->ServerName.Length &&
  157. endpoint->ServerName.Buffer[ (endpoint->ServerName.Length / sizeof(WCHAR))-1 ] == L' ' ) {
  158. endpoint->ServerName.Length -= sizeof( WCHAR );
  159. }
  160. endpoint->DomainName.Length = DomainName->Length;
  161. endpoint->DomainName.MaximumLength = DNLEN * sizeof( *endpoint->DomainName.Buffer );
  162. endpoint->DomainName.Buffer = (PWCH)((PCHAR)endpoint->TransportAddress.Buffer +
  163. TransportAddress->MaximumLength);
  164. RtlCopyMemory(
  165. endpoint->DomainName.Buffer,
  166. DomainName->Buffer,
  167. DomainName->Length
  168. );
  169. endpoint->OemDomainName.Length = (SHORT)RtlUnicodeStringToOemSize( DomainName );
  170. endpoint->OemDomainName.MaximumLength = DNLEN + sizeof( CHAR );
  171. endpoint->OemDomainName.Buffer = (PCHAR)endpoint->DomainName.Buffer +
  172. endpoint->DomainName.MaximumLength;
  173. status = RtlUnicodeStringToOemString(
  174. &endpoint->OemDomainName,
  175. &endpoint->DomainName,
  176. FALSE // Do not allocate the OEM string
  177. );
  178. ASSERT( NT_SUCCESS(status) );
  179. //
  180. // Initialize the network address field.
  181. //
  182. endpoint->NetworkAddress.Buffer = endpoint->NetworkAddressData;
  183. endpoint->NetworkAddress.Length = sizeof( endpoint->NetworkAddressData ) -
  184. sizeof(endpoint->NetworkAddressData[0]);
  185. endpoint->NetworkAddress.MaximumLength = sizeof( endpoint->NetworkAddressData );
  186. //
  187. // Increment the count of endpoints in the server.
  188. //
  189. ACQUIRE_LOCK( &SrvEndpointLock );
  190. SrvEndpointCount++;
  191. RELEASE_LOCK( &SrvEndpointLock );
  192. INITIALIZE_REFERENCE_HISTORY( endpoint );
  193. INCREMENT_DEBUG_STAT( SrvDbgStatistics.EndpointInfo.Allocations );
  194. return;
  195. } // SrvAllocateEndpoint
  196. BOOLEAN SRVFASTCALL
  197. SrvCheckAndReferenceEndpoint (
  198. PENDPOINT Endpoint
  199. )
  200. /*++
  201. Routine Description:
  202. This function atomically verifies that an endpoint is active and
  203. increments the reference count on the endpoint if it is.
  204. Arguments:
  205. Endpoint - Address of endpoint
  206. Return Value:
  207. BOOLEAN - Returns TRUE if the endpoint is active, FALSE otherwise.
  208. --*/
  209. {
  210. PAGED_CODE( );
  211. //
  212. // Acquire the lock that guards the endpoint's state field.
  213. //
  214. ACQUIRE_LOCK( &SrvEndpointLock );
  215. //
  216. // If the endpoint is active, reference it and return TRUE.
  217. //
  218. if ( GET_BLOCK_STATE(Endpoint) == BlockStateActive ) {
  219. SrvReferenceEndpoint( Endpoint );
  220. RELEASE_LOCK( &SrvEndpointLock );
  221. return TRUE;
  222. }
  223. //
  224. // The endpoint isn't active. Return FALSE.
  225. //
  226. RELEASE_LOCK( &SrvEndpointLock );
  227. return FALSE;
  228. } // SrvCheckAndReferenceEndpoint
  229. VOID
  230. SrvCloseEndpoint (
  231. IN PENDPOINT Endpoint
  232. )
  233. /*++
  234. Routine Description:
  235. This function closes a transport endpoint.
  236. *** This function must be called with SrvEndpointLock held exactly
  237. once. The lock is released on exit.
  238. Arguments:
  239. Endpoint - Supplies a pointer to an Endpoint Block
  240. Return Value:
  241. None.
  242. --*/
  243. {
  244. USHORT index;
  245. PCONNECTION connection;
  246. PAGED_CODE( );
  247. ASSERT( ExIsResourceAcquiredExclusiveLite(&RESOURCE_OF(SrvEndpointLock)) );
  248. if ( GET_BLOCK_STATE(Endpoint) == BlockStateActive ) {
  249. IF_DEBUG(BLOCK1) SrvPrint1( "Closing endpoint at %p\n", Endpoint );
  250. SET_BLOCK_STATE( Endpoint, BlockStateClosing );
  251. //
  252. // Close all active connections.
  253. //
  254. index = (USHORT)-1;
  255. while ( TRUE ) {
  256. //
  257. // Get the next active connection in the table. If no more
  258. // are available, WalkConnectionTable returns NULL.
  259. // Otherwise, it returns a referenced pointer to a
  260. // connection.
  261. //
  262. connection = WalkConnectionTable( Endpoint, &index );
  263. if ( connection == NULL ) {
  264. break;
  265. }
  266. //
  267. // We don't want to hold the endpoint lock while we close the
  268. // connection (this causes lock level problems). Since we
  269. // already have a referenced pointer to the connection, this
  270. // is safe.
  271. //
  272. RELEASE_LOCK( &SrvEndpointLock );
  273. #if SRVDBG29
  274. UpdateConnectionHistory( "CEND", Endpoint, connection );
  275. #endif
  276. connection->DisconnectReason = DisconnectEndpointClosing;
  277. SrvCloseConnection( connection, FALSE );
  278. ACQUIRE_LOCK( &SrvEndpointLock );
  279. SrvDereferenceConnection( connection );
  280. }
  281. //
  282. // Close all free connections.
  283. //
  284. EmptyFreeConnectionList( Endpoint );
  285. //
  286. // We don't need to hold the endpoint lock anymore.
  287. //
  288. RELEASE_LOCK( &SrvEndpointLock );
  289. //
  290. // Close the endpoint file handle. This causes all pending
  291. // requests to be aborted. It also deregisters all event
  292. // handlers.
  293. //
  294. // *** Note that we have a separate reference to the file
  295. // object, in addition to the handle. We don't release that
  296. // reference until all activity on the endpoint has ceased
  297. // (in SrvDereferenceEndpoint).
  298. //
  299. SRVDBG_RELEASE_HANDLE( Endpoint->EndpointHandle, "END", 2, Endpoint );
  300. SrvNtClose( Endpoint->EndpointHandle, FALSE );
  301. if ( Endpoint->IsConnectionless ) {
  302. SRVDBG_RELEASE_HANDLE( Endpoint->NameSocketHandle, "END", 2, Endpoint );
  303. SrvNtClose( Endpoint->NameSocketHandle, FALSE );
  304. }
  305. //
  306. // Dereference the endpoint (to indicate that it's no longer
  307. // open).
  308. //
  309. SrvDereferenceEndpoint( Endpoint );
  310. INCREMENT_DEBUG_STAT( SrvDbgStatistics.EndpointInfo.Closes );
  311. } else {
  312. RELEASE_LOCK( &SrvEndpointLock );
  313. }
  314. return;
  315. } // SrvCloseEndpoint
  316. VOID SRVFASTCALL
  317. SrvDereferenceEndpoint (
  318. IN PENDPOINT Endpoint
  319. )
  320. /*++
  321. Routine Description:
  322. This function decrements the reference count on an endpoint. If the
  323. reference count goes to zero, the endpoint block is deleted.
  324. Arguments:
  325. Endpoint - Address of endpoint
  326. Return Value:
  327. None.
  328. --*/
  329. {
  330. ULONG newEndpointCount;
  331. PAGED_CODE( );
  332. //
  333. // Enter a critical section and decrement the reference count on the
  334. // block.
  335. //
  336. ACQUIRE_LOCK( &SrvEndpointLock );
  337. IF_DEBUG(REFCNT) {
  338. SrvPrint2( "Dereferencing endpoint %p; old refcnt %lx\n",
  339. Endpoint, Endpoint->BlockHeader.ReferenceCount );
  340. }
  341. ASSERT( GET_BLOCK_TYPE( Endpoint ) == BlockTypeEndpoint );
  342. ASSERT( (LONG)Endpoint->BlockHeader.ReferenceCount > 0 );
  343. UPDATE_REFERENCE_HISTORY( Endpoint, TRUE );
  344. if ( --Endpoint->BlockHeader.ReferenceCount == 0 ) {
  345. //
  346. // The new reference count is 0, meaning that it's time to
  347. // delete this block.
  348. //
  349. ASSERT( GET_BLOCK_STATE(Endpoint) != BlockStateActive );
  350. //
  351. // Decrement the count of endpoints in the server. If the new
  352. // count is zero, set the endpoint event.
  353. //
  354. ASSERT( SrvEndpointCount >= 1 );
  355. newEndpointCount = --SrvEndpointCount;
  356. RELEASE_LOCK( &SrvEndpointLock );
  357. if ( newEndpointCount == 0 ) {
  358. KeSetEvent( &SrvEndpointEvent, 0, FALSE );
  359. }
  360. //
  361. // Remove the endpoint from the global list of endpoints.
  362. //
  363. SrvRemoveEntryOrderedList( &SrvEndpointList, Endpoint );
  364. //
  365. // Dereference the file object pointer. (The handle to the file
  366. // object was closed in SrvCloseEndpoint.)
  367. //
  368. ObDereferenceObject( Endpoint->FileObject );
  369. if ( Endpoint->IsConnectionless ) {
  370. ObDereferenceObject( Endpoint->NameSocketFileObject );
  371. }
  372. //
  373. // Free the endpoint block's storage.
  374. //
  375. SrvFreeEndpoint( Endpoint );
  376. } else {
  377. RELEASE_LOCK( &SrvEndpointLock );
  378. }
  379. return;
  380. } // SrvDereferenceEndpoint
  381. VOID
  382. SrvFreeEndpoint (
  383. IN PENDPOINT Endpoint
  384. )
  385. /*++
  386. Routine Description:
  387. This function returns an Endpoint Block to the system nonpaged pool.
  388. Arguments:
  389. Endpoint - Address of endpoint
  390. Return Value:
  391. None.
  392. --*/
  393. {
  394. PAGED_CODE( );
  395. DEBUG SET_BLOCK_TYPE_STATE_SIZE( Endpoint, BlockTypeGarbage, BlockStateDead, -1 );
  396. DEBUG Endpoint->BlockHeader.ReferenceCount = (ULONG)-1;
  397. TERMINATE_REFERENCE_HISTORY( Endpoint );
  398. if ( Endpoint->IpxMaxPacketSizeArray != NULL ) {
  399. FREE_HEAP( Endpoint->IpxMaxPacketSizeArray );
  400. }
  401. if ( Endpoint->ConnectionTable.Table != NULL ) {
  402. SrvFreeTable( &Endpoint->ConnectionTable );
  403. }
  404. DEALLOCATE_NONPAGED_POOL( Endpoint );
  405. IF_DEBUG(HEAP) SrvPrint1( "SrvFreeEndpoint: Freed endpoint block at %p\n", Endpoint );
  406. INCREMENT_DEBUG_STAT( SrvDbgStatistics.EndpointInfo.Frees );
  407. return;
  408. } // SrvFreeEndpoint
  409. VOID
  410. SrvReferenceEndpoint (
  411. PENDPOINT Endpoint
  412. )
  413. /*++
  414. Routine Description:
  415. This function increments the reference count on an endpoint block.
  416. Arguments:
  417. Endpoint - Address of endpoint
  418. Return Value:
  419. None.
  420. --*/
  421. {
  422. PAGED_CODE( );
  423. //
  424. // Enter a critical section and increment the reference count on the
  425. // endpoint.
  426. //
  427. ACQUIRE_LOCK( &SrvEndpointLock );
  428. ASSERT( (LONG)Endpoint->BlockHeader.ReferenceCount > 0 );
  429. ASSERT( GET_BLOCK_TYPE(Endpoint) == BlockTypeEndpoint );
  430. ASSERT( GET_BLOCK_STATE(Endpoint) == BlockStateActive );
  431. UPDATE_REFERENCE_HISTORY( Endpoint, FALSE );
  432. Endpoint->BlockHeader.ReferenceCount++;
  433. IF_DEBUG(REFCNT) SrvPrint2( "Referencing endpoint %p; new refcnt %lx\n",
  434. Endpoint, Endpoint->BlockHeader.ReferenceCount );
  435. RELEASE_LOCK( &SrvEndpointLock );
  436. return;
  437. } // SrvReferenceEndpoint
  438. BOOLEAN
  439. SrvFindNamedEndpoint(
  440. IN PUNICODE_STRING ServerName,
  441. OUT PBOOLEAN RemapPipeNames OPTIONAL
  442. )
  443. /*++
  444. Routine Description:
  445. This routine returns TRUE of any endpoint is supporting 'ServerName'.
  446. Additionally, set the RemapPipeNames variable from the found endpoint.
  447. --*/
  448. {
  449. PLIST_ENTRY listEntry;
  450. PENDPOINT endpoint = NULL;
  451. PAGED_CODE( );
  452. if( ARGUMENT_PRESENT( RemapPipeNames ) ) {
  453. *RemapPipeNames = FALSE;
  454. }
  455. //
  456. // Find an endpoint block supporting the specified name.
  457. //
  458. ACQUIRE_LOCK_SHARED( &SrvEndpointLock );
  459. for( listEntry = SrvEndpointList.ListHead.Flink;
  460. listEntry != &SrvEndpointList.ListHead;
  461. endpoint = NULL, listEntry = listEntry->Flink ) {
  462. endpoint = CONTAINING_RECORD(
  463. listEntry,
  464. ENDPOINT,
  465. GlobalEndpointListEntry
  466. );
  467. //
  468. // Skip any inappropriate endpoints
  469. //
  470. if( GET_BLOCK_STATE( endpoint ) != BlockStateActive ||
  471. endpoint->IsConnectionless ||
  472. (ARGUMENT_PRESENT( RemapPipeNames ) && endpoint->IsNoNetBios) ) {
  473. continue;
  474. }
  475. //
  476. // See if this endpoint literally matches the name we're looking for
  477. //
  478. if( RtlEqualUnicodeString( ServerName, &endpoint->ServerName, TRUE ) ) {
  479. break;
  480. }
  481. //
  482. // We might have a case where the ServerName is something like
  483. // server.dns.company.com
  484. // but the endpoint netbios name is only 'server'. We should match this
  485. //
  486. if( endpoint->ServerName.Length < ServerName->Length ) {
  487. UNICODE_STRING shortServerName;
  488. shortServerName = *ServerName;
  489. shortServerName.Length = endpoint->ServerName.Length;
  490. if (RtlEqualUnicodeString( &endpoint->ServerName, &shortServerName, TRUE)) {
  491. if (endpoint->ServerName.Length < ((NETBIOS_NAME_LEN - 1) * sizeof(WCHAR))) {
  492. if (ServerName->Buffer[ shortServerName.Length / sizeof( WCHAR ) ] == L'.') {
  493. break;
  494. }
  495. } else {
  496. if (endpoint->ServerName.Length == (NETBIOS_NAME_LEN - 1) * sizeof(WCHAR)) {
  497. break;
  498. }
  499. }
  500. }
  501. }
  502. //
  503. // See if this endpoint domain name literally matches the name we're
  504. // looking for. The following two tests against the domain name are
  505. // required to cover the case when there are certain components that
  506. // use the domain name to talk to the server. Given the way name resolution
  507. // records are setup this used to work before this checkin. This change
  508. // breaks them. These tests provide us the backward compatibility.
  509. //
  510. if( RtlEqualUnicodeString( ServerName, &endpoint->DomainName, TRUE ) ) {
  511. break;
  512. }
  513. //
  514. // We might have a case where the ServerName is something like
  515. // server.dns.company.com
  516. // but the endpoint netbios name is only 'server'. We should match this
  517. //
  518. if( endpoint->DomainName.Length < ServerName->Length ) {
  519. UNICODE_STRING shortServerName;
  520. shortServerName = *ServerName;
  521. shortServerName.Length = endpoint->DomainName.Length;
  522. if (RtlEqualUnicodeString( &endpoint->DomainName, &shortServerName, TRUE)) {
  523. if (endpoint->DomainName.Length <= (NETBIOS_NAME_LEN * sizeof(WCHAR))) {
  524. if (ServerName->Buffer[ shortServerName.Length / sizeof( WCHAR ) ] == L'.') {
  525. break;
  526. }
  527. } else {
  528. if (endpoint->DomainName.Length == (NETBIOS_NAME_LEN - 1) * sizeof(WCHAR)) {
  529. break;
  530. }
  531. }
  532. }
  533. }
  534. }
  535. if( ARGUMENT_PRESENT( RemapPipeNames ) && endpoint != NULL ) {
  536. *RemapPipeNames = ( endpoint->RemapPipeNames == TRUE );
  537. }
  538. RELEASE_LOCK( &SrvEndpointLock );
  539. return endpoint != NULL;
  540. }
  541. VOID
  542. EmptyFreeConnectionList (
  543. IN PENDPOINT Endpoint
  544. )
  545. {
  546. PCONNECTION connection;
  547. PLIST_ENTRY listEntry;
  548. KIRQL oldIrql;
  549. //
  550. // *** In order to synchronize with the TDI connect handler in
  551. // the FSD, which only uses a spin lock to serialize access
  552. // to the free connection list (and does not check the
  553. // endpoint state), we need to atomically capture the list
  554. // head and empty the list.
  555. //
  556. ACQUIRE_GLOBAL_SPIN_LOCK( Fsd, &oldIrql );
  557. listEntry = Endpoint->FreeConnectionList.Flink;
  558. InitializeListHead( &Endpoint->FreeConnectionList );
  559. #if SRVDBG29
  560. UpdateConnectionHistory( "CLOS", Endpoint, NULL );
  561. #endif
  562. RELEASE_GLOBAL_SPIN_LOCK( Fsd, oldIrql );
  563. while ( listEntry != &Endpoint->FreeConnectionList ) {
  564. connection = CONTAINING_RECORD(
  565. listEntry,
  566. CONNECTION,
  567. EndpointFreeListEntry
  568. );
  569. listEntry = listEntry->Flink;
  570. SrvCloseFreeConnection( connection );
  571. }
  572. return;
  573. } // EmptyFreeConnectionList
  574. PCONNECTION
  575. WalkConnectionTable (
  576. IN PENDPOINT Endpoint,
  577. IN OUT PUSHORT Index
  578. )
  579. {
  580. USHORT i;
  581. PTABLE_HEADER tableHeader;
  582. PCONNECTION connection;
  583. KIRQL oldIrql;
  584. ACQUIRE_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(0), &oldIrql );
  585. for ( i = 1; i < ENDPOINT_LOCK_COUNT ; i++ ) {
  586. ACQUIRE_DPC_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(i) );
  587. }
  588. tableHeader = &Endpoint->ConnectionTable;
  589. for ( i = *Index + 1; i < tableHeader->TableSize; i++ ) {
  590. connection = (PCONNECTION)tableHeader->Table[i].Owner;
  591. if ( (connection != NULL) &&
  592. (GET_BLOCK_STATE(connection) == BlockStateActive) ) {
  593. *Index = i;
  594. SrvReferenceConnectionLocked( connection );
  595. goto exit;
  596. }
  597. }
  598. connection = NULL;
  599. exit:
  600. for ( i = ENDPOINT_LOCK_COUNT-1 ; i > 0 ; i-- ) {
  601. RELEASE_DPC_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(i) );
  602. }
  603. RELEASE_SPIN_LOCK( &ENDPOINT_SPIN_LOCK(0), oldIrql );
  604. return connection;
  605. } // WalkConnectionTable