/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A SecurityDescriptor for use when setting a file's ACL or creating a file
* with an initial ACL.
*/
class WindowsSecurityDescriptor {
/**
* typedef struct _ACL {
* BYTE AclRevision;
* BYTE Sbz1;
* WORD AclSize;
* WORD AceCount;
* WORD Sbz2;
* } ACL;
*
* typedef struct _ACE_HEADER {
* BYTE AceType;
* BYTE AceFlags;
* WORD AceSize;
* } ACE_HEADER;
*
* typedef struct _ACCESS_ALLOWED_ACE {
* ACE_HEADER Header;
* ACCESS_MASK Mask;
* DWORD SidStart;
* } ACCESS_ALLOWED_ACE;
*
* typedef struct _ACCESS_DENIED_ACE {
* ACE_HEADER Header;
* ACCESS_MASK Mask;
* DWORD SidStart;
* } ACCESS_DENIED_ACE;
*
* typedef struct _SECURITY_DESCRIPTOR {
* BYTE Revision;
* BYTE Sbz1;
* SECURITY_DESCRIPTOR_CONTROL Control;
* PSID Owner;
* PSID Group;
* PACL Sacl;
* PACL Dacl;
* } SECURITY_DESCRIPTOR;
*/
// null security descriptor
new WindowsSecurityDescriptor();
// native resources
/**
* Creates the "null" SecurityDescriptor
*/
private WindowsSecurityDescriptor() {
}
/**
* Creates a SecurityDescriptor from the given ACL
*/
boolean initialized = false;
// SECURITY: need to copy list in case size changes during processing
// list of SIDs
try {
// initial size of ACL
int size = SIZEOF_ACL;
// get the SID for each entry
throw new ProviderMismatchException();
try {
// increase size to allow for entry
} catch (WindowsException x) {
+ ": " + x.errorString());
}
}
// allocate memory for the ACL
// Add entry ACE to the ACL
int i = 0;
try {
} catch (WindowsException x) {
throw new IOException("Failed to encode ACE: " +
x.errorString());
}
i++;
}
// initialize security descriptor and set DACL
initialized = true;
} catch (WindowsException x) {
throw new IOException(x.getMessage());
} finally {
// release resources if not completely initialized
if (!initialized)
release();
}
}
/**
* Releases memory associated with SecurityDescriptor
*/
void release() {
// release memory for SIDs
}
}
}
/**
* Returns address of SecurityDescriptor
*/
long address() {
}
// decode Windows ACE to NFSv4 AclEntry
throws IOException
{
// map type
return null;
if (aceType == ACCESS_ALLOWED_ACE_TYPE) {
} else {
}
// map flags
// map access mask
// lookup SID to create UserPrincipal
return AclEntry.newBuilder()
}
// encode NFSv4 AclEntry as Windows ACE to given ACL
throws WindowsException
{
return;
// map access mask
int mask = 0;
mask |= FILE_READ_DATA;
mask |= FILE_WRITE_DATA;
mask |= FILE_APPEND_DATA;
mask |= FILE_READ_EA;
mask |= FILE_WRITE_EA;
mask |= FILE_EXECUTE;
mask |= READ_CONTROL;
mask |= WRITE_OWNER;
mask |= SYNCHRONIZE;
// map flags
byte flags = 0;
if (allow) {
} else {
}
}
/**
* Creates a security descriptor with a DACL representing the given ACL.
*/
throws IOException
{
return new WindowsSecurityDescriptor(acl);
}
/**
* Processes the array of attributes looking for the attribute "acl:acl".
* Returns security descriptor representing the ACL or the "null" security
* descriptor if the attribute is not in the array.
*/
@SuppressWarnings("unchecked")
throws IOException
{
// if more than one ACL specified then last one wins
if (sd != NULL_DESCRIPTOR)
throw new NullPointerException();
} else {
"' not supported as initial attribute");
}
}
return sd;
}
/**
* Extracts DACL from security descriptor.
*/
// get address of DACL
// get ACE count
int aceCount = 0;
if (aclAddress == 0L) {
// no ACEs
aceCount = 0;
} else {
}
// decode each of the ACEs to AclEntry objects
for (int i=0; i<aceCount; i++) {
}
return result;
}
}