jdk/src/java.management/windows/native/libmanagement/FileSystemImpl.c
author zmajo
Thu, 15 Oct 2015 17:40:39 +0000
changeset 33189 e7d20eb45c7d
parent 25859 3317bb8137f4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 9027
diff changeset
     2
 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <malloc.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "sun_management_FileSystemImpl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Access mask to represent any file access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#define ANY_ACCESS (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Returns JNI_TRUE if the specified file is on a file system that supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * persistent ACLs (On NTFS file systems returns true, on FAT32 file systems
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * returns false).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
static jboolean isSecuritySupported(JNIEnv* env, const char* path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    char* root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    char* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    BOOL res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    DWORD dwMaxComponentLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    DWORD dwFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    char fsName[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    DWORD fsNameLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Get root directory. Assume that files are absolute paths. For UNCs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * the slash after the share name is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    root = strdup(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    if (*root == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * \\server\share\file ==> \\server\share\
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int slashskip = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        p = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        while ((*p == '\\') && (slashskip > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            char* p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            p2 = strchr(p, '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if ((p2 == NULL) || (*p2 != '\\')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                free(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                JNU_ThrowIOException(env, "Malformed UNC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            p = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            slashskip--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (slashskip != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            free(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            JNU_ThrowIOException(env, "Malformed UNC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        p = strchr(root, '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (p == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            free(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            JNU_ThrowIOException(env, "Absolute filename not specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Get the volume information - this gives us the file system file and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * also tells us if the file system supports persistent ACLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    fsNameLength = sizeof(fsName)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    res = GetVolumeInformation(root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                               NULL,        // address of name of the volume, can be NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                               0,           // length of volume name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                               NULL,        // address of volume serial number, can be NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                               &dwMaxComponentLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                               &dwFlags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                               fsName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                               fsNameLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (res == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        free(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        JNU_ThrowIOExceptionWithLastError(env, "GetVolumeInformation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    free(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    return (dwFlags & FS_PERSISTENT_ACLS) ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * Returns the security descriptor for a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
static SECURITY_DESCRIPTOR* getFileSecurityDescriptor(JNIEnv* env, const char* path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    SECURITY_DESCRIPTOR* sd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    DWORD len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    SECURITY_INFORMATION info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        OWNER_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   129
    GetFileSecurityA(path, info , 0, 0, &len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        JNU_ThrowIOExceptionWithLastError(env, "GetFileSecurity failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    sd = (SECURITY_DESCRIPTOR *)malloc(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (sd == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    } else {
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   138
        if (!(*GetFileSecurityA)(path, info, sd, len, &len)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            JNU_ThrowIOExceptionWithLastError(env, "GetFileSecurity failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            free(sd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    return sd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * Returns pointer to the SID identifying the owner of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
static SID* getFileOwner(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    SID* owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    BOOL defaulted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   155
    if (!GetSecurityDescriptorOwner(sd, &owner, &defaulted)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        JNU_ThrowIOExceptionWithLastError(env, "GetSecurityDescriptorOwner failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    return owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Returns pointer discretionary access-control list (ACL) from the security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * descriptor of the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
static ACL* getFileDACL(JNIEnv* env, SECURITY_DESCRIPTOR* sd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    ACL *acl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    int defaulted, present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   170
    if (!GetSecurityDescriptorDacl(sd, &present, &acl, &defaulted)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        JNU_ThrowIOExceptionWithLastError(env, "GetSecurityDescriptorDacl failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    if (!present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        JNU_ThrowInternalError(env, "Security descriptor does not contain a DACL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    return acl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * Returns JNI_TRUE if the specified owner is the only SID will access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * to the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
static jboolean isAccessUserOnly(JNIEnv* env, SID* owner, ACL* acl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    ACL_SIZE_INFORMATION acl_size_info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    DWORD i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * If there's no DACL then there's no access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    if (acl == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Get the ACE count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   199
    if (!GetAclInformation(acl, (void *) &acl_size_info, sizeof(acl_size_info),
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   200
                           AclSizeInformation)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        JNU_ThrowIOExceptionWithLastError(env, "GetAclInformation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Iterate over the ACEs. For each "allow" type check that the SID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * matches the owner, and check that the access is read only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    for (i = 0; i < acl_size_info.AceCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        void* ace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        ACCESS_ALLOWED_ACE *access;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        SID* sid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   214
        if (!GetAce(acl, i, &ace)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            JNU_ThrowIOExceptionWithLastError(env, "GetAce failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (((ACCESS_ALLOWED_ACE *)ace)->Header.AceType != ACCESS_ALLOWED_ACE_TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        access = (ACCESS_ALLOWED_ACE *)ace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        sid = (SID *) &access->SidStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (!EqualSid(owner, sid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
             * If the ACE allows any access then the file is not secure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (access->Mask & ANY_ACCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * Class:     sun_management_FileSystemImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * Method:    init0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
JNIEXPORT void JNICALL Java_sun_management_FileSystemImpl_init0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  (JNIEnv *env, jclass ignored)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
9027
540bd52f1881 7030249: Eliminate use of LoadLibrary and other clean-ups
alanb
parents: 5506
diff changeset
   244
        /* nothing to do */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * Class:     sun_management_FileSystemImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * Method:    isSecuritySupported0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * Signature: (Ljava/lang/String;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isSecuritySupported0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  (JNIEnv *env, jclass ignored, jstring str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    jboolean res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    const char* path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    path = JNU_GetStringPlatformChars(env, str, &isCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if (path != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        res = isSecuritySupported(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (isCopy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            JNU_ReleaseStringPlatformChars(env, str, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        /* exception thrown - doesn't matter what we return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * Class:     sun_management_FileSystemImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * Method:    isAccessUserOnly0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * Signature: (Ljava/lang/String;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
JNIEXPORT jboolean JNICALL Java_sun_management_FileSystemImpl_isAccessUserOnly0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  (JNIEnv *env, jclass ignored, jstring str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    jboolean res = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    const char* path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    path = JNU_GetStringPlatformChars(env, str, &isCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    if (path != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * From the security descriptor get the file owner and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         * DACL. Then check if anybody but the owner has access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
         * to the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        SECURITY_DESCRIPTOR* sd = getFileSecurityDescriptor(env, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (sd != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            SID *owner = getFileOwner(env, sd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (owner != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                ACL* acl = getFileDACL(env, sd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (acl != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    res = isAccessUserOnly(env, owner, acl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                     * If acl is NULL it means that an exception was thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                     * or there is "all acess" to the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    res = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            free(sd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (isCopy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            JNU_ReleaseStringPlatformChars(env, str, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}