diff --git a/SMBLibrary/Enums/NTStatus.cs b/SMBLibrary/Enums/NTStatus.cs index 19e5d25..d1cfaa2 100644 --- a/SMBLibrary/Enums/NTStatus.cs +++ b/SMBLibrary/Enums/NTStatus.cs @@ -32,6 +32,7 @@ namespace SMBLibrary STATUS_NOT_SUPPORTED = 0xC00000BB, STATUS_NETWORK_NAME_DELETED = 0xC00000C9, STATUS_TOO_MANY_SESSIONS = 0xC00000CE, + STATUS_DIRECTORY_NOT_EMPTY = 0xC0000101, STATUS_TOO_MANY_OPENED_FILES = 0xC000011F, STATUS_CANNOT_DELETE = 0xC0000121, STATUS_FILE_CLOSED = 0xC0000128, diff --git a/SMBLibrary/Enums/Win32Error.cs b/SMBLibrary/Enums/Win32Error.cs index 7daa5ce..bd44d67 100644 --- a/SMBLibrary/Enums/Win32Error.cs +++ b/SMBLibrary/Enums/Win32Error.cs @@ -8,6 +8,7 @@ namespace SMBLibrary ERROR_ACCESS_DENIED = 0x0005, ERROR_SHARING_VIOLATION = 0x0020, ERROR_DISK_FULL = 0x0070, + ERROR_DIR_NOT_EMPTY = 0x0091, ERROR_ALREADY_EXISTS = 0x00B7, ERROR_LOGON_FAILURE = 0x052E, ERROR_ACCOUNT_RESTRICTION = 0x052F, diff --git a/SMBLibrary/Server/Helpers/NTFileSystemHelper.cs b/SMBLibrary/Server/Helpers/NTFileSystemHelper.cs index 9712177..64428ef 100644 --- a/SMBLibrary/Server/Helpers/NTFileSystemHelper.cs +++ b/SMBLibrary/Server/Helpers/NTFileSystemHelper.cs @@ -382,6 +382,12 @@ namespace SMBLibrary.Server { return NTStatus.STATUS_DISK_FULL; } + else if (errorCode == (ushort)Win32Error.ERROR_DIR_NOT_EMPTY) + { + // If a user tries to rename folder1 to folder2 when folder2 already exists, Windows 7 will offer to merge folder1 into folder2. + // In such case, Windows 7 will delete folder 1 and will expect STATUS_DIRECTORY_NOT_EMPTY if there are files to merge. + return NTStatus.STATUS_DIRECTORY_NOT_EMPTY; + } else if (errorCode == (ushort)Win32Error.ERROR_ALREADY_EXISTS) { // According to [MS-FSCC], FileRenameInformation MUST return STATUS_OBJECT_NAME_COLLISION when the specified name already exists and ReplaceIfExists is zero. diff --git a/SMBServer/DirectoryFileSystem/DirectoryFileSystem.cs b/SMBServer/DirectoryFileSystem/DirectoryFileSystem.cs index d3efcf6..478b362 100644 --- a/SMBServer/DirectoryFileSystem/DirectoryFileSystem.cs +++ b/SMBServer/DirectoryFileSystem/DirectoryFileSystem.cs @@ -100,7 +100,7 @@ namespace SMBServer } else if (Directory.Exists(fullPath)) { - Directory.Delete(fullPath, true); + Directory.Delete(fullPath, false); } else {