Windows: Enforce Share Access
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSCreate.cpp
index bc1358f..c534890 100644 (file)
@@ -145,6 +145,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
     ULONG               ulParseFlags = 0;
     GUID                stAuthGroup;
     ULONG               ulNameProcessingFlags = 0;
+    BOOLEAN             bOpenedReparsePoint = FALSE;
 
     __Enter
     {
@@ -647,17 +648,31 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
             try_return( ntStatus);
         }
 
-        if ( BooleanFlagOn( ulOptions, FILE_OPEN_REPARSE_POINT) &&
-             pDirectoryCB != NULL &&
-             !BooleanFlagOn( pDirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
+        if ( BooleanFlagOn( ulOptions, FILE_OPEN_REPARSE_POINT))
         {
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                          AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSCommonCreate (%08lX) Reparse open request but attribute not set for %wZ Type %08lX\n",
-                          Irp,
-                          &uniFileName,
-                          pDirectoryCB->ObjectInformation->FileType);
+            if( pDirectoryCB == NULL ||
+                !BooleanFlagOn( pDirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
+            {
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCommonCreate (%08lX) Reparse open request but attribute not set for %wZ DirCB %p Type %08lX\n",
+                              Irp,
+                              &uniFileName,
+                              pDirectoryCB,
+                              pDirectoryCB ? pDirectoryCB->ObjectInformation->FileType : 0);
+            }
+            else
+            {
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCommonCreate (%08lX) Opening as reparse point %wZ Type %08lX\n",
+                              Irp,
+                              &uniFileName,
+                              pDirectoryCB->ObjectInformation->FileType);
+
+                bOpenedReparsePoint = TRUE;
+            }
         }
 
         //
@@ -1052,6 +1067,11 @@ try_exit:
                     }
                 }
 
+                if( bOpenedReparsePoint)
+                {
+                    SetFlag( pCcb->Flags, CCB_FLAG_MASK_OPENED_REPARSE_POINT);
+                }
+
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCreate Count on %wZ DE %p Ccb %p Cnt %d\n",
@@ -1447,7 +1467,7 @@ AFSOpenRoot( IN PIRP Irp,
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_ERROR,
-                          "AFSOpenRoot (%08lX) Failed to open file in service Status %08lX\n",
+                          "AFSOpenRoot (%08lX) Failed open in service AFSRoot Status %08lX\n",
                           Irp,
                           ntStatus);
 
@@ -2396,6 +2416,8 @@ AFSProcessOpen( IN PIRP Irp,
     ULONG       ulResultLen = 0;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    ULONG       ulFileAccess = 0;
+    AFSFileAccessReleaseCB stReleaseFileAccess;
 
     __Enter
     {
@@ -2646,6 +2668,10 @@ AFSProcessOpen( IN PIRP Irp,
 
         stOpenCB.ShareAccess = usShareAccess;
 
+        stOpenCB.ProcessId = (ULONGLONG)PsGetCurrentProcessId();
+
+        stOpenCB.Identifier = (ULONGLONG)pFileObject;
+
         stOpenResultCB.GrantedAccess = 0;
 
         ulResultLen = sizeof( AFSFileOpenResultCB);
@@ -2674,6 +2700,12 @@ AFSProcessOpen( IN PIRP Irp,
         }
 
         //
+        // Save the granted access in case we need to release it below
+        //
+
+        ulFileAccess = stOpenResultCB.FileAccess;
+
+        //
         // Check if there is a conflict
         //
 
@@ -2719,6 +2751,8 @@ AFSProcessOpen( IN PIRP Irp,
 
         (*Ccb)->DirectoryCB = DirectoryCB;
 
+        (*Ccb)->FileAccess = ulFileAccess;
+
         //
         // Perform the access check on the target if this is a mount point or symlink
         //
@@ -2836,6 +2870,26 @@ try_exit:
         if( !NT_SUCCESS( ntStatus))
         {
 
+            if ( ulFileAccess > 0)
+            {
+
+                stReleaseFileAccess.ProcessId = (ULONGLONG)PsGetCurrentProcessId();
+
+                stReleaseFileAccess.FileAccess = ulFileAccess;
+
+                stReleaseFileAccess.Identifier = (ULONGLONG)pFileObject;
+
+                AFSProcessRequest( AFS_REQUEST_TYPE_RELEASE_FILE_ACCESS,
+                                   AFS_REQUEST_FLAG_SYNCHRONOUS,
+                                   AuthGroup,
+                                   &DirectoryCB->NameInformation.FileName,
+                                   &pObjectInfo->FileId,
+                                   (void *)&stReleaseFileAccess,
+                                   sizeof( AFSFileAccessReleaseCB),
+                                   NULL,
+                                   NULL);
+            }
+
             if( bAllocatedCcb)
             {