1 /*
2 * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1026
1027 /* checkAccessRights is in-out parameter */
1028 MapGenericMask(&checkAccessRights, &mapping);
1029 if (AccessCheck(security, hImpersonatedToken, checkAccessRights,
1030 &mapping, &privileges, &privilegesLength, &grantedAccess, &result) == 0)
1031 throwWindowsException(env, GetLastError());
1032
1033 return (result == FALSE) ? JNI_FALSE : JNI_TRUE;
1034 }
1035
1036 JNIEXPORT jlong JNICALL
1037 Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env,
1038 jclass this, jlong name)
1039 {
1040 LPCWSTR lpName = (LPCWSTR)jlong_to_ptr(name);
1041 PLUID pLuid = LocalAlloc(0, sizeof(LUID));
1042
1043 if (pLuid == NULL) {
1044 JNU_ThrowInternalError(env, "Unable to allocate LUID structure");
1045 } else {
1046 if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0)
1047 throwWindowsException(env, GetLastError());
1048 }
1049 return ptr_to_jlong(pLuid);
1050 }
1051
1052 JNIEXPORT void JNICALL
1053 Java_sun_nio_fs_WindowsNativeDispatcher_CreateSymbolicLink0(JNIEnv* env,
1054 jclass this, jlong linkAddress, jlong targetAddress, jint flags)
1055 {
1056 LPCWSTR link = jlong_to_ptr(linkAddress);
1057 LPCWSTR target = jlong_to_ptr(targetAddress);
1058
1059 /* On Windows 64-bit this appears to succeed even when there is insufficient privileges */
1060 if (CreateSymbolicLinkW(link, target, (DWORD)flags) == 0)
1061 throwWindowsException(env, GetLastError());
1062 }
1063
1064 JNIEXPORT void JNICALL
1065 Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env,
1066 jclass this, jlong newFileAddress, jlong existingFileAddress)
1067 {
|
1 /*
2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
1026
1027 /* checkAccessRights is in-out parameter */
1028 MapGenericMask(&checkAccessRights, &mapping);
1029 if (AccessCheck(security, hImpersonatedToken, checkAccessRights,
1030 &mapping, &privileges, &privilegesLength, &grantedAccess, &result) == 0)
1031 throwWindowsException(env, GetLastError());
1032
1033 return (result == FALSE) ? JNI_FALSE : JNI_TRUE;
1034 }
1035
1036 JNIEXPORT jlong JNICALL
1037 Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env,
1038 jclass this, jlong name)
1039 {
1040 LPCWSTR lpName = (LPCWSTR)jlong_to_ptr(name);
1041 PLUID pLuid = LocalAlloc(0, sizeof(LUID));
1042
1043 if (pLuid == NULL) {
1044 JNU_ThrowInternalError(env, "Unable to allocate LUID structure");
1045 } else {
1046 if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) {
1047 LocalFree(pLuid);
1048 throwWindowsException(env, GetLastError());
1049 return (jlong)0;
1050 }
1051 }
1052 return ptr_to_jlong(pLuid);
1053 }
1054
1055 JNIEXPORT void JNICALL
1056 Java_sun_nio_fs_WindowsNativeDispatcher_CreateSymbolicLink0(JNIEnv* env,
1057 jclass this, jlong linkAddress, jlong targetAddress, jint flags)
1058 {
1059 LPCWSTR link = jlong_to_ptr(linkAddress);
1060 LPCWSTR target = jlong_to_ptr(targetAddress);
1061
1062 /* On Windows 64-bit this appears to succeed even when there is insufficient privileges */
1063 if (CreateSymbolicLinkW(link, target, (DWORD)flags) == 0)
1064 throwWindowsException(env, GetLastError());
1065 }
1066
1067 JNIEXPORT void JNICALL
1068 Java_sun_nio_fs_WindowsNativeDispatcher_CreateHardLink0(JNIEnv* env,
1069 jclass this, jlong newFileAddress, jlong existingFileAddress)
1070 {
|