AclEdit.java revision 2362
/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Sample utility for editing a file's ACL.
*/
public class AclEdit {
// parse string as list of ACE permissions separated by /
if (s.equals(""))
continue;
try {
} catch (IllegalArgumentException x) {
}
}
return perms;
}
// parse string as list of ACE flags separated by /
if (s.equals(""))
continue;
try {
} catch (IllegalArgumentException x) {
}
}
return flags;
}
// parse ACE type
// FIXME: support audit and alarm types in the future
return AclEntryType.ALLOW;
return AclEntryType.DENY;
return null; // keep compiler happy
}
/**
* Parse string of the form:
* [user|group:]<username|groupname>:<perms>[:flags]:<allow|deny>
*/
{
// must have at least 3 components (username:perms:type)
usage();
int index = 0;
// optional first component can indicate user or group type
boolean isGroup = false;
{
if (--remaining < 3)
usage();
}
// user and permissions required
// flags are optional
if (remaining == 1) {
} else {
if (remaining == 2) {
} else {
usage();
}
}
// lookup UserPrincipal
try {
} catch (UserPrincipalNotFoundException x) {
} catch (IOException x) {
}
// map string representation of permissions, flags, and type
// build the ACL entry
return AclEntry.newBuilder()
}
static void usage() {
}
static enum Action {
ADD,
}
/**
* Main class: parses arguments and prints or edits ACL
*/
int index = -1;
// parse arguments
usage();
} else {
// A[index]+entry
index = 0;
} else {
}
}
}
// Aindex-
}
}
// Aindex=entry
}
}
}
usage();
// read file's ACL
}
switch (action) {
// print ACL
case PRINT : {
}
break;
}
// add ACE to existing ACL
case ADD: {
} else {
}
break;
}
// remove ACE
case REMOVE: {
}
break;
}
// replace ACE
case REPLACE: {
}
break;
}
}
}
}