| 460 | |
| 461 | #ifdef _WIN32 |
| 462 | DWORD |
| 463 | get_file_information(CryptContext *con, function<LPCWSTR()> getEncPath, LPCWSTR inputPath, HANDLE handle, LPBY_HANDLE_FILE_INFORMATION pInfo) |
| 464 | { |
| 465 | BOOL opened = FALSE; |
| 466 | |
| 467 | DWORD dwRet = 0; |
| 468 | |
| 469 | bool is_config = rt_is_config_file(con, inputPath); |
| 470 | |
| 471 | bool is_dir_iv = rt_is_dir_iv_file(con, inputPath); |
| 472 | |
| 473 | bool is_virtual = rt_is_virtual_file(con, inputPath); |
| 474 | |
| 475 | bool is_name_file = rt_is_name_file(con, inputPath); |
| 476 | |
| 477 | try { |
| 478 | |
| 479 | |
| 480 | if (!handle || (handle == INVALID_HANDLE_VALUE && !is_virtual)) { |
| 481 | |
| 482 | throw((int)ERROR_INVALID_PARAMETER); |
| 483 | |
| 484 | } |
| 485 | |
| 486 | if (is_dir_iv) { |
| 487 | wstring dirpath; |
| 488 | if (!get_file_directory(getEncPath(), dirpath)) |
| 489 | throw((int)ERROR_ACCESS_DENIED); |
| 490 | |
| 491 | HANDLE hDir = CreateFile(&dirpath[0], FILE_READ_ATTRIBUTES, |
| 492 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 493 | NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
| 494 | if (hDir == INVALID_HANDLE_VALUE) |
| 495 | throw((int)GetLastError()); |
| 496 | |
| 497 | BOOL bResult = GetFileInformationByHandle(hDir, pInfo); |
| 498 | |
| 499 | if (!bResult) { |
| 500 | DWORD lastErr = GetLastError(); |
| 501 | CloseHandle(hDir); |
| 502 | throw((int)lastErr); |
| 503 | } |
| 504 | |
| 505 | CloseHandle(hDir); |
| 506 | |
| 507 | pInfo->dwFileAttributes = VirtualAttributesDirIv(pInfo->dwFileAttributes); |
| 508 | pInfo->ftLastWriteTime = pInfo->ftCreationTime; |
| 509 | pInfo->nFileSizeHigh = 0; |
| 510 | pInfo->nFileSizeLow = DIR_IV_LEN; |
| 511 | pInfo->nNumberOfLinks = 1; |
| 512 | |
| 513 | } else if (is_name_file) { |
| 514 | |
| 515 | wstring enc_filename; |
| 516 | |
| 517 | remove_longname_suffix(inputPath, enc_filename); |
| 518 | |
| 519 | wstring decrypted_name; |
no test coverage detected