Windows: NPCancelConnection without drive letter
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSNetworkProviderSupport.cpp
index 26d3a6c..c6cd352 100644 (file)
@@ -47,27 +47,26 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSProviderConnectionCB *pConnection = NULL, *pLastConnection = NULL;
     UNICODE_STRING uniRemoteName;
-    USHORT usIndex = 0;
     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
 
     __Enter
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAddConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
+                      "AFSAddConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         if( ConnectCB->AuthenticationId.QuadPart == 0)
         {
 
             ConnectCB->AuthenticationId = AFSGetAuthenticationId();
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSAddConnection Retrieved authentication id %I64X\n",
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
@@ -116,21 +115,21 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( ConnectCB->LocalName != L'\0')
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local %C authentication id %I64X\n",
                               &uniRemoteName,
                               ConnectCB->LocalName,
-                              ConnectCB->AuthenticationId.QuadPart);
+                              ConnectCB->AuthenticationId.QuadPart));
             }
             else
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local (NULL) authentication id %I64X\n",
                               &uniRemoteName,
-                              ConnectCB->AuthenticationId.QuadPart);
+                              ConnectCB->AuthenticationId.QuadPart));
             }
 
             *ResultStatus = WN_ALREADY_CONNECTED;
@@ -165,21 +164,21 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
                 if( ConnectCB->LocalName != L'\0')
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                    AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local %C authentication id %I64X\n",
                                   &uniRemoteName,
                                   ConnectCB->LocalName,
-                                  ConnectCB->AuthenticationId.QuadPart);
+                                  ConnectCB->AuthenticationId.QuadPart));
                 }
                 else
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                    AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local (NULL) authentication id %I64X\n",
                                   &uniRemoteName,
-                                  ConnectCB->AuthenticationId.QuadPart);
+                                  ConnectCB->AuthenticationId.QuadPart));
                 }
 
                 *ResultStatus = WN_BAD_NETNAME;
@@ -199,21 +198,21 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
                 if( ConnectCB->LocalName != L'\0')
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                    AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local %C authentication id %I64X\n",
                                   &uniRemoteName,
                                   ConnectCB->LocalName,
-                                  ConnectCB->AuthenticationId.QuadPart);
+                                  ConnectCB->AuthenticationId.QuadPart));
                 }
                 else
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                    AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local (NULL) authentication id %I64X\n",
                                   &uniRemoteName,
-                                  ConnectCB->AuthenticationId.QuadPart);
+                                  ConnectCB->AuthenticationId.QuadPart));
                 }
 
                 *ResultStatus = WN_BAD_NETNAME;
@@ -231,21 +230,21 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( ConnectCB->LocalName != L'\0')
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local %C authentication id %I64X\n",
                               &uniRemoteName,
                               ConnectCB->LocalName,
-                              ConnectCB->AuthenticationId.QuadPart);
+                              ConnectCB->AuthenticationId.QuadPart));
             }
             else
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local (NULL) authentication id %I64X\n",
                               &uniRemoteName,
-                              ConnectCB->AuthenticationId.QuadPart);
+                              ConnectCB->AuthenticationId.QuadPart));
             }
 
             *ResultStatus = WN_BAD_NETNAME;
@@ -310,21 +309,21 @@ AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( ConnectCB->LocalName != L'\0')
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSAddConnection Adding connection remote name %wZ Local %C authentication id %I64X\n",
                           &uniRemoteName,
                           ConnectCB->LocalName,
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
         else
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSAddConnection Adding connection remote name %wZ Local (NULL) authentication id %I64X\n",
                           &uniRemoteName,
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         //
@@ -416,21 +415,21 @@ AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         ConnectionResult->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSCancelConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
+                      "AFSCancelConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         if( ConnectCB->AuthenticationId.QuadPart == 0)
         {
 
             ConnectCB->AuthenticationId = AFSGetAuthenticationId();
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCancelConnection Retrieved authentication id %I64X\n",
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
@@ -459,18 +458,20 @@ AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( ( ConnectCB->LocalName != L'\0' &&
                   pConnection->LocalName == ConnectCB->LocalName)
                 ||
-                ( RtlCompareUnicodeString( &uniRemoteName,
+                ( ConnectCB->LocalName == L'\0' &&
+                  pConnection->LocalName == L'\0' &&
+                  RtlCompareUnicodeString( &uniRemoteName,
                                            &pConnection->RemoteName,
                                            TRUE) == 0))
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCancelConnection Checking remote name %wZ to stored %wZ authentication id %I64X - %I64X\n",
                               &uniRemoteName,
                               &pConnection->RemoteName,
                               ConnectCB->AuthenticationId.QuadPart,
-                              pConnection->AuthenticationId.QuadPart);
+                              pConnection->AuthenticationId.QuadPart));
 
                 if( ConnectCB->AuthenticationId.QuadPart == pConnection->AuthenticationId.QuadPart &&
                     ( ConnectCB->LocalName == L'\0' ||
@@ -512,12 +513,12 @@ AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection->Comment.Buffer != NULL)
         {
 
-            AFSExFreePool( pConnection->Comment.Buffer);
+            AFSExFreePoolWithTag( pConnection->Comment.Buffer, 0);
         }
 
         ConnectionResult->LocalName = pConnection->LocalName;
 
-        AFSExFreePool( pConnection);
+        AFSExFreePoolWithTag( pConnection, AFS_PROVIDER_CB);
 
         ConnectionResult->Status = WN_SUCCESS;
 
@@ -548,36 +549,36 @@ AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( ConnectCB->LocalName != L'\0')
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnection Local %C authentication id %I64X\n",
                           ConnectCB->LocalName,
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
         else
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnection Local (NULL) authentication id %I64X\n",
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSGetConnection Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSGetConnection Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         if( ConnectCB->AuthenticationId.QuadPart == 0)
         {
 
             ConnectCB->AuthenticationId = AFSGetAuthenticationId();
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnection Retrieved authentication id %I64X\n",
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
@@ -595,23 +596,23 @@ AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( pConnection->LocalName != L'\0')
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetConnection Comparing passed in %C to %C authentication id %I64X - %I64X\n",
                               ConnectCB->LocalName,
                               pConnection->LocalName,
                               ConnectCB->AuthenticationId.QuadPart,
-                              pConnection->AuthenticationId.QuadPart);
+                              pConnection->AuthenticationId.QuadPart));
             }
             else
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetConnection Comparing passed in %C to (NULL) authentication id %I64X - %I64X\n",
                               ConnectCB->LocalName,
                               ConnectCB->AuthenticationId.QuadPart,
-                              pConnection->AuthenticationId.QuadPart);
+                              pConnection->AuthenticationId.QuadPart));
             }
 
             if( pConnection->LocalName == ConnectCB->LocalName &&
@@ -627,9 +628,9 @@ AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection == NULL)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnection INVALID_PARAMETER\n");
+                          "AFSGetConnection INVALID_PARAMETER\n"));
 
             try_return( ntStatus = STATUS_INVALID_PARAMETER);
         }
@@ -637,9 +638,9 @@ AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( RemoteNameBufferLength < pConnection->RemoteName.Length)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnection INSUFFICIENT_RESOURCES\n");
+                          "AFSGetConnection INSUFFICIENT_RESOURCES\n"));
 
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
@@ -690,10 +691,10 @@ AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
 
             ConnectCB->AuthenticationId = AFSGetAuthenticationId();
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSListConnections Retrieved authentication id %I64X\n",
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         liAuthenticationID.QuadPart = ConnectCB->AuthenticationId.QuadPart;
@@ -774,11 +775,11 @@ AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             }
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSListConnections Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSListConnections Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
                           TRUE);
@@ -871,25 +872,25 @@ AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             if( pConnection->LocalName != L'\0')
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSListConnections Processing entry %wZ %C authentication id %I64X - %I64X Scope %08lX\n",
                               &pConnection->RemoteName,
                               pConnection->LocalName,
                               liAuthenticationID.QuadPart,
                               pConnection->AuthenticationId.QuadPart,
-                              pConnection->Scope);
+                              pConnection->Scope));
             }
             else
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSListConnections Processing entry %wZ NULL LocalName authentication id %I64X - %I64X Scope %08lX\n",
                               &pConnection->RemoteName,
                               liAuthenticationID.QuadPart,
                               pConnection->AuthenticationId.QuadPart,
-                              pConnection->Scope);
+                              pConnection->Scope));
             }
 
             if( ulScope != RESOURCE_GLOBALNET &&
@@ -983,7 +984,7 @@ try_exit:
         if( uniRemoteName.Buffer != NULL)
         {
 
-            AFSExFreePool( uniRemoteName.Buffer);
+            AFSExFreePoolWithTag( uniRemoteName.Buffer, 0);
         }
     }
 
@@ -1184,7 +1185,7 @@ AFSLocateEnumRootEntry( IN UNICODE_STRING *RemoteName)
 {
 
     AFSProviderConnectionCB *pConnection = NULL;
-    UNICODE_STRING uniServerName, uniRemoteName = *RemoteName;
+    UNICODE_STRING uniRemoteName = *RemoteName;
     AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
 
     __Enter
@@ -1228,13 +1229,11 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
-    AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     ULONG ulCRC = 0, ulCopiedLength = 0;
     AFSDirectoryCB *pShareDirEntry = NULL;
     AFSDirectoryCB *pDirEntry = NULL, *pTargetDirEntry = NULL;
     ULONG ulIndex = 0;
-    BOOLEAN bContinueProcessing = TRUE;
-    AFSFileInfoCB stFileInformation;
+    LONG lCount;
 
     __Enter
     {
@@ -1242,9 +1241,9 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
         if( AFSGlobalRoot == NULL)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSEnumerateConnection Global root not yet initialized\n");
+                          "AFSEnumerateConnection Global root not yet initialized\n"));
 
             try_return( ntStatus = STATUS_DEVICE_NOT_READY);
         }
@@ -1256,11 +1255,11 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
         // Grab our tree lock shared
         //
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %08lX SHARED %08lX\n",
+                      "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %p SHARED %08lX\n",
                       AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         AFSAcquireShared( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
                           TRUE);
@@ -1298,20 +1297,21 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             }
         }
 
-        InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pShareDirEntry->DirOpenReferenceCount);
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEnumerateConnection1 Increment count on %wZ DE %p Ccb %p Cnt %d\n",
                       &pShareDirEntry->NameInformation.FileName,
                       pShareDirEntry,
                       NULL,
-                      pShareDirEntry->OpenReferenceCount);
+                      lCount));
 
         AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
         //
         // Setup the request to evaluate the entry
+        // On success, pTargetDirEntry has the DirOpenReferenceCount held
         //
 
         ntStatus = AFSEvaluateRootEntry( pShareDirEntry,
@@ -1394,15 +1394,21 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
         }
 
-        InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+        //
+        // Release the DirOpenReferenceCount obtained from AFSEvaluateRootEntry
+        //
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+        lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
+
+        AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEnumerateConnection Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
-                                                    &pTargetDirEntry->NameInformation.FileName,
-                                                    pTargetDirEntry,
-                                                    NULL,
-                                                    pTargetDirEntry->OpenReferenceCount);
+                      &pTargetDirEntry->NameInformation.FileName,
+                      pTargetDirEntry,
+                      NULL,
+                      lCount));
+
+        ASSERT( lCount >= 0);
 
         *CopiedLength = ulCopiedLength;
 
@@ -1412,7 +1418,17 @@ try_exit:
 
         if( pShareDirEntry != NULL)
         {
-            InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pShareDirEntry->DirOpenReferenceCount);
+
+            AFSDbgTrace(( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSEnumerateConnection1 Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pShareDirEntry->NameInformation.FileName,
+                          pShareDirEntry,
+                          NULL,
+                          lCount));
+
+            ASSERT( lCount >= 0);
         }
     }
 
@@ -1454,34 +1470,34 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( ConnectCB->LocalName != L'\0')
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnectionInfo remote name %wZ Local %C authentication id %I64X\n",
                           &uniRemoteName,
                           ConnectCB->LocalName,
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
         else
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnectionInfo remote name %wZ Local (NULL) authentication id %I64X\n",
                           &uniRemoteName,
-                          ConnectCB->AuthenticationId.QuadPart);
+                          ConnectCB->AuthenticationId.QuadPart));
         }
 
         if( AFSGlobalRoot == NULL)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSGetConnectionInfo Global root not yet initialized\n");
+                          "AFSGetConnectionInfo Global root not yet initialized\n"));
 
             try_return( ntStatus = STATUS_DEVICE_NOT_READY);
         }
 
-               uniFullName = uniRemoteName;
+        uniFullName = uniRemoteName;
 
         if( uniRemoteName.Buffer[ 0] == L'\\' &&
             uniRemoteName.Buffer[ 1] == L'\\')
@@ -1500,9 +1516,10 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             uniFullName.Length -= sizeof( WCHAR);
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+        AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSGetConnectionInfo Processing name %wZ\n", &uniFullName);
+                      "AFSGetConnectionInfo Processing name %wZ\n",
+                      &uniFullName));
 
         FsRtlDissectName( uniRemoteName,
                           &uniServerName,
@@ -1548,9 +1565,9 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( uniRemainingPathLocal.Buffer == NULL)
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n");
+                              "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n"));
 
                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
             }
@@ -1563,11 +1580,11 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
                            uniRemainingPath.Length);
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                      "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                       &pRDRDevExt->Specific.RDR.ProviderListLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
                           TRUE);
@@ -1594,9 +1611,10 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
             pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnectionInfo Searching for full name %wZ\n", &uniFullName);
+                          "AFSGetConnectionInfo Searching for full name %wZ\n",
+                          &uniFullName));
 
             while( pConnection != NULL)
             {
@@ -1619,9 +1637,10 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
                         pBestMatch = pConnection;
 
-                        AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                        AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                                       AFS_TRACE_LEVEL_VERBOSE,
-                                      "AFSGetConnectionInfo Found match for %wZ\n", &pConnection->RemoteName);
+                                      "AFSGetConnectionInfo Found match for %wZ\n",
+                                      &pConnection->RemoteName));
                     }
 
                     uniFullName.Length = usNameLen;
@@ -1637,9 +1656,10 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
                 bEnumerationEntry = TRUE;
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSGetConnectionInfo Using best match for %wZ\n", &pConnection->RemoteName);
+                              "AFSGetConnectionInfo Using best match for %wZ\n",
+                              &pConnection->RemoteName));
             }
 
             if( pConnection == NULL)
@@ -1656,12 +1676,12 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection == NULL)
         {
             UNICODE_STRING uniFullName;
-            AFSFileID stFileID;
             AFSDirEnumEntry *pDirEnumEntry = NULL;
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnectionInfo No connection for full name %wZ\n", &uniFullName);
+                          "AFSGetConnectionInfo No connection for full name %wZ\n",
+                          &uniFullName));
 
             //
             // Drop the lock, we will pick it up again later
@@ -1670,27 +1690,22 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
 
             //
-            // Perform a case insensitive search
-            //
-
-            //
             // OK, ask the CM about this component name
             //
 
-            stFileID = AFSGlobalRoot->ObjectInformation.FileId;
-
             ntStatus = AFSEvaluateTargetByName( NULL,
-                                                &stFileID,
+                                                &AFSGlobalRoot->ObjectInformation,
                                                 &uniShareName,
+                                                0,
                                                 &pDirEnumEntry);
 
             if( !NT_SUCCESS( ntStatus))
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetConnectionInfo Evaluation Failed share name %wZ\n",
-                              uniShareName);
+                              uniShareName));
 
                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
 
@@ -1700,7 +1715,7 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             // Don't need this
             //
 
-            AFSExFreePool( pDirEnumEntry);
+            AFSExFreePoolWithTag( pDirEnumEntry, AFS_GENERIC_MEMORY_3_TAG);
 
             //
             // The share name is valid
@@ -1716,9 +1731,9 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
             if( uniFullName.Buffer == NULL)
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+                AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n");
+                              "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n"));
 
                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
             }
@@ -1753,13 +1768,13 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
             AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
-            AFSExFreePool( uniFullName.Buffer);
+            AFSExFreePoolWithTag( uniFullName.Buffer, 0);
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
+                          "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
                           &pRDRDevExt->Specific.RDR.ProviderListLock,
-                          PsGetCurrentThread());
+                          PsGetCurrentThread()));
 
             AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
                               TRUE);
@@ -1778,9 +1793,10 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
         if( pConnection == NULL)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSGetConnectionInfo Failed to locate entry for full name %wZ\n", &uniFullName);
+                          "AFSGetConnectionInfo Failed to locate entry for full name %wZ\n",
+                          &uniFullName));
 
             AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
 
@@ -1797,20 +1813,20 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
                                                 uniRemainingPath.Length)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+            AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetConnectionInfo Buffer too small for full name %wZ\n",
-                          &uniFullName);
+                          &uniFullName));
 
             AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
 
             try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+        AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSGetConnectionInfo Returning entry Scope %08lX partial name %wZ full name %wZ\n",
-                      pConnection->Scope, &pConnection->RemoteName, &uniFullName);
+                      pConnection->Scope, &pConnection->RemoteName, &uniFullName));
 
         ConnectCB->RemoteNameLength = pConnection->RemoteName.Length;
 
@@ -1843,12 +1859,12 @@ AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
 
         ConnectCB->RemainingPathLength = uniRemainingPathLocal.Length;
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
+        AFSDbgTrace(( AFS_SUBSYSTEM_NETWORK_PROVIDER,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSGetConnectionInfo Returning lengths: remote %u comment %u remaining %u\n",
                       ConnectCB->RemoteNameLength,
                       ConnectCB->CommentLength,
-                      ConnectCB->RemainingPathLength);
+                      ConnectCB->RemainingPathLength));
 
         if( ConnectCB->CommentLength > 0)
         {
@@ -1885,7 +1901,7 @@ try_exit:
         if ( uniRemainingPathLocal.Buffer )
         {
 
-            AFSExFreePool( uniRemainingPathLocal.Buffer);
+            AFSExFreePoolWithTag( uniRemainingPathLocal.Buffer, 0);
         }
     }