changeset 55643:66185e52b979

8218418: (fs) Files.createSymbolicLink should use SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (win) Reviewed-by: alanb
author bpb
date Mon, 01 Apr 2019 15:59:45 -0700
parents f15b5d110fbc
children e057e45b49af
files src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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());
 }