[RDBSS]
[reactos.git] / reactos / sdk / lib / drivers / rdbsslib / rdbss.c
index 852c1c2..0f27fe9 100644 (file)
@@ -1328,6 +1328,7 @@ RxCheckFcbStructuresForAlignment(
     UNIMPLEMENTED;
 }
 
+#if DBG
 NTSTATUS
 RxCheckShareAccess(
     _In_ ACCESS_MASK DesiredAccess,
@@ -1345,6 +1346,7 @@ RxCheckShareAccess(
 
     return IoCheckShareAccess(DesiredAccess, DesiredShareAccess, FileObject, ShareAccess, Update);
 }
+#endif
 
 /*
  * @implemented
@@ -5291,6 +5293,7 @@ RxDriverEntry(
 #endif
 }
 
+#if DBG
 /*
  * @implemented
  */
@@ -5317,6 +5320,7 @@ RxDumpWantedAccess(
 {
     PAGED_CODE();
 }
+#endif
 
 /*
  * @implemented
@@ -5980,7 +5984,7 @@ RxFsdCommonDispatch(
                 Fobx = StackFileObject->FsContext2;
 
                 if (BooleanFlagOn(Fcb->FcbState, FCB_STATE_ORPHANED) ||
-                    BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_ORPHANED))
+                    ((Fobx != NULL) && BooleanFlagOn(Fobx->pSrvOpen->Flags, SRVOPEN_FLAG_ORPHANED)))
                 {
                     if (Closing)
                     {
@@ -7492,6 +7496,9 @@ Leave:
     return Status;
 }
 
+/*
+ * @implemented
+ */
 NTSTATUS
 NTAPI
 RxPrepareToReparseSymbolicLink(
@@ -7501,8 +7508,74 @@ RxPrepareToReparseSymbolicLink(
     BOOLEAN NewPathIsAbsolute,
     PBOOLEAN ReparseRequired)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PWSTR NewBuffer;
+    USHORT NewLength;
+    PFILE_OBJECT FileObject;
+
+    /* Assume no reparse is required first */
+    *ReparseRequired = FALSE;
+
+    /* Only supported for IRP_MJ_CREATE */
+    if (RxContext->MajorFunction != IRP_MJ_CREATE)
+    {
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    /* If symbolic link is not embedded, and DELETE is specified, fail */
+    if (!SymbolicLinkEmbeddedInOldPath)
+    {
+        /* Excepted if DELETE is the only flag specified, then, open has to succeed
+         * See: https://msdn.microsoft.com/en-us/library/windows/hardware/ff554649(v=vs.85).aspx (remarks)
+         */
+        if (BooleanFlagOn(RxContext->Create.NtCreateParameters.DesiredAccess, DELETE) &&
+            BooleanFlagOn(RxContext->Create.NtCreateParameters.DesiredAccess, ~DELETE))
+        {
+            return STATUS_ACCESS_DENIED;
+        }
+    }
+
+    /* At that point, assume reparse will be required */
+    *ReparseRequired = TRUE;
+
+    /* If new path isn't absolute, it's up to us to make it absolute */
+    if (!NewPathIsAbsolute)
+    {
+        /* The prefix will be \Device\Mup */
+        NewLength = NewPath->Length + (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL));
+        NewBuffer = ExAllocatePoolWithTag(PagedPool | POOL_COLD_ALLOCATION, NewLength,
+                                          RX_MISC_POOLTAG);
+        if (NewBuffer == NULL)
+        {
+            return STATUS_INSUFFICIENT_RESOURCES;
+        }
+
+        /* Copy data for the new path */
+        RtlMoveMemory(NewBuffer, L"\\Device\\Mup", (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL)));
+        RtlMoveMemory(Add2Ptr(NewBuffer, (sizeof(L"\\Device\\Mup") - sizeof(UNICODE_NULL))),
+                      NewPath->Buffer, NewPath->Length);
+    }
+    /* Otherwise, use caller path as it */
+    else
+    {
+        NewLength = NewPath->Length;
+        NewBuffer = NewPath->Buffer;
+    }
+
+    /* Get the FILE_OBJECT we'll modify */
+    FileObject = RxContext->CurrentIrpSp->FileObject;
+
+    /* Free old path first */
+    ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
+    /* And setup new one */
+    FileObject->FileName.Length = NewLength;
+    FileObject->FileName.MaximumLength = NewLength;
+    FileObject->FileName.Buffer = NewBuffer;
+
+    /* And set reparse flag */
+    SetFlag(RxContext->Create.Flags, RX_CONTEXT_CREATE_FLAG_REPARSE);
+
+    /* Done! */
+    return STATUS_SUCCESS;
 }
 
 /*
@@ -8170,6 +8243,7 @@ RxRemoveOverflowEntry(
     return Context;
 }
 
+#if DBG
 /*
  * @implemented
  */
@@ -8186,6 +8260,7 @@ RxRemoveShareAccess(
     IoRemoveShareAccess(FileObject, ShareAccess);
     RxDumpCurrentAccess(where, "after", wherelogtag, ShareAccess);
 }
+#endif
 
 /*
  * @implemented
@@ -8570,6 +8645,7 @@ RxSetRenameInfo(
     return STATUS_NOT_IMPLEMENTED;
 }
 
+#if DBG
 /*
  * @implemented
  */
@@ -8588,6 +8664,7 @@ RxSetShareAccess(
     IoSetShareAccess(DesiredAccess, DesiredShareAccess, FileObject, ShareAccess);
     RxDumpCurrentAccess(where, "after", wherelogtag, ShareAccess);
 }
+#endif
 
 NTSTATUS
 RxSetSimpleInfo(
@@ -8845,6 +8922,7 @@ RxTryToBecomeTheTopLevelIrp(
     return TRUE;
 }
 
+#if DBG
 /*
  * @implemented
  */
@@ -8861,6 +8939,7 @@ RxUpdateShareAccess(
     IoUpdateShareAccess(FileObject, ShareAccess);
     RxDumpCurrentAccess(where, "after", wherelogtag, ShareAccess);
 }
+#endif
 
 /*
  * @implemented