]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Disable CreateFileA calls in UWP builds
authorSteve Lhomme <robux4@ycbcr.xyz>
Fri, 26 May 2023 07:58:48 +0000 (09:58 +0200)
committerMartin Matuška <martin@matuska.de>
Thu, 13 Jul 2023 22:31:19 +0000 (00:31 +0200)
Only CreateFile2 and CreateFileFromAppW are allowed.

cpio/cpio_windows.c
libarchive/archive_windows.c

index 15cccaf947221fd621d46a12f0fb39d829d211e0..2809ca821e2ca535f0856aa4560d051649095c2a 100644 (file)
@@ -160,6 +160,7 @@ cpio_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
        CREATEFILE2_EXTENDED_PARAMETERS createExParams;
 #endif
 
+#if !defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
        handle = CreateFileA(path, dwDesiredAccess, dwShareMode,
            lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
            hTemplateFile);
@@ -167,9 +168,10 @@ cpio_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
                return (handle);
        if (GetLastError() != ERROR_PATH_NOT_FOUND)
                return (handle);
+#endif
        wpath = permissive_name(path);
        if (wpath == NULL)
-               return (handle);
+               return INVALID_HANDLE_VALUE;
 # if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
        ZeroMemory(&createExParams, sizeof(createExParams));
        createExParams.dwSize = sizeof(createExParams);
index 53d4b55879fcaad93304e1e3bc70f837f1bcd05a..ebc5eefb800af7c4b43feb868b44e3ab75fb8df5 100644 (file)
@@ -238,6 +238,7 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
        CREATEFILE2_EXTENDED_PARAMETERS createExParams;
 #endif
 
+#if !defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
        handle = CreateFileA(path, dwDesiredAccess, dwShareMode,
            lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
            hTemplateFile);
@@ -245,9 +246,10 @@ la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode,
                return (handle);
        if (GetLastError() != ERROR_PATH_NOT_FOUND)
                return (handle);
+#endif
        wpath = __la_win_permissive_name(path);
        if (wpath == NULL)
-               return (handle);
+               return INVALID_HANDLE_VALUE;
 # if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
        ZeroMemory(&createExParams, sizeof(createExParams));
        createExParams.dwSize = sizeof(createExParams);
@@ -320,7 +322,10 @@ __la_open(const char *path, int flags, ...)
                 * "Permission denied" error.
                 */
                attr = GetFileAttributesA(path);
-               if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND) {
+#if !defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
+               if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND)
+#endif
+               {
                        ws = __la_win_permissive_name(path);
                        if (ws == NULL) {
                                errno = EINVAL;
@@ -335,7 +340,7 @@ __la_open(const char *path, int flags, ...)
                }
                if (attr & FILE_ATTRIBUTE_DIRECTORY) {
                        HANDLE handle;
-
+#if !defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
                        if (ws != NULL)
                                handle = CreateFileW(ws, 0, 0, NULL,
                                    OPEN_EXISTING,
@@ -348,6 +353,15 @@ __la_open(const char *path, int flags, ...)
                                    FILE_FLAG_BACKUP_SEMANTICS |
                                    FILE_ATTRIBUTE_READONLY,
                                        NULL);
+#else /* !WINAPI_PARTITION_DESKTOP */
+                       CREATEFILE2_EXTENDED_PARAMETERS createExParams;
+                       ZeroMemory(&createExParams, sizeof(createExParams));
+                       createExParams.dwSize = sizeof(createExParams);
+                       createExParams.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
+                       createExParams.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS;
+                       handle = CreateFile2(ws, 0, 0,
+                               OPEN_EXISTING, &createExParams);
+#endif /* !WINAPI_PARTITION_DESKTOP */
                        free(ws);
                        if (handle == INVALID_HANDLE_VALUE) {
                                la_dosmaperr(GetLastError());