8218418: (fs) Files.createSymbolicLink should use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (win)
authorbpb
Mon, 01 Apr 2019 15:59:45 -0700
changeset 54369 66185e52b979
parent 54368 f15b5d110fbc
child 54370 e057e45b49af
8218418: (fs) Files.createSymbolicLink should use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (win) Reviewed-by: alanb
src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
--- a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Mon Apr 01 14:54:48 2019 -0700
+++ b/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Mon Apr 01 15:59:45 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -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());
 }