This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
win32 symlink: only use the unprivileged flag if windows is new enough
authorTony Cook <tony@develop-help.com>
Thu, 15 Oct 2020 00:21:31 +0000 (11:21 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 1 Dec 2020 04:29:33 +0000 (15:29 +1100)
win32/win32.c

index 1046f6c..8cbe4da 100644 (file)
@@ -3432,7 +3432,15 @@ win32_symlink(const char *oldfile, const char *newfile)
     char szTargetName[MAX_PATH+1];
     size_t oldfile_len = strlen(oldfile);
     DWORD dest_attr;
-    DWORD create_flags = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
+    DWORD create_flags = 0;
+
+    /* this flag can be used only on Windows 10 1703 or newer */
+    if (g_osver.dwMajorVersion > 10 ||
+        (g_osver.dwMajorVersion == 10 &&
+         (g_osver.dwMinorVersion > 0 || g_osver.dwBuildNumber > 15063)))
+    {
+        create_flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
+    }
 
     /* oldfile might be relative and we don't want to change that,
        so don't map that.