Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bugfix] Make sure exec/non-exec is set for setUid, setGid and Sticky…

… correctly when parsing from String
  • Loading branch information...
commit 67c460afe03e2b381f1de2a8472af19707e0ec37 1 parent a769500
Adam Retter adamretter authored
12 src/org/exist/security/internal/aider/UnixStylePermissionAider.java
View
@@ -305,9 +305,21 @@ public static UnixStylePermissionAider fromString(final String modeStr) throws S
} else if(i == 3) {
mode |= (SET_GID << 9);
}
+ mode |= (EXECUTE << (6 - i));
+ break;
+ case SETUID_CHAR_NO_EXEC | SETGID_CHAR_NO_EXEC:
+ if(i == 0) {
+ mode |= (SET_UID << 9);
+ } else if(i == 3) {
+ mode |= (SET_GID << 9);
+ }
break;
case STICKY_CHAR:
mode |= (STICKY << 9);
+ mode |= (EXECUTE << (6 - i));
+ break;
+ case STICKY_CHAR_NO_EXEC:
+ mode |= (STICKY << 9);
break;
case UNSET_CHAR:
break;
79 test/src/org/exist/security/internal/aider/UnixStylePermissionAiderTest.java
View
@@ -2,9 +2,13 @@
import java.util.List;
import java.util.ArrayList;
+import org.exist.security.Permission;
+import org.exist.security.PermissionDeniedException;
import org.exist.util.SyntaxException;
-import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
*
@@ -22,22 +26,71 @@ public SecurityTestPair(final String permissionString, final int permission) {
public String permissionString;
public int permission;
}
+
+ @Test
+ public void setUid_roundtrip() throws PermissionDeniedException {
+ Permission permission = new UnixStylePermissionAider(0555);
+ assertFalse(permission.isSetUid());
+ permission.setSetUid(true);
+ assertTrue(permission.isSetUid());
+ assertEquals(04555, permission.getMode());
+
+ permission = new UnixStylePermissionAider(04555);
+ assertTrue(permission.isSetUid());
+ permission.setSetUid(false);
+ assertFalse(permission.isSetUid());
+ assertEquals(0555, permission.getMode());
+ }
+
+ @Test
+ public void setGid_roundtrip() throws PermissionDeniedException {
+ Permission permission = new UnixStylePermissionAider(0555);
+ assertFalse(permission.isSetGid());
+ permission.setSetGid(true);
+ assertTrue(permission.isSetGid());
+ assertEquals(02555, permission.getMode());
+
+ permission = new UnixStylePermissionAider(02555);
+ assertTrue(permission.isSetGid());
+ permission.setSetGid(false);
+ assertFalse(permission.isSetGid());
+ assertEquals(0555, permission.getMode());
+ }
+
+ @Test
+ public void setSticky_roundtrip() throws PermissionDeniedException {
+ Permission permission = new UnixStylePermissionAider(0555);
+ assertFalse(permission.isSticky());
+ permission.setSticky(true);
+ assertTrue(permission.isSticky());
+ assertEquals(01555, permission.getMode());
+
+ permission = new UnixStylePermissionAider(01555);
+ assertTrue(permission.isSticky());
+ permission.setSticky(false);
+ assertFalse(permission.isSticky());
+ assertEquals(0555, permission.getMode());
+ }
@Test
- public void fromString() throws SyntaxException {
+ public void fromString_toString() throws SyntaxException {
final List<SecurityTestPair> securityTestPairs = new ArrayList<SecurityTestPair>();
- securityTestPairs.add(new SecurityTestPair("rwxrwxrwx", 511));
- securityTestPairs.add(new SecurityTestPair("rwxrwx---", 504));
- securityTestPairs.add(new SecurityTestPair("rwx------", 448));
- securityTestPairs.add(new SecurityTestPair("------rwx", 7));
- securityTestPairs.add(new SecurityTestPair("---rwxrwx", 63));
- securityTestPairs.add(new SecurityTestPair("r--r--r--", 292));
- securityTestPairs.add(new SecurityTestPair("rwxr--r--", 484));
- securityTestPairs.add(new SecurityTestPair("rwxr--r--", 484));
- securityTestPairs.add(new SecurityTestPair("--s------", 2048));
- securityTestPairs.add(new SecurityTestPair("-----s---", 1024));
- securityTestPairs.add(new SecurityTestPair("--------t", 512));
+ securityTestPairs.add(new SecurityTestPair("rwxrwxrwx", 0777));
+ securityTestPairs.add(new SecurityTestPair("rwxrwx---", 0770));
+ securityTestPairs.add(new SecurityTestPair("rwx------", 0700));
+ securityTestPairs.add(new SecurityTestPair("------rwx", 07));
+ securityTestPairs.add(new SecurityTestPair("---rwxrwx", 077));
+ securityTestPairs.add(new SecurityTestPair("r--r--r--", 0444));
+ securityTestPairs.add(new SecurityTestPair("rwxr--r--", 0744));
+ securityTestPairs.add(new SecurityTestPair("rwxrw-rw-", 0766));
+ securityTestPairs.add(new SecurityTestPair("rwxr-xr-x", 0755));
+ securityTestPairs.add(new SecurityTestPair("--s------", 04100));
+ securityTestPairs.add(new SecurityTestPair("--S------", 04000));
+ securityTestPairs.add(new SecurityTestPair("-----s---", 02010));
+ securityTestPairs.add(new SecurityTestPair("-----S---", 02000));
+ securityTestPairs.add(new SecurityTestPair("--------t", 01001));
+ securityTestPairs.add(new SecurityTestPair("--------T", 01000));
for(final SecurityTestPair sec : securityTestPairs) {
final UnixStylePermissionAider perm = UnixStylePermissionAider.fromString(sec.permissionString);
Please sign in to comment.
Something went wrong with that request. Please try again.