8218418: (fs) Files.createSymbolicLink should use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (win)

Brian Burkhalter brian.burkhalter at oracle.com
Fri Feb 15 00:42:02 UTC 2019


https://bugs.openjdk.java.net/browse/JDK-8218418

The proposed change below ran without error through the jdk_core tests on Windows. Presumably it is covered sufficiently by test/jdk/java/nio/file/Files/Links.java so the issue could be labelled noreg-other.

Thanks,

Brian

--- a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
+++ b/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c

@@ -1063,8 +1063,14 @@
     LPCWSTR link = jlong_to_ptr(linkAddress);
     LPCWSTR target = jlong_to_ptr(targetAddress);
 
-    /* On Windows 64-bit this appears to succeed even when there is insufficient privileges */
-    if (CreateSymbolicLinkW(link, target, (DWORD)flags) == 0)
+    // Allow creation of symbolic links when the process is not elevated.
+    // Developer Mode must be enabled for this option to function, otherwise
+    // it will be ignored.
+    DWORD dwFlags = (DWORD)flags | SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
+
+    // On Windows 64-bit this appears to succeed even when there are
+    // insufficient privileges
+    if (CreateSymbolicLinkW(link, target, dwFlags) == 0)
         throwWindowsException(env, GetLastError());
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190214/f7ba31a4/attachment.html>


More information about the nio-dev mailing list