-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ACL constructor that tolerates files with unknown ACE types #947
Closed
jrobhoward
wants to merge
3
commits into
java-native-access:master
from
jrobhoward:jhoward/inhibit_illegal_argument_exception
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
*/ | ||
package com.sun.jna.platform.win32; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
@@ -2553,8 +2554,6 @@ public static class ACL extends Structure { | |
public short AceCount; | ||
public short Sbz2; | ||
|
||
private ACCESS_ACEStructure[] ACEs; | ||
|
||
public ACL() { | ||
super(); | ||
} | ||
|
@@ -2567,30 +2566,42 @@ public ACL(int size) { | |
public ACL(Pointer pointer) { | ||
super(pointer); | ||
read(); | ||
ACEs = new ACCESS_ACEStructure[AceCount]; | ||
} | ||
|
||
public ACCESS_ACEStructure[] getACEStructures() { | ||
return getACEStructures(false); | ||
} | ||
|
||
public ACCESS_ACEStructure[] getACEStructures(boolean tolerateUnknownAceTypes) { | ||
final List<ACCESS_ACEStructure> ACEs = new ArrayList<ACCESS_ACEStructure>(AceCount); | ||
final Pointer pointer = this.getPointer(); | ||
int offset = size(); | ||
for (int i = 0; i < AceCount; i++) { | ||
Pointer share = pointer.share(offset); | ||
// ACE_HEADER.AceType | ||
final byte aceType = share.getByte(0); | ||
ACCESS_ACEStructure ace; | ||
final Pointer share = pointer.share(offset); | ||
final byte aceType = share.getByte(0); // ACE_HEADER.AceType | ||
final short aceSize; | ||
switch (aceType) { | ||
case ACCESS_ALLOWED_ACE_TYPE: | ||
ace = new ACCESS_ALLOWED_ACE(share); | ||
final ACCESS_ALLOWED_ACE allowedAce = new ACCESS_ALLOWED_ACE(share); | ||
aceSize = allowedAce.AceSize; | ||
ACEs.add(allowedAce); | ||
break; | ||
case ACCESS_DENIED_ACE_TYPE: | ||
ace = new ACCESS_DENIED_ACE(share); | ||
final ACCESS_DENIED_ACE deniedAce = new ACCESS_DENIED_ACE(share); | ||
aceSize = deniedAce.AceSize; | ||
ACEs.add(deniedAce); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Unknown ACE type " + aceType); | ||
if (! tolerateUnknownAceTypes) { | ||
throw new IllegalStateException("Unknown ACE type " + aceType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A change in contract:
|
||
} | ||
final ACE_HEADER aceHeader = new ACE_HEADER(share); | ||
aceSize = aceHeader.AceSize; | ||
break; | ||
} | ||
ACEs[i] = ace; | ||
offset += ace.AceSize; | ||
offset += aceSize; | ||
} | ||
} | ||
|
||
public ACCESS_ACEStructure[] getACEStructures() { | ||
return ACEs; | ||
return ACEs.toArray(new ACCESS_ACEStructure[ACEs.size()]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible source of confusion:
|
||
} | ||
|
||
@Override | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the default behavior to not tolerate unknown ACE types