Skip to content
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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sun.jna.platform.win32;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -2553,8 +2554,6 @@ public static class ACL extends Structure {
public short AceCount;
public short Sbz2;

private ACCESS_ACEStructure[] ACEs;

public ACL() {
super();
}
Expand All @@ -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);
Copy link
Author

@jrobhoward jrobhoward Apr 5, 2018

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

  • It's closer to the original implementation ..but an exception is now thrown from getACEStructures() instead of the constructor.

}

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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A change in contract:

  • IllegalArgumentException (on construction) now becomes an IllegalStateException (on consumption)

}
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()]);
Copy link
Author

@jrobhoward jrobhoward Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible source of confusion:

  • If tolerateUnknownAceTypes is true, and an unknown ACE type is encountered, the returned array size may be less than AceCount
  • If they iterate through AceCount (calling GetAce()), it will yield different results

}

@Override
Expand Down