Compare commits

...

7 Commits

Author SHA1 Message Date
EdgeArcher129840 d0a71ec8d8
Merge ab8ff691d1 into d99e556f29 2024-04-28 20:28:41 +03:00
DavidXanatos d99e556f29 Update file_del.c 2024-04-28 16:46:12 +02:00
DavidXanatos e194528cb8 fix 2024-04-28 16:40:14 +02:00
DavidXanatos 846a3ea29e Update file_link.c 2024-04-28 16:38:38 +02:00
DavidXanatos 4a8650ca9d refactory 2024-04-28 16:36:37 +02:00
DavidXanatos bda087c1a6 Update file_dir.c 2024-04-28 15:20:23 +02:00
DavidXanatos f5070bbe81 symlink fix 2024-04-28 15:19:13 +02:00
5 changed files with 120 additions and 80 deletions

View File

@ -118,6 +118,9 @@ SBIEDLL_EXPORT NTSTATUS File_GetName(
HANDLE RootDirectory, UNICODE_STRING *ObjectName,
WCHAR **OutTruePath, WCHAR **OutCopyPath, ULONG *OutFlags);
static WCHAR *File_TranslateDosToNtPath2(
const WCHAR *DosPath, ULONG DosPathLen);
static WCHAR *File_GetName_TranslateSymlinks(
THREAD_DATA *TlsData, const WCHAR *objname_buf, ULONG objname_len,
BOOLEAN *translated);
@ -262,6 +265,12 @@ static NTSTATUS File_NtDeleteFile(OBJECT_ATTRIBUTES *ObjectAttributes);
static NTSTATUS File_NtDeleteFileImpl(OBJECT_ATTRIBUTES *ObjectAttributes);
static WCHAR *File_ConcatPath2(
const WCHAR *Path1, ULONG Path1Len, const WCHAR *Path2, ULONG Path2Len);
static WCHAR* File_CanonizePath(
const wchar_t* absolute_path, ULONG abs_path_len, const wchar_t* relative_path, ULONG rel_path_len);
static NTSTATUS File_OpenForRenameFile(
HANDLE* pSourceHandle, const WCHAR *TruePath);

View File

@ -549,11 +549,11 @@ _FX VOID File_SavePathTree_internal(LIST* Root, const WCHAR* name, WCHAR* (*Tran
//---------------------------------------------------------------------------
// File_TranslateNtToDosPath2
// File_TranslateNtToDosPathForDatFile
//---------------------------------------------------------------------------
_FX WCHAR* File_TranslateNtToDosPath2(const WCHAR *NtPath)
_FX WCHAR* File_TranslateNtToDosPathForDatFile(const WCHAR *NtPath)
{
WCHAR *DosPath = NULL;
ULONG len_nt;
@ -635,7 +635,7 @@ _FX BOOLEAN File_SavePathTree()
{
EnterCriticalSection(File_PathRoot_CritSec);
File_SavePathTree_internal(&File_PathRoot, FILE_PATH_FILE_NAME, File_TranslateNtToDosPath2);
File_SavePathTree_internal(&File_PathRoot, FILE_PATH_FILE_NAME, File_TranslateNtToDosPathForDatFile);
File_GetAttributes_internal(FILE_PATH_FILE_NAME, &File_PathsFileSize, &File_PathsFileDate, NULL);
@ -764,14 +764,13 @@ _FX BOOLEAN File_LoadPathTree_internal(LIST* Root, const WCHAR* name, WCHAR* (*T
//---------------------------------------------------------------------------
// File_TranslateDosToNtPath2
// File_TranslateDosToNtPathForDatFile
//---------------------------------------------------------------------------
_FX WCHAR *File_TranslateDosToNtPath2(const WCHAR *DosPath)
_FX WCHAR *File_TranslateDosToNtPathForDatFile(const WCHAR *DosPath)
{
WCHAR *NtPath = NULL;
ULONG len_dos;
if (DosPath && DosPath[0] && DosPath[1]) {
@ -782,10 +781,7 @@ _FX WCHAR *File_TranslateDosToNtPath2(const WCHAR *DosPath)
//
DosPath += 2;
len_dos = wcslen(DosPath) + 1;
NtPath = Dll_Alloc((File_MupLen + len_dos) * sizeof(WCHAR));
wmemcpy(NtPath, File_Mup, File_MupLen);
wmemcpy(NtPath + File_MupLen, DosPath, len_dos);
NtPath = File_ConcatPath2(File_Mup, File_MupLen, DosPath, wcslen(DosPath));
} else if (DosPath[0] != L'\\') {
@ -815,10 +811,7 @@ _FX WCHAR *File_TranslateDosToNtPath2(const WCHAR *DosPath)
}
DosPath += path_pos;
len_dos = wcslen(DosPath) + 1;
NtPath = Dll_Alloc((drive->len + len_dos) * sizeof(WCHAR));
wmemcpy(NtPath, drive->path, drive->len);
wmemcpy(NtPath + drive->len, DosPath, len_dos);
NtPath = File_ConcatPath2(drive->path, drive->len, DosPath, wcslen(DosPath));
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
@ -841,7 +834,7 @@ _FX BOOLEAN File_LoadPathTree()
EnterCriticalSection(File_PathRoot_CritSec);
File_LoadPathTree_internal(&File_PathRoot, FILE_PATH_FILE_NAME, File_TranslateDosToNtPath2);
File_LoadPathTree_internal(&File_PathRoot, FILE_PATH_FILE_NAME, File_TranslateDosToNtPathForDatFile);
LeaveCriticalSection(File_PathRoot_CritSec);
@ -1038,7 +1031,7 @@ _FX NTSTATUS File_MarkDeleted_v2(const WCHAR* TruePath)
HANDLE hPathsFile;
if (File_OpenDataFile(FILE_PATH_FILE_NAME, &hPathsFile, TRUE))
{
File_AppendPathEntry_internal(hPathsFile, Path, FILE_DELETED_FLAG, NULL, File_TranslateNtToDosPath2);
File_AppendPathEntry_internal(hPathsFile, Path, FILE_DELETED_FLAG, NULL, File_TranslateNtToDosPathForDatFile);
NtClose(hPathsFile);

View File

@ -3353,9 +3353,17 @@ _FX NTSTATUS File_SetReparsePoint(
//TargetPath = Dll_Alloc((wcslen(CopyPath) + 4) * sizeof(WCHAR));
//wcscpy(TargetPath, CopyPath);
WCHAR* NewSubstituteNameBuffer = CopyPath;
WCHAR* OldPrintNameBuffer = PrintNameBuffer; // we don't need to change the display name
if (Data->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
SubstituteNameLength = wcslen(CopyPath) * sizeof(WCHAR);
SbieDll_TranslateNtToDosPath(NewSubstituteNameBuffer);
memmove(NewSubstituteNameBuffer + 4, NewSubstituteNameBuffer, (wcslen(NewSubstituteNameBuffer) + 1) * sizeof(wchar_t));
wcsncpy(NewSubstituteNameBuffer, L"\\??\\", 4);
}
SubstituteNameLength = wcslen(NewSubstituteNameBuffer) * sizeof(WCHAR);
NewDataLen += SubstituteNameLength + sizeof(WCHAR) + PrintNameLength + sizeof(WCHAR) + 8;
NewData = Dll_Alloc(NewDataLen);
@ -3385,7 +3393,7 @@ _FX NTSTATUS File_SetReparsePoint(
PrintNameBuffer = &NewData->MountPointReparseBuffer.PathBuffer[NewData->MountPointReparseBuffer.PrintNameOffset/sizeof(WCHAR)];
}
memcpy(SubstituteNameBuffer, CopyPath, SubstituteNameLength + sizeof(WCHAR));
memcpy(SubstituteNameBuffer, NewSubstituteNameBuffer, SubstituteNameLength + sizeof(WCHAR));
memcpy(PrintNameBuffer, OldPrintNameBuffer, PrintNameLength + sizeof(WCHAR));
} __except (EXCEPTION_EXECUTE_HANDLER) {

View File

@ -1665,14 +1665,29 @@ _FX WCHAR *File_AllocAndInitEnvironment_2(
//---------------------------------------------------------------------------
// File_TranslateDosToNtPath
// File_ConcatPath2
//---------------------------------------------------------------------------
_FX WCHAR *File_TranslateDosToNtPath(const WCHAR *DosPath)
_FX WCHAR *File_ConcatPath2(const WCHAR *Path1, ULONG Path1Len, const WCHAR *Path2, ULONG Path2Len)
{
ULONG Length = Path1Len + Path2Len;
WCHAR* Path = Dll_Alloc((Length + 1) * sizeof(WCHAR));
wmemcpy(Path, Path1, Path1Len);
wmemcpy(Path + Path1Len, Path2, Path2Len);
Path[Length] = L'\0';
return Path;
}
//---------------------------------------------------------------------------
// File_TranslateDosToNtPath2
//---------------------------------------------------------------------------
_FX WCHAR *File_TranslateDosToNtPath2(const WCHAR *DosPath, ULONG DosPathLen)
{
WCHAR *NtPath = NULL;
ULONG len_dos;
if (DosPath && DosPath[0] && DosPath[1]) {
@ -1682,11 +1697,7 @@ _FX WCHAR *File_TranslateDosToNtPath(const WCHAR *DosPath)
// network path
//
DosPath += 2;
len_dos = wcslen(DosPath) + 1;
NtPath = Dll_Alloc((File_MupLen + len_dos) * sizeof(WCHAR));
wmemcpy(NtPath, File_Mup, File_MupLen);
wmemcpy(NtPath + File_MupLen, DosPath, len_dos);
NtPath = File_ConcatPath2(File_Mup, File_MupLen, DosPath + 2, DosPathLen - 2);
} else if (DosPath[1] == L':' &&
(DosPath[2] == L'\\' || DosPath[2] == L'\0')) {
@ -1698,11 +1709,7 @@ _FX WCHAR *File_TranslateDosToNtPath(const WCHAR *DosPath)
FILE_DRIVE *drive = File_GetDriveForLetter(DosPath[0]);
if (drive) {
DosPath += 2;
len_dos = wcslen(DosPath) + 1;
NtPath = Dll_Alloc((drive->len + len_dos) * sizeof(WCHAR));
wmemcpy(NtPath, drive->path, drive->len);
wmemcpy(NtPath + drive->len, DosPath, len_dos);
NtPath = File_ConcatPath2(drive->path, drive->len, DosPath + 2, DosPathLen - 2);
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
@ -1713,6 +1720,17 @@ _FX WCHAR *File_TranslateDosToNtPath(const WCHAR *DosPath)
}
//---------------------------------------------------------------------------
// File_TranslateDosToNtPath
//---------------------------------------------------------------------------
_FX WCHAR *File_TranslateDosToNtPath(const WCHAR *DosPath)
{
return File_TranslateDosToNtPath2(DosPath, DosPath ? wcslen(DosPath) : 0);
}
//---------------------------------------------------------------------------
// File_GetSetDeviceMap
//---------------------------------------------------------------------------

View File

@ -322,35 +322,45 @@ _FX FILE_GUID *File_GetLinkForGuid(const WCHAR* guid_str)
}
//---------------------------------------------------------------------------
// File_TranslateGuidToNtPath2
//---------------------------------------------------------------------------
_FX WCHAR* File_TranslateGuidToNtPath2(const WCHAR* GuidPath, ULONG GuidPathLen)
{
WCHAR* NtPath = NULL;
if (GuidPath && GuidPathLen >= 48 && _wcsnicmp(GuidPath, L"\\??\\Volume{", 11) == 0) {
//
// guid path
//
FILE_GUID* guid = File_GetLinkForGuid(&GuidPath[10]);
if (guid) {
File_ConcatPath2(guid->path, guid->len, GuidPath + 48, GuidPathLen - 48);
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
}
return NtPath;
}
//---------------------------------------------------------------------------
// File_TranslateGuidToNtPath
//---------------------------------------------------------------------------
_FX WCHAR* File_TranslateGuidToNtPath(const WCHAR* input_str)
_FX WCHAR* File_TranslateGuidToNtPath(const WCHAR* GuidPath)
{
ULONG len;
WCHAR* NtPath;
if (_wcsnicmp(input_str, L"\\??\\Volume{", 11) != 0)
return NULL;
FILE_GUID* guid = File_GetLinkForGuid(&input_str[10]);
if (guid) {
input_str += 48;
len = wcslen(input_str) + 1;
NtPath = Dll_Alloc((guid->len + len) * sizeof(WCHAR));
wmemcpy(NtPath, guid->path, guid->len);
wmemcpy(NtPath + guid->len, input_str, len);
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
return NtPath;
}
return NULL;
return File_TranslateGuidToNtPath2(GuidPath, GuidPath ? wcslen(GuidPath) : 0);
}
//---------------------------------------------------------------------------
// File_AddLink
//---------------------------------------------------------------------------
@ -1036,47 +1046,49 @@ _FX FILE_LINK *File_AddTempLink(WCHAR *path)
if (NT_SUCCESS(status)) {
WCHAR* SubstituteNameBuffer = NULL;
//WCHAR* PrintNameBuffer = NULL;
ULONG SubstituteNameLength = 0;
BOOL RelativePath = FALSE;
if (reparseDataBuffer->ReparseTag == IO_REPARSE_TAG_SYMLINK)
{
if (reparseDataBuffer->ReparseTag == IO_REPARSE_TAG_SYMLINK) {
SubstituteNameBuffer = &reparseDataBuffer->SymbolicLinkReparseBuffer.PathBuffer[reparseDataBuffer->SymbolicLinkReparseBuffer.SubstituteNameOffset/sizeof(WCHAR)];
if (reparseDataBuffer->SymbolicLinkReparseBuffer.Flags & SYMLINK_FLAG_RELATIVE)
RelativePath = TRUE;
SubstituteNameBuffer[reparseDataBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR)] = 0;
}
else if (reparseDataBuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT)
{
SubstituteNameLength = reparseDataBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength;
} else if (reparseDataBuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) {
SubstituteNameBuffer = &reparseDataBuffer->MountPointReparseBuffer.PathBuffer[reparseDataBuffer->MountPointReparseBuffer.SubstituteNameOffset/sizeof(WCHAR)];
SubstituteNameBuffer[reparseDataBuffer->MountPointReparseBuffer.SubstituteNameLength / sizeof(WCHAR)] = 0;
SubstituteNameLength = reparseDataBuffer->MountPointReparseBuffer.SubstituteNameLength;
}
if (SubstituteNameBuffer)
{
if (RelativePath)
{
// todo RelativePath - for now we fall back to the old method
}
else
{
WCHAR* input_str = SubstituteNameBuffer;
if (SubstituteNameBuffer) {
WCHAR* input_str = NULL;
if (RelativePath) {
WCHAR* LinkName = wcsrchr(path, L'\\');
input_str = File_CanonizePath(path, (ULONG)(LinkName - path), SubstituteNameBuffer, SubstituteNameLength / sizeof(WCHAR));
} else {
input_str = SubstituteNameBuffer;
if (_wcsnicmp(input_str, L"\\??\\Volume{", 11) == 0)
input_str = File_TranslateGuidToNtPath(SubstituteNameBuffer);
input_str = File_TranslateGuidToNtPath2(SubstituteNameBuffer, SubstituteNameLength / sizeof(WCHAR));
else if (_wcsnicmp(input_str, File_BQQB, 4) == 0)
input_str = File_TranslateDosToNtPath(SubstituteNameBuffer + 4);
input_str = File_TranslateDosToNtPath2(SubstituteNameBuffer + 4, SubstituteNameLength / sizeof(WCHAR));
}
if (input_str) {
if (input_str) {
ULONG input_len = wcslen(input_str);
while (input_len > 0 && input_str[input_len - 1] == L'\\')
input_len -= 1; // remove trailing backslash
ULONG input_len = wcslen(input_str);
while (input_len > 0 && input_str[input_len - 1] == L'\\')
input_len -= 1; // remove trailing backslash
newpath = File_TranslateTempLinks_2(input_str, input_len);
newpath = File_TranslateTempLinks_2(input_str, input_len);
if (input_str != SubstituteNameBuffer)
Dll_Free(input_str);
}
if (input_str != SubstituteNameBuffer)
Dll_Free(input_str);
}
}
}