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.

3893 lines
127 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. smbcedb.c
  5. Abstract:
  6. This module implements all functions related to accessing the SMB connection engine
  7. database
  8. Revision History:
  9. Balan Sethu Raman [SethuR] 6-March-1995
  10. Notes:
  11. The construction of server, net root and session entries involve a certain
  12. amount of network traffic. Therefore, all these entities are constructed
  13. using a two phase protocol
  14. This continuation context is that of the RDBSS during construction of
  15. srv call and net root entries. For the session entries it is an SMB exchange
  16. that needs to be resumed.
  17. Two of the three primary data structures in the SMB mini redirector, i.e.,
  18. SMBCEDB_SERVER_ENTRY, SMBCEDB_SESSION_ENTRY and SMBCEDB_NET_ROOT_ENTRY have
  19. directcounterparts in the RDBSS (MRX_SRV_CALL, MRX_V_NET_ROOT and MRX_NET_ROOT)
  20. constitute the core of the SMB mini redirector connection engine. There exists
  21. a one to one mapping between the SERVER_ENTRY and the MRX_SRV_CALL, as well
  22. as NET_ROOT_ENTRY and MRX_NET_ROOT.
  23. The SMBCEDB_SESSION_ENTRY does not have a direct mapping to a wrapper data
  24. structue, It is a part of SMBCE_V_NET_ROOT_CONTEXT which is the data
  25. structure associated with a MRX_V_NET_ROOT instance.
  26. More than one tree connect to a server can use the same session on a USER level
  27. security share. Consequently mapping rules need to be established to manage this
  28. relationship. The SMB mini redirector implements the following rules ...
  29. 1) The first session with explicitly specified credentials will be
  30. treated as the default session for all subsequent requests to any given
  31. server unless credentials are explicitly specified for the new session.
  32. 2) If no session with explicitly specified credentials exist then a
  33. session with the same logon id. is choosen.
  34. 3) If no session with the same logon id. exists a new session is created.
  35. These rules are liable to change as we experiment with rules for establishing
  36. sessions with differing credentials to a given server. The problem is not with
  37. creating/manipulating these sessions but providing an adequate set of
  38. fallback rules for emulating the behaviour of the old redirector.
  39. These rules are implemented in SmbCeFindOrConstructSessionEntry.
  40. --*/
  41. #include "precomp.h"
  42. #pragma hdrstop
  43. #include "exsessup.h"
  44. #include "secext.h"
  45. #include "csc.h"
  46. #ifdef ALLOC_PRAGMA
  47. #pragma alloc_text(PAGE, SmbCeUpdateSrvCall)
  48. #pragma alloc_text(PAGE, SmbCeTearDownServerEntry)
  49. #pragma alloc_text(PAGE, SmbCeGetUserNameAndDomainName)
  50. #pragma alloc_text(PAGE, SmbCeTearDownSessionEntry)
  51. #pragma alloc_text(PAGE, SmbCeTearDownNetRootEntry)
  52. #pragma alloc_text(PAGE, SmbCeUpdateNetRoot)
  53. #pragma alloc_text(PAGE, SmbCeDbInit)
  54. #endif
  55. extern BOOLEAN MRxSmbSecuritySignaturesRequired;
  56. extern BOOLEAN MRxSmbSecuritySignaturesEnabled;
  57. extern BOOLEAN Win9xSessionRestriction;
  58. RXDT_DefineCategory(SMBCEDB);
  59. #define Dbg (DEBUG_TRACE_SMBCEDB)
  60. // The flag mask to control reference count tracing.
  61. ULONG MRxSmbReferenceTracingValue = 0;
  62. PSMBCEDB_SERVER_ENTRY
  63. SmbCeFindServerEntry(
  64. PUNICODE_STRING pServerName,
  65. SMBCEDB_SERVER_TYPE ServerType,
  66. PRX_CONNECTION_ID RxConnectionId )
  67. /*++
  68. Routine Description:
  69. This routine searches the list of server entries and locates a matching
  70. entry
  71. Arguments:
  72. pServerName - the name of the server
  73. ServerType - the server type
  74. RxConnectionId - Used to control whether this will be multiplexed or not
  75. Notes:
  76. The SmbCeResource must be held on entry and its ownership state will remain
  77. unchanged on exit
  78. --*/
  79. {
  80. PSMBCEDB_SERVER_ENTRY pServerEntry;
  81. RX_CONNECTION_ID LocalId;
  82. ASSERT(SmbCeIsResourceOwned());
  83. if( !RxConnectionId )
  84. {
  85. RtlZeroMemory( &LocalId, sizeof(RX_CONNECTION_ID) );
  86. RxConnectionId = &LocalId;
  87. }
  88. pServerEntry = SmbCeGetFirstServerEntry();
  89. while (pServerEntry != NULL) {
  90. if ((RtlCompareUnicodeString(
  91. pServerName,
  92. &pServerEntry->Name,
  93. TRUE) == 0)) {
  94. // Check the connection ID
  95. if( RxEqualConnectionId( RxConnectionId, &pServerEntry->ConnectionId ) )
  96. {
  97. SmbCeReferenceServerEntry(pServerEntry);
  98. break;
  99. }
  100. else
  101. {
  102. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  103. }
  104. } else {
  105. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  106. }
  107. }
  108. return pServerEntry;
  109. }
  110. PSMBCEDB_SERVER_ENTRY
  111. SmbCeFindServerEntryNoId(
  112. PUNICODE_STRING pServerName,
  113. SMBCEDB_SERVER_TYPE ServerType)
  114. /*++
  115. Routine Description:
  116. This routine searches the list of server entries and locates a matching
  117. entry and ignores the ConnectionId
  118. Arguments:
  119. pServerName - the name of the server
  120. ServerType - the server type
  121. Notes:
  122. The SmbCeResource must be held on entry and its ownership state will remain
  123. unchanged on exit
  124. --*/
  125. {
  126. PSMBCEDB_SERVER_ENTRY pServerEntry;
  127. RX_CONNECTION_ID LocalId;
  128. ASSERT(SmbCeIsResourceOwned());
  129. RtlZeroMemory( &LocalId, sizeof(RX_CONNECTION_ID) );
  130. pServerEntry = SmbCeGetFirstServerEntry();
  131. while (pServerEntry != NULL) {
  132. if ((RtlCompareUnicodeString(
  133. pServerName,
  134. &pServerEntry->Name,
  135. TRUE) == 0)) {
  136. if( RxEqualConnectionId( &LocalId, &pServerEntry->ConnectionId ) )
  137. {
  138. SmbCeReferenceServerEntry(pServerEntry);
  139. break;
  140. }
  141. else
  142. {
  143. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  144. }
  145. } else {
  146. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  147. }
  148. }
  149. return pServerEntry;
  150. }
  151. PSMBCEDB_SERVER_ENTRY
  152. SmbCeFindDfsServerEntry(
  153. PUNICODE_STRING pServerName,
  154. SMBCEDB_SERVER_TYPE ServerType)
  155. /*++
  156. Routine Description:
  157. This routine searches the list of server entries and locates a matching
  158. entry
  159. Arguments:
  160. pServerName - the name of the server
  161. ServerType - the server type
  162. Notes:
  163. The SmbCeResource must be held on entry and its ownership state will remain
  164. unchanged on exit
  165. --*/
  166. {
  167. PSMBCEDB_SERVER_ENTRY pServerEntry;
  168. ASSERT(SmbCeIsResourceOwned());
  169. pServerEntry = SmbCeGetFirstServerEntry();
  170. while (pServerEntry != NULL) {
  171. if ((RtlCompareUnicodeString(
  172. pServerName,
  173. &pServerEntry->DfsRootName,
  174. TRUE) == 0)) {
  175. SmbCeReferenceServerEntry(pServerEntry);
  176. break;
  177. } else {
  178. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  179. }
  180. }
  181. return pServerEntry;
  182. }
  183. NTSTATUS
  184. SmbCeFindOrConstructServerEntry(
  185. PUNICODE_STRING pServerName,
  186. SMBCEDB_SERVER_TYPE ServerType,
  187. PSMBCEDB_SERVER_ENTRY *pServerEntryPtr,
  188. PBOOLEAN pNewServerEntry,
  189. PRX_CONNECTION_ID RxConnectionId )
  190. /*++
  191. Routine Description:
  192. This routine searches the list of server entries and locates a matching
  193. entry or constructs a new one with the given name
  194. Arguments:
  195. pServerName - the name of the server
  196. ServerType - the type of server
  197. pServerEntryPtr - placeholder for the server entry
  198. pNewServerEntry - set to TRUE if it is a newly created server entry
  199. Notes:
  200. The SmbCeResource must be held on entry and its ownership state will remain
  201. unchanged on exit
  202. --*/
  203. {
  204. NTSTATUS Status = STATUS_SUCCESS;
  205. BOOLEAN fNewServerEntry = FALSE;
  206. PSMBCEDB_SERVER_ENTRY pServerEntry;
  207. RX_CONNECTION_ID LocalId;
  208. ASSERT(SmbCeIsResourceOwned());
  209. if( !RxConnectionId )
  210. {
  211. RtlZeroMemory( &LocalId, sizeof(RX_CONNECTION_ID) );
  212. RxConnectionId = &LocalId;
  213. }
  214. pServerEntry = SmbCeFindServerEntry(
  215. pServerName,
  216. ServerType,
  217. RxConnectionId);
  218. if (pServerEntry == NULL) {
  219. // Create a server instance, initialize its state, add it to the list
  220. pServerEntry = (PSMBCEDB_SERVER_ENTRY)SmbMmAllocateObject(SMBCEDB_OT_SERVER);
  221. if (pServerEntry != NULL) {
  222. pServerEntry->Name.Buffer = RxAllocatePoolWithTag(
  223. NonPagedPool,
  224. pServerName->Length,
  225. MRXSMB_SERVER_POOLTAG);
  226. if (pServerEntry->Name.Buffer == NULL) {
  227. SmbMmFreeObject(pServerEntry);
  228. pServerEntry = NULL;
  229. }
  230. }
  231. if (pServerEntry != NULL) {
  232. fNewServerEntry = TRUE;
  233. pServerEntry->Name.Length = pServerName->Length;
  234. pServerEntry->Name.MaximumLength = pServerEntry->Name.Length;
  235. RtlCopyMemory(
  236. pServerEntry->Name.Buffer,
  237. pServerName->Buffer,
  238. pServerEntry->Name.Length);
  239. SmbCeUpdateServerEntryState(
  240. pServerEntry,
  241. SMBCEDB_CONSTRUCTION_IN_PROGRESS);
  242. SmbCeSetServerType(
  243. pServerEntry,
  244. ServerType);
  245. pServerEntry->PreferredTransport = NULL;
  246. SmbCeReferenceServerEntry(pServerEntry);
  247. SmbCeAddServerEntry(pServerEntry);
  248. pServerEntry->Server.IsRemoteBootServer = FALSE;
  249. if (MRxSmbBootedRemotely &&
  250. (MRxSmbRemoteBootShare.Length > pServerEntry->Name.Length)) {
  251. UNICODE_STRING RemoteBootServer;
  252. RemoteBootServer.Length = pServerEntry->Name.Length;
  253. RemoteBootServer.MaximumLength = pServerEntry->Name.MaximumLength;
  254. RemoteBootServer.Buffer = MRxSmbRemoteBootShare.Buffer;
  255. if (RtlEqualUnicodeString(
  256. &pServerEntry->Name,
  257. &RemoteBootServer,
  258. TRUE)) {
  259. pServerEntry->Server.IsRemoteBootServer = TRUE;
  260. }
  261. }
  262. pServerEntry->Server.IsFakeDfsServerForOfflineUse = FALSE;
  263. pServerEntry->Server.IsPinnedOffline = FALSE;
  264. pServerEntry->Server.SecurityMode = SECURITY_MODE_USER_LEVEL;
  265. RtlCopyMemory( &pServerEntry->ConnectionId, RxConnectionId, sizeof(RX_CONNECTION_ID) );
  266. if (SmbCeContext.ServersWithExtendedSessTimeout.Length != 0) {
  267. PWSTR pSmbMRxServers = (PWSTR)SmbCeContext.ServersWithExtendedSessTimeout.Buffer;
  268. UNICODE_STRING SmbMRxServer, TargetServer;
  269. TargetServer.Length = pServerEntry->Name.Length - sizeof(WCHAR);
  270. TargetServer.MaximumLength = pServerEntry->Name.MaximumLength;
  271. TargetServer.Buffer = &pServerEntry->Name.Buffer[1];
  272. while (*pSmbMRxServers) {
  273. SmbMRxServer.Length = wcslen(pSmbMRxServers) * sizeof(WCHAR);
  274. if (SmbMRxServer.Length == TargetServer.Length) {
  275. SmbMRxServer.MaximumLength = SmbMRxServer.Length;
  276. SmbMRxServer.Buffer = pSmbMRxServers;
  277. if (RtlCompareUnicodeString(
  278. &SmbMRxServer,
  279. &TargetServer,
  280. TRUE) == 0) {
  281. pServerEntry->Server.ExtendedSessTimeout = TRUE;
  282. //DbgPrint("Extended SessTimeout %wZ\n",&pServerEntry->Name);
  283. break;
  284. }
  285. }
  286. pSmbMRxServers += (SmbMRxServer.Length / sizeof(WCHAR) + 1);
  287. }
  288. }
  289. SmbCeLog(("NewSrvEntry %lx %wZ\n",pServerEntry,&pServerEntry->Name));
  290. SmbLog(LOG,
  291. SmbCeFindOrConstructServerEntry_1,
  292. LOGPTR(pServerEntry)
  293. LOGUSTR(pServerEntry->Name));
  294. } else {
  295. RxDbgTrace(0, Dbg, ("SmbCeOpenServer : Server Entry Allocation failed\n"));
  296. Status = STATUS_INSUFFICIENT_RESOURCES;
  297. }
  298. } else {
  299. if (pServerEntry->PreferredTransport != NULL) {
  300. // reset the preferred transport created by previous owner
  301. SmbCeDereferenceTransport(pServerEntry->PreferredTransport);
  302. pServerEntry->PreferredTransport = NULL;
  303. }
  304. SmbCeLog(("CachedSrvEntry %lx %wZ\n",pServerEntry,&pServerEntry->Name));
  305. SmbLog(LOG,
  306. SmbCeFindOrConstructServerEntry_2,
  307. LOGPTR(pServerEntry)
  308. LOGUSTR(pServerEntry->Name));
  309. }
  310. *pServerEntryPtr = pServerEntry;
  311. *pNewServerEntry = fNewServerEntry;
  312. return Status;
  313. }
  314. VOID
  315. SmbCeCompleteSrvCallConstruction(
  316. PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext)
  317. /*++
  318. Routine Description:
  319. This routine comlpletes the srvcall construtcion routine by invoking
  320. the callback routine to the wrapper.
  321. Arguments:
  322. pCallbackContext - the RDBSS context
  323. Notes:
  324. --*/
  325. {
  326. PMRX_SRVCALLDOWN_STRUCTURE SrvCalldownStructure;
  327. PMRX_SRV_CALL pSrvCall;
  328. PSMBCEDB_SERVER_ENTRY pServerEntry;
  329. BOOLEAN MustSucceed = FALSE;
  330. NTSTATUS Status;
  331. PAGED_CODE();
  332. SrvCalldownStructure =
  333. (PMRX_SRVCALLDOWN_STRUCTURE)(pCallbackContext->SrvCalldownStructure);
  334. pSrvCall = SrvCalldownStructure->SrvCall;
  335. pServerEntry = (PSMBCEDB_SERVER_ENTRY)pCallbackContext->RecommunicateContext;
  336. if (pServerEntry != NULL) {
  337. if (!NT_SUCCESS(pCallbackContext->Status)) {
  338. if (pServerEntry->Server.IsRemoteBootServer ||
  339. pCallbackContext->Status == STATUS_RETRY) {
  340. MustSucceed = TRUE;
  341. }
  342. SmbCeDereferenceServerEntry(pServerEntry);
  343. } else {
  344. if (SmbCeGetServerType(pServerEntry) == SMBCEDB_MAILSLOT_SERVER) {
  345. pServerEntry->Header.State = SMBCEDB_ACTIVE;
  346. }
  347. }
  348. } else {
  349. if (pCallbackContext->Status == STATUS_SUCCESS) {
  350. pCallbackContext->Status = STATUS_INSUFFICIENT_RESOURCES;
  351. }
  352. }
  353. if (MustSucceed) {
  354. //DbgPrint("Build ServerEntry %X try again.\n",pCallbackContext->Status);
  355. // in case it is the remote boot server, if the server entry cannot be created for some
  356. // reason, i.e. transport is not ready and the cache is not filled, we need to create the
  357. // server entry again until it succeeds.
  358. Status = RxDispatchToWorkerThread(
  359. MRxSmbDeviceObject,
  360. CriticalWorkQueue,
  361. SmbCeCreateSrvCall,
  362. pCallbackContext);
  363. } else {
  364. SrvCalldownStructure->CallBack(pCallbackContext);
  365. }
  366. }
  367. NTSTATUS
  368. SmbCeInitializeServerEntry(
  369. PMRX_SRV_CALL pSrvCall,
  370. PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext,
  371. BOOLEAN fDeferNetworkInitialization)
  372. /*++
  373. Routine Description:
  374. This routine opens/creates a server entry in the connection engine database
  375. Arguments:
  376. pSrvCall - the SrvCall instance
  377. pCallbackContext - the RDBSS context
  378. Return Value:
  379. STATUS_SUCCESS - the server call construction has been finalized.
  380. Other Status codes correspond to error situations.
  381. Notes:
  382. --*/
  383. {
  384. NTSTATUS Status = STATUS_SUCCESS;
  385. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  386. BOOLEAN MailSlotCreate = FALSE;
  387. PSMBCE_TRANSPORT PreferredTransport = NULL;
  388. BOOLEAN fNewServerEntry = FALSE;
  389. SMBCEDB_SERVER_TYPE ServerType = SMBCEDB_FILE_SERVER;
  390. UNICODE_STRING TransportName;
  391. RX_CONNECTION_ID sRxConnectionId;
  392. // RxProfile(SmbCe,SmbCeOpenServer);
  393. ASSERT(pSrvCall->Context == NULL);
  394. TransportName = pCallbackContext->SrvCalldownStructure->RxContext->Create.TransportName;
  395. Status = MRxSmbGetConnectionId( pCallbackContext->SrvCalldownStructure->RxContext, &sRxConnectionId );
  396. if( !NT_SUCCESS(Status) )
  397. {
  398. DbgPrint( "MRXSMB: GetConnectionId failed.\n" );
  399. ASSERT(FALSE);
  400. RtlZeroMemory( &sRxConnectionId, sizeof(RX_CONNECTION_ID) );
  401. }
  402. if (TransportName.Length > 0) {
  403. if ((PreferredTransport=SmbCeFindTransport(&TransportName)) == NULL) {
  404. ASSERT(pCallbackContext->RecommunicateContext == NULL);
  405. Status = STATUS_NETWORK_UNREACHABLE;
  406. goto FINALLY;
  407. }
  408. }
  409. MailSlotCreate = BooleanFlagOn(
  410. pCallbackContext->SrvCalldownStructure->RxContext->Flags,
  411. RX_CONTEXT_FLAG_CREATE_MAILSLOT);
  412. if (MailSlotCreate) {
  413. fDeferNetworkInitialization = FALSE;
  414. ServerType = SMBCEDB_MAILSLOT_SERVER;
  415. }
  416. SmbCeAcquireResource();
  417. Status = SmbCeFindOrConstructServerEntry(
  418. pSrvCall->pSrvCallName,
  419. ServerType,
  420. &pServerEntry,
  421. &fNewServerEntry,
  422. &sRxConnectionId);
  423. SmbCeReleaseResource();
  424. pCallbackContext->RecommunicateContext = pServerEntry;
  425. if (Status == STATUS_SUCCESS) {
  426. ASSERT(pServerEntry != NULL);
  427. InterlockedExchangePointer(
  428. &pServerEntry->pRdbssSrvCall,
  429. pSrvCall);
  430. Status = SmbCeUpdateSrvCall(pServerEntry);
  431. if(!SmbCeIsServerInDisconnectedMode(pServerEntry)) {
  432. if (Status == STATUS_SUCCESS) {
  433. if (PreferredTransport != NULL) {
  434. // Transfer the ownership of the preferred transport to the
  435. // server entry.
  436. pServerEntry->PreferredTransport = PreferredTransport;
  437. PreferredTransport = NULL;
  438. } else {
  439. pServerEntry->PreferredTransport = NULL;
  440. }
  441. if (fNewServerEntry) {
  442. pServerEntry->Header.State = SMBCEDB_INVALID;
  443. // Initialize the mailslot server parameters.
  444. pServerEntry->Server.Dialect = LANMAN21_DIALECT;
  445. // MaximumBufferSize will be set based on negotiate response
  446. pServerEntry->Server.MaximumBufferSize = 0xffff;
  447. Status = CscInitializeServerEntryDfsRoot(
  448. pCallbackContext->SrvCalldownStructure->RxContext,
  449. pServerEntry);
  450. }
  451. if (Status == STATUS_SUCCESS) {
  452. if (!fDeferNetworkInitialization &&
  453. !MailSlotCreate) {
  454. Status = SmbCeInitializeServerTransport(
  455. pServerEntry,
  456. SmbCeCompleteSrvCallConstruction,
  457. pCallbackContext);
  458. } else {
  459. Status = SmbCeInitializeServerMailSlotTransport(
  460. pServerEntry,
  461. SmbCeCompleteSrvCallConstruction,
  462. pCallbackContext);
  463. }
  464. }
  465. }
  466. }
  467. }
  468. FINALLY:
  469. if (Status != STATUS_PENDING) {
  470. pCallbackContext->Status = Status;
  471. SmbCeCompleteSrvCallConstruction(pCallbackContext);
  472. }
  473. if (PreferredTransport != NULL) {
  474. SmbCeDereferenceTransport(PreferredTransport);
  475. }
  476. return STATUS_PENDING;
  477. }
  478. NTSTATUS
  479. SmbCeUpdateSrvCall(
  480. PSMBCEDB_SERVER_ENTRY pServerEntry)
  481. /*++
  482. Routine Description:
  483. This routine initializes the wrapper data structure corresponding to a
  484. given server entry.
  485. Arguments:
  486. pServerEntry - the server entry
  487. Return Value:
  488. STATUS_SUCCESS if successful
  489. --*/
  490. {
  491. NTSTATUS Status = STATUS_SUCCESS;
  492. PMRX_SRV_CALL pSrvCall = pServerEntry->pRdbssSrvCall;
  493. PAGED_CODE();
  494. if (pSrvCall != NULL) {
  495. // Copy the domain name into the server entry
  496. Status = RxSetSrvCallDomainName(
  497. pSrvCall,
  498. &pServerEntry->DomainName);
  499. // Initialize the SrvCall flags based upon the capabilities of the remote
  500. // server. The only flag that the SMB mini redirector updates is the
  501. // SRVCALL_FLAG_DFS_AWARE
  502. if (pServerEntry->Server.Capabilities & CAP_DFS) {
  503. SetFlag(
  504. pSrvCall->Flags,
  505. SRVCALL_FLAG_DFS_AWARE_SERVER);
  506. }
  507. }
  508. return Status;
  509. }
  510. BOOLEAN
  511. SmbCeAreServerEntriesAliased(
  512. PSMBCEDB_SERVER_ENTRY pServerEntry1,
  513. PSMBCEDB_SERVER_ENTRY pServerEntry2)
  514. /*++
  515. Routine Description:
  516. This routine is used to determine if two server entries are aliased. For uplevel
  517. servers (NT5 or greater) the server GUID can be used to determine if the two
  518. server entries are aliased. For downlevel servers it is determined by checking if
  519. they have the same IP address.
  520. Arguments:
  521. pServerEntry1 - the first server entry
  522. pServerEntry2 - the second server entry
  523. Return Value:
  524. TRUE if the two server entries are aliased and FALSE otherwise
  525. Notes:
  526. There are two interesting points to note ...
  527. 1) a server entry cannot be an alias of itself. The first test in the implementation.
  528. This semantic makes checking a server entry against a collection of entries easy.
  529. 2) the mechanism that we have for detecting aliases is not complete. There are cases
  530. (downlevel) when the two server entries are aliases of each other but we will conclude
  531. otherwise. This is because there is no foolproof way of establishing the absence of
  532. aliasing. The algorithm that is currently implemented detects the most important case
  533. of aliasing, i.e., DNS names and NETBIOS names to the same server on TCP.
  534. --*/
  535. {
  536. BOOLEAN ServerEntriesAliased = FALSE;
  537. if (pServerEntry1 != pServerEntry2) {
  538. if (BooleanFlagOn(
  539. pServerEntry1->Server.DialectFlags,
  540. DF_EXTENDED_SECURITY) &&
  541. BooleanFlagOn(
  542. pServerEntry2->Server.DialectFlags,
  543. DF_EXTENDED_SECURITY)) {
  544. if (RtlEqualMemory(
  545. &pServerEntry1->Server.NtServer.ServerGuid,
  546. &pServerEntry2->Server.NtServer.ServerGuid,
  547. sizeof(GUID))) {
  548. ServerEntriesAliased = TRUE;
  549. }
  550. } else {
  551. if ((pServerEntry1->Server.IpAddress == pServerEntry2->Server.IpAddress) &&
  552. (pServerEntry1->Server.IpAddress != 0)) {
  553. ServerEntriesAliased = TRUE;
  554. }
  555. }
  556. }
  557. return ServerEntriesAliased;
  558. }
  559. VOID
  560. SmbCeCompleteServerEntryInitialization(
  561. PSMBCEDB_SERVER_ENTRY pServerEntry,
  562. NTSTATUS Status)
  563. /*++
  564. Routine Description:
  565. This routine is invoked in the context of a worker thread to finalize the
  566. construction of a server entry
  567. Arguments:
  568. pServerEntry - the server entry to be finalized
  569. ServerState - the final state of the server
  570. --*/
  571. {
  572. NTSTATUS ServerStatus;
  573. SMBCEDB_OBJECT_STATE PreviousState;
  574. SMBCEDB_REQUESTS ReconnectRequests;
  575. PSMBCEDB_REQUEST_ENTRY pRequestEntry;
  576. KIRQL SavedIrql;
  577. RxDbgTrace( 0, Dbg, ("Server Entry Finalization\n"));
  578. ASSERT(pServerEntry->Header.ObjectType == SMBCEDB_OT_SERVER);
  579. InitializeListHead(&ReconnectRequests.ListHead);
  580. // Acquire the SMBCE resource
  581. SmbCeAcquireResource();
  582. SmbCeAcquireSpinLock();
  583. // The server status could have changed because of the transport disconnects
  584. // from the time the admin exchange was completed to the time the server
  585. // entry initialization complete routine is called. Update the state
  586. // accordingly.
  587. PreviousState = pServerEntry->Header.State;
  588. if (PreviousState == SMBCEDB_CONSTRUCTION_IN_PROGRESS) {
  589. pServerEntry->ServerStatus = Status;
  590. if (Status == STATUS_SUCCESS) {
  591. pServerEntry->Header.State = SMBCEDB_ACTIVE;
  592. } else {
  593. pServerEntry->Header.State = SMBCEDB_INVALID;
  594. }
  595. }
  596. ServerStatus = pServerEntry->ServerStatus;
  597. pServerEntry->NegotiateInProgress = FALSE;
  598. // Weed out all the reconnect requests so that they can be resumed
  599. pRequestEntry = SmbCeGetFirstRequestEntry(&pServerEntry->OutstandingRequests);
  600. while (pRequestEntry != NULL) {
  601. if (pRequestEntry->GenericRequest.Type == RECONNECT_REQUEST) {
  602. PSMBCEDB_REQUEST_ENTRY pTempRequestEntry;
  603. pTempRequestEntry = pRequestEntry;
  604. pRequestEntry = SmbCeGetNextRequestEntry(
  605. &pServerEntry->OutstandingRequests,
  606. pRequestEntry);
  607. SmbCeRemoveRequestEntryLite(
  608. &pServerEntry->OutstandingRequests,
  609. pTempRequestEntry);
  610. SmbCeAddRequestEntryLite(
  611. &ReconnectRequests,
  612. pTempRequestEntry);
  613. } else {
  614. pRequestEntry = SmbCeGetNextRequestEntry(
  615. &pServerEntry->OutstandingRequests,
  616. pRequestEntry);
  617. }
  618. }
  619. pServerEntry->Server.NumberOfVNetRootContextsForScavenging = 0;
  620. pServerEntry->Server.AliasedServers = FALSE;
  621. if ((Status == STATUS_SUCCESS) && (ServerStatus == STATUS_SUCCESS)) {
  622. // Walk through the list of currently active servers to establish the
  623. // session numbering. This traversal is required because of server
  624. // name aliasing that occurs when the different name formats are used
  625. // to access the server, i.e., dotted IP address, DNS name, NETBIOS name.
  626. // The disambiguation between different servers is done in one of two
  627. // ways. For uplevel servers ( NT5.0 or later ) the Server GUID is used.
  628. // For downlevel servers ( NT 4.0 or before ) the IP address is used
  629. // to distinguish the two. Note that there is one case that is not
  630. // covered by the current solution, the connection using a NETBIOS
  631. // name is established over some transport other than NetBt and this
  632. // is followed by establishing a connection establishment using the
  633. // DNS name over NetBt. In such cases this numbering scheme fails. In
  634. // some ways there is no complete solution for this once we start using
  635. // *SMBSERVER names as opposed to the NETBIOS name for connection
  636. // establishment with dotted IP address.
  637. PSMBCEDB_SERVER_ENTRY pTempServerEntry;
  638. pTempServerEntry = SmbCeGetFirstServerEntry();
  639. while (pTempServerEntry != NULL) {
  640. if (pTempServerEntry->Header.State == SMBCEDB_ACTIVE) {
  641. if (SmbCeAreServerEntriesAliased(
  642. pServerEntry,
  643. pTempServerEntry)) {
  644. pServerEntry->Server.AliasedServers = TRUE;
  645. pTempServerEntry->Server.AliasedServers = TRUE;
  646. }
  647. }
  648. pTempServerEntry = SmbCeGetNextServerEntry(pTempServerEntry);
  649. }
  650. }
  651. SmbCeReleaseSpinLock();
  652. if ((Status == STATUS_SUCCESS) &&
  653. (ServerStatus == STATUS_SUCCESS) &&
  654. (PreviousState == SMBCEDB_CONSTRUCTION_IN_PROGRESS)) {
  655. PSMBCEDB_SESSION_ENTRY pSessionEntry;
  656. SESSION_TYPE SessionType;
  657. InterlockedIncrement(&pServerEntry->Server.Version);
  658. pServerEntry->Server.NumberOfSrvOpens = 0;
  659. ASSERT(pServerEntry->pMidAtlas == NULL);
  660. // Initialize the MID Atlas
  661. pServerEntry->pMidAtlas = FsRtlCreateMidAtlas(
  662. pServerEntry->Server.MaximumRequests,
  663. pServerEntry->Server.MaximumRequests);
  664. if (pServerEntry->pMidAtlas == NULL) {
  665. pServerEntry->ServerStatus = RX_MAP_STATUS(INSUFFICIENT_RESOURCES);
  666. }
  667. if (MRxSmbSecuritySignaturesEnabled &&
  668. pServerEntry->Server.SecuritySignaturesEnabled) {
  669. pServerEntry->SecuritySignaturesEnabled = TRUE;
  670. } else {
  671. pServerEntry->SecuritySignaturesEnabled = FALSE;
  672. }
  673. // The sessions that have been created but whose initialization has been
  674. // deferred will have the session types set incorrectly. This is because
  675. // there is no previous knowledge of the session type required for deferred
  676. // servers.
  677. if (pServerEntry->Server.DialectFlags & DF_EXTENDED_SECURITY) {
  678. SessionType = EXTENDED_NT_SESSION;
  679. } else {
  680. SessionType = LANMAN_SESSION;
  681. }
  682. pSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  683. while (pSessionEntry != NULL) {
  684. if (!FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION)) {
  685. pSessionEntry->Session.Type = SessionType;
  686. } else {
  687. pSessionEntry->Session.Type = LANMAN_SESSION;
  688. }
  689. pSessionEntry = SmbCeGetNextSessionEntry(
  690. pServerEntry,
  691. pSessionEntry);
  692. }
  693. MRxSmbCheckForLoopBack(pServerEntry);
  694. }
  695. // Release the resource for the server entry
  696. SmbCeReleaseResource();
  697. // Resume all the outstanding reconnect requests that were held up because an earlier
  698. // reconnect request was under way.
  699. // Iterate over the list of pending requests and resume all of them
  700. SmbCeResumeOutstandingRequests(&ReconnectRequests,ServerStatus);
  701. }
  702. VOID
  703. SmbCepDereferenceServerEntry(
  704. PSMBCEDB_SERVER_ENTRY pServerEntry)
  705. /*++
  706. Routine Description:
  707. This routine dereferences a server entry instance
  708. Arguments:
  709. pServerEntry - the server entry to be dereferenced
  710. --*/
  711. {
  712. if (pServerEntry != NULL) {
  713. BOOLEAN fTearDownEntry = FALSE;
  714. LONG FinalRefCount;
  715. ASSERT((pServerEntry->Header.ObjectType == SMBCEDB_OT_SERVER) &&
  716. (pServerEntry->Header.SwizzleCount > 0));
  717. SmbCeAcquireResource();
  718. SmbCeAcquireSpinLock();
  719. /* if this is a work item request then clear the flag */
  720. /* WorkerRoutine is set to NULL just before work items are called */
  721. if((pServerEntry->WorkQueueItemForDisconnect.WorkerRoutine == NULL) &&
  722. pServerEntry->DisconnectWorkItemOutstanding == TRUE) {
  723. pServerEntry->DisconnectWorkItemOutstanding = FALSE;
  724. }
  725. FinalRefCount = InterlockedDecrement(&pServerEntry->Header.SwizzleCount);
  726. fTearDownEntry = (FinalRefCount == 0);
  727. if (fTearDownEntry) {
  728. // This is to ensure that the routines for traversing the server
  729. // entry list, i.e., probing servers do not colide with the teardown.
  730. if (pServerEntry->Header.SwizzleCount == 0) {
  731. pServerEntry->Header.State = SMBCEDB_MARKED_FOR_DELETION;
  732. SmbCeRemoveServerEntryLite(pServerEntry);
  733. if (SmbCeGetFirstServerEntry() == NULL &&
  734. SmbCeStartStopContext.pServerEntryTearDownEvent != NULL) {
  735. KeSetEvent(SmbCeStartStopContext.pServerEntryTearDownEvent,0,FALSE);
  736. }
  737. } else {
  738. fTearDownEntry = FALSE;
  739. }
  740. }
  741. SmbCeReleaseSpinLock();
  742. SmbCeReleaseResource();
  743. if (fTearDownEntry) {
  744. if (IoGetCurrentProcess() == RxGetRDBSSProcess()) {
  745. SmbCeTearDownServerEntry(pServerEntry);
  746. } else {
  747. InitializeListHead(&pServerEntry->WorkQueueItem.List);
  748. RxPostToWorkerThread(
  749. MRxSmbDeviceObject,
  750. CriticalWorkQueue,
  751. &pServerEntry->WorkQueueItem,
  752. SmbCeTearDownServerEntry,
  753. pServerEntry);
  754. }
  755. }
  756. }
  757. }
  758. VOID
  759. SmbCeTearDownServerEntry(
  760. PSMBCEDB_SERVER_ENTRY pServerEntry)
  761. /*++
  762. Routine Description:
  763. This routine tears down a server entry instance
  764. Arguments:
  765. pServerEntry - the server entry to be dereferenced
  766. --*/
  767. {
  768. NTSTATUS Status = STATUS_SUCCESS;
  769. PAGED_CODE();
  770. SmbCeLog(("TearSrvEntry %lx %wZ\n",pServerEntry,&pServerEntry->Name));
  771. SmbLog(LOG,
  772. SmbCeTearDownServerEntry,
  773. LOGPTR(pServerEntry)
  774. LOGUSTR(pServerEntry->Name));
  775. ASSERT(pServerEntry->Header.State == SMBCEDB_MARKED_FOR_DELETION);
  776. if (pServerEntry->pMidAtlas != NULL) {
  777. FsRtlDestroyMidAtlas(pServerEntry->pMidAtlas,NULL);
  778. pServerEntry->pMidAtlas = NULL;
  779. }
  780. if (pServerEntry->pTransport != NULL ||
  781. pServerEntry->pMailSlotTransport != NULL) {
  782. Status = SmbCeUninitializeServerTransport(pServerEntry,NULL,NULL);
  783. ASSERT(Status == STATUS_SUCCESS);
  784. }
  785. if (pServerEntry->Server.NtServer.pSecurityBlob != NULL) {
  786. RxFreePool(pServerEntry->Server.NtServer.pSecurityBlob);
  787. }
  788. if (pServerEntry->Name.Buffer != NULL) {
  789. RxFreePool(pServerEntry->Name.Buffer);
  790. }
  791. if (pServerEntry->DomainName.Buffer != NULL) {
  792. RxFreePool(pServerEntry->DomainName.Buffer);
  793. }
  794. if (pServerEntry->DfsRootName.Buffer != NULL) {
  795. RxFreePool(pServerEntry->DfsRootName.Buffer);
  796. }
  797. if (pServerEntry->DnsName.Buffer != NULL) {
  798. RxFreePool(pServerEntry->DnsName.Buffer);
  799. }
  800. if (pServerEntry->PreferredTransport != NULL) {
  801. SmbCeDereferenceTransport(pServerEntry->PreferredTransport);
  802. }
  803. SmbMmFreeObject(pServerEntry);
  804. }
  805. NTSTATUS
  806. SmbCeFindOrConstructSessionEntry(
  807. PMRX_V_NET_ROOT pVNetRoot,
  808. PSMBCEDB_SESSION_ENTRY *pSessionEntryPtr)
  809. /*++
  810. Routine Description:
  811. This routine opens/creates a session for a given user in the connection engine database
  812. Arguments:
  813. pVNetRoot - the RDBSS Virtual net root instance
  814. Return Value:
  815. STATUS_SUCCESS - if successful
  816. Other Status codes correspond to error situations.
  817. Notes:
  818. This routine assumes that the necesary concurreny control mechanism has already
  819. been taken.
  820. On Entry the connection engine resource must have been acquired exclusive and
  821. ownership remains invariant on exit.
  822. In case of UPN, we should pass a NULL string instead of NULL as domain name.
  823. --*/
  824. {
  825. NTSTATUS Status = STATUS_SUCCESS;
  826. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  827. PSMBCEDB_SESSION_ENTRY pSessionEntry = NULL;
  828. BOOLEAN fSessionEntryFound = FALSE;
  829. PUNICODE_STRING UserName;
  830. PUNICODE_STRING Password;
  831. PUNICODE_STRING UserDomainName;
  832. DWORD SessionType;
  833. LUID AnonymousLogonID = ANONYMOUS_LOGON_LUID;
  834. #define SessionTypeDefault 1
  835. #define SessionTypeUser 2
  836. #define SessionTypeNull 3
  837. #define SessionTypeRemoteBoot 4
  838. ASSERT(SmbCeIsResourceOwned());
  839. UserName = pVNetRoot->pUserName;
  840. Password = pVNetRoot->pPassword;
  841. UserDomainName = pVNetRoot->pUserDomainName;
  842. //
  843. // If this is a remote boot client, and we're connecting to the boot share,
  844. // we always use the machine account, not the user account. This is
  845. // necessary in order to get security (ACL checking) to behave correctly.
  846. //
  847. SessionType = SessionTypeDefault;
  848. if ( MRxSmbBootedRemotely ) {
  849. //DbgPrint( "FindOrConstructSessionEntry: root %wZ\n", pVNetRoot->pNetRoot->pNetRootName );
  850. //DbgBreakPoint();
  851. if ( RtlCompareUnicodeString(
  852. pVNetRoot->pNetRoot->pNetRootName,
  853. &MRxSmbRemoteBootShare,
  854. TRUE
  855. ) == 0 ) {
  856. SessionType = SessionTypeRemoteBoot;
  857. //DbgPrint( " Original user/password/domain: %wZ/%wZ/%wZ\n", UserName, Password, UserDomainName );
  858. UserName = &MRxSmbRemoteBootMachineName;
  859. Password = &MRxSmbRemoteBootMachinePassword;
  860. UserDomainName = &MRxSmbRemoteBootMachineDomain;
  861. //DbgPrint( " Machine user/password/domain: %wZ/%wZ/%wZ\n", UserName, Password, UserDomainName );
  862. }
  863. }
  864. if (SessionType != SessionTypeRemoteBoot) {
  865. if ((UserName != NULL) &&
  866. (UserName->Length == 0) &&
  867. (Password != NULL) &&
  868. (Password->Length == 0) &&
  869. (UserDomainName != NULL) &&
  870. (UserDomainName->Length == 0)) {
  871. SessionType = SessionTypeNull;
  872. } else if ((UserName != NULL) ||
  873. ((Password != NULL) &&
  874. (Password->Length > 0))) {
  875. SessionType = SessionTypeUser;
  876. }
  877. }
  878. *pSessionEntryPtr = NULL;
  879. // Reference the server handle
  880. pServerEntry = SmbCeReferenceAssociatedServerEntry(pVNetRoot->pNetRoot->pSrvCall);
  881. if (pServerEntry != NULL) {
  882. if (SessionType != SessionTypeUser &&
  883. pServerEntry->Server.SecurityMode != SECURITY_MODE_SHARE_LEVEL) {
  884. SmbCeAcquireSpinLock();
  885. // Rule No. 1
  886. // 1) The first session with explicitly specified credentials will be treated as the
  887. // default session for all subsequent requests to any given server.
  888. if (SessionType == SessionTypeDefault) {
  889. pSessionEntry = SmbCeGetDefaultSessionEntry(
  890. pServerEntry,
  891. pVNetRoot->SessionId,
  892. &pVNetRoot->LogonId);
  893. while (pSessionEntry != NULL &&
  894. FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_MARKED_FOR_DELETION)) {
  895. SmbCeRemoveDefaultSessionEntry(pSessionEntry);
  896. pSessionEntry = SmbCeGetDefaultSessionEntry(
  897. pServerEntry,
  898. pVNetRoot->SessionId,
  899. &pVNetRoot->LogonId);
  900. }
  901. }
  902. if (pSessionEntry == NULL) {
  903. // Enumerate the sessions to detect if a session satisfying rule 2 exists
  904. pSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  905. while (pSessionEntry != NULL) {
  906. if (!FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_MARKED_FOR_DELETION)) {
  907. if (SessionType == SessionTypeDefault) {
  908. //
  909. // Rule No. 2
  910. // 2) If no session with explicitly specified credentials exist then a
  911. // session with the same logon id. is choosen.
  912. //
  913. if (RtlEqualLuid(
  914. &pSessionEntry->Session.LogonId,
  915. &pVNetRoot->LogonId)) {
  916. break;
  917. }
  918. } else if (SessionType == SessionTypeNull) {
  919. if (FlagOn(
  920. pSessionEntry->Session.Flags,
  921. SMBCE_SESSION_FLAGS_NULL_CREDENTIALS)) {
  922. break;
  923. }
  924. } else {
  925. ASSERT(SessionType == SessionTypeRemoteBoot);
  926. if (FlagOn(
  927. pSessionEntry->Session.Flags,
  928. SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION)) {
  929. break;
  930. }
  931. }
  932. }
  933. pSessionEntry = SmbCeGetNextSessionEntry(pServerEntry,pSessionEntry);
  934. }
  935. }
  936. if (pSessionEntry != NULL) {
  937. SmbCeReferenceSessionEntry(pSessionEntry);
  938. }
  939. SmbCeReleaseSpinLock();
  940. } else {
  941. BOOLEAN SessionEntryFound = FALSE;
  942. SmbCeAcquireSpinLock();
  943. pSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  944. if (pSessionEntry != NULL) {
  945. SmbCeReferenceSessionEntry(pSessionEntry);
  946. }
  947. SmbCeReleaseSpinLock();
  948. while ((pSessionEntry != NULL) && !SessionEntryFound) {
  949. if (!FlagOn(pSessionEntry->Session.Flags,
  950. SMBCE_SESSION_FLAGS_NULL_CREDENTIALS |
  951. SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION |
  952. SMBCE_SESSION_FLAGS_MARKED_FOR_DELETION)) {
  953. PSecurityUserData pSecurityData = NULL;
  954. if (pServerEntry->Server.SecurityMode != SECURITY_MODE_SHARE_LEVEL) {
  955. for (;;) {
  956. PSMBCE_SESSION pSession = &pSessionEntry->Session;
  957. PUNICODE_STRING TempUserName,TempUserDomainName;
  958. // For each existing session check to determine if the credentials
  959. // supplied match the credentials used to construct the session.
  960. if( pSession->SessionId != pVNetRoot->SessionId ) {
  961. break;
  962. }
  963. if (!RtlEqualLuid(
  964. &pSessionEntry->Session.LogonId,
  965. &pVNetRoot->LogonId)) {
  966. break;
  967. }
  968. TempUserName = pSession->pUserName;
  969. TempUserDomainName = pSession->pUserDomainName;
  970. if (TempUserName == NULL ||
  971. TempUserDomainName == NULL) {
  972. Status = GetSecurityUserInfo(
  973. &pVNetRoot->LogonId,
  974. UNDERSTANDS_LONG_NAMES,
  975. &pSecurityData);
  976. if (NT_SUCCESS(Status)) {
  977. if (TempUserName == NULL) {
  978. TempUserName = &(pSecurityData->UserName);
  979. }
  980. if (TempUserDomainName == NULL) {
  981. TempUserDomainName = &(pSecurityData->LogonDomainName);
  982. }
  983. } else {
  984. break;
  985. }
  986. }
  987. if (UserName != NULL &&
  988. !RtlEqualUnicodeString(UserName,TempUserName,TRUE)) {
  989. Status = STATUS_NETWORK_CREDENTIAL_CONFLICT;
  990. break;
  991. }
  992. if (UserDomainName != NULL &&
  993. !RtlEqualUnicodeString(UserDomainName,TempUserDomainName,TRUE)) {
  994. Status = STATUS_NETWORK_CREDENTIAL_CONFLICT;
  995. break;
  996. }
  997. if ((Password != NULL) &&
  998. (pSession->pPassword != NULL)) {
  999. if (!RtlEqualUnicodeString(
  1000. Password,
  1001. pSession->pPassword,
  1002. FALSE)) {
  1003. Status = STATUS_NETWORK_CREDENTIAL_CONFLICT;
  1004. break;
  1005. }
  1006. }
  1007. SessionEntryFound = TRUE;
  1008. // We use existing session if either the stored or new password is NULL.
  1009. // Later, a new security API will be created for verify the password
  1010. // based on the logon ID.
  1011. // An entry that matches the credentials supplied has been found. use it.
  1012. break;
  1013. }
  1014. //ASSERT(Status != STATUS_NETWORK_CREDENTIAL_CONFLICT);
  1015. if (pSecurityData != NULL) {
  1016. LsaFreeReturnBuffer(pSecurityData);
  1017. pSecurityData = NULL;
  1018. }
  1019. } else {
  1020. if (RtlEqualLuid(
  1021. &pSessionEntry->Session.LogonId,
  1022. &pVNetRoot->LogonId)) {
  1023. // For share level security, each share will have a different session
  1024. if (pSessionEntry->pNetRootName != NULL) {
  1025. if (RtlEqualUnicodeString(
  1026. pVNetRoot->pNetRoot->pNetRootName,
  1027. pSessionEntry->pNetRootName,
  1028. FALSE)) {
  1029. SessionEntryFound = TRUE;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. }
  1035. if (!SessionEntryFound) {
  1036. if (Status == STATUS_SUCCESS) {
  1037. PSMBCEDB_SESSION_ENTRY pNextSessionEntry;
  1038. SmbCeAcquireSpinLock();
  1039. pNextSessionEntry = SmbCeGetNextSessionEntry(
  1040. pServerEntry,
  1041. pSessionEntry);
  1042. if (pNextSessionEntry != NULL) {
  1043. SmbCeReferenceSessionEntry(pNextSessionEntry);
  1044. }
  1045. SmbCeReleaseSpinLock();
  1046. SmbCeDereferenceSessionEntry(pSessionEntry);
  1047. pSessionEntry = pNextSessionEntry;
  1048. } else {
  1049. // An error situation was encountered. Terminate the iteration.
  1050. // Typically a set of conflicting credentials have been presented
  1051. SmbCeDereferenceSessionEntry(pSessionEntry);
  1052. pSessionEntry = NULL;
  1053. }
  1054. } else {
  1055. if (RtlEqualLuid(&pSessionEntry->Session.LogonId,&AnonymousLogonID) &&
  1056. (Password != NULL || UserName != NULL || UserDomainName != NULL)) {
  1057. Status = STATUS_NETWORK_CREDENTIAL_CONFLICT;
  1058. }
  1059. }
  1060. }
  1061. }
  1062. if (Win9xSessionRestriction &&
  1063. (pSessionEntry == NULL) &&
  1064. (Status == STATUS_SUCCESS) &&
  1065. FlagOn(pServerEntry->Server.DialectFlags,DF_W95)) {
  1066. PSMBCEDB_SESSION_ENTRY TempSessionEntry;
  1067. TempSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  1068. while (TempSessionEntry != NULL) {
  1069. if (!FlagOn(TempSessionEntry->Session.Flags,
  1070. SMBCE_SESSION_FLAGS_NULL_CREDENTIALS)) {
  1071. Status = STATUS_LOGIN_WKSTA_RESTRICTION;
  1072. break;
  1073. }
  1074. TempSessionEntry = SmbCeGetNextSessionEntry(pServerEntry,TempSessionEntry);
  1075. }
  1076. }
  1077. if ((pSessionEntry == NULL) && (Status == STATUS_SUCCESS)) {
  1078. // Rule No. 3
  1079. // 3) If no session with the same logon id. exists a new session is created.
  1080. //
  1081. // Allocate a new session entry
  1082. // This is the point at which a many to mapping between session entries and
  1083. // V_NET_ROOT's in the RDBSS is being established. From this point it is
  1084. // true that the session entry can outlive the associated V_NET_ROOT entry.
  1085. // Therefore copies of the parameters used in the session setup need be made.
  1086. PSMBCE_SESSION pSession = &pSessionEntry->Session;
  1087. PUNICODE_STRING pPassword,pUserName,pUserDomainName,pNetRootName;
  1088. if (Password != NULL) {
  1089. pPassword = (PUNICODE_STRING)
  1090. RxAllocatePoolWithTag(
  1091. NonPagedPool,
  1092. sizeof(UNICODE_STRING) + Password->Length,
  1093. MRXSMB_SESSION_POOLTAG);
  1094. if (pPassword != NULL) {
  1095. pPassword->Buffer = (PWCHAR)((PCHAR)pPassword + sizeof(UNICODE_STRING));
  1096. pPassword->Length = Password->Length;
  1097. pPassword->MaximumLength = pPassword->Length;
  1098. RtlCopyMemory(
  1099. pPassword->Buffer,
  1100. Password->Buffer,
  1101. pPassword->Length);
  1102. } else {
  1103. Status = STATUS_INSUFFICIENT_RESOURCES;
  1104. }
  1105. } else {
  1106. pPassword = NULL;
  1107. }
  1108. if ((UserName != NULL) &&
  1109. (Status == RX_MAP_STATUS(SUCCESS))) {
  1110. pUserName = (PUNICODE_STRING)
  1111. RxAllocatePoolWithTag(
  1112. NonPagedPool,
  1113. sizeof(UNICODE_STRING) + UserName->Length,
  1114. MRXSMB_SESSION_POOLTAG);
  1115. if (pUserName != NULL) {
  1116. pUserName->Buffer = (PWCHAR)((PCHAR)pUserName + sizeof(UNICODE_STRING));
  1117. pUserName->Length = UserName->Length;
  1118. pUserName->MaximumLength = pUserName->Length;
  1119. RtlCopyMemory(
  1120. pUserName->Buffer,
  1121. UserName->Buffer,
  1122. pUserName->Length);
  1123. } else {
  1124. Status = STATUS_INSUFFICIENT_RESOURCES;
  1125. }
  1126. } else {
  1127. pUserName = NULL;
  1128. }
  1129. if ((UserDomainName != NULL) &&
  1130. (Status == RX_MAP_STATUS(SUCCESS))) {
  1131. pUserDomainName = (PUNICODE_STRING)
  1132. RxAllocatePoolWithTag(
  1133. NonPagedPool,
  1134. sizeof(UNICODE_STRING) + UserDomainName->Length + sizeof(WCHAR),
  1135. MRXSMB_SESSION_POOLTAG);
  1136. if (pUserDomainName != NULL) {
  1137. pUserDomainName->Buffer = (PWCHAR)((PCHAR)pUserDomainName + sizeof(UNICODE_STRING));
  1138. pUserDomainName->Length = UserDomainName->Length;
  1139. pUserDomainName->MaximumLength = pUserDomainName->Length;
  1140. // in case of UPN name, domain name will be a NULL string
  1141. *pUserDomainName->Buffer = 0;
  1142. if (UserDomainName->Length > 0) {
  1143. RtlCopyMemory(
  1144. pUserDomainName->Buffer,
  1145. UserDomainName->Buffer,
  1146. pUserDomainName->Length);
  1147. }
  1148. } else {
  1149. Status = STATUS_INSUFFICIENT_RESOURCES;
  1150. }
  1151. } else {
  1152. pUserDomainName = NULL;
  1153. }
  1154. if (pServerEntry->Server.SecurityMode == SECURITY_MODE_SHARE_LEVEL) {
  1155. pNetRootName = (PUNICODE_STRING)RxAllocatePoolWithTag(
  1156. NonPagedPool,
  1157. sizeof(UNICODE_STRING) +
  1158. pVNetRoot->pNetRoot->pNetRootName->Length,
  1159. MRXSMB_SESSION_POOLTAG);
  1160. if (pNetRootName != NULL) {
  1161. pNetRootName->Buffer = (PWCHAR)((PCHAR)pNetRootName + sizeof(UNICODE_STRING));
  1162. pNetRootName->Length = pVNetRoot->pNetRoot->pNetRootName->Length;
  1163. pNetRootName->MaximumLength = pNetRootName->Length;
  1164. if (pNetRootName->Length > 0) {
  1165. RtlCopyMemory(
  1166. pNetRootName->Buffer,
  1167. pVNetRoot->pNetRoot->pNetRootName->Buffer,
  1168. pNetRootName->Length);
  1169. }
  1170. } else {
  1171. Status = STATUS_INSUFFICIENT_RESOURCES;
  1172. }
  1173. } else {
  1174. pNetRootName = NULL;
  1175. }
  1176. if (Status == STATUS_SUCCESS) {
  1177. pSessionEntry = SmbMmAllocateSessionEntry(
  1178. pServerEntry,
  1179. (BOOLEAN)(SessionType == SessionTypeRemoteBoot));
  1180. if (pSessionEntry != NULL) {
  1181. PSMBCE_SESSION pSession = & pSessionEntry->Session;
  1182. SmbCeLog(("NewSessEntry %lx\n",pSessionEntry));
  1183. SmbLog(LOG,
  1184. SmbCeFindOrConstructSessionEntry_1,
  1185. LOGPTR(pSessionEntry));
  1186. pSessionEntry->Header.State = SMBCEDB_INVALID;
  1187. pSessionEntry->pServerEntry = pServerEntry;
  1188. pSessionEntry->pNetRootName = pNetRootName;
  1189. if (pServerEntry->Server.SecurityMode == SECURITY_MODE_SHARE_LEVEL) {
  1190. pSessionEntry->Session.UserId = (SMB_USER_ID)SMBCE_SHARE_LEVEL_SERVER_USERID;
  1191. }
  1192. pSession->Flags = 0;
  1193. if ( SessionType == SessionTypeRemoteBoot ) {
  1194. pSession->Flags = SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION;
  1195. }
  1196. if ( SessionType == SessionTypeNull ) {
  1197. pSession->Flags |= SMBCE_SESSION_FLAGS_NULL_CREDENTIALS;
  1198. }
  1199. pSession->LogonId = pVNetRoot->LogonId;
  1200. pSession->pUserName = pUserName;
  1201. pSession->pPassword = pPassword;
  1202. pSession->pUserDomainName = pUserDomainName;
  1203. pSession->SessionId = pVNetRoot->SessionId;
  1204. SmbCeReferenceSessionEntry(pSessionEntry);
  1205. SmbCeAddSessionEntry(pServerEntry,pSessionEntry);
  1206. } else {
  1207. Status = STATUS_INSUFFICIENT_RESOURCES;
  1208. }
  1209. }
  1210. if (Status != STATUS_SUCCESS) {
  1211. if (pUserName != NULL) {
  1212. RxFreePool(pUserName);
  1213. }
  1214. if (pPassword != NULL) {
  1215. RxFreePool(pPassword);
  1216. }
  1217. if (pUserDomainName != NULL) {
  1218. RxFreePool(pUserDomainName);
  1219. }
  1220. if (pNetRootName != NULL) {
  1221. RxFreePool(pNetRootName);
  1222. }
  1223. }
  1224. } else {
  1225. if (Status == STATUS_SUCCESS) {
  1226. SmbCeLog(("CachedSessEntry %lx\n",pSessionEntry));
  1227. SmbLog(LOG,
  1228. SmbCeFindOrConstructSessionEntry_2,
  1229. LOGPTR(pSessionEntry));
  1230. }
  1231. }
  1232. if (Status == STATUS_SUCCESS) {
  1233. *pSessionEntryPtr = pSessionEntry;
  1234. }
  1235. SmbCeDereferenceServerEntry(pServerEntry);
  1236. } else {
  1237. Status = STATUS_INVALID_PARAMETER;
  1238. }
  1239. return Status;
  1240. }
  1241. VOID
  1242. SmbCeCompleteSessionEntryInitialization(
  1243. PVOID pContext,
  1244. NTSTATUS Status,
  1245. BOOLEAN SecuritySignatureReturned)
  1246. /*++
  1247. Routine Description:
  1248. This routine is invoked in the context of a worker thread to finalize the
  1249. construction of a session entry
  1250. Arguments:
  1251. pContext - the session entry to be activated
  1252. Notes:
  1253. PRE_CONDITION: The session entry must have been referenced to ensure that
  1254. even it has been finalized it will not be deleted.
  1255. --*/
  1256. {
  1257. PSMBCEDB_SESSION_ENTRY pSessionEntry = (PSMBCEDB_SESSION_ENTRY)pContext;
  1258. PSMBCE_SESSION pSession = &pSessionEntry->Session;
  1259. PSMBCEDB_SERVER_ENTRY pServerEntry = pSessionEntry->pServerEntry;
  1260. PSMBCEDB_REQUEST_ENTRY pRequestEntry;
  1261. SMBCEDB_REQUESTS Requests;
  1262. SMBCEDB_REQUESTS SecuritySignatureSyncRequests;
  1263. RxDbgTrace( 0, Dbg, ("Session Entry Finalization\n"));
  1264. ASSERT(pSessionEntry->Header.ObjectType == SMBCEDB_OT_SESSION);
  1265. // Acquire the SMBCE resource
  1266. SmbCeAcquireResource();
  1267. // reset the constructor exchange field since the construction is complete
  1268. pSessionEntry->pExchange = NULL;
  1269. //
  1270. SmbCeUnblockSerializedSessionSetupRequests(pSessionEntry);
  1271. // Create a temporary copy of the list that can be traversed after releasing the
  1272. // resource.
  1273. SmbCeTransferRequests(&Requests,&pSessionEntry->Requests);
  1274. SmbCeTransferRequests(&SecuritySignatureSyncRequests,&pServerEntry->SecuritySignatureSyncRequests);
  1275. pServerEntry->ExtSessionSetupInProgress = FALSE;
  1276. if (Status == STATUS_SUCCESS) {
  1277. SmbCeUpdateSessionEntryState(
  1278. pSessionEntry,
  1279. SMBCEDB_ACTIVE);
  1280. if ((pSession->pPassword != NULL || pSession->pUserName != NULL) &&
  1281. !BooleanFlagOn(pSession->Flags,SMBCE_SESSION_FLAGS_NULL_CREDENTIALS)) {
  1282. if (pSessionEntry->DefaultSessionLink.Flink == NULL ) {
  1283. ASSERT( pSessionEntry->DefaultSessionLink.Blink == NULL );
  1284. InsertHeadList(&pServerEntry->Sessions.DefaultSessionList,
  1285. &pSessionEntry->DefaultSessionLink );
  1286. }
  1287. }
  1288. if (SecuritySignatureReturned &&
  1289. pServerEntry->SecuritySignaturesEnabled == TRUE &&
  1290. pServerEntry->SecuritySignaturesActive == FALSE) {
  1291. if (pSession->Type == EXTENDED_NT_SESSION) {
  1292. SmbInitializeSmbSecuritySignature(&pServerEntry->Server,
  1293. NULL,
  1294. pSession->UserSessionKey,
  1295. pSession->SessionKeyLength);
  1296. //DbgPrint("MRXSMB: Security Signature is active to W2K server %wZ\n", &pServerEntry->Name);
  1297. } else {
  1298. //DbgPrint("MRXSMB: Security Signature is active to NT4 server %wZ\n", &pServerEntry->Name);
  1299. }
  1300. // turn on the security signature on the client side
  1301. pServerEntry->SecuritySignaturesActive = TRUE;
  1302. pServerEntry->Server.SmbSecuritySignatureIndex = 2;
  1303. }
  1304. } else {
  1305. SmbCeUpdateSessionEntryState(
  1306. pSessionEntry,
  1307. SMBCEDB_INVALID);
  1308. }
  1309. pSessionEntry->SessionRecoverInProgress = FALSE;
  1310. //RxLog(("UnMark Sess Rec %lx\n",pSessionEntry));
  1311. // Release the resource for the session entry
  1312. SmbCeReleaseResource();
  1313. if (!IsListEmpty(&Requests.ListHead)) {
  1314. // Iterate over the list of pending requests and resume all of them
  1315. SmbCeResumeOutstandingRequests(&Requests,Status);
  1316. }
  1317. if (!IsListEmpty(&SecuritySignatureSyncRequests.ListHead)) {
  1318. SmbCeResumeOutstandingRequests(&SecuritySignatureSyncRequests,STATUS_SUCCESS);
  1319. }
  1320. SmbCeDereferenceSessionEntry(pSessionEntry);
  1321. }
  1322. NTSTATUS
  1323. SmbCeGetUserNameAndDomainName(
  1324. PSMBCEDB_SESSION_ENTRY pSessionEntry,
  1325. PUNICODE_STRING pUserName,
  1326. PUNICODE_STRING pUserDomainName)
  1327. /*++
  1328. Routine Description:
  1329. This routine returns the user name and domain name associated with a session
  1330. in a caller allocated buffer.
  1331. Arguments:
  1332. pSessionEntry - the session entry to be dereferenced
  1333. pUserName - the User name
  1334. pUserDomainName - the user domain name
  1335. Return Value:
  1336. STATUS_SUCCESS if successful
  1337. --*/
  1338. {
  1339. NTSTATUS Status;
  1340. PSMBCE_SESSION pSession;
  1341. PUNICODE_STRING pSessionUserName,pSessionDomainName;
  1342. PSecurityUserData pSecurityData;
  1343. PAGED_CODE();
  1344. ASSERT(pSessionEntry != NULL);
  1345. pSession = &pSessionEntry->Session;
  1346. if ((pUserName == NULL) ||
  1347. (pUserDomainName == NULL) ||
  1348. (pUserName->MaximumLength < (UNLEN * sizeof(WCHAR))) ||
  1349. (pUserDomainName->MaximumLength < (DNLEN * sizeof(WCHAR)))) {
  1350. return STATUS_INVALID_PARAMETER;
  1351. }
  1352. Status = STATUS_SUCCESS;
  1353. pSecurityData = NULL;
  1354. pSessionUserName = pSession->pUserName;
  1355. pSessionDomainName = pSession->pUserDomainName;
  1356. try {
  1357. if (pSessionUserName == NULL ||
  1358. pSessionDomainName == NULL) {
  1359. Status = GetSecurityUserInfo(
  1360. &pSession->LogonId,
  1361. UNDERSTANDS_LONG_NAMES,
  1362. &pSecurityData);
  1363. if (NT_SUCCESS(Status)) {
  1364. if (pSessionUserName == NULL) {
  1365. pSessionUserName = &(pSecurityData->UserName);
  1366. }
  1367. if (pSessionDomainName == NULL) {
  1368. pSessionDomainName = &(pSecurityData->LogonDomainName);
  1369. }
  1370. }
  1371. }
  1372. if (NT_SUCCESS(Status)) {
  1373. ASSERT(pSessionUserName->Length <= pUserName->MaximumLength);
  1374. ASSERT(pSessionDomainName->Length <= pUserDomainName->MaximumLength);
  1375. pUserName->Length = pSessionUserName->Length;
  1376. RtlCopyMemory(
  1377. pUserName->Buffer,
  1378. pSessionUserName->Buffer,
  1379. pUserName->Length);
  1380. pUserDomainName->Length = pSessionDomainName->Length;
  1381. if (pUserDomainName->Length > 0) {
  1382. RtlCopyMemory(
  1383. pUserDomainName->Buffer,
  1384. pSessionDomainName->Buffer,
  1385. pUserDomainName->Length);
  1386. }
  1387. }
  1388. } finally {
  1389. if (pSecurityData != NULL) {
  1390. LsaFreeReturnBuffer(pSecurityData);
  1391. }
  1392. }
  1393. return Status;
  1394. }
  1395. VOID
  1396. SmbCepDereferenceSessionEntry(
  1397. PSMBCEDB_SESSION_ENTRY pSessionEntry)
  1398. /*++
  1399. Routine Description:
  1400. This routine dereferences a session entry instance
  1401. Arguments:
  1402. pSessionEntry - the session entry to be dereferenced
  1403. --*/
  1404. {
  1405. if (pSessionEntry != NULL) {
  1406. BOOLEAN fTearDownEntry;
  1407. BOOLEAN fLogOffRequired;
  1408. LONG FinalRefCount;
  1409. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1410. ASSERT((pSessionEntry->Header.ObjectType == SMBCEDB_OT_SESSION) &&
  1411. (pSessionEntry->Header.SwizzleCount > 0));
  1412. pServerEntry = pSessionEntry->pServerEntry;
  1413. SmbCeAcquireResource();
  1414. FinalRefCount = InterlockedDecrement(&pSessionEntry->Header.SwizzleCount);
  1415. fTearDownEntry = (FinalRefCount == 0);
  1416. if (fTearDownEntry) {
  1417. // A logoff smb needs to be sent if the user id associated with
  1418. // the session is not zero. Note that we cannot rely on the state
  1419. // of the session to indicate this since extended session setups
  1420. // cna be terminated midway through the construction
  1421. SmbCeReferenceServerEntry(pServerEntry);
  1422. if (pSessionEntry->Header.SwizzleCount == 0) {
  1423. if (!FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_LOGGED_OFF)) {
  1424. SmbCeRemoveSessionEntry(pServerEntry,pSessionEntry);
  1425. }
  1426. SmbCeRemoveDefaultSessionEntry(pSessionEntry);
  1427. if ((pSessionEntry->Session.UserId != (SMB_USER_ID)(SMBCE_SHARE_LEVEL_SERVER_USERID)) &&
  1428. (pSessionEntry->Session.UserId != 0) &&
  1429. (pSessionEntry->Header.State == SMBCEDB_ACTIVE) &&
  1430. !FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_LOGGED_OFF)) {
  1431. SmbCeReferenceServerEntry(pServerEntry);
  1432. SmbCeReferenceSessionEntry(pSessionEntry);
  1433. fLogOffRequired = TRUE;
  1434. } else {
  1435. fLogOffRequired = FALSE;
  1436. }
  1437. pSessionEntry->Header.State = SMBCEDB_MARKED_FOR_DELETION;
  1438. pSessionEntry->Session.Flags |= SMBCE_SESSION_FLAGS_LOGGED_OFF;
  1439. fTearDownEntry = TRUE;
  1440. } else {
  1441. fTearDownEntry = FALSE;
  1442. }
  1443. SmbCeDereferenceServerEntry(pServerEntry);
  1444. }
  1445. SmbCeReleaseResource();
  1446. if (fTearDownEntry) {
  1447. if (fLogOffRequired) {
  1448. SmbCeLogOff(pServerEntry,pSessionEntry);
  1449. SmbCeDereferenceServerEntry(pServerEntry);
  1450. } else {
  1451. SmbCeTearDownSessionEntry(pSessionEntry);
  1452. }
  1453. }
  1454. }
  1455. }
  1456. NTSTATUS
  1457. MRxSmbLogonSessionTerminationHandler(
  1458. PLUID pLogonId)
  1459. /*++
  1460. Routine Description:
  1461. This routine issues a log off command to the server on all the sessions
  1462. for the given logon id.
  1463. Arguments:
  1464. pLogonId - the logon id of the logon session that was terminated
  1465. --*/
  1466. {
  1467. #if 0
  1468. PSMBCEDB_SERVER_ENTRY pServerEntry,pNextServerEntry;
  1469. PSMBCEDB_SESSION_ENTRY pSessionEntry,pNextSessionEntry;
  1470. SmbCeAcquireResource();
  1471. pServerEntry = SmbCeGetFirstServerEntry();
  1472. while (pServerEntry != NULL) {
  1473. ASSERT(SmbCeIsResourceOwned());
  1474. SmbCeReferenceServerEntry(pServerEntry);
  1475. pSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  1476. while (pSessionEntry != NULL) {
  1477. if (RtlEqualLuid(
  1478. &pSessionEntry->Session.LogonId,
  1479. pLogonId)) {
  1480. if ((pSessionEntry->Session.UserId != (SMB_USER_ID)(SMBCE_SHARE_LEVEL_SERVER_USERID)) &&
  1481. (pSessionEntry->Session.UserId != 0) &&
  1482. !FlagOn(pSessionEntry->Session.Flags,SMBCE_SESSION_FLAGS_LOGGED_OFF)) {
  1483. SmbCeRemoveSessionEntry(pServerEntry,pSessionEntry);
  1484. SmbCeRemoveDefaultSessionEntry(pSessionEntry);
  1485. pSessionEntry->Header.State = SMBCEDB_MARKED_FOR_DELETION;
  1486. pSessionEntry->Session.Flags |= SMBCE_SESSION_FLAGS_LOGGED_OFF;
  1487. SmbCeReferenceSessionEntry(pSessionEntry);
  1488. SmbCeReleaseResource();
  1489. if (pSessionEntry->Header.State == SMBCEDB_ACTIVE) {
  1490. SmbCeLogOff(pServerEntry,pSessionEntry);
  1491. } else {
  1492. SmbCeDereferenceSessionEntry(pSessionEntry);
  1493. }
  1494. SmbCeAcquireResource();
  1495. pNextSessionEntry = SmbCeGetNextSessionEntry(pServerEntry,pSessionEntry);
  1496. SmbCeDereferenceSessionEntry(pSessionEntry);
  1497. pSessionEntry = pNextSessionEntry;
  1498. }
  1499. } else {
  1500. pSessionEntry = SmbCeGetNextSessionEntry(pServerEntry,pSessionEntry);
  1501. }
  1502. }
  1503. pNextServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  1504. SmbCeDereferenceServerEntry(pServerEntry);
  1505. pServerEntry = pNextServerEntry;
  1506. }
  1507. SmbCeReleaseResource();
  1508. #endif
  1509. return STATUS_SUCCESS;
  1510. }
  1511. VOID
  1512. SmbCeTearDownSessionEntry(
  1513. PSMBCEDB_SESSION_ENTRY pSessionEntry)
  1514. /*++
  1515. Routine Description:
  1516. This routine tears down a session entry instance
  1517. Arguments:
  1518. pSessionEntry - the session entry to be dereferenced
  1519. --*/
  1520. {
  1521. PAGED_CODE();
  1522. ASSERT((pSessionEntry->Header.SwizzleCount == 0) &&
  1523. (pSessionEntry->Header.State == SMBCEDB_MARKED_FOR_DELETION));
  1524. ASSERT(IsListEmpty(&pSessionEntry->SerializationList));
  1525. SmbCeLog(("TearSessEntry %lx\n",pSessionEntry));
  1526. SmbLog(LOG,
  1527. SmbCeTearDownSessionEntry,
  1528. LOGPTR(pSessionEntry));
  1529. if (pSessionEntry->Session.pUserName != NULL) {
  1530. RxFreePool(pSessionEntry->Session.pUserName);
  1531. }
  1532. if (pSessionEntry->Session.pPassword != NULL) {
  1533. RxFreePool(pSessionEntry->Session.pPassword);
  1534. }
  1535. if (pSessionEntry->Session.pUserDomainName != NULL) {
  1536. RxFreePool(pSessionEntry->Session.pUserDomainName);
  1537. }
  1538. if (pSessionEntry->Session.TargetInfoMarshalled != NULL) {
  1539. RxFreePool(pSessionEntry->Session.TargetInfoMarshalled);
  1540. }
  1541. if (pSessionEntry->pNetRootName != NULL) {
  1542. RxFreePool(pSessionEntry->pNetRootName);
  1543. }
  1544. UninitializeSecurityContextsForSession(&pSessionEntry->Session);
  1545. SmbMmFreeSessionEntry(pSessionEntry);
  1546. }
  1547. PSMBCEDB_NET_ROOT_ENTRY
  1548. SmbCeFindNetRootEntry(
  1549. PSMBCEDB_SERVER_ENTRY pServerEntry,
  1550. PUNICODE_STRING pServerShare
  1551. )
  1552. {
  1553. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry = NULL;
  1554. ASSERT(SmbCeIsResourceOwned());
  1555. pNetRootEntry = SmbCeGetFirstNetRootEntry(pServerEntry);
  1556. while (pNetRootEntry != NULL) {
  1557. if (RtlCompareUnicodeString(
  1558. pServerShare,
  1559. &pNetRootEntry->Name,
  1560. TRUE) == 0) {
  1561. break;
  1562. }
  1563. pNetRootEntry = SmbCeGetNextNetRootEntry(pServerEntry,pNetRootEntry);
  1564. }
  1565. return pNetRootEntry;
  1566. }
  1567. NTSTATUS
  1568. SmbCeFindOrConstructNetRootEntry(
  1569. IN PMRX_NET_ROOT pNetRoot,
  1570. OUT PSMBCEDB_NET_ROOT_ENTRY *pNetRootEntryPtr)
  1571. /*++
  1572. Routine Description:
  1573. This routine opens/creates a net root entry in the connection engine database
  1574. Arguments:
  1575. pNetRoot -- the RDBSS net root instance
  1576. pNetRootEntryPtr -- Initialized to the SMBCEDB_NET_ROOT_ENTRY instance if
  1577. successful
  1578. Return Value:
  1579. STATUS_SUCCESS - the construction of the net root instance has been finalized
  1580. Other Status codes correspond to error situations.
  1581. Notes:
  1582. This routine assumes that the necesary concurreny control mechanism has already
  1583. been taken.
  1584. On Entry the connection engine resource must have been acquired exclusive and
  1585. ownership remains invariant on exit.
  1586. --*/
  1587. {
  1588. NTSTATUS Status = STATUS_SUCCESS;
  1589. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  1590. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry = NULL;
  1591. PSMBCEDB_SESSION_ENTRY pSessionEntry = NULL;
  1592. SMB_USER_ID UserId = 0;
  1593. ASSERT(SmbCeIsResourceOwned());
  1594. *pNetRootEntryPtr = NULL;
  1595. pServerEntry = SmbCeReferenceAssociatedServerEntry(pNetRoot->pSrvCall);
  1596. if (pServerEntry != NULL) {
  1597. // Check if any of the SMBCEDB_NET_ROOT_ENTRY associated with the server
  1598. // can be used. An existing entry is reusable if the names match
  1599. pNetRootEntry = SmbCeGetFirstNetRootEntry(pServerEntry);
  1600. while (pNetRootEntry != NULL) {
  1601. if (RtlCompareUnicodeString(
  1602. pNetRoot->pNetRootName,
  1603. &pNetRootEntry->Name,
  1604. TRUE) == 0) {
  1605. SmbCeLog(("CachedNREntry %lx\n",pNetRootEntry));
  1606. SmbLog(LOG,
  1607. SmbCeFindOrConstructNetRootEntry_1,
  1608. LOGPTR(pNetRootEntry));
  1609. break;
  1610. }
  1611. pNetRootEntry = SmbCeGetNextNetRootEntry(pServerEntry,pNetRootEntry);
  1612. }
  1613. if (pNetRootEntry != NULL) {
  1614. SmbCeReferenceNetRootEntry(pNetRootEntry);
  1615. } else {
  1616. pNetRootEntry = (PSMBCEDB_NET_ROOT_ENTRY)SmbMmAllocateObject(SMBCEDB_OT_NETROOT);
  1617. if (pNetRootEntry != NULL) {
  1618. Status = MRxSmbCscInitializeNetRootEntry(pNetRootEntry);
  1619. if (Status != STATUS_SUCCESS) {
  1620. SmbMmFreeObject(pNetRootEntry);
  1621. } else {
  1622. pNetRootEntry->Name.Buffer = RxAllocatePoolWithTag(
  1623. PagedPool | POOL_COLD_ALLOCATION,
  1624. pNetRoot->pNetRootName->Length,
  1625. MRXSMB_NETROOT_POOLTAG);
  1626. if (pNetRootEntry->Name.Buffer != NULL) {
  1627. SmbCeLog(("NewNetREntry %lx\n",pNetRootEntry));
  1628. SmbLog(LOG,
  1629. SmbCeFindOrConstructNetRootEntry_2,
  1630. LOGPTR(pNetRootEntry));
  1631. pNetRootEntry->Name.Length = pNetRoot->pNetRootName->Length;
  1632. pNetRootEntry->Name.MaximumLength = pNetRootEntry->Name.Length;
  1633. RtlCopyMemory(
  1634. pNetRootEntry->Name.Buffer,
  1635. pNetRoot->pNetRootName->Buffer,
  1636. pNetRootEntry->Name.Length);
  1637. pNetRootEntry->pServerEntry = pServerEntry;
  1638. pNetRootEntry->NetRoot.UserId = UserId;
  1639. pNetRootEntry->NetRoot.NetRootType = pNetRoot->Type;
  1640. InitializeListHead(&pNetRootEntry->NetRoot.ClusterSizeSerializationQueue);
  1641. pNetRootEntry->Header.State = SMBCEDB_ACTIVE;
  1642. // Init the NetRoot Name Caches.
  1643. //
  1644. // The get file attributes name cache tracks the file attributes response
  1645. // from the last GFA sent to the server for a given file.
  1646. // NB: There is no struct defined for the extension to the GFA name
  1647. // cache since the extension is only an SMBPSE_FILEINFO_BUNDLE.
  1648. //
  1649. RxNameCacheInitialize(
  1650. &pNetRootEntry->NameCacheCtlGFABasic,
  1651. sizeof(FILE_BASIC_INFORMATION),
  1652. NAME_CACHE_NETROOT_MAX_ENTRIES);
  1653. RxNameCacheInitialize(
  1654. &pNetRootEntry->NameCacheCtlGFAStandard,
  1655. sizeof(FILE_STANDARD_INFORMATION),
  1656. NAME_CACHE_NETROOT_MAX_ENTRIES);
  1657. RxNameCacheInitialize(
  1658. &pNetRootEntry->NameCacheCtlGFAInternal,
  1659. sizeof(FILE_INTERNAL_INFORMATION),
  1660. NAME_CACHE_NETROOT_MAX_ENTRIES);
  1661. //
  1662. // The file not found name cache just tracks opens on files where the
  1663. // response was file not found.
  1664. //
  1665. RxNameCacheInitialize(
  1666. &pNetRootEntry->NameCacheCtlFNF,
  1667. 0,
  1668. NAME_CACHE_NETROOT_MAX_ENTRIES);
  1669. SmbCeReferenceNetRootEntry(pNetRootEntry);
  1670. SmbCeAddNetRootEntry(pServerEntry,pNetRootEntry);
  1671. if ( RtlCompareUnicodeString(
  1672. pNetRoot->pNetRootName,
  1673. &MRxSmbRemoteBootShare,
  1674. TRUE
  1675. ) == 0 ) {
  1676. pNetRootEntry->IsRemoteBoot = TRUE;
  1677. }
  1678. } else {
  1679. SmbMmFreeObject(pNetRootEntry);
  1680. Status = STATUS_INSUFFICIENT_RESOURCES;
  1681. }
  1682. }
  1683. } else {
  1684. Status = STATUS_INSUFFICIENT_RESOURCES;
  1685. }
  1686. }
  1687. if (Status == STATUS_SUCCESS) {
  1688. ASSERT(pNetRootEntry != NULL);
  1689. *pNetRootEntryPtr = pNetRootEntry;
  1690. }
  1691. SmbCeDereferenceServerEntry(pServerEntry);
  1692. } else {
  1693. Status = STATUS_INVALID_PARAMETER;
  1694. }
  1695. return Status;
  1696. }
  1697. VOID
  1698. SmbCepDereferenceNetRootEntry(
  1699. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry,
  1700. PVOID FileName,
  1701. ULONG FileLine)
  1702. /*++
  1703. Routine Description:
  1704. This routine dereferences a net root entry instance
  1705. Arguments:
  1706. pNetRootEntry - the NEt Root entry to be dereferenced
  1707. Notes:
  1708. Disconnects are not required for mailslot servers. They need to be
  1709. sent to File servers only.
  1710. --*/
  1711. {
  1712. if (pNetRootEntry != NULL) {
  1713. LONG FinalRefCount;
  1714. BOOLEAN fTearDownEntry;
  1715. BOOLEAN fDisconnectRequired;
  1716. ASSERT((pNetRootEntry->Header.ObjectType == SMBCEDB_OT_NETROOT) &&
  1717. (pNetRootEntry->Header.SwizzleCount > 0));
  1718. SmbCeAcquireResource();
  1719. FinalRefCount = InterlockedDecrement(&pNetRootEntry->Header.SwizzleCount);
  1720. fTearDownEntry = (FinalRefCount == 0);
  1721. if (fTearDownEntry) {
  1722. if (pNetRootEntry->Header.SwizzleCount == 0) {
  1723. PSMBCEDB_SERVER_ENTRY pServerEntry = pNetRootEntry->pServerEntry;
  1724. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext = NULL;
  1725. SmbCeRemoveNetRootEntryLite(pNetRootEntry->pServerEntry,pNetRootEntry);
  1726. pNetRootEntry->Header.State = SMBCEDB_MARKED_FOR_DELETION;
  1727. fTearDownEntry = TRUE;
  1728. pVNetRootContext = SmbCeGetFirstVNetRootContext(&pServerEntry->VNetRootContexts);
  1729. while (pVNetRootContext != NULL) {
  1730. ASSERT(pVNetRootContext->pNetRootEntry != pNetRootEntry);
  1731. pVNetRootContext = SmbCeGetNextVNetRootContext(
  1732. &pServerEntry->VNetRootContexts,
  1733. pVNetRootContext);
  1734. }
  1735. } else {
  1736. fTearDownEntry = FALSE;
  1737. }
  1738. }
  1739. SmbCeReleaseResource();
  1740. if (fTearDownEntry) {
  1741. SmbCeTearDownNetRootEntry(pNetRootEntry);
  1742. }
  1743. }
  1744. }
  1745. VOID
  1746. SmbCeTearDownNetRootEntry(
  1747. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry)
  1748. /*++
  1749. Routine Description:
  1750. This routine tears down a net root entry instance
  1751. Arguments:
  1752. pNetRootEntry - the NEt Root entry to be dereferenced
  1753. --*/
  1754. {
  1755. PAGED_CODE();
  1756. ASSERT((pNetRootEntry->Header.SwizzleCount == 0) &&
  1757. (pNetRootEntry->Header.State == SMBCEDB_MARKED_FOR_DELETION));
  1758. SmbCeLog(("TearNetREntry %lx\n",pNetRootEntry));
  1759. SmbLog(LOG,
  1760. SmbCeTearDownNetRootEntry,
  1761. LOGPTR(pNetRootEntry));
  1762. MRxSmbCscUninitializeNetRootEntry(pNetRootEntry);
  1763. //
  1764. // Free storage associated with all entries in the name caches.
  1765. //
  1766. RxNameCacheFinalize(&pNetRootEntry->NameCacheCtlGFABasic);
  1767. RxNameCacheFinalize(&pNetRootEntry->NameCacheCtlGFAStandard);
  1768. RxNameCacheFinalize(&pNetRootEntry->NameCacheCtlGFAInternal);
  1769. RxNameCacheFinalize(&pNetRootEntry->NameCacheCtlFNF);
  1770. if (pNetRootEntry->Name.Buffer != NULL) {
  1771. RxFreePool(pNetRootEntry->Name.Buffer);
  1772. pNetRootEntry->Name.Buffer = NULL;
  1773. }
  1774. if (pNetRootEntry->VolumeInfo != NULL) {
  1775. RxFreePool(pNetRootEntry->VolumeInfo);
  1776. pNetRootEntry->VolumeInfo = NULL;
  1777. }
  1778. SmbMmFreeObject(pNetRootEntry);
  1779. }
  1780. NTSTATUS
  1781. SmbCeUpdateNetRoot(
  1782. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry,
  1783. PMRX_NET_ROOT pNetRoot)
  1784. /*++
  1785. Routine Description:
  1786. This routine initializes the wrapper data structure corresponding to a
  1787. given net root entry.
  1788. Arguments:
  1789. pNetRootEntry - the server entry
  1790. Return Value:
  1791. STATUS_SUCCESS if successful
  1792. --*/
  1793. {
  1794. PAGED_CODE();
  1795. if (pNetRootEntry->NetRoot.NetRootType != NET_ROOT_WILD) {
  1796. pNetRoot->Type = pNetRootEntry->NetRoot.NetRootType;
  1797. }
  1798. switch (pNetRoot->Type) {
  1799. case NET_ROOT_DISK:
  1800. {
  1801. pNetRoot->DeviceType = RxDeviceType(DISK);
  1802. RxInitializeNetRootThrottlingParameters(
  1803. &pNetRoot->DiskParameters.LockThrottlingParameters,
  1804. MRxSmbConfiguration.LockIncrement,
  1805. MRxSmbConfiguration.MaximumLock);
  1806. }
  1807. break;
  1808. case NET_ROOT_PIPE:
  1809. {
  1810. pNetRoot->DeviceType = RxDeviceType(NAMED_PIPE);
  1811. RxInitializeNetRootThrottlingParameters(
  1812. &pNetRoot->NamedPipeParameters.PipeReadThrottlingParameters,
  1813. MRxSmbConfiguration.PipeIncrement,
  1814. MRxSmbConfiguration.PipeMaximum);
  1815. }
  1816. break;
  1817. case NET_ROOT_COMM:
  1818. pNetRoot->DeviceType = RxDeviceType(SERIAL_PORT);
  1819. break;
  1820. case NET_ROOT_PRINT:
  1821. pNetRoot->DeviceType = RxDeviceType(PRINTER);
  1822. break;
  1823. case NET_ROOT_MAILSLOT:
  1824. pNetRoot->DeviceType = RxDeviceType(MAILSLOT);
  1825. break;
  1826. case NET_ROOT_WILD:
  1827. break;
  1828. default:
  1829. ASSERT(!"Valid Net Root Type");
  1830. }
  1831. if (pNetRootEntry->NetRoot.DfsAware) {
  1832. SetFlag(pNetRoot->Flags,NETROOT_FLAG_DFS_AWARE_NETROOT);
  1833. } else {
  1834. ClearFlag(pNetRoot->Flags,NETROOT_FLAG_DFS_AWARE_NETROOT);
  1835. }
  1836. return STATUS_SUCCESS;
  1837. }
  1838. NTSTATUS
  1839. SmbCeProbeServers(
  1840. PVOID pContext)
  1841. /*++
  1842. Routine Description:
  1843. This routine probes all the remote servers on which no activity has been
  1844. detected in the recent past.
  1845. Notes:
  1846. The current implementation of walking through the list of all servers to
  1847. initiate echo processing will not scale very well for gateway servers. A
  1848. different mechanism needs to be implemented.
  1849. --*/
  1850. {
  1851. LIST_ENTRY DiscardedServersList;
  1852. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1853. PMRXSMB_ECHO_PROBE_SERVICE_CONTEXT pEchoProbeContext;
  1854. PSMBCEDB_SERVER_ENTRY pPreviousServerEntry = NULL;
  1855. pEchoProbeContext = (PMRXSMB_ECHO_PROBE_SERVICE_CONTEXT)pContext;
  1856. InitializeListHead(&DiscardedServersList);
  1857. SmbCeAcquireSpinLock();
  1858. pServerEntry = SmbCeGetFirstServerEntry();
  1859. while (pServerEntry != NULL) {
  1860. BOOLEAN TearDownTransport = FALSE;
  1861. if ((SmbCeGetServerType(pServerEntry) == SMBCEDB_FILE_SERVER) &&
  1862. ((pServerEntry->Header.State == SMBCEDB_ACTIVE) ||
  1863. (pServerEntry->Header.State == SMBCEDB_CONSTRUCTION_IN_PROGRESS))) {
  1864. // The additional reference is required to keep this server entry
  1865. // as a place marker in the list of server entries.
  1866. // This will be released on resumption of the processinf further
  1867. // down in this routine
  1868. InterlockedIncrement(&pServerEntry->Header.SwizzleCount);
  1869. SmbCeReleaseSpinLock();
  1870. if (pPreviousServerEntry != NULL) {
  1871. SmbCeDereferenceServerEntry(pPreviousServerEntry);
  1872. }
  1873. // For loop back servers we forego the expired exchange detection
  1874. // mechanism. Since the I/O is directed to the same machine this
  1875. // indicates a problem with the local system.
  1876. TearDownTransport = SmbCeDetectExpiredExchanges(pServerEntry);
  1877. if (!TearDownTransport) {
  1878. if ((pServerEntry->Server.SmbsReceivedSinceLastStrobe == 0) &&
  1879. (pServerEntry->pMidAtlas != NULL) &&
  1880. (pServerEntry->pMidAtlas->NumberOfMidsInUse > 0)) {
  1881. if (pServerEntry->Server.EchoProbeState == ECHO_PROBE_IDLE) {
  1882. NTSTATUS Status;
  1883. LARGE_INTEGER CurrentTime,ExpiryTimeInTicks;
  1884. KeQueryTickCount( &CurrentTime );
  1885. ExpiryTimeInTicks.QuadPart = (1000 * 1000 * 10) / KeQueryTimeIncrement();
  1886. ExpiryTimeInTicks.QuadPart = MRxSmbConfiguration.SessionTimeoutInterval * ExpiryTimeInTicks.QuadPart;
  1887. pServerEntry->Server.EchoExpiryTime.QuadPart = CurrentTime.QuadPart +
  1888. ExpiryTimeInTicks.QuadPart;
  1889. InterlockedExchange(
  1890. &pServerEntry->Server.EchoProbeState,
  1891. ECHO_PROBE_AWAITING_RESPONSE);
  1892. Status = SmbCeSendEchoProbe(
  1893. pServerEntry,
  1894. pEchoProbeContext);
  1895. RxDbgTrace(0,Dbg,("Sending ECHO SMB %lx Status %lx\n",pServerEntry,Status));
  1896. TearDownTransport = ((Status != STATUS_SUCCESS) &&
  1897. (Status != STATUS_PENDING));
  1898. if( TearDownTransport )
  1899. {
  1900. RxLogRetail(( "Echo failed %x (%x)\n", pServerEntry, Status ));
  1901. }
  1902. } else if (pServerEntry->Server.EchoProbeState == ECHO_PROBE_AWAITING_RESPONSE) {
  1903. // Compare the current time with the time at which the echo probe
  1904. // was sent. If the interval is greater than the response time then
  1905. // it can be deemed that the echo response is not forthcoming and
  1906. // the tear down can be initiated.
  1907. LARGE_INTEGER CurrentTime;
  1908. KeQueryTickCount( &CurrentTime );
  1909. if ((pServerEntry->Server.EchoExpiryTime.QuadPart != 0) &&
  1910. (pServerEntry->Server.EchoExpiryTime.QuadPart < CurrentTime.QuadPart)) {
  1911. RxLogRetail(( "Echo failed %x (timeout)\n", pServerEntry ));
  1912. TearDownTransport = TRUE;
  1913. }
  1914. }
  1915. if (TearDownTransport) {
  1916. RxLog(("Echo Problem for srvr%lx \n",pServerEntry));
  1917. SmbLog(LOG,
  1918. SmbCeProbeServers,
  1919. LOGPTR(pServerEntry)
  1920. LOGUSTR(pServerEntry->Name));
  1921. }
  1922. } else {
  1923. InterlockedExchange(&pServerEntry->Server.SmbsReceivedSinceLastStrobe,0);
  1924. }
  1925. }
  1926. if (TearDownTransport) {
  1927. InterlockedIncrement(&MRxSmbStatistics.HungSessions);
  1928. SmbCeTransportDisconnectIndicated(pServerEntry);
  1929. }
  1930. // reacquire the spin lock to traverse the list.
  1931. SmbCeAcquireSpinLock();
  1932. pPreviousServerEntry = pServerEntry;
  1933. pServerEntry = SmbCeGetNextServerEntry(pPreviousServerEntry);
  1934. } else {
  1935. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  1936. }
  1937. }
  1938. SmbCeReleaseSpinLock();
  1939. if (pPreviousServerEntry != NULL) {
  1940. SmbCeDereferenceServerEntry(pPreviousServerEntry);
  1941. }
  1942. return STATUS_SUCCESS;
  1943. }
  1944. VOID
  1945. SmbCeTransportDisconnectIndicated(
  1946. PSMBCEDB_SERVER_ENTRY pServerEntry)
  1947. /*++
  1948. Routine Description:
  1949. This routine invalidates a server entry on notification from the underlying transport
  1950. Arguments:
  1951. pServerEntry - the server entry to be dereferenced
  1952. Notes:
  1953. The server entry and the associated net roots and sessions are marked as invalid. A
  1954. reconnect is facilitated on other requests as and when required. In addition all
  1955. pending requests are resumed with the appropriate error indication.
  1956. --*/
  1957. {
  1958. NTSTATUS Status;
  1959. BOOLEAN ShouldResumeRequests = FALSE;
  1960. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry;
  1961. PSMBCEDB_SESSION_ENTRY pSessionEntry;
  1962. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext;
  1963. RxDbgTrace(0,
  1964. Dbg,
  1965. ("SmbCeDbTransportDisconnectIndicated for %lx -- Entry\n",pServerEntry));
  1966. // Acquire the database resource (DPC Level)
  1967. SmbCeAcquireSpinLock();
  1968. if (!pServerEntry->ResumeRequestsInProgress) {
  1969. ShouldResumeRequests = TRUE;
  1970. pServerEntry->ResumeRequestsInProgress = TRUE;
  1971. pServerEntry->ServerStatus = STATUS_CONNECTION_DISCONNECTED;
  1972. pServerEntry->Header.State = SMBCEDB_DESTRUCTION_IN_PROGRESS;
  1973. pServerEntry->SecuritySignaturesActive = FALSE;
  1974. SmbCeReferenceServerEntry(pServerEntry);
  1975. // Increment the associated version count so as to invalidate all existing Fids
  1976. InterlockedIncrement(&pServerEntry->Server.Version);
  1977. }
  1978. // release the database resource (DPC Level)
  1979. SmbCeReleaseSpinLock();
  1980. SmbLog(LOG,
  1981. SmbCeTransportDisconnectIndicated,
  1982. LOGPTR(pServerEntry)
  1983. LOGUSTR(pServerEntry->Name));
  1984. if (ShouldResumeRequests) {
  1985. if (RxShouldPostCompletion()) {
  1986. InitializeListHead(&pServerEntry->WorkQueueItemForResume.List);
  1987. RxPostToWorkerThread(
  1988. MRxSmbDeviceObject,
  1989. CriticalWorkQueue,
  1990. &pServerEntry->WorkQueueItemForResume,
  1991. SmbCeResumeAllOutstandingRequestsOnError,
  1992. pServerEntry);
  1993. } else {
  1994. SmbCeResumeAllOutstandingRequestsOnError(pServerEntry);
  1995. }
  1996. }
  1997. RxDbgTrace(0,
  1998. Dbg,
  1999. ("SmbCeTransportDisconnectIndicated -- Exit\n"));
  2000. }
  2001. VOID
  2002. SmbCeHandleTransportInvalidation(
  2003. IN PSMBCE_TRANSPORT pTransport)
  2004. /*++
  2005. Routine Description:
  2006. This routine invalidates all servers using a particular transport. This is different from
  2007. a disconnect indication in which one server is invalidated. In this case a transport is being
  2008. removed/invalidated locally and all servers using that transport must be invalidated
  2009. Arguments:
  2010. pTransport - the transport being invalidated
  2011. --*/
  2012. {
  2013. PSMBCEDB_SERVER_ENTRY pServerEntry;
  2014. SmbCeAcquireSpinLock();
  2015. pServerEntry = SmbCeGetFirstServerEntry();
  2016. while (pServerEntry != NULL) {
  2017. if ((pServerEntry->pTransport != NULL) &&
  2018. (pServerEntry->pTransport->pTransport == pTransport)) {
  2019. pServerEntry->Header.State = SMBCEDB_DESTRUCTION_IN_PROGRESS;
  2020. // The invalidation needs to hold onto an extra reference to avoid
  2021. // race conditions which could lead to premature destruction of
  2022. // this server entry.
  2023. SmbCeReferenceServerEntry(pServerEntry);
  2024. }
  2025. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  2026. }
  2027. SmbCeReleaseSpinLock();
  2028. SmbCeAcquireResource();
  2029. pServerEntry = SmbCeGetFirstServerEntry();
  2030. while (pServerEntry != NULL) {
  2031. PSMBCEDB_SERVER_ENTRY pPrevServerEntry;
  2032. BOOLEAN fDereferencePrevServerEntry = FALSE;
  2033. if ((pServerEntry->pTransport != NULL) &&
  2034. (pServerEntry->pTransport->pTransport == pTransport)) {
  2035. SmbCeReleaseResource();
  2036. SmbCeTransportDisconnectIndicated(pServerEntry);
  2037. SmbCeReferenceServerEntry(pServerEntry);
  2038. // the reference count of Server Entry will be taken away while the transport
  2039. // is torn down, which prevents the server tranports being torn down again at
  2040. // time the server entry being freed.
  2041. SmbCeUninitializeServerTransport(pServerEntry,
  2042. SmbCeCompleteUninitializeServerTransport,
  2043. pServerEntry);
  2044. SmbCeAcquireResource();
  2045. if (pServerEntry->PreferredTransport != NULL) {
  2046. SmbCeDereferenceTransport(pServerEntry->PreferredTransport);
  2047. pServerEntry->PreferredTransport = NULL;
  2048. }
  2049. fDereferencePrevServerEntry = TRUE;
  2050. }
  2051. pPrevServerEntry = pServerEntry;
  2052. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  2053. if (fDereferencePrevServerEntry) {
  2054. SmbCeDereferenceServerEntry(pPrevServerEntry);
  2055. }
  2056. }
  2057. SmbCeReleaseResource();
  2058. }
  2059. VOID
  2060. SmbCeResumeOutstandingRequests(
  2061. PSMBCEDB_REQUESTS pRequests,
  2062. NTSTATUS RequestStatus)
  2063. /*++
  2064. Routine Description:
  2065. This routine resumes the outstanding requests with the appropriate status
  2066. Arguments:
  2067. pRequests - the list of requests
  2068. RequestStatus - the resumption status ..
  2069. Notes:
  2070. As a side effect the list of requests is torn down.
  2071. --*/
  2072. {
  2073. NTSTATUS Status;
  2074. PSMBCEDB_REQUEST_ENTRY pRequestEntry;
  2075. // Resume all the outstanding reconnect requests that were held up because an earlier
  2076. // reconnect request was under way.
  2077. // Iterate over the list of pending requests and resume all of them
  2078. pRequestEntry = SmbCeGetFirstRequestEntry(pRequests);
  2079. while (pRequestEntry != NULL) {
  2080. PSMB_EXCHANGE pExchange = pRequestEntry->ReconnectRequest.pExchange;
  2081. RxDbgTrace(0, Dbg, ("Resuming outstanding reconnect request exchange %lx \n",pExchange));
  2082. pExchange->Status = RequestStatus;
  2083. SmbCeDecrementPendingLocalOperations(pExchange);
  2084. // Resume the exchange.
  2085. if (pRequestEntry->Request.pExchange->pSmbCeSynchronizationEvent == NULL) {
  2086. if (RequestStatus == STATUS_SUCCESS) {
  2087. Status = SmbCeResumeExchange(pExchange);
  2088. } else {
  2089. // Invoke the error handler
  2090. RxDbgTrace( 0, Dbg, ("Resuming exchange%lx with error\n",pRequestEntry->Request.pExchange));
  2091. SmbCeFinalizeExchange(pExchange);
  2092. }
  2093. } else {
  2094. KeSetEvent(
  2095. pRequestEntry->Request.pExchange->pSmbCeSynchronizationEvent,
  2096. 0,
  2097. FALSE);
  2098. }
  2099. // Delete the request entry
  2100. SmbCeRemoveRequestEntryLite(pRequests,pRequestEntry);
  2101. // Tear down the continuation entry
  2102. SmbCeTearDownRequestEntry(pRequestEntry);
  2103. // Skip to the next one.
  2104. pRequestEntry = SmbCeGetFirstRequestEntry(pRequests);
  2105. }
  2106. }
  2107. VOID
  2108. SmbCeResumeAllOutstandingRequestsOnError(
  2109. PSMBCEDB_SERVER_ENTRY pServerEntry)
  2110. /*++
  2111. Routine Description:
  2112. This routine handles the resumption of all outstanding requests on an error
  2113. Arguments:
  2114. pServerEntry - the Server entry which is being classified as disconnected
  2115. Notes:
  2116. This routine requires the caller to have obtained a reference on the corresponding
  2117. server entry. This is required because invocation of this routine can be posted
  2118. which implies that a reference is required to avoid premature destruction of
  2119. the associated server entry.
  2120. --*/
  2121. {
  2122. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry;
  2123. PSMBCEDB_SESSION_ENTRY pSessionEntry;
  2124. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext;
  2125. SMBCEDB_REQUESTS Requests;
  2126. SMBCEDB_REQUESTS MidRequests;
  2127. PSMBCEDB_REQUEST_ENTRY pRequestEntry;
  2128. PMID_ATLAS pMidAtlas;
  2129. PSMB_EXCHANGE pNegotiateExchange = NULL;
  2130. LIST_ENTRY ExpiredExchanges;
  2131. //DbgPrint("SmbCeResumeAllOutstandingRequestsOnError: Invoked \n");
  2132. InitializeListHead(&ExpiredExchanges);
  2133. InitializeListHead(&Requests.ListHead);
  2134. SmbCeAcquireResource();
  2135. SmbCeAcquireSpinLock();
  2136. if (pServerEntry->Header.State != SMBCEDB_DESTRUCTION_IN_PROGRESS) {
  2137. SmbCeReleaseSpinLock();
  2138. SmbCeReleaseResource();
  2139. SmbCeDereferenceServerEntry(pServerEntry);
  2140. return;
  2141. }
  2142. if (pServerEntry->pNegotiateExchange != NULL) {
  2143. if (pServerEntry->pNegotiateExchange->ReceivePendingOperations > 0) {
  2144. pNegotiateExchange = SmbResetServerEntryNegotiateExchange(pServerEntry);
  2145. }
  2146. }
  2147. // Create a temporary copy of the list that can be traversed after releasing the
  2148. // resource.
  2149. // Copy all the MID assignment requests pending.
  2150. SmbCeTransferRequests(&MidRequests,&pServerEntry->MidAssignmentRequests);
  2151. // Weed out all the reconnect requests so that they can be resumed
  2152. pRequestEntry = SmbCeGetFirstRequestEntry(&pServerEntry->OutstandingRequests);
  2153. while (pRequestEntry != NULL) {
  2154. if (pRequestEntry->GenericRequest.Type == RECONNECT_REQUEST) {
  2155. PSMBCEDB_REQUEST_ENTRY pTempRequestEntry;
  2156. pTempRequestEntry = pRequestEntry;
  2157. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->OutstandingRequests,pRequestEntry);
  2158. SmbCeRemoveRequestEntryLite(&pServerEntry->OutstandingRequests,pTempRequestEntry);
  2159. SmbCeAddRequestEntryLite(&Requests,pTempRequestEntry);
  2160. } else {
  2161. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->OutstandingRequests,pRequestEntry);
  2162. }
  2163. }
  2164. // The exchanges that have valid MID's assigned to them fall into two categories
  2165. // Those that have a ReceivePendingOperation count of > 0 and those that have
  2166. // a ReceievePendingOperation count of zero. For all the exchanges that belong
  2167. // to the first category the finalize ( quiescent state ) routine must be invoked
  2168. // since no receives will be forthcoming. For those exchanges that are in the
  2169. // second category it is sufficient to mark the MID as being invalid. The
  2170. // finalization( quiescent state ) routine is going to be called on completion
  2171. // of other opertaions in this case.
  2172. pMidAtlas = pServerEntry->pMidAtlas;
  2173. if (pMidAtlas != NULL) {
  2174. PVOID pContext;
  2175. USHORT MidsProcessed = 0;
  2176. USHORT NumberOfMidsInUse;
  2177. USHORT MaximumNumberOfMids;
  2178. USHORT NextMid = 0;
  2179. MaximumNumberOfMids = FsRtlGetMaximumNumberOfMids(pMidAtlas);
  2180. NumberOfMidsInUse = FsRtlGetNumberOfMidsInUse(pMidAtlas);
  2181. while ((NumberOfMidsInUse > MidsProcessed) &&
  2182. (NextMid < MaximumNumberOfMids)) {
  2183. pContext = FsRtlMapMidToContext(pMidAtlas,NextMid);
  2184. if (pContext != NULL) {
  2185. PSMB_EXCHANGE pExchange = (PSMB_EXCHANGE)pContext;
  2186. pExchange->SmbCeFlags &= ~SMBCE_EXCHANGE_MID_VALID;
  2187. pExchange->Status = STATUS_CONNECTION_DISCONNECTED;
  2188. pExchange->SmbStatus = STATUS_CONNECTION_DISCONNECTED;
  2189. if ((pExchange->ReceivePendingOperations > 0) &&
  2190. ((pExchange->LocalPendingOperations > 0) ||
  2191. (pExchange->CopyDataPendingOperations > 0) ||
  2192. (pExchange->SendCompletePendingOperations > 0))) {
  2193. // There are other pending operations. By merely setting the
  2194. // pending receive operations to zero, the finalization of
  2195. // the exchange is ensured.
  2196. pExchange->ReceivePendingOperations = 0;
  2197. }
  2198. if (pExchange->ReceivePendingOperations == 0) {
  2199. FsRtlMapAndDissociateMidFromContext(pMidAtlas,NextMid,&pContext);
  2200. }
  2201. MidsProcessed++;
  2202. }
  2203. NextMid++;
  2204. }
  2205. }
  2206. // Transfer all the active exchanges to expired exchanges. This will prevent these
  2207. // exchanges from being considered for time outs again.
  2208. if (!IsListEmpty(&pServerEntry->ActiveExchanges)) {
  2209. pServerEntry->ExpiredExchanges.Blink->Flink = pServerEntry->ActiveExchanges.Flink;
  2210. pServerEntry->ActiveExchanges.Flink->Blink = pServerEntry->ExpiredExchanges.Blink;
  2211. pServerEntry->ExpiredExchanges.Blink = pServerEntry->ActiveExchanges.Blink;
  2212. pServerEntry->ActiveExchanges.Blink->Flink = &pServerEntry->ExpiredExchanges;
  2213. InitializeListHead(&pServerEntry->ActiveExchanges);
  2214. }
  2215. // Splice together all the requests that are awaiting the completion of the
  2216. // session/netroot construction.
  2217. pSessionEntry = SmbCeGetFirstSessionEntry(pServerEntry);
  2218. while (pSessionEntry != NULL) {
  2219. if (pSessionEntry->Header.State == SMBCEDB_ACTIVE) {
  2220. pSessionEntry->Header.State = SMBCEDB_INVALID;
  2221. }
  2222. if (!IsListEmpty(&pSessionEntry->Requests.ListHead)) {
  2223. Requests.ListHead.Blink->Flink = pSessionEntry->Requests.ListHead.Flink;
  2224. pSessionEntry->Requests.ListHead.Flink->Blink = Requests.ListHead.Blink;
  2225. Requests.ListHead.Blink = pSessionEntry->Requests.ListHead.Blink;
  2226. pSessionEntry->Requests.ListHead.Blink->Flink = &Requests.ListHead;
  2227. SmbCeInitializeRequests(&pSessionEntry->Requests);
  2228. }
  2229. pSessionEntry = SmbCeGetNextSessionEntry(pServerEntry,pSessionEntry);
  2230. }
  2231. pNetRootEntry = SmbCeGetFirstNetRootEntry(pServerEntry);
  2232. while (pNetRootEntry != NULL) {
  2233. if (pNetRootEntry->Header.State == SMBCEDB_ACTIVE) {
  2234. pNetRootEntry->Header.State = SMBCEDB_INVALID;
  2235. }
  2236. if (!IsListEmpty(&pNetRootEntry->Requests.ListHead)) {
  2237. Requests.ListHead.Blink->Flink = pNetRootEntry->Requests.ListHead.Flink;
  2238. pNetRootEntry->Requests.ListHead.Flink->Blink = Requests.ListHead.Blink;
  2239. Requests.ListHead.Blink = pNetRootEntry->Requests.ListHead.Blink;
  2240. pNetRootEntry->Requests.ListHead.Blink->Flink = &Requests.ListHead;
  2241. SmbCeInitializeRequests(&pNetRootEntry->Requests);
  2242. }
  2243. pNetRootEntry = SmbCeGetNextNetRootEntry(pServerEntry,pNetRootEntry);
  2244. }
  2245. pVNetRootContext = SmbCeGetFirstVNetRootContext(&pServerEntry->VNetRootContexts);
  2246. while (pVNetRootContext != NULL) {
  2247. pVNetRootContext->Header.State = SMBCEDB_INVALID;
  2248. ClearFlag(
  2249. pVNetRootContext->Flags,
  2250. SMBCE_V_NET_ROOT_CONTEXT_FLAG_VALID_TID);
  2251. pVNetRootContext->TreeId = 0;
  2252. if (!IsListEmpty(&pVNetRootContext->Requests.ListHead)) {
  2253. Requests.ListHead.Blink->Flink = pVNetRootContext->Requests.ListHead.Flink;
  2254. pVNetRootContext->Requests.ListHead.Flink->Blink = Requests.ListHead.Blink;
  2255. Requests.ListHead.Blink = pVNetRootContext->Requests.ListHead.Blink;
  2256. pVNetRootContext->Requests.ListHead.Blink->Flink = &Requests.ListHead;
  2257. SmbCeInitializeRequests(&pVNetRootContext->Requests);
  2258. }
  2259. pVNetRootContext = SmbCeGetNextVNetRootContext(
  2260. &pServerEntry->VNetRootContexts,
  2261. pVNetRootContext);
  2262. }
  2263. pVNetRootContext = SmbCeGetFirstVNetRootContext(&MRxSmbScavengerServiceContext.VNetRootContexts);
  2264. while (pVNetRootContext != NULL &&
  2265. pVNetRootContext->pServerEntry == pServerEntry) {
  2266. // prevent the VNetRootContexts on the scavenger list from being reused
  2267. pVNetRootContext->Header.State = SMBCEDB_INVALID;
  2268. ClearFlag(
  2269. pVNetRootContext->Flags,
  2270. SMBCE_V_NET_ROOT_CONTEXT_FLAG_VALID_TID);
  2271. pVNetRootContext->TreeId = 0;
  2272. pVNetRootContext = SmbCeGetNextVNetRootContext(
  2273. &MRxSmbScavengerServiceContext.VNetRootContexts,
  2274. pVNetRootContext);
  2275. }
  2276. pServerEntry->pMidAtlas = NULL;
  2277. if (pServerEntry->NegotiateInProgress) {
  2278. pServerEntry->Header.State = SMBCEDB_CONSTRUCTION_IN_PROGRESS;
  2279. } else {
  2280. pServerEntry->Header.State = SMBCEDB_INVALID;
  2281. }
  2282. pServerEntry->ResumeRequestsInProgress = FALSE;
  2283. SmbCeReleaseSpinLock();
  2284. if (IoGetCurrentProcess() == RxGetRDBSSProcess()) {
  2285. SmbCeInitiateDisconnect(pServerEntry);
  2286. }
  2287. SmbCeReleaseResource();
  2288. //DbgPrint("SmbCeResumeAllOutstandingRequestsOnError: Processing outsanding request \n");
  2289. SmbCeResumeOutstandingRequests(&Requests,STATUS_CONNECTION_DISCONNECTED);
  2290. //DbgPrint("SmbCeResumeAllOutstandingRequestsOnError: Processing MID request \n");
  2291. SmbCeResumeDiscardedMidAssignmentRequests(
  2292. &MidRequests,
  2293. STATUS_CONNECTION_DISCONNECTED);
  2294. // Resume all the outstanding requests with the error indication
  2295. // The FsRtlDestroyMidAtlas destroys the Mid atlas and at the same
  2296. // time invokes the specified routine on each valid context.
  2297. if (pMidAtlas != NULL) {
  2298. FsRtlDestroyMidAtlas(pMidAtlas,SmbCeFinalizeExchangeOnDisconnect);
  2299. }
  2300. if (pNegotiateExchange != NULL) {
  2301. pNegotiateExchange->Status = STATUS_CONNECTION_DISCONNECTED;
  2302. pNegotiateExchange->SmbStatus = STATUS_CONNECTION_DISCONNECTED;
  2303. pNegotiateExchange->ReceivePendingOperations = 0;
  2304. SmbCeDecrementPendingLocalOperationsAndFinalize(pNegotiateExchange);
  2305. }
  2306. // The remaining ECHO exchanges on the expired exchanges list in the server entry
  2307. // needs to be finalized as well.
  2308. SmbCeAcquireResource();
  2309. SmbCeAcquireSpinLock();
  2310. if (!IsListEmpty(&pServerEntry->ExpiredExchanges)) {
  2311. PLIST_ENTRY pListEntry;
  2312. PSMB_EXCHANGE pExchange;
  2313. pListEntry = pServerEntry->ExpiredExchanges.Flink;
  2314. while (pListEntry != &pServerEntry->ExpiredExchanges) {
  2315. PLIST_ENTRY pNextListEntry = pListEntry->Flink;
  2316. pExchange = (PSMB_EXCHANGE)CONTAINING_RECORD(pListEntry,SMB_EXCHANGE,ExchangeList);
  2317. if ((pExchange->Mid == SMBCE_ECHO_PROBE_MID) &&
  2318. !FlagOn(pExchange->SmbCeFlags,SMBCE_EXCHANGE_FINALIZED) &&
  2319. ((pExchange->ReceivePendingOperations > 0) ||
  2320. (pExchange->LocalPendingOperations > 0) ||
  2321. (pExchange->CopyDataPendingOperations > 0) ||
  2322. (pExchange->SendCompletePendingOperations > 0))) {
  2323. RemoveEntryList(&pExchange->ExchangeList);
  2324. InsertTailList(&ExpiredExchanges,&pExchange->ExchangeList);
  2325. InterlockedIncrement(&pExchange->LocalPendingOperations);
  2326. }
  2327. pListEntry = pNextListEntry;
  2328. }
  2329. }
  2330. SmbCeReleaseSpinLock();
  2331. SmbCeReleaseResource();
  2332. while (!IsListEmpty(&ExpiredExchanges)) {
  2333. PLIST_ENTRY pListEntry;
  2334. PSMB_EXCHANGE pExchange;
  2335. pListEntry = ExpiredExchanges.Flink;
  2336. RemoveHeadList(&ExpiredExchanges);
  2337. pExchange = (PSMB_EXCHANGE)CONTAINING_RECORD(pListEntry,SMB_EXCHANGE,ExchangeList);
  2338. InitializeListHead(&pExchange->ExchangeList);
  2339. RxLog(("Finalizing scavenged exchange %lx Type %ld\n",pExchange,pExchange->Type));
  2340. SmbLog(LOG,
  2341. SmbCeResumeAllOutstandingRequestsOnError,
  2342. LOGPTR(pExchange)
  2343. LOGUCHAR(pExchange->Type));
  2344. pExchange->Status = STATUS_CONNECTION_DISCONNECTED;
  2345. pExchange->SmbStatus = STATUS_CONNECTION_DISCONNECTED;
  2346. pExchange->ReceivePendingOperations = 0;
  2347. SmbCeDecrementPendingLocalOperationsAndFinalize(pExchange);
  2348. }
  2349. //DbgPrint("SmbCeResumeAllOutstandingRequestsOnError: Exit \n");
  2350. SmbCeDereferenceServerEntry(pServerEntry);
  2351. }
  2352. VOID
  2353. SmbCeFinalizeAllExchangesForNetRoot(
  2354. PMRX_NET_ROOT pNetRoot)
  2355. /*++
  2356. Routine Description:
  2357. This routine handles the resumption of all outstanding requests on a forced
  2358. finalization of a connection
  2359. Arguments:
  2360. pNetRoot - the NetRoot which is being fianlized forcibly
  2361. Notes:
  2362. --*/
  2363. {
  2364. PMRX_SRV_CALL pSrvCall;
  2365. PSMBCEDB_SERVER_ENTRY pServerEntry;
  2366. SMBCEDB_REQUESTS Requests;
  2367. LIST_ENTRY ExpiredExchanges;
  2368. PSMB_EXCHANGE pExchange;
  2369. PSMBCEDB_REQUEST_ENTRY pRequestEntry;
  2370. PLIST_ENTRY pListEntry;
  2371. pSrvCall = pNetRoot->pSrvCall;
  2372. pServerEntry = SmbCeGetAssociatedServerEntry(pSrvCall);
  2373. InitializeListHead(&Requests.ListHead);
  2374. InitializeListHead(&ExpiredExchanges);
  2375. SmbCeAcquireSpinLock();
  2376. // Walk through the list of active exchanges, and the pending requests to
  2377. // weed out the exchanges for the given VNET_ROOT.
  2378. pRequestEntry = SmbCeGetFirstRequestEntry(&pServerEntry->OutstandingRequests);
  2379. while (pRequestEntry != NULL) {
  2380. pExchange = pRequestEntry->GenericRequest.pExchange;
  2381. if ((pRequestEntry->GenericRequest.Type == RECONNECT_REQUEST) &&
  2382. (pExchange->SmbCeContext.pVNetRoot != NULL) &&
  2383. (pExchange->SmbCeContext.pVNetRoot->pNetRoot == pNetRoot)) {
  2384. PSMBCEDB_REQUEST_ENTRY pTempRequestEntry;
  2385. pTempRequestEntry = pRequestEntry;
  2386. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->OutstandingRequests,pRequestEntry);
  2387. SmbCeRemoveRequestEntryLite(&pServerEntry->OutstandingRequests,pTempRequestEntry);
  2388. SmbCeAddRequestEntryLite(&Requests,pTempRequestEntry);
  2389. } else {
  2390. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->OutstandingRequests,pRequestEntry);
  2391. }
  2392. }
  2393. pRequestEntry = SmbCeGetFirstRequestEntry(&pServerEntry->MidAssignmentRequests);
  2394. while (pRequestEntry != NULL) {
  2395. pExchange = pRequestEntry->GenericRequest.pExchange;
  2396. ASSERT(pRequestEntry->GenericRequest.Type == ACQUIRE_MID_REQUEST);
  2397. if ((pRequestEntry->GenericRequest.Type == ACQUIRE_MID_REQUEST) &&
  2398. (pExchange->SmbCeContext.pVNetRoot != NULL) &&
  2399. (pExchange->SmbCeContext.pVNetRoot->pNetRoot == pNetRoot)) {
  2400. PSMBCEDB_REQUEST_ENTRY pTempRequestEntry;
  2401. pTempRequestEntry = pRequestEntry;
  2402. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->MidAssignmentRequests,pRequestEntry);
  2403. SmbCeRemoveRequestEntryLite(&pServerEntry->MidAssignmentRequests,pTempRequestEntry);
  2404. // Signal the waiter for resumption
  2405. pTempRequestEntry->MidRequest.pResumptionContext->Status = STATUS_CONNECTION_DISCONNECTED;
  2406. SmbCeResume(pTempRequestEntry->MidRequest.pResumptionContext);
  2407. SmbCeTearDownRequestEntry(pTempRequestEntry);
  2408. } else {
  2409. pRequestEntry = SmbCeGetNextRequestEntry(&pServerEntry->MidAssignmentRequests,pRequestEntry);
  2410. }
  2411. }
  2412. pListEntry = pServerEntry->ActiveExchanges.Flink;
  2413. while (pListEntry != &pServerEntry->ActiveExchanges) {
  2414. PLIST_ENTRY pNextListEntry = pListEntry->Flink;
  2415. pExchange = (PSMB_EXCHANGE)CONTAINING_RECORD(pListEntry,SMB_EXCHANGE,ExchangeList);
  2416. if ((pExchange->SmbCeContext.pVNetRoot != NULL) &&
  2417. (pExchange->SmbCeContext.pVNetRoot->pNetRoot == pNetRoot)) {
  2418. if (!FlagOn(pExchange->SmbCeFlags,SMBCE_EXCHANGE_FINALIZED)) {
  2419. if (pExchange->SmbCeFlags & SMBCE_EXCHANGE_MID_VALID) {
  2420. NTSTATUS LocalStatus;
  2421. LocalStatus = SmbCepDiscardMidAssociatedWithExchange(
  2422. pExchange);
  2423. ASSERT(LocalStatus == STATUS_SUCCESS);
  2424. }
  2425. if ((pExchange->ReceivePendingOperations > 0) ||
  2426. (pExchange->LocalPendingOperations > 0) ||
  2427. (pExchange->CopyDataPendingOperations > 0) ||
  2428. (pExchange->SendCompletePendingOperations > 0)) {
  2429. RemoveEntryList(&pExchange->ExchangeList);
  2430. InsertTailList(&ExpiredExchanges,&pExchange->ExchangeList);
  2431. InterlockedIncrement(&pExchange->LocalPendingOperations);
  2432. }
  2433. }
  2434. }
  2435. pListEntry = pNextListEntry;
  2436. }
  2437. SmbCeReleaseSpinLock();
  2438. while (!IsListEmpty(&ExpiredExchanges)) {
  2439. PLIST_ENTRY pListEntry;
  2440. PSMB_EXCHANGE pExchange;
  2441. pListEntry = ExpiredExchanges.Flink;
  2442. RemoveHeadList(&ExpiredExchanges);
  2443. pExchange = (PSMB_EXCHANGE)CONTAINING_RECORD(pListEntry,SMB_EXCHANGE,ExchangeList);
  2444. InitializeListHead(&pExchange->ExchangeList);
  2445. RxLog(("Finalizing scavenged exchange %lx Type %ld\n",pExchange,pExchange->Type));
  2446. SmbLog(LOG,
  2447. SmbCeFinalizeAllExchangesForNetRoot,
  2448. LOGPTR(pExchange)
  2449. LOGUCHAR(pExchange->Type));
  2450. pExchange->Status = STATUS_CONNECTION_DISCONNECTED;
  2451. pExchange->SmbStatus = STATUS_CONNECTION_DISCONNECTED;
  2452. pExchange->ReceivePendingOperations = 0;
  2453. SmbCeDecrementPendingLocalOperationsAndFinalize(pExchange);
  2454. }
  2455. SmbCeResumeOutstandingRequests(&Requests,STATUS_CONNECTION_DISCONNECTED);
  2456. }
  2457. VOID
  2458. SmbCeTearDownRequestEntry(
  2459. PSMBCEDB_REQUEST_ENTRY pRequestEntry)
  2460. /*++
  2461. Routine Description:
  2462. This routine tears down a request entry
  2463. Arguments:
  2464. pRequestEntry - the request entry to be torn down
  2465. Notes:
  2466. --*/
  2467. {
  2468. SmbMmFreeObject(pRequestEntry);
  2469. }
  2470. //
  2471. // The connection engine database initializtion/tear down routines
  2472. //
  2473. extern NTSTATUS
  2474. SmbMmInit();
  2475. extern VOID
  2476. SmbMmTearDown();
  2477. KIRQL s_SmbCeDbSpinLockSavedIrql;
  2478. KSPIN_LOCK s_SmbCeDbSpinLock;
  2479. ERESOURCE s_SmbCeDbResource;
  2480. ERESOURCE s_SmbSecuritySignatureResource;
  2481. SMBCEDB_SERVERS s_DbServers;
  2482. BOOLEAN s_SmbCeDbSpinLockAcquired;
  2483. NTSTATUS
  2484. SmbCeDbInit()
  2485. /*++
  2486. Routine Description:
  2487. This routine initializes the SMBCe database
  2488. Notes:
  2489. --*/
  2490. {
  2491. NTSTATUS Status;
  2492. PAGED_CODE();
  2493. // Initialize the lists associated with various database entities
  2494. InitializeListHead(&s_DbServers.ListHead);
  2495. // Initialize the resource associated with the database.
  2496. KeInitializeSpinLock(&s_SmbCeDbSpinLock );
  2497. ExInitializeResource(&s_SmbCeDbResource);
  2498. ExInitializeResource(&s_SmbSecuritySignatureResource);
  2499. s_SmbCeDbSpinLockAcquired = FALSE;
  2500. MRxSmbInitializeSmbCe();
  2501. // Initialize the memory management data structures.
  2502. Status = SmbMmInit();
  2503. return Status;
  2504. }
  2505. VOID
  2506. SmbCeDbTearDown()
  2507. /*++
  2508. Routine Description:
  2509. This routine tears down the SMB connection engine database
  2510. Notes:
  2511. --*/
  2512. {
  2513. // Walk through the list of servers and tear them down.
  2514. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  2515. KEVENT ServerEntryTearDownEvent;
  2516. BOOLEAN NeedToWait = FALSE;
  2517. KeInitializeEvent(
  2518. &ServerEntryTearDownEvent,
  2519. NotificationEvent,
  2520. FALSE);
  2521. SmbCeStartStopContext.pServerEntryTearDownEvent = &ServerEntryTearDownEvent;
  2522. // The CSC code obtains references on all the servers that are operating in
  2523. // disconnected mode. Force it to release the references since we are shutting
  2524. // down.
  2525. CscTransitionServerToOnline(0);
  2526. SmbCeAcquireResource();
  2527. SmbCeAcquireSpinLock();
  2528. pServerEntry = SmbCeGetFirstServerEntry();
  2529. if (pServerEntry != NULL) {
  2530. SmbCeReferenceServerEntry(pServerEntry);
  2531. NeedToWait = TRUE;
  2532. }
  2533. while (pServerEntry != NULL) {
  2534. PSMBCEDB_SERVER_ENTRY pTempServerEntry;
  2535. pTempServerEntry = pServerEntry;
  2536. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  2537. if (pServerEntry != NULL) {
  2538. SmbCeReferenceServerEntry(pServerEntry);
  2539. }
  2540. SmbCeReleaseSpinLock();
  2541. SmbCeReleaseResource();
  2542. pTempServerEntry->Header.State = SMBCEDB_DESTRUCTION_IN_PROGRESS;
  2543. pTempServerEntry->ServerStatus = RX_MAP_STATUS(REDIRECTOR_PAUSED);
  2544. SmbCeResumeAllOutstandingRequestsOnError(pTempServerEntry);
  2545. SmbCeAcquireResource();
  2546. SmbCeAcquireSpinLock();
  2547. }
  2548. SmbCeReleaseSpinLock();
  2549. SmbCeReleaseResource();
  2550. MRxSmbUninitializeTransport();
  2551. MRxSmbTearDownSmbCe();
  2552. if (NeedToWait) {
  2553. KeWaitForSingleObject(
  2554. &ServerEntryTearDownEvent,
  2555. Executive,
  2556. KernelMode,
  2557. FALSE,
  2558. NULL);
  2559. }
  2560. // Tear down the connection engine memory management data structures.
  2561. SmbMmTearDown();
  2562. }
  2563. NTSTATUS
  2564. FindServerEntryFromCompleteUNCPath(
  2565. USHORT *lpuServerShareName,
  2566. PSMBCEDB_SERVER_ENTRY *ppServerEntry
  2567. )
  2568. /*++
  2569. Routine Description:
  2570. Given a UNC path of the form \\server\share, this routine looks up the redir
  2571. in-memory data structures to locate such s SMBCEDB_SERVER_ENTRY for the server
  2572. Arguments:
  2573. lpuServerShareName \\server\share
  2574. ppServerEntry Contains the server entry if successful
  2575. Notes:
  2576. The server entry is refcounted, hence the caller must dereference it after use by
  2577. calling SmbCeDereferenceServerEntry
  2578. --*/
  2579. {
  2580. UNICODE_STRING unistrServerName;
  2581. USHORT *lpuT = lpuServerShareName;
  2582. DWORD dwlenServerShare, dwlenServer=0;
  2583. if ((*lpuT++ != (USHORT)'\\') || (*lpuT++ != (USHORT)'\\'))
  2584. {
  2585. return STATUS_INVALID_PARAMETER;
  2586. }
  2587. for (dwlenServerShare = 1; *lpuT; lpuT++, dwlenServerShare++)
  2588. {
  2589. if (*lpuT == (USHORT)'\\')
  2590. {
  2591. if (dwlenServer)
  2592. {
  2593. break;
  2594. }
  2595. else
  2596. {
  2597. dwlenServer = dwlenServerShare; // length of the \server part
  2598. }
  2599. }
  2600. }
  2601. unistrServerName.Length = unistrServerName.MaximumLength = (USHORT)(dwlenServer * sizeof(USHORT));
  2602. unistrServerName.Buffer = lpuServerShareName+1;
  2603. SmbCeAcquireResource();
  2604. try
  2605. {
  2606. *ppServerEntry = SmbCeFindServerEntry(&unistrServerName, SMBCEDB_FILE_SERVER, NULL);
  2607. if (!*ppServerEntry)
  2608. {
  2609. *ppServerEntry = SmbCeFindDfsServerEntry(&unistrServerName, SMBCEDB_FILE_SERVER);
  2610. }
  2611. }
  2612. except(EXCEPTION_EXECUTE_HANDLER)
  2613. {
  2614. SmbCeReleaseResource();
  2615. return STATUS_UNSUCCESSFUL;
  2616. }
  2617. SmbCeReleaseResource();
  2618. if (*ppServerEntry)
  2619. {
  2620. return STATUS_SUCCESS;
  2621. }
  2622. return STATUS_UNSUCCESSFUL;
  2623. }
  2624. NTSTATUS
  2625. FindNetRootEntryFromCompleteUNCPath(
  2626. USHORT *lpuServerShareName,
  2627. PSMBCEDB_NET_ROOT_ENTRY *ppNetRootEntry
  2628. )
  2629. /*++
  2630. Routine Description:
  2631. Given a UNC path of the form \\server\share, this routine looks up the redir
  2632. in-memory data structures to locate such a NETROOT
  2633. Arguments:
  2634. lpuServerShareName \\server\share
  2635. ppNetRootEntry Contains the netroot entry if successful.
  2636. Notes:
  2637. The netroot entry is refcounted, hence the caller must dereference it after use by
  2638. calling SmbCeDereferenceNetRootEntry
  2639. --*/
  2640. {
  2641. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  2642. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry = NULL;
  2643. UNICODE_STRING unistrServerName, unistrServerShare;
  2644. USHORT *lpuT = lpuServerShareName, *lpuDfsShare=NULL, *lpuSav;
  2645. DWORD dwlenServerShare, dwlenServer=0;
  2646. NTSTATUS Status = STATUS_UNSUCCESSFUL;
  2647. if ((*lpuT++ != (USHORT)'\\') || (*lpuT++ != (USHORT)'\\'))
  2648. {
  2649. return STATUS_INVALID_PARAMETER;
  2650. }
  2651. for (dwlenServerShare = 1; *lpuT; lpuT++, dwlenServerShare++)
  2652. {
  2653. if (*lpuT == (USHORT)'\\')
  2654. {
  2655. if (dwlenServer)
  2656. {
  2657. break;
  2658. }
  2659. else
  2660. {
  2661. dwlenServer = dwlenServerShare; // length of the \server part
  2662. }
  2663. }
  2664. }
  2665. ASSERT((dwlenServerShare>dwlenServer));
  2666. unistrServerName.Length = unistrServerName.MaximumLength = (USHORT)(dwlenServer * sizeof(USHORT));
  2667. unistrServerName.Buffer = lpuServerShareName+1;
  2668. unistrServerShare.Length = unistrServerShare.MaximumLength = (USHORT)(dwlenServerShare * sizeof(USHORT));
  2669. unistrServerShare.Buffer = lpuServerShareName+1;
  2670. SmbCeAcquireResource();
  2671. try
  2672. {
  2673. // lookup in standard places
  2674. pServerEntry = SmbCeFindServerEntry(&unistrServerName, SMBCEDB_FILE_SERVER, NULL);
  2675. if (pServerEntry)
  2676. {
  2677. pNetRootEntry = SmbCeFindNetRootEntry(pServerEntry, &unistrServerShare);
  2678. SmbCeDereferenceServerEntry(pServerEntry);
  2679. if (pNetRootEntry)
  2680. {
  2681. goto bailout;
  2682. }
  2683. }
  2684. // now look to see if a DFS alternate has this share
  2685. pServerEntry = SmbCeGetFirstServerEntry();
  2686. while (pServerEntry != NULL) {
  2687. DWORD dwAllocationSize = 0;
  2688. if ((RtlCompareUnicodeString(
  2689. &unistrServerName,
  2690. &pServerEntry->DfsRootName,
  2691. TRUE) == 0)) {
  2692. dwAllocationSize = pServerEntry->Name.MaximumLength+
  2693. (dwlenServerShare-dwlenServer+2) * sizeof(USHORT);
  2694. lpuDfsShare = RxAllocatePoolWithTag(
  2695. NonPagedPool,
  2696. dwAllocationSize,
  2697. MRXSMB_SESSION_POOLTAG);
  2698. if (!lpuDfsShare)
  2699. {
  2700. Status = STATUS_INSUFFICIENT_RESOURCES;
  2701. goto bailout;
  2702. }
  2703. ASSERT(dwAllocationSize > pServerEntry->Name.MaximumLength);
  2704. unistrServerShare.Length = (USHORT)(pServerEntry->Name.Length + (dwlenServerShare-dwlenServer) * sizeof(USHORT));
  2705. unistrServerShare.MaximumLength = (USHORT)(pServerEntry->Name.MaximumLength+
  2706. (dwlenServerShare-dwlenServer+2) * sizeof(USHORT));
  2707. memcpy(lpuDfsShare, pServerEntry->Name.Buffer, pServerEntry->Name.Length);
  2708. memcpy(&lpuDfsShare[pServerEntry->Name.Length/sizeof(USHORT)],
  2709. &(unistrServerShare.Buffer[dwlenServer]),
  2710. (dwlenServerShare-dwlenServer) * sizeof(USHORT));
  2711. lpuSav = unistrServerShare.Buffer;
  2712. unistrServerShare.Buffer = lpuDfsShare;
  2713. pNetRootEntry = SmbCeFindNetRootEntry(pServerEntry, &unistrServerShare);
  2714. unistrServerShare.Buffer = lpuSav;
  2715. RxFreePool(lpuDfsShare);
  2716. // stop if we found it
  2717. if (pNetRootEntry)
  2718. {
  2719. break;
  2720. }
  2721. }
  2722. pServerEntry = SmbCeGetNextServerEntry(pServerEntry);
  2723. }
  2724. }
  2725. except(EXCEPTION_EXECUTE_HANDLER)
  2726. {
  2727. goto bailout;
  2728. }
  2729. bailout:
  2730. if (pNetRootEntry)
  2731. {
  2732. SmbCeReferenceNetRootEntry(pNetRootEntry);
  2733. *ppNetRootEntry = pNetRootEntry;
  2734. Status = STATUS_SUCCESS;
  2735. }
  2736. SmbCeReleaseResource();
  2737. return Status;
  2738. }
  2739. NTSTATUS
  2740. MRxSmbCscCachingBitsFromCompleteUNCPath(
  2741. PWSTR lpServerShare,
  2742. ULONG *lpulBits
  2743. )
  2744. /*++
  2745. Routine Description:
  2746. Given a UNC path of the form \\server\share, this routine checks to see whether
  2747. such a NETROOT exists, and if so, it gets the SMB flags for that entry
  2748. Arguments:
  2749. lpuServerShareName \\server\share
  2750. lpulBits SMB bits
  2751. Notes:
  2752. --*/
  2753. {
  2754. PSMBCEDB_NET_ROOT_ENTRY pNetRootEntry=NULL;
  2755. NTSTATUS Status;
  2756. if ((Status = FindNetRootEntryFromCompleteUNCPath(lpServerShare, &pNetRootEntry)) == STATUS_SUCCESS)
  2757. {
  2758. // convert these bits to those defined in csc\inc\shdcom.h
  2759. *lpulBits = (pNetRootEntry->NetRoot.CscFlags << 4);
  2760. SmbCeDereferenceNetRootEntry(pNetRootEntry);
  2761. }
  2762. return Status;
  2763. }
  2764. NTSTATUS
  2765. MRxSmbCscServerStateFromCompleteUNCPath(
  2766. PWSTR lpServerShare,
  2767. BOOL *lpfOnline,
  2768. BOOL *lpfPinnedOffline
  2769. )
  2770. {
  2771. PSMBCEDB_SERVER_ENTRY pServerEntry = NULL;
  2772. NTSTATUS Status;
  2773. if ((Status = FindServerEntryFromCompleteUNCPath(lpServerShare, &pServerEntry)) == STATUS_SUCCESS)
  2774. {
  2775. *lpfOnline = (pServerEntry->Server.CscState == ServerCscShadowing);
  2776. *lpfPinnedOffline = (pServerEntry->Server.IsPinnedOffline == TRUE);
  2777. SmbCeDereferenceServerEntry(pServerEntry);
  2778. }
  2779. return Status;
  2780. }
  2781. PSMBCEDB_SESSION_ENTRY
  2782. SmbCeGetDefaultSessionEntry(
  2783. PSMBCEDB_SERVER_ENTRY pServerEntry,
  2784. ULONG SessionId,
  2785. PLUID pLogonId
  2786. )
  2787. /*++
  2788. Routine Description:
  2789. This routine returns the session entry from the default sessions list.
  2790. Arguments:
  2791. pServerEntry - Server entry
  2792. SessionId - Hydra session Id.
  2793. pLogonId - the logon id.
  2794. Notes:
  2795. This is called with the SmbCe spinlock held.
  2796. --*/
  2797. {
  2798. PLIST_ENTRY pListEntry;
  2799. PSMBCEDB_SESSION_ENTRY pSession;
  2800. PSMBCEDB_SESSION_ENTRY pReturnSession = NULL;
  2801. ASSERT( pServerEntry != NULL );
  2802. pListEntry = pServerEntry->Sessions.DefaultSessionList.Flink;
  2803. while( pListEntry != &pServerEntry->Sessions.DefaultSessionList ) {
  2804. pSession = CONTAINING_RECORD( pListEntry, SMBCEDB_SESSION_ENTRY, DefaultSessionLink );
  2805. if( pSession->Session.SessionId == SessionId ) {
  2806. if (RtlEqualLuid(
  2807. &pSession->Session.LogonId,
  2808. pLogonId)) {
  2809. pReturnSession = pSession;
  2810. break;
  2811. }
  2812. }
  2813. pListEntry = pListEntry->Flink;
  2814. }
  2815. return( pReturnSession );
  2816. }
  2817. VOID
  2818. SmbCeRemoveDefaultSessionEntry(
  2819. PSMBCEDB_SESSION_ENTRY pDefaultSessionEntry
  2820. )
  2821. /*++
  2822. Routine Description:
  2823. This routine removes the session entry from the default sessions list.
  2824. Arguments:
  2825. pServerEntry - Server entry
  2826. SessionId - Hydra session Id.
  2827. pLogonId - the logon id.
  2828. Notes:
  2829. This is called with the SmbCe spinlock held.
  2830. --*/
  2831. {
  2832. if( pDefaultSessionEntry &&
  2833. pDefaultSessionEntry->DefaultSessionLink.Flink ) {
  2834. RemoveEntryList( &pDefaultSessionEntry->DefaultSessionLink );
  2835. pDefaultSessionEntry->DefaultSessionLink.Flink = NULL;
  2836. pDefaultSessionEntry->DefaultSessionLink.Blink = NULL;
  2837. }
  2838. }
  2839. VOID
  2840. MRxSmbTrackRefCount(
  2841. PVOID pInstance,
  2842. PCHAR FileName,
  2843. ULONG Line)
  2844. {
  2845. LONG State = ((PSMBCE_OBJECT_HEADER)pInstance)->State;
  2846. LONG RefCount = ((PSMBCE_OBJECT_HEADER)pInstance)->SwizzleCount;
  2847. SMBCEDB_OBJECT_TYPE ObjectType = ((PSMBCE_OBJECT_HEADER)pInstance)->ObjectType;
  2848. switch (ObjectType) {
  2849. case SMBCEDB_OT_SERVER :
  2850. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_SERVER_ENTRY)) {
  2851. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2852. RxLog((" Ref ServerEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2853. }
  2854. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2855. DbgPrint(" Ref ServerEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2856. }
  2857. }
  2858. SmbLog(SERVER,MRxSmbRefServerEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2859. break;
  2860. case SMBCEDB_OT_NETROOT :
  2861. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_NETROOT_ENTRY)) {
  2862. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2863. RxLog((" Ref NetRootEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2864. }
  2865. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2866. DbgPrint(" Ref NetRootEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2867. }
  2868. }
  2869. SmbLog(NETROOT,MRxSmbRefNetRootEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2870. break;
  2871. case SMBCEDB_OT_SESSION :
  2872. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_SESSION_ENTRY)) {
  2873. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2874. RxLog((" Ref SessionEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2875. }
  2876. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2877. DbgPrint(" Ref SessionEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2878. }
  2879. }
  2880. SmbLog(SESSION,MRxSmbRefSessionEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2881. break;
  2882. case SMBCEDB_OT_VNETROOTCONTEXT :
  2883. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_VNETROOT_CONTEXT)) {
  2884. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2885. RxLog((" Ref VNetRootConext %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2886. }
  2887. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2888. DbgPrint(" Ref VNetRootContext %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2889. }
  2890. }
  2891. SmbLog(VNETROOT,MRxSmbRefVNetRootContext,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2892. break;
  2893. }
  2894. }
  2895. VOID
  2896. MRxSmbTrackDerefCount(
  2897. PVOID pInstance,
  2898. PCHAR FileName,
  2899. ULONG Line)
  2900. {
  2901. LONG State = ((PSMBCE_OBJECT_HEADER)pInstance)->State;
  2902. LONG RefCount = ((PSMBCE_OBJECT_HEADER)pInstance)->SwizzleCount;
  2903. SMBCEDB_OBJECT_TYPE ObjectType = ((PSMBCE_OBJECT_HEADER)pInstance)->ObjectType;
  2904. switch (ObjectType) {
  2905. case SMBCEDB_OT_SERVER :
  2906. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_SERVER_ENTRY)) {
  2907. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2908. RxLog(("Deref ServerEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2909. }
  2910. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2911. DbgPrint("Deref ServerEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2912. }
  2913. }
  2914. SmbLog(SERVER,MRxSmbDerefServerEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2915. break;
  2916. case SMBCEDB_OT_NETROOT :
  2917. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_NETROOT_ENTRY)) {
  2918. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2919. RxLog(("Deref NetRootEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2920. }
  2921. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2922. DbgPrint("Deref NetRootEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2923. }
  2924. }
  2925. SmbLog(NETROOT,MRxSmbDerefNetRootEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2926. break;
  2927. case SMBCEDB_OT_SESSION :
  2928. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_SESSION_ENTRY)) {
  2929. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2930. RxLog(("Deref SessionEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2931. }
  2932. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2933. DbgPrint("Deref SessionEntry %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2934. }
  2935. }
  2936. SmbLog(SESSION,MRxSmbDerefSessionEntry,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2937. break;
  2938. case SMBCEDB_OT_VNETROOTCONTEXT :
  2939. if (MRXSMB_REF_TRACING_ON(MRXSMB_REF_TRACE_VNETROOT_CONTEXT)) {
  2940. if (MRxSmbReferenceTracingValue & MRXSMB_LOG_REF_TRACKING) {
  2941. RxLog(("Deref VNetRootConext %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName));
  2942. }
  2943. if (MRxSmbReferenceTracingValue & MRXSMB_PRINT_REF_TRACKING) {
  2944. DbgPrint("Deref VNetRootContext %lx %d %d %ld %s\n",pInstance,State,RefCount,Line,FileName);
  2945. }
  2946. }
  2947. SmbLog(VNETROOT,MRxSmbDerefVNetRootContext,LOGPTR(pInstance)LOGULONG(State)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  2948. break;
  2949. }
  2950. }