-/*
- * Clear FILE_ATTRIBUTE_ENCRYPTED if the file or directory is not supposed to be
- * encrypted.
- *
- * You can provide FILE_ATTRIBUTE_ENCRYPTED to NtCreateFile() to set it on the
- * created file. However, the file or directory will otherwise default to the
- * encryption state of the parent directory. This function works around this
- * limitation by using DecryptFile() to remove FILE_ATTRIBUTE_ENCRYPTED on files
- * (and directories) that are not supposed to have it set.
- *
- * Regardless of whether it succeeds or fails, this function may close the
- * handle to the file. If it does, it sets it to NULL.
- */
-static int
-maybe_clear_encryption_attribute(HANDLE *h_ptr, const struct wim_dentry *dentry,
- struct win32_apply_ctx *ctx)
-{
- if (dentry->d_inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED)
- return 0;
-
- if (ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES)
- return 0;
-
- if (!ctx->common.supported_features.encrypted_files)
- return 0;
-
- FILE_BASIC_INFORMATION info;
- NTSTATUS status;
- BOOL bret;
-
- /* Get current attributes */
- status = (*func_NtQueryInformationFile)(*h_ptr, &ctx->iosb,
- &info, sizeof(info),
- FileBasicInformation);
- if (NT_SUCCESS(status) &&
- !(info.FileAttributes & FILE_ATTRIBUTE_ENCRYPTED))
- {
- /* Nothing needs to be done. */
- return 0;
- }
-
- /* Set the new encryption state */
-
- /* Due to Windows' crappy file encryption APIs, we need to close the
- * handle to the file so we don't get ERROR_SHARING_VIOLATION. We also
- * hack together a Win32 path, although we will use the \\?\ prefix so
- * it will actually be a NT path in disguise... */
- (*func_NtClose)(*h_ptr);
- *h_ptr = NULL;
-
- build_win32_extraction_path(dentry, ctx);
-
- bret = DecryptFile(ctx->pathbuf.Buffer, 0);
-
- /* Restore the NT namespace path */
- build_extraction_path(dentry, ctx);
-
- if (!bret) {
- DWORD err = GetLastError();
- set_errno_from_win32_error(err);
- ERROR_WITH_ERRNO("Can't decrypt file \"%ls\" (err=%"PRIu32")",
- current_path(ctx), (u32)err);
- return WIMLIB_ERR_SET_ATTRIBUTES;
- }
- return 0;
-}
-