From aaa78d43bcfd5edfd8116c2f3309b706c86ff6d1 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 23 Mar 2013 20:21:41 -0500 Subject: [PATCH] Win32 fixes --- configure.ac | 2 +- programs/imagex-win32.c | 7 ++----- src/metadata_resource.c | 2 +- src/verify.c | 2 +- src/win32.c | 26 +++++++++++++++++++++++++- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index 80ea8df2..13da4dd0 100644 --- a/configure.ac +++ b/configure.ac @@ -192,7 +192,7 @@ case "$host" in WINDOWS_NATIVE_BUILD="yes" VISIBILITY_CFLAGS="" WINDOWS_CFLAGS="-municode" - WINDOWS_CPPFLAGS="-D_POSIX" + WINDOWS_CPPFLAGS="-D_POSIX -DUNICODE -D_UNICODE" WINDOWS_LDFLAGS="-no-undefined" WINDOWS_LDADD="-lshlwapi" ;; diff --git a/programs/imagex-win32.c b/programs/imagex-win32.c index 18581ed0..19aa92cf 100644 --- a/programs/imagex-win32.c +++ b/programs/imagex-win32.c @@ -119,7 +119,7 @@ globfree(glob_t *pglob) } static bool -win32_modify_privilege(const char *privilege, bool enable) +win32_modify_privilege(const wchar_t *privilege, bool enable) { HANDLE hToken; LUID luid; @@ -129,13 +129,10 @@ win32_modify_privilege(const char *privilege, bool enable) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) - { goto out; - } - if (!LookupPrivilegeValue(NULL, privilege, &luid)) { + if (!LookupPrivilegeValueW(NULL, privilege, &luid)) goto out; - } newState.PrivilegeCount = 1; newState.Privileges[0].Luid = luid; diff --git a/src/metadata_resource.c b/src/metadata_resource.c index d54641de..a2ae93c6 100644 --- a/src/metadata_resource.c +++ b/src/metadata_resource.c @@ -213,7 +213,7 @@ write_wim_resource_from_buffer(const u8 *buf, u64 buf_size, lte.resource_entry.size = buf_size; lte.resource_entry.offset = 0; lte.resource_location = RESOURCE_IN_ATTACHED_BUFFER; - lte.attached_buffer = buf; + lte.attached_buffer = (void*)buf; zero_out_hash(lte.hash); ret = write_wim_resource(<e, out_fp, out_ctype, out_res_entry, 0); diff --git a/src/verify.c b/src/verify.c index efaca0da..decd90c0 100644 --- a/src/verify.c +++ b/src/verify.c @@ -265,7 +265,7 @@ verify_swm_set(WIMStruct *w, WIMStruct **additional_swms, } if (w->hdr.part_number != 1) { ERROR("WIM `%"TS"' is not the first part of the split WIM.", - T(w->filename)); + w->filename); return WIMLIB_ERR_SPLIT_INVALID; } for (unsigned i = 0; i < num_additional_swms; i++) { diff --git a/src/win32.c b/src/win32.c index dfa92ffd..21225e2f 100644 --- a/src/win32.c +++ b/src/win32.c @@ -949,6 +949,23 @@ do_win32_extract_stream(HANDLE hStream, struct wim_lookup_table_entry *lte) win32_extract_chunk, hStream); } +static bool +path_is_root_of_drive(const wchar_t *path) +{ + if (!*path) + return false; + + if (*path != L'/' && *path != L'\\') { + if (*(path + 1) == L':') + path += 2; + else + return false; + } + while (*path == L'/' || *path == L'\\') + path++; + return (*path == L'\0'); +} + static int win32_extract_stream(const struct wim_inode *inode, const wchar_t *path, @@ -1013,7 +1030,14 @@ win32_extract_stream(const struct wim_inode *inode, if (inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) { if (!CreateDirectoryW(stream_path, secattr)) { err = GetLastError(); - if (err != ERROR_ALREADY_EXISTS) { + switch (err) { + case ERROR_ALREADY_EXISTS: + break; + case ERROR_ACCESS_DENIED: + if (path_is_root_of_drive(path)) + break; + /* Fall through */ + default: ERROR("Failed to create directory \"%ls\"", stream_path); win32_error(err); -- 2.43.0