]> wimlib.net Git - wimlib/blobdiff - src/win32_apply.c
Win32: compile
[wimlib] / src / win32_apply.c
index adf605b961bfd8e54f1bed59b30a0b40212e9176..c8f65ef0e2db218c4a1ba203c04900497bcee6af 100644 (file)
 #include "wimlib/error.h"
 #include "wimlib/lookup_table.h"
 
-#ifdef WITH_NTDLL
-#  include <winternl.h>
-#  include <ntstatus.h>
-NTSTATUS WINAPI
-NtSetSecurityObject(HANDLE Handle,
-                   SECURITY_INFORMATION SecurityInformation,
-                   PSECURITY_DESCRIPTOR SecurityDescriptor);
-#endif
-
 static int
 win32_start_extract(const wchar_t *path, struct apply_ctx *ctx)
 {
@@ -191,7 +182,7 @@ win32_extract_stream(const wchar_t *path, const wchar_t *stream_name,
                stream_path = alloca(sizeof(wchar_t) *
                                     (wcslen(path) + 1 +
                                      wcslen(stream_name) + 1));
-               swprintf(stream_path, L"%ls:%ls", path, stream_name);
+               tsprintf(stream_path, L"%ls:%ls", path, stream_name);
        }
 
        h = CreateFile(stream_path, FILE_WRITE_DATA, 0, NULL,
@@ -204,8 +195,7 @@ win32_extract_stream(const wchar_t *path, const wchar_t *stream_name,
        ret = 0;
        if (!lte)
                goto out_close_handle;
-       ret = extract_wim_resource(lte, wim_resource_size(lte),
-                                  win32_extract_wim_chunk, h);
+       ret = extract_stream(lte, lte->size, win32_extract_wim_chunk, h);
 out_close_handle:
        if (!CloseHandle(h))
                goto error;
@@ -248,9 +238,9 @@ win32_encrypted_import_cb(unsigned char *data, void *_import_ctx,
        unsigned long len = *len_p;
        const struct wim_lookup_table_entry *lte = import_ctx->lte;
 
-       len = min(len, wim_resource_size(lte) - import_ctx->offset);
+       len = min(len, lte->size - import_ctx->offset);
 
-       if (read_partial_wim_resource_into_buf(lte, len, import_ctx->offset, data))
+       if (read_partial_wim_stream_into_buf(lte, len, import_ctx->offset, data))
                return ERROR_READ_FAULT;
 
        import_ctx->offset += len;
@@ -259,11 +249,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;
@@ -301,10 +290,7 @@ win32_set_special_file_attributes(const wchar_t *path, u32 attributes)
        USHORT compression_format = COMPRESSION_FORMAT_DEFAULT;
        DWORD bytes_returned;
 
-       h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -388,10 +374,7 @@ win32_set_file_attributes(const wchar_t *path, u32 attributes,
                DWORD bytes_returned;
                USHORT compression_format = COMPRESSION_FORMAT_NONE;
 
-               h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                              OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                             FILE_FLAG_OPEN_REPARSE_POINT,
-                              NULL);
+               h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
                if (h == INVALID_HANDLE_VALUE)
                        goto error;
 
@@ -425,10 +408,7 @@ win32_set_reparse_data(const wchar_t *path, const u8 *rpbuf, u16 rpbuflen,
        DWORD err;
        DWORD bytes_returned;
 
-       h = CreateFile(path, GENERIC_WRITE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_WRITE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -458,10 +438,7 @@ win32_set_short_name(const wchar_t *path, const wchar_t *short_name,
        HANDLE h;
        DWORD err;
 
-       h = CreateFile(path, GENERIC_WRITE | DELETE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_WRITE | DELETE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -493,13 +470,15 @@ do_win32_set_security_descriptor(HANDLE h, const wchar_t *path,
                                 PSECURITY_DESCRIPTOR desc)
 {
 #ifdef WITH_NTDLL
-       return RtlNtStatusToDosError(NtSetSecurityObject(h, info, desc));
-#else
+       if (func_NtSetSecurityObject) {
+               return (*func_RtlNtStatusToDosError)(
+                               (*func_NtSetSecurityObject)(h, info, desc));
+       }
+#endif
        if (SetFileSecurity(path, info, desc))
                return ERROR_SUCCESS;
        else
                return GetLastError();
-#endif
 }
 
 static int
@@ -516,13 +495,12 @@ win32_set_security_descriptor(const wchar_t *path, const u8 *desc,
        h = INVALID_HANDLE_VALUE;
 
 #ifdef WITH_NTDLL
-       h = CreateFile(path, MAXIMUM_ALLOWED, 0, NULL, OPEN_EXISTING,
-                      FILE_FLAG_BACKUP_SEMANTICS |
-                              FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
-       if (h == INVALID_HANDLE_VALUE) {
-               ERROR_WITH_ERRNO("Can't open %ls (%u)", path, GetLastError());
-               goto error;
+       if (func_NtSetSecurityObject) {
+               h = win32_open_existing_file(path, MAXIMUM_ALLOWED);
+               if (h == INVALID_HANDLE_VALUE) {
+                       ERROR_WITH_ERRNO("Can't open %ls (%u)", path, GetLastError());
+                       goto error;
+               }
        }
 #endif
 
@@ -552,12 +530,14 @@ win32_set_security_descriptor(const wchar_t *path, const u8 *desc,
                        ctx->no_security_descriptors++;
                        break;
                }
+               SetLastError(err);
                goto error;
        }
        ret = 0;
 out_close:
 #ifdef WITH_NTDLL
-       CloseHandle(h);
+       if (func_NtSetSecurityObject)
+               CloseHandle(h);
 #endif
        return ret;
 
@@ -581,10 +561,7 @@ win32_set_timestamps(const wchar_t *path, u64 creation_time,
        FILETIME lastWriteTime = {.dwLowDateTime = last_write_time & 0xffffffff,
                                  .dwHighDateTime = last_write_time >> 32};
 
-       h = CreateFile(path, FILE_WRITE_ATTRIBUTES, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, FILE_WRITE_ATTRIBUTES);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -632,6 +609,8 @@ 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,
+       .requires_short_name_reordering = 1, /* TODO: check if this is really needed  */
 };
 
 #endif /* __WIN32__ */