]> wimlib.net Git - wimlib/commitdiff
Win32 apply: Create encrypted files with OpenEncryptedFileRaw()
authorEric Biggers <ebiggers3@gmail.com>
Sun, 18 Aug 2013 17:37:46 +0000 (12:37 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 18 Aug 2013 17:38:14 +0000 (12:38 -0500)
include/wimlib/apply.h
src/extract.c
src/win32_apply.c

index ef623a6f2652a8fe0cbc5b9f3577dcf9e36892f2..1019a48a15116eb65d7d747be88f4ef1cb1b4cac 100644 (file)
@@ -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)
        /* 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.
                 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 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 {
 };
 
 struct wim_features {
index 3b434c425291ea191aba88b29bd7ad7ebb082964..b40d708d6c6e8b5fc4f64ef8e61e31514e4b2edf 100644 (file)
@@ -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);
                }
                        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) {
        } 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_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)
                        update_extract_progress(ctx, lte);
                }
                else if (inode->i_attributes & FILE_ATTRIBUTE_REPARSE_POINT)
index 4a0a8a46d77ad22b41edf0354127ffb5ed61f520..e554b95d22029f752da59f363717b21deeb30f81 100644 (file)
@@ -259,11 +259,10 @@ win32_encrypted_import_cb(unsigned char *data, void *_import_ctx,
 }
 
 static int
 }
 
 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)
 {
                               struct wim_lookup_table_entry *lte,
                               struct apply_ctx *ctx)
 {
-       const tchar *path = file.path;
        void *file_ctx;
        DWORD err;
        int ret;
        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,
        .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__ */
 };
 
 #endif /* __WIN32__ */