From: Eric Biggers Date: Sun, 18 Aug 2013 17:37:46 +0000 (-0500) Subject: Win32 apply: Create encrypted files with OpenEncryptedFileRaw() X-Git-Tag: v1.5.0~36 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=57117039d9fe296fb160217aea226856c44c5d10 Win32 apply: Create encrypted files with OpenEncryptedFileRaw() --- diff --git a/include/wimlib/apply.h b/include/wimlib/apply.h index ef623a6f..1019a48a 100644 --- a/include/wimlib/apply.h +++ b/include/wimlib/apply.h @@ -83,7 +83,7 @@ struct apply_operations { /* OPTIONAL: Extracted encrypted stream. In start_extract(), set * ctx->supported_features.encrypted_files if supported. */ int (*extract_encrypted_stream) - (file_spec_t file, struct wim_lookup_table_entry *lte, + (const tchar *path, struct wim_lookup_table_entry *lte, struct apply_ctx *ctx); /* OPTIONAL: Set file attributes. Calling code calls this if non-NULL. @@ -172,6 +172,10 @@ struct apply_operations { /* OPTIONAL: Set to 1 if set_file_attributes() needs to be called a * second time towards the end of the extraction. */ unsigned requires_final_set_attributes_pass : 1; + + /* OPTIONAL: Set to 1 if extract_encrypted_stream() must be used to + * create encrypted files. */ + unsigned extract_encrypted_stream_creates_file : 1; }; struct wim_features { diff --git a/src/extract.c b/src/extract.c index 3b434c42..b40d708d 100644 --- a/src/extract.c +++ b/src/extract.c @@ -338,6 +338,15 @@ extract_inode(const tchar *path, struct apply_ctx *ctx, struct wim_inode *inode) ERROR_WITH_ERRNO("Failed to create the directory " "\"%"TS"\"", path); } + } else if ((inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) && + ctx->ops->extract_encrypted_stream_creates_file && + ctx->supported_features.encrypted_files) { + ret = ctx->ops->extract_encrypted_stream( + path, inode_unnamed_lte_resolved(inode), ctx); + if (ret) { + ERROR_WITH_ERRNO("Failed to create and extract " + "encrypted file \"%"TS"\"", path); + } } else { ret = ctx->ops->create_file(path, ctx, &inode->extract_cookie); if (ret) { @@ -585,13 +594,20 @@ extract_streams(const tchar *path, struct apply_ctx *ctx, if (!(inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT))) { - if ((inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED) && - ctx->supported_features.encrypted_files) - ret = ctx->ops->extract_encrypted_stream(file_spec, lte, ctx); - else - ret = ctx->ops->extract_unnamed_stream(file_spec, lte, ctx); - if (ret) - goto error; + if (inode->i_attributes & FILE_ATTRIBUTE_ENCRYPTED && + ctx->supported_features.encrypted_files) { + if (!ctx->ops->extract_encrypted_stream_creates_file) { + ret = ctx->ops->extract_encrypted_stream( + path, lte, ctx); + if (ret) + goto error; + } + } else { + ret = ctx->ops->extract_unnamed_stream( + file_spec, lte, ctx); + if (ret) + goto error; + } update_extract_progress(ctx, lte); } else if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT) diff --git a/src/win32_apply.c b/src/win32_apply.c index 4a0a8a46..e554b95d 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -259,11 +259,10 @@ win32_encrypted_import_cb(unsigned char *data, void *_import_ctx, } static int -win32_extract_encrypted_stream(file_spec_t file, +win32_extract_encrypted_stream(const wchar_t *path, struct wim_lookup_table_entry *lte, struct apply_ctx *ctx) { - const tchar *path = file.path; void *file_ctx; DWORD err; int ret; @@ -614,6 +613,7 @@ const struct apply_operations win32_apply_ops = { .realpath_works_on_nonexisting_files = 1, .root_directory_is_special = 1, .requires_final_set_attributes_pass = 1, + .extract_encrypted_stream_creates_file = 1, }; #endif /* __WIN32__ */