Windows: Restrict redir trace buffer to 10240KB
[openafs.git] / src / WINNT / afsrdr / kernel / fs / AFSGeneric.cpp
index bc12bdb..27503bb 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
- * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Kernel Drivers, LLC.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Your File System, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * - Redistributions of source code must retain the above copyright notice,
  *   this list of conditions and the following disclaimer.
  * - Redistributions in binary form must reproduce the above copyright
- *   notice,
- *   this list of conditions and the following disclaimer in the
- *   documentation
- *   and/or other materials provided with the distribution.
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
  * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
  *   nor the names of their contributors may be used to endorse or promote
  *   products derived from this software without specific prior written
@@ -67,7 +65,7 @@ AFSExceptionFilter( IN CHAR *FunctionString,
 
         Context = ExceptPtrs->ContextRecord;
 
-        AFSDbgLogMsg( 0,
+        AFSDbgTrace(( 0,
                       0,
                       "AFSExceptionFilter (Framework) - EXR %p CXR %p Function %s Code %08lX Address %p Routine %p\n",
                       ExceptRec,
@@ -75,7 +73,7 @@ AFSExceptionFilter( IN CHAR *FunctionString,
                       FunctionString,
                       ExceptRec->ExceptionCode,
                       ExceptRec->ExceptionAddress,
-                      (void *)AFSExceptionFilter);
+                      (void *)AFSExceptionFilter));
 
         DbgPrint("**** Exception Caught in AFS Redirector ****\n");
 
@@ -217,11 +215,11 @@ AFSReleaseResource( IN PERESOURCE Resource)
     if( Resource != &AFSDbgLogLock)
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSReleaseResource Releasing lock %08lX Thread %08lX\n",
+                      "AFSReleaseResource Releasing lock %p Thread %08lX\n",
                       Resource,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
     }
 
     ExReleaseResourceLite( Resource);
@@ -235,11 +233,11 @@ void
 AFSConvertToShared( IN PERESOURCE Resource)
 {
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+    AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSConvertToShared Converting lock %08lX Thread %08lX\n",
+                  "AFSConvertToShared Converting lock %p Thread %08lX\n",
                   Resource,
-                  PsGetCurrentThread());
+                  PsGetCurrentThread()));
 
     ExConvertExclusiveToSharedLite( Resource);
 
@@ -419,10 +417,10 @@ AFSReadRegistry( IN PUNICODE_STRING RegistryPath)
             // Let's limit things a bit ...
             //
 
-            if( AFSDbgBufferLength > 10240)
+           if( AFSDbgBufferLength > AFS_DBG_LOG_MAXLENGTH)
             {
 
-                AFSDbgBufferLength = 1024;
+               AFSDbgBufferLength = AFS_DBG_LOG_MAXLENGTH;
             }
         }
         else
@@ -808,6 +806,14 @@ AFSInitializeControlDevice()
         pDeviceExt->Specific.Control.AuthGroupTree.TreeLock = &pDeviceExt->Specific.Control.AuthGroupTreeLock;
 
         pDeviceExt->Specific.Control.AuthGroupTree.TreeHead = NULL;
+
+        //
+        // Increase the StackSize to support the extra stack frame required
+        // for use of IoCompletion routines.
+        //
+
+        AFSDeviceObject->StackSize++;
+
     }
 
     return ntStatus;
@@ -1142,11 +1148,11 @@ AFSSetSysNameInformation( IN AFSSysNameNotificationCB *SysNameInfo,
         // Process the request
         //
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSSetSysNameInformation Acquiring SysName lock %08lX EXCL %08lX\n",
+                      "AFSSetSysNameInformation Acquiring SysName lock %p EXCL %08lX\n",
                       pSysNameLock,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         AFSAcquireExcl( pSysNameLock,
                         TRUE);
@@ -1327,6 +1333,11 @@ AFSSendDeviceIoControl( IN DEVICE_OBJECT *TargetDeviceObject,
         // Set the completion routine.
         //
 
+        AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "Setting AFSIrpComplete as IoCompletion Routine Irp %p\n",
+                      pIrp));
+
         IoSetCompletionRoutine( pIrp,
                                 AFSIrpComplete,
                                 &kEvent,
@@ -1452,13 +1463,13 @@ AFSExAllocatePoolWithTag( IN POOL_TYPE  PoolType,
             if ( bTimeout || pControlDevExt == NULL)
             {
 
-                AFSDbgLogMsg( 0,
+                AFSDbgTrace(( 0,
                               0,
                               "AFSExAllocatePoolWithTag failure Type %08lX Size %08lX Tag %08lX %08lX\n",
                               PoolType,
                               NumberOfBytes,
                               Tag,
-                              PsGetCurrentThread());
+                              PsGetCurrentThread()));
 
                 switch ( Tag ) {
 
@@ -1550,12 +1561,12 @@ AFSShutdownRedirector()
     __Enter
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "%s Shutting down redirector Extent count %08lX Request count %08lX\n",
                       __FUNCTION__,
                       pControlDevExt->Specific.Control.ExtentCount,
-                      pControlDevExt->Specific.Control.OutstandingServiceRequestCount);
+                      pControlDevExt->Specific.Control.OutstandingServiceRequestCount));
 
         //
         // Set the shutdown flag so the worker is more agressive in tearing down extents
@@ -1578,10 +1589,10 @@ AFSShutdownRedirector()
         if( ntStatus == STATUS_TIMEOUT)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_WARNING,
                           "AFSShutdownRedirector Failed to complete all service requests Remaining count %08lX\n",
-                          pControlDevExt->Specific.Control.OutstandingServiceRequestCount);
+                          pControlDevExt->Specific.Control.OutstandingServiceRequestCount));
 
             try_return( ntStatus = STATUS_UNSUCCESSFUL);
         }
@@ -1603,10 +1614,10 @@ AFSShutdownRedirector()
         if( ntStatus == STATUS_TIMEOUT)
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_WARNING,
                           "AFSShutdownRedirector Failed to purge all extents Remaining count %08lX\n",
-                          pControlDevExt->Specific.Control.ExtentCount);
+                          pControlDevExt->Specific.Control.ExtentCount));
 
             try_return( ntStatus = STATUS_UNSUCCESSFUL);
         }
@@ -1621,13 +1632,13 @@ AFSShutdownRedirector()
 
 try_exit:
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "%s Completed shut down of redirector Extent count %08lX Request count %08lX Status %08lX\n",
                       __FUNCTION__,
                       pControlDevExt->Specific.Control.ExtentCount,
                       pControlDevExt->Specific.Control.OutstandingServiceRequestCount,
-                      ntStatus);
+                      ntStatus));
     }
 
     return ntStatus;
@@ -1650,48 +1661,48 @@ AFSAcquireFcbForLazyWrite( IN PVOID Fcb,
     // Try and acquire the Fcb resource
     //
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+    AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSAcquireFcbForLazyWrite Acquiring Fcb %08lX\n",
-                  Fcb);
+                  "AFSAcquireFcbForLazyWrite Acquiring Fcb %p\n",
+                  Fcb));
 
     //
     // Try and grab the paging
     //
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+    AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %08lX SHARED %08lX\n",
+                  "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb PagingIo lock %p SHARED %08lX\n",
                   &pFcb->NPFcb->PagingResource,
-                  PsGetCurrentThread());
+                  PsGetCurrentThread()));
 
     if( AFSAcquireShared( &pFcb->NPFcb->PagingResource,
                           Wait))
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %08lX SHARED %08lX\n",
+                      "AFSAcquireFcbForLazyWrite Acquired Fcb PagingIo lock %p SHARED %08lX\n",
                       &pFcb->NPFcb->PagingResource,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         bReleasePaging = TRUE;
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      "AFSAcquireFcbForLazyWrite Attempt to acquire Fcb SectionObject lock %p SHARED %08lX\n",
                       &pFcb->NPFcb->SectionObjectResource,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                               Wait))
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSAcquireFcbForLazyWrite Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+                          "AFSAcquireFcbForLazyWrite Acquired Fcb SectionObject lock %p SHARED %08lX\n",
                           &pFcb->NPFcb->SectionObjectResource,
-                          PsGetCurrentThread());
+                          PsGetCurrentThread()));
 
             bReleaseSectionObject = TRUE;
 
@@ -1730,10 +1741,10 @@ AFSReleaseFcbFromLazyWrite( IN PVOID Fcb)
 
     AFSFcb *pFcb = (AFSFcb *)Fcb;
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+    AFSDbgTrace(( AFS_SUBSYSTEM_IO_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSReleaseFcbFromLazyWrite Releasing Fcb %08lX\n",
-                  Fcb);
+                  "AFSReleaseFcbFromLazyWrite Releasing Fcb %p\n",
+                  Fcb));
 
     IoSetTopLevelIrp( NULL);
 
@@ -1752,21 +1763,21 @@ AFSAcquireFcbForReadAhead( IN PVOID Fcb,
     BOOLEAN bStatus = FALSE;
     AFSFcb *pFcb = (AFSFcb *)Fcb;
 
-    AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+    AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
-                  "AFSAcquireFcbForReadAhead Attempt to acquire Fcb SectionObject lock %08lX SHARED %08lX\n",
+                  "AFSAcquireFcbForReadAhead Attempt to acquire Fcb SectionObject lock %p SHARED %08lX\n",
                   &pFcb->NPFcb->SectionObjectResource,
-                  PsGetCurrentThread());
+                  PsGetCurrentThread()));
 
     if( AFSAcquireShared( &pFcb->NPFcb->SectionObjectResource,
                           Wait))
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_LOCK_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSAcquireFcbForReadAhead Acquired Fcb SectionObject lock %08lX SHARED %08lX\n",
+                      "AFSAcquireFcbForReadAhead Acquired Fcb SectionObject lock %p SHARED %08lX\n",
                       &pFcb->NPFcb->SectionObjectResource,
-                      PsGetCurrentThread());
+                      PsGetCurrentThread()));
 
         bStatus = TRUE;
 
@@ -1818,9 +1829,9 @@ AFSGetCallerSID( OUT UNICODE_STRING *SIDString, OUT BOOLEAN *pbImpersonation)
             if( hToken == NULL)
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
-                              "AFSGetCallerSID Failed to retrieve impersonation or primary token\n");
+                              "AFSGetCallerSID Failed to retrieve impersonation or primary token\n"));
 
                 try_return( ntStatus);
             }
@@ -1835,9 +1846,10 @@ AFSGetCallerSID( OUT UNICODE_STRING *SIDString, OUT BOOLEAN *pbImpersonation)
         if( !NT_SUCCESS( ntStatus))
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSGetCallerSID Failed to retrieve information Status %08lX\n", ntStatus);
+                          "AFSGetCallerSID Failed to retrieve information Status %08lX\n",
+                          ntStatus));
 
             try_return( ntStatus);
         }
@@ -1853,19 +1865,20 @@ AFSGetCallerSID( OUT UNICODE_STRING *SIDString, OUT BOOLEAN *pbImpersonation)
         if( !NT_SUCCESS( ntStatus))
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSGetCallerSID Failed to convert sid to string Status %08lX\n", ntStatus);
+                          "AFSGetCallerSID Failed to convert sid to string Status %08lX\n",
+                          ntStatus));
 
             try_return( ntStatus);
         }
 
         *SIDString = uniSIDString;
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_AUTHGROUP_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_AUTHGROUP_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
                       "AFSGetCallerSID Successfully retrieved SID %wZ\n",
-                      SIDString);
+                      SIDString));
 
         if ( bPrimaryToken == FALSE &&
              pbImpersonation)
@@ -1925,9 +1938,9 @@ AFSGetSessionId( IN HANDLE ProcessId, OUT BOOLEAN *pbImpersonation)
             if( hToken == NULL)
             {
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
-                              "AFSGetSessionId Failed to retrieve impersonation or primary token\n");
+                              "AFSGetSessionId Failed to retrieve impersonation or primary token\n"));
 
                 try_return( ntStatus);
             }
@@ -1943,18 +1956,18 @@ AFSGetSessionId( IN HANDLE ProcessId, OUT BOOLEAN *pbImpersonation)
         {
             ulSessionId = (ULONG)-1;
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
                           "AFSGetSessionId Failed to retrieve session id Status %08lX\n",
-                          ntStatus);
+                          ntStatus));
 
             try_return( ntStatus);
         }
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_AUTHGROUP_PROCESSING,
+        AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_AUTHGROUP_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
                       "AFSGetSessionId found %08lX\n",
-                      ulSessionId);
+                      ulSessionId));
 
         if ( bPrimaryToken == FALSE &&
              pbImpersonation)
@@ -2219,4 +2232,58 @@ try_exit:
     return ntStatus;
 }
 
+NTSTATUS
+AFSSetReparsePointPolicy( IN AFSSetReparsePointPolicyCB *PolicyCB)
+{
+
+    NTSTATUS    ntStatus = STATUS_SUCCESS;
+    AFSDeviceExt* pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
+    ULONG       ulPolicy = 0;
+
+    __Enter
+    {
+
+       ulPolicy = (PolicyCB->Policy & AFS_REPARSE_POINT_VALID_POLICY_FLAGS);
+
+       if ( PolicyCB->Scope == AFS_REPARSE_POINT_POLICY_GLOBAL)
+       {
+
+           pDeviceExt->Specific.RDR.ReparsePointPolicy = ulPolicy;
+       }
+       else if ( PolicyCB->Scope == AFS_REPARSE_POINT_POLICY_AUTHGROUP)
+       {
+
+           ntStatus = STATUS_NOT_SUPPORTED;
+       }
+    }
+
+    return ntStatus;
+}
+
+
+NTSTATUS
+AFSGetReparsePointPolicy( OUT AFSGetReparsePointPolicyCB *PolicyCB)
+{
+
+    NTSTATUS    ntStatus = STATUS_SUCCESS;
+    AFSDeviceExt* pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
+
+    __Enter
+    {
+
+       PolicyCB->GlobalPolicy = pDeviceExt->Specific.RDR.ReparsePointPolicy;
+
+       //
+       // When per-AuthGroup or per-Process policies are permitted
+       // this function will need to query the policies when determining
+       // the active policy.
+       //
+
+       {
 
+           PolicyCB->ActivePolicy = PolicyCB->GlobalPolicy;
+       }
+    }
+
+    return ntStatus;
+}