| 1104 | // see comment in CryptMoveFile() about what the repair stuff is for |
| 1105 | |
| 1106 | static NTSTATUS CryptMoveFileInternal(LPCWSTR FileName, // existing file name |
| 1107 | LPCWSTR NewFileName, |
| 1108 | BOOL ReplaceIfExisting, |
| 1109 | PDOKAN_FILE_INFO DokanFileInfo, |
| 1110 | bool &needRepair, bool repairName) { |
| 1111 | |
| 1112 | needRepair = false; |
| 1113 | |
| 1114 | string actual_encrypted; |
| 1115 | FileNameEnc filePath(DokanFileInfo, FileName); |
| 1116 | FileNameEnc newFilePath(DokanFileInfo, NewFileName, &actual_encrypted, |
| 1117 | repairName); |
| 1118 | |
| 1119 | DbgPrint(L"MoveFile %s -> %s\n\n", FileName, NewFileName); |
| 1120 | |
| 1121 | HANDLE handle; |
| 1122 | DWORD bufferSize; |
| 1123 | BOOL result; |
| 1124 | size_t newFilePathLen; |
| 1125 | |
| 1126 | PFILE_RENAME_INFO renameInfo = NULL; |
| 1127 | |
| 1128 | handle = (HANDLE)DokanFileInfo->Context; |
| 1129 | if (!handle || handle == INVALID_HANDLE_VALUE) { |
| 1130 | DbgPrint(L"\tinvalid handle\n\n"); |
| 1131 | return STATUS_INVALID_HANDLE; |
| 1132 | } |
| 1133 | |
| 1134 | auto new_path = static_cast<const WCHAR*>(newFilePath); |
| 1135 | |
| 1136 | if (new_path == nullptr) { |
| 1137 | // this can happen e.g. if we can't read a diriv in the "to" path |
| 1138 | auto lasterr = GetLastError(); |
| 1139 | DbgPrint(L"\tnewFilePath is null, last error was %u\n", lasterr); |
| 1140 | // we return accessed denied because whatever error really happened might |
| 1141 | // not make any sense to the caller. |
| 1142 | return STATUS_ACCESS_DENIED; |
| 1143 | } |
| 1144 | |
| 1145 | newFilePathLen = wcslen(newFilePath); |
| 1146 | |
| 1147 | // the FILE_RENAME_INFO struct has space for one WCHAR for the name at |
| 1148 | // the end, so that |
| 1149 | // accounts for the null terminator |
| 1150 | |
| 1151 | bufferSize = (DWORD)(sizeof(FILE_RENAME_INFO) + |
| 1152 | newFilePathLen * sizeof(newFilePath[0])); |
| 1153 | |
| 1154 | renameInfo = (PFILE_RENAME_INFO)malloc(bufferSize); |
| 1155 | if (!renameInfo) { |
| 1156 | return STATUS_BUFFER_OVERFLOW; |
| 1157 | } |
| 1158 | ZeroMemory(renameInfo, bufferSize); |
| 1159 | |
| 1160 | renameInfo->ReplaceIfExists = |
| 1161 | ReplaceIfExisting |
| 1162 | ? TRUE |
| 1163 | : FALSE; // some warning about converting BOOL to BOOLEAN |
no test coverage detected