Permalink
Browse files

[bugfix] Make sure to set the correct characters in the permissions s…

…tring when execute bits are not set
  • Loading branch information...
1 parent 4dd00b5 commit 975a2e46ca0e06dab2c0b3882a9795603db9eff0 @adamretter adamretter committed Nov 12, 2013
@@ -58,8 +58,11 @@
public final static String EXECUTE_STRING = "execute";
public final static char SETUID_CHAR = 's';
+ public final static char SETUID_CHAR_NO_EXEC = 'S';
public final static char SETGID_CHAR = 's';
+ public final static char SETGID_CHAR_NO_EXEC = 'S';
public final static char STICKY_CHAR = 't';
+ public final static char STICKY_CHAR_NO_EXEC = 'T';
public final static char READ_CHAR = 'r';
public final static char WRITE_CHAR = 'w';
public final static char EXECUTE_CHAR = 'x';
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2001-2013 The eXist-db Project
+ * Copyright (C) 2013 The eXist-db Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -349,15 +349,15 @@ public String toString() {
final char ch[] = new char[] {
(vector & (READ << 28)) == 0 ? UNSET_CHAR : READ_CHAR,
(vector & (WRITE << 28)) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (vector & (1L << 31)) == 0 ? ((vector & (EXECUTE << 28)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : SETUID_CHAR,
+ (vector & (1L << 31)) == 0 ? ((vector & (EXECUTE << 28)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((vector & (EXECUTE << 28)) == 0 ? SETUID_CHAR_NO_EXEC : SETUID_CHAR),
(vector & (READ << 4)) == 0 ? UNSET_CHAR : READ_CHAR,
(vector & (WRITE << 4)) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (vector & (1 << 7)) == 0 ? ((vector & (EXECUTE << 4)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : SETGID_CHAR,
+ (vector & (1 << 7)) == 0 ? ((vector & (EXECUTE << 4)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((vector & (EXECUTE << 4)) == 0 ? SETGID_CHAR_NO_EXEC : SETGID_CHAR),
(vector & READ) == 0 ? UNSET_CHAR : READ_CHAR,
(vector & WRITE) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (vector & (1 << 3)) == 0 ? ((vector & EXECUTE) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : STICKY_CHAR
+ (vector & (1 << 3)) == 0 ? ((vector & EXECUTE) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((vector & EXECUTE) == 0 ? STICKY_CHAR_NO_EXEC : STICKY_CHAR)
};
return String.valueOf(ch);
}
@@ -1,6 +1,6 @@
/*
* eXist Open Source Native XML Database
- * Copyright (C) 2010-2011 The eXist Project
+ * Copyright (C) 2013 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
@@ -268,15 +268,15 @@ public String toString() {
final char ch[] = new char[] {
(mode & (READ << 6)) == 0 ? UNSET_CHAR : READ_CHAR,
(mode & (WRITE << 6)) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (mode & (SET_UID << 9)) == 0 ? ((mode & (EXECUTE << 6)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : SETUID_CHAR,
+ (mode & (SET_UID << 9)) == 0 ? ((mode & (EXECUTE << 6)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((mode & (EXECUTE << 6)) == 0 ? SETUID_CHAR_NO_EXEC : SETUID_CHAR),
(mode & (READ << 3)) == 0 ? UNSET_CHAR : READ_CHAR,
(mode & (WRITE << 3)) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (mode & (SET_GID << 9)) == 0 ? ((mode & (EXECUTE << 3)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : SETGID_CHAR,
+ (mode & (SET_GID << 9)) == 0 ? ((mode & (EXECUTE << 3)) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((mode & (EXECUTE << 3)) == 0 ? SETGID_CHAR_NO_EXEC : SETGID_CHAR),
(mode & READ) == 0 ? UNSET_CHAR : READ_CHAR,
(mode & WRITE) == 0 ? UNSET_CHAR : WRITE_CHAR,
- (mode & (STICKY << 9)) == 0 ? ((mode & EXECUTE) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : STICKY_CHAR
+ (mode & (STICKY << 9)) == 0 ? ((mode & EXECUTE) == 0 ? UNSET_CHAR : EXECUTE_CHAR) : ((mode & EXECUTE) == 0 ? STICKY_CHAR_NO_EXEC : STICKY_CHAR)
};
return String.valueOf(ch);
}
@@ -267,8 +267,6 @@ public void validate_cant_write_WhenNotOwner_and_NotInGroup_and_OtherWithoutWrit
@Test
public void permission_toString() {
- //TODO need tests for toString() to produce 's' and 'S' where appropriate... big 'S' indicates not 'x'
-
final SecurityManager mockSecurityManager = EasyMock.createMock(SecurityManager.class);
final int ownerId = new Random().nextInt(SecurityManagerImpl.MAX_USER_ID);
@@ -280,24 +278,42 @@ public void permission_toString() {
permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 04777);
assertEquals("rwsrwxrwx", permission.toString());
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 04666);
+ assertEquals("rwSrw-rw-", permission.toString());
+
permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 02777);
assertEquals("rwxrwsrwx", permission.toString());
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 02666);
+ assertEquals("rw-rwSrw-", permission.toString());
+
permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 01777);
assertEquals("rwxrwxrwt", permission.toString());
- permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 07000);
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 07111);
assertEquals("--s--s--t", permission.toString());
+
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 07000);
+ assertEquals("--S--S--T", permission.toString());
- permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 04000);
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 04100);
assertEquals("--s------", permission.toString());
+
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 04000);
+ assertEquals("--S------", permission.toString());
- permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 02000);
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 02010);
assertEquals("-----s---", permission.toString());
+
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 02000);
+ assertEquals("-----S---", permission.toString());
- permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 01000);
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 01001);
assertEquals("--------t", permission.toString());
+ permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 01000);
+ assertEquals("--------T", permission.toString());
+
permission = new UnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, 0777);
assertEquals("rwxrwxrwx", permission.toString());

0 comments on commit 975a2e4

Please sign in to comment.