Convert shell-based ACL test (tacl_xattr.sh) to C
v4 cover Convert shell-based ACL test (tacl_xattr.sh) to C
This patch series converts the existing shell-based ACL test (tacl_xattr.sh) to C implementation, providing better integration with the LTP test framework and more precise control over test execution.
v3 -> v4
Updated patches 1/8, 4/8 & 6/8 to address review comments. No changes to other patches in the series.
v2 -> v3
Updated patches 1 through 7 to address review comments.
v1 -> v2
Updated patches 1/8, 6/8 and 7/8 to address review comments. Remaining patches remain unchanged
Partially closes(convert tacl_xattr.sh to C)
https://github.com/linux-test-project/ltp/issues/1265
The conversion splits functionality into seven focused test files. Patch 1/8 adds acl_user_obj01.c
Patch 2/8 adds acl_mask01.c
Patch 3/8 adds acl_other01.c
Patch 4/8 adds acl_inherit01.c
Patch 5/8 adds acl_file_ops01.c
Patch 6/8 adds acl_link01.c
Patch 7/8 adds xattr_test01.c
The code has been successfully tested on SLES (kernel 6.12) and fedora (kernel 7.0) releases on ppc64le arch.
Test build is clean in various distros. CI build report at
https://github.com/sacsant/ltp/actions/runs/26932470285
Running the test in a distro missing acl development package or acl library comes out clean with TCONF
root@linux:/opt/ltp# ./testcases/bin/acl_user_obj01 tst_test.c:1414: TCONF: libacl or ACL headers are not available root@linux:/opt/ltp#
Sachin Sant (8):
fs/acl: Add ACL_USER_OBJ permissions test
fs/acl: Add ACL mask interaction tests
fs/acl: Add ACL_OTHER permissions test
fs/acl: Add default ACL inheritance test
fs/acl: Add chmod/chown ACL interaction tests
fs/acl: Add symlink ACL operations test
fs/acl: Add extended attributes test
fs/acl: Remove old shell-based ACL test
runtest/fs | 9 + testcases/kernel/fs/acl/.gitignore | 7 + testcases/kernel/fs/acl/Makefile | 10 + testcases/kernel/fs/acl/acl_file_ops01.c | 302 +++++++++ testcases/kernel/fs/acl/acl_inherit01.c | 116 ++++ testcases/kernel/fs/acl/acl_lib.h | 357 ++++++++++ testcases/kernel/fs/acl/acl_link01.c | 148 +++++ testcases/kernel/fs/acl/acl_mask01.c | 283 ++++++++ testcases/kernel/fs/acl/acl_other01.c | 107 +++ testcases/kernel/fs/acl/acl_user_obj01.c | 116 ++++ testcases/kernel/fs/acl/tacl_xattr.sh | 807 ----------------------- testcases/kernel/fs/acl/xattr_test01.c | 336 ++++++++++ 12 files changed, 1791 insertions(+), 807 deletions(-) create mode 100644 testcases/kernel/fs/acl/.gitignore create mode 100644 testcases/kernel/fs/acl/Makefile create mode 100644 testcases/kernel/fs/acl/acl_file_ops01.c create mode 100644 testcases/kernel/fs/acl/acl_inherit01.c create mode 100644 testcases/kernel/fs/acl/acl_lib.h create mode 100644 testcases/kernel/fs/acl/acl_link01.c create mode 100644 testcases/kernel/fs/acl/acl_mask01.c create mode 100644 testcases/kernel/fs/acl/acl_other01.c create mode 100644 testcases/kernel/fs/acl/acl_user_obj01.c delete mode 100755 testcases/kernel/fs/acl/tacl_xattr.sh create mode 100644 testcases/kernel/fs/acl/xattr_test01.c
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/8 fs/acl: Add ACL_USER_OBJ permissions test
Add acl_user_obj01 test to validate ACL_USER_OBJ (owner) permissions. This test verifies that:
- Traditional permission bits restrict owner access
- ACL_USER_OBJ entries override permission bits
- Owner permissions work correctly with ACL entries
The test creates a directory with restrictive permissions, verifies that file creation is denied, then sets ACL_USER_OBJ with write permissions and confirms that file creation succeeds.
The patch also adds acl_lib.h containing shared helper functions and definitions for ACL and extended attribute tests. This library provides:
- Test user management (ltpuser1, ltpuser2, ltpuser3)
- ACL entry creation and manipulation helpers
- File operation helpers with different uid/gid
- Test path management and cleanup functions
- Extended attribute test definitions
- reset_test_path_no_chown variant to skip chown step
---
V4 changes:
- Add -U flag in create_user_if_needed() to useradd for guaranteed user-private groups.
- Move EOPNOTSUPP handling into set_acl_file() helper
- v3 link https://lore.kernel.org/ltp/[email protected]/T/#t
V3 changes:
- Updated copyright header as per LTP format.
- v2 link https://lore.kernel.org/ltp/[email protected]/T/#t
V2 changes:
- Added reset_test_path_no_chown variant to skip chown step.
acl_link01 and xattr_test01 tests are updated to use this
variant.
- Updated acl_user_obj01.c to correct incorrect description
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use ACL_LIBS variable instead of hardcoded -lacl in Makefile
- Move ACL header includes inside feature guards in acl_lib.h
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 3 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/Makefile | 10 + testcases/kernel/fs/acl/acl_lib.h | 357 +++++++++++++++++++++++ testcases/kernel/fs/acl/acl_user_obj01.c | 116 ++++++++ 5 files changed, 487 insertions(+) create mode 100644 testcases/kernel/fs/acl/.gitignore create mode 100644 testcases/kernel/fs/acl/Makefile create mode 100644 testcases/kernel/fs/acl/acl_lib.h create mode 100644 testcases/kernel/fs/acl/acl_user_obj01.c
runtest/fs +3 -0
@@ -87,3 +87,6 @@ binfmt_misc01 binfmt_misc01.sh binfmt_misc02 binfmt_misc02.sh squashfs01 squashfs01 + +# Run the acl tests +acl_user_obj01 acl_user_obj01
testcases/kernel/fs/acl/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/acl_user_obj01
testcases/kernel/fs/acl/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2026 IBM + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +LDLIBS += $(ACL_LIBS) + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/fs/acl/acl_lib.h new file +357 -0
357 lines not on this page · raw message
testcases/kernel/fs/acl/acl_user_obj01.c new file +116 -0
116 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] fs/acl: Add ACL_USER_OBJ permissions test
Quoted 8 lines · Sachin Sant
fs/acl: Add
ACL_USER_OBJpermissions test fs/acl: Add ACL mask interaction tests fs/acl: AddACL_OTHERpermissions test fs/acl: Add default ACL inheritance test fs/acl: Add chmod/chown ACL interaction tests fs/acl: Add symlink ACL operations test fs/acl: Add extended attributes test fs/acl: Remove old shell-based ACL test
Hi Sachin,
Thanks for the patch series. The overall direction is good — replacing the old bash-based tacl_xattr.sh with modular C tests is the right move. I have a few issues below that need addressing before this can be merged.
---
[PATCH 1/8] fs/acl: Add ACL_USER_OBJ permissions test (acl_user_obj01.c)
The run() function contains two independent test cases — deny-by-mode and grant-by-ACL — both calling tst_res(TPASS/TFAIL,...) and with the second depending on no shared mutable state from the first. Using .test_all for two distinct cases means a failure of the first silently skips the second, and both results appear under the same test counter. Change this to:
.test = run,
.tcnt = 2,
and dispatch on n inside run():
static void run(unsigned int n)
{
switch (n) {
case 0: test_deny_by_mode(); break;
case 1: test_grant_by_acl(); break;
}
}This matches the pattern used in acl_mask01.c and acl_file_ops01.c.
---
[PATCH 6/8] fs/acl: Add symlink ACL operations test (acl_link01.c)
The test verifies that acl_get_file() via a symlink returns the same result as acl_get_file() on the target file directly. It does NOT verify that the ACL was actually set to the intended value.
Consider the failure mode: if acl_set_file(TESTSYMLINK, ...) silently acted on the symlink's own metadata rather than following it to the target, the call would still return 0 (or EOPNOTSUPP), then both acl_get_file(TESTFILE) and acl_get_file(TESTSYMLINK) would still agree with each other (both reflecting the original 0600 permission), and the test would TPASS even though the ACL was never applied to the target.
The commit message and the TPASS string both claim "ACL set via symlink was applied to target file (rwxrw----)" but the code never checks that the actual ACL content is rwxrw----.
After the set-via-symlink step, read back the ACL from the target file directly and verify it matches the expected entries (ACL_USER_OBJ=rwx, ACL_GROUP_OBJ=rw, ACL_OTHER=---) before proceeding to the symlink-vs-direct comparison.
---
[PATCH 7/8] fs/acl: Add extended attributes test (xattr_test01.c)
Two issues:
1. test_xattr_backup_restore() does not test backup/restore
The backup step hard-codes the attribute values into the file using the same compile-time constants (XATTR_TEST1_VALUE, XATTR_TEST2_VALUE) that were used to set the xattrs:
fprintf(fp, "%s=\"%s\"\n", XATTR_TEST1_NAME, XATTR_TEST1_VALUE);
fprintf(fp, "%s=\"%s\"\n", XATTR_TEST2_NAME, XATTR_TEST2_VALUE);This means the backup file is written from constants, not read from the filesystem. The test exercises the restore-and-verify path, but not the backup path (reading live xattrs from the filesystem and saving them). A genuine backup/restore test must generate the backup by reading the attributes off the file (e.g., via getxattr/listxattr) and saving the actual runtime values. As written, the test would pass even if the previous setxattr calls had silently written wrong values or nothing at all, because the backup never actually reads from the filesystem state.
Either rename the test to reflect what it actually tests ("xattr_set_restore" or similar) or fix the backup step to genuinely read live xattr values before removing them.
2. Mixed use of TST_EXP_PASS / TST_EXP_PASS_SILENT inflates the TPASS count
test_xattr() on a clean run emits five TPASS results:
- TST_EXP_POSITIVE(getxattr TESTDIR) → TPASS
- TST_EXP_POSITIVE(getxattr TESTFILE) → TPASS
- TST_EXP_PASS(removexattr) → TPASS
- TST_EXP_FAIL(getxattr after removal) → TPASS - tst_res(TPASS, "Extended attributes...") → TPASS
Likewise test_xattr_backup_restore() emits four. Each function is run as a single test slot (.tcnt = 2), so each slot should produce exactly one TPASS on success. Use TST_EXP_PASS_SILENT (and TST_EXP_POSITIVE_SILENT / manual errno checks) for all intermediate operations, and emit one tst_res(TPASS, ...) per function at the end. Or conversely, remove the final tst_res(TPASS, ...) and keep only the individual macro results — but then be consistent throughout.
---
Minor nits (not blocking, fix at discretion):
* acl_lib.h: The extern declarations for user1_uid, user2_uid, etc. must be matched by a definition in every translation unit that actually references them. Tests that don't use the user infrastructure (acl_link01.c, xattr_test01.c) include the header but provide no definition. This happens to be harmless today because none of the static-inline helpers that use those variables are instantiated in those binaries. However it is fragile: adding a single call to any user-aware helper in those files would cause a link error. Consider moving the globals (and their initializers) to an acl_lib.c file so the header only needs the extern declarations, or at minimum add a comment documenting the requirement.
* acl_lib.h: cleanup_test_paths() unconditionally tries to unlink XATTR_BACKUP_FILE. Tests that never create that file (acl_link01.c, acl_mask01.c, etc.) silently get an ENOENT, which is harmless, but the cleanup function is carrying responsibility for a resource it cannot know was created. Consider splitting out cleanup_xattr_backup() or handling the backup file inside xattr_test01.c's own cleanup.
Thanks,
Copilot
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 1/8] fs/acl: Add ACL_USER_OBJ permissions test
In reply to Sachin SantHi!
Quoted 301 lines
testcases/kernel/fs/acl/acl_lib.h new file +301
-0+/* Extended attribute test values */ +#define XATTR_TEST_DIR_NAME "user.test_attr" +#define XATTR_TEST_DIR_VALUE "test_value" +#define XATTR_TEST_DIR_SIZE 10 +#define XATTR_TEST_FILE_NAME "user.file_attr" +#define XATTR_TEST_FILE_VALUE "file_val" +#define XATTR_TEST_FILE_SIZE 8 +#define XATTR_TEST1_NAME "user.test1" +#define XATTR_TEST1_VALUE "value1" +#define XATTR_TEST1_SIZE 6 +#define XATTR_TEST2_NAME "user.test2" +#define XATTR_TEST2_VALUE "value2" +#define XATTR_TEST2_SIZE 6 + +/* Global variables for test users */ +extern uid_t user1_uid, user2_uid, user3_uid; +extern gid_t user1_gid, user2_gid, user3_gid; +extern int users_created; + +/* Helper functions */ +static inline void reset_test_path_no_chown (void ) +{ +if (unlink (TESTSYMLINK ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" ,TESTSYMLINK ); + +if (unlink (TESTFILE ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" ,TESTFILE ); + +if (rmdir (TESTDIR ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"rmdir(%s) failed" ,TESTDIR ); + +SAFE_MKDIR (TESTDIR ,0755 ); +} + +static inline void reset_test_path (void ) +{ +reset_test_path_no_chown (); +SAFE_CHOWN (TESTDIR , user1_uid, user1_gid); +} + +static inline void cleanup_testfile (void ) +{ +if (unlink (TESTFILE ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" ,TESTFILE ); +} + +#ifdef HAVE_LIBACL +static inline void safe_acl_free (void *ptr) +{ +if (ptr &&acl_free (ptr) ==-1 ) +tst_res (TWARN |TERRNO ,"acl_free failed" ); +} + +static inline void safe_add_perm (acl_permset_t permset,acl_perm_t perm) +{ +if (acl_add_perm (permset, perm) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_add_perm failed" ); +} + +static inline void safe_fill_permset (acl_permset_t permset,int perms) +{ +if (acl_clear_perms (permset) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_clear_perms failed" ); + +if (perms &ACL_READ ) +safe_add_perm (permset,ACL_READ ); + +if (perms &ACL_WRITE ) +safe_add_perm (permset,ACL_WRITE ); + +if (perms &ACL_EXECUTE ) +safe_add_perm (permset,ACL_EXECUTE ); +} + +/* +* Helper to clear ACL mask permissions. +* Finds the ACL_MASK entry in the given ACL and sets its permissions to 0. +*/ +static inline void clear_acl_mask_perms (acl_t acl) +{ +acl_entry_t entry; +acl_permset_t permset; +acl_tag_t tag; +int i; + +for (i =ACL_FIRST_ENTRY ; ; i =ACL_NEXT_ENTRY ) { +int ret =acl_get_entry (acl, i, &entry); + +if (ret ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_get_entry failed" ); + +if (ret !=1 ) +break ; + +if (acl_get_tag_type (entry, &tag) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_get_tag_type failed" ); + +if (tag !=ACL_MASK ) +continue ; + +if (acl_get_permset (entry, &permset) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_get_permset failed" ); + +safe_fill_permset (permset,0 ); + +if (acl_set_permset (entry, permset) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_set_permset failed" ); + +break ; + } +} + +/* +* Helper to add an ACL entry with optional qualifier. +* For ACL_USER and ACL_GROUP tags, qualifier must be provided. +* For other tags (ACL_USER_OBJ, ACL_GROUP_OBJ, ACL_OTHER, ACL_MASK), +* qualifier should be NULL. +*/ +static inline void add_acl_entry_with_qualifier (acl_t acl,acl_tag_t tag, +const void *qualifier, +int perms) +{ +acl_entry_t entry; +acl_permset_t permset; + +if (acl_create_entry (&acl, &entry) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_create_entry failed" ); + +if (acl_set_tag_type (entry, tag) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_set_tag_type failed" ); + +/* Set qualifier for ACL_USER and ACL_GROUP entries */ +if (qualifier &&acl_set_qualifier (entry, qualifier) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_set_qualifier failed" ); + +if (acl_get_permset (entry, &permset) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_get_permset failed" ); + +safe_fill_permset (permset, perms); + +if (acl_set_permset (entry, permset) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_set_permset failed" ); +} + +/* Convenience wrapper for entries without qualifiers */ +static inline void add_acl_entry (acl_t acl,acl_tag_t tag,int perms) +{ +add_acl_entry_with_qualifier (acl, tag,NULL , perms); +} + +/* Convenience wrapper for named user entries */ +static inline void add_named_user_acl_entry (acl_t acl,uid_t uid,int perms) +{ +add_acl_entry_with_qualifier (acl,ACL_USER , &uid, perms); +} + +/* Convenience wrapper for named group entries */ +static inline void add_named_group_acl_entry (acl_t acl,gid_t gid,int perms) +{ +add_acl_entry_with_qualifier (acl,ACL_GROUP , &gid, perms); +} + +static inline void add_empty_acl_entry (acl_t acl,acl_tag_t tag) +{ +add_acl_entry (acl, tag,0 ); +} + +static inline void set_acl_file (const char *path,acl_type_t type,acl_t acl) +{ +if (acl_valid (acl) ==-1 ) +tst_brk (TBROK |TERRNO ,"acl_valid failed" ); + +if (acl_set_file (path, type, acl) ==-1 ) { +if (errno ==EOPNOTSUPP ) +tst_brk (TCONF |TERRNO ,"ACL not supported on %s" , + path); +tst_brk (TBROK |TERRNO ,"acl_set_file(%s) failed" , path); + } +} +#endif + +static inline int create_file_as (uid_t uid,gid_t gid,mode_t mode, +int use_umask,mode_t mask) +{ +pid_t pid; +int status; + + pid =SAFE_FORK (); +if (!pid) { +int fd, err; + +if (setgroups (0 ,NULL ) ==-1 ) { + err = errno; +_exit (err); + } + +if (setgid (gid) ==-1 ) { + err = errno; +_exit (err); + } + +if (setuid (uid) ==-1 ) { + err = errno; +_exit (err); + } + +if (use_umask) +umask (mask); + + fd =open (TESTFILE ,O_CREAT |O_WRONLY , mode); +if (fd >=0 ) { +close (fd); +_exit (0 ); + } + + err = errno; +_exit (err); + } + +SAFE_WAITPID (pid, &status,0 ); + +if (!WIFEXITED (status)) +tst_brk (TBROK ,"Child terminated abnormally" ); + +return WEXITSTATUS (status); +} + +static inline int try_create_as (uid_t uid,gid_t gid,mode_t mode) +{ +return create_file_as (uid, gid, mode,0 ,0 ); +} + +static inline int create_with_umask_as (uid_t uid,gid_t gid,mode_t mode, +mode_t mask) +{ +return create_file_as (uid, gid, mode,1 , mask); +} + +static inline void create_user_if_needed (const char *username,int flag) +{ +struct passwd *pw; + + errno =0 ; + pw =getpwnam (username); +if (!pw && errno !=0 ) +tst_brk (TBROK |TERRNO ,"getpwnam(%s) failed" , username); + +if (!pw) { +if (tst_cmd ((const char *[]){"useradd" ,"-M" ,"-U" , username, +NULL },NULL ,NULL ,TST_CMD_PASS_RETVAL ) !=0 ) +tst_brk (TBROK ,"Failed to create user %s" , username); + users_created |= flag; + } +} + +static inline void create_test_users (void ) +{ +create_user_if_needed (TEST_USER1 ,USER1_CREATED ); +create_user_if_needed (TEST_USER2 ,USER2_CREATED ); +create_user_if_needed (TEST_USER3 ,USER3_CREATED ); +} + +static inline void init_test_users (void ) +{ +struct passwd *pw; + +create_test_users (); + + pw =SAFE_GETPWNAM (TEST_USER1 ); + user1_uid = pw->pw_uid; + user1_gid = pw->pw_gid; + + pw =SAFE_GETPWNAM (TEST_USER2 ); + user2_uid = pw->pw_uid; + user2_gid = pw->pw_gid; + + pw =SAFE_GETPWNAM (TEST_USER3 ); + user3_uid = pw->pw_uid; + user3_gid = pw->pw_gid; +} + +static inline void cleanup_test_users (void ) +{ +if (users_created &USER1_CREATED ) +tst_cmd ((const char *[]){"userdel" ,TEST_USER1 ,NULL }, +NULL ,NULL ,TST_CMD_PASS_RETVAL ); + +if (users_created &USER2_CREATED ) +tst_cmd ((const char *[]){"userdel" ,TEST_USER2 ,NULL }, +NULL ,NULL ,TST_CMD_PASS_RETVAL ); + +if (users_created &USER3_CREATED ) +tst_cmd ((const char *[]){"userdel" ,TEST_USER3 ,NULL }, +NULL ,NULL ,TST_CMD_PASS_RETVAL ); +} + +static inline void cleanup_test_paths (void ) +{ +if (unlink (TESTSYMLINK ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" ,TESTSYMLINK ); +
testcases/kernel/fs/acl/acl_lib.h line 355
Quoted 10 lines
testcases/kernel/fs/acl/acl_lib.h new file +10
-0+if (unlink (TESTFILE ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" ,TESTFILE ); + +if (unlink (XATTR_BACKUP_FILE ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"unlink(%s) failed" , +XATTR_BACKUP_FILE ); + +if (rmdir (TESTDIR ) ==-1 && errno !=ENOENT ) +tst_res (TWARN |TERRNO ,"rmdir(%s) failed" ,TESTDIR ); +}
I think that it would actually be way simpler and easier if we avoided the whole userspace username to UID lookups. The test does not need to create users, etc. if we simply focus on the kernel part of the ACL implementation. For that we would create extended attributes with UIDs (that is what is stored in kernel) and then we could simply run a child process that sets its UIDs so that they match the rules in extended attributes. That way there would be no dependency on libacl, no userspace lookups and we would validate only the kernel part, which is what LTP should do.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 1/8] fs/acl: Add ACL_USER_OBJ permissions test
Quoted 10 lines · Cyril Hrubis
Hi!
I think that it would actually be way simpler and easier if we avoided the whole userspace username to UID lookups. The test does not need to create users, etc. if we simply focus on the kernel part of the ACL implementation. For that we would create extended attributes with UIDs (that is what is stored in kernel) and then we could simply run a child process that sets its UIDs so that they match the rules in extended attributes. That way there would be no dependency on libacl, no userspace lookups and we would validate only the kernel part, which is what LTP should do.
This is an excellent suggestion. This will avoid userspace username-to-UID lookups and libacl dependency. It simplifies tests while maintaining full coverage of kernel ACL functionality.
The existing create_file_as() helper already demonstrates the fork+setuid pattern needed for testing with arbitrary UIDs.
The logic can be:
- Use setxattr(path, "system.posix_acl_access", buf, size, 0) to set ACLs directly
- Build xattr buffers with raw UID/GID values (no username lookups needed)
- Fork child processes that call setuid(uid) + setgid(gid) to match ACL entries
- Test file access in child to validate kernel ACL enforcement
Let me know if this approach is acceptable.
Signature · 7 lines
Thanks - Sachin -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 1/8] fs/acl: Add ACL_USER_OBJ permissions test
Hi!
Quoted 18 lines
This is an excellent suggestion. This will avoid userspace username-to-UID lookups
and libacl dependency. It simplifies tests while maintaining full coverage of kernel
ACL functionality.The existing
create_file_as()helper already demonstrates the fork+setuid pattern
needed for testing with arbitrary UIDs.The logic can be:
- Usesetxattr(path, "system.posix_acl_access", buf, size, 0)to set ACLs directly
- Build xattr buffers with raw UID/GID values (no username lookups needed)
- Fork child processes that call setuid(uid) + setgid(gid) to match ACL entries
- Test file access in child to validate kernel ACL enforcement
Quoted 1 line
Let me know if this approach is acceptable.
Sounds good.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] fs/acl: Add ACL_USER_OBJ permissions test
In reply to Sachin SantHi Sachin,
Quoted 1 line · Sachin Sant
fs/acl: Add
ACL_USER_OBJpermissions test
--- [PATCH 1/8] ---
Quoted 2 lines
The patch also adds
acl_lib.hcontaining shared helper functions and definitions for ACL and extended attribute tests.
The commit adds two distinct things: the shared helper library acl_lib.h, and the first test acl_user_obj01.c. Per Ground Rule 7, each patch must contain exactly one logical change. acl_lib.h should be introduced in a preparatory commit before the tests that use it.
testcases/kernel/fs/acl/acl_user_obj01.c line 60
Quoted 5 lines
then sets
ACL_USER_OBJwith write permissions and confirms that file creation succeeds.testcases/kernel/fs/acl/acl_user_obj01.c new file +2
-0+add_acl_entry (acl,ACL_USER_OBJ , +ACL_READ |ACL_WRITE |ACL_EXECUTE );
The body says "sets ACL_USER_OBJ with write permissions" but the code grants read, write, and execute (rwx). The description should say "full permissions (rwx)" or "rwx".
testcases/kernel/fs/acl/acl_user_obj01.c line 26
Quoted 5 lines
testcases/kernel/fs/acl/acl_user_obj01.c new file +5
-0+uid_t user1_uid, user2_uid, user3_uid; +gid_t user1_gid, user2_gid, user3_gid; +int users_created =0 ; + +#ifdef HAVE_LIBACL
These variable definitions are outside the #ifdef HAVE_LIBACL guard but are only used inside it. Per c-tests.md Rule 16, all test code must be wrapped by the feature guard. Move these three lines inside the #ifdef block.
The same pattern appears in acl_mask01.c (patch 2/8), acl_other01.c (patch 3/8), acl_inherit01.c (patch 4/8), and acl_file_ops01.c (patch 5/8).
Quoted 1 line
+LDLIBS += $(ACL_LIBS)
This applies the ACL library link flag to every binary in the directory, including xattr_test01, which uses only xattr syscalls and does not call any libacl functions. Per the build-system rules, per-target flags are preferred when not every test truly needs them.
Verdict: Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/8 fs/acl: Add ACL mask interaction tests
In reply to Sachin SantAdd acl_mask01 test with 3 test cases to validate ACL_MASK interaction with named user and group entries:
1. ACL_USER with mask - Named user permissions restricted by mask
2. ACL_GROUP with mask - Named group permissions restricted by mask
3. ACL_GROUP_OBJ with mask - Group owner permissions restricted by mask
Each test verifies that:
- With mask set to rwx, access is granted
- With mask cleared (---), access is denied with EACCES
This validates that ACL_MASK correctly restricts permissions for ACL_USER, ACL_GROUP, and ACL_GROUP_OBJ entries.
---
V2 changes:
- Updated copyright header as per LTP format.
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_mask01.c | 283 +++++++++++++++++++++++++++ 3 files changed, 285 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_mask01.c
runtest/fs +1 -0
@@ -90,3 +90,4 @@ squashfs01 squashfs01 # Run the acl tests acl_user_obj01 acl_user_obj01 +acl_mask01 acl_mask01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -1 +1,2 @@ /acl_user_obj01 +/acl_mask01
testcases/kernel/fs/acl/acl_mask01.c new file +283 -0
283 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/8 fs/acl: Add ACL_OTHER permissions test
In reply to Sachin SantAdd acl_other01 test to validate that ACL_OTHER permissions are not affected by ACL_MASK.
The test verifies that:
- ACL_OTHER entry with rwx permissions allows access
- ACL_MASK set to --- does not restrict ACL_OTHER
- Users not matching owner, named users, or groups use ACL_OTHER
This confirms that ACL_MASK only affects ACL_USER, ACL_GROUP_OBJ, and ACL_GROUP entries, but not ACL_OTHER.
---
V2 changes:
- Updated copyright header as per LTP format.
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_other01.c | 107 ++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_other01.c
runtest/fs +1 -0
@@ -91,3 +91,4 @@ squashfs01 squashfs01 # Run the acl tests acl_user_obj01 acl_user_obj01 acl_mask01 acl_mask01 +acl_other01 acl_other01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -1,2 +1,3 @@ /acl_user_obj01 /acl_mask01 +/acl_other01
testcases/kernel/fs/acl/acl_other01.c new file +107 -0
107 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/8 fs/acl: Add chmod/chown ACL interaction tests
In reply to Sachin SantAdd acl_file_ops01 test with 2 test cases to validate chmod and chown interaction with ACL entries:
1. chmod interaction - Verifies that chmod updates ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER entries to match new permission bits. Sets ACL with read-only, then chmod 0777, and confirms all three ACL entries now have rwx permissions.
2. chown interaction - Verifies that chown changes file owner and group without modifying ACL entry permissions. Sets ACL entries, performs chown, and confirms ACL permissions are preserved.
These tests ensure chmod and chown work correctly with ACL-enabled files.
---
V2 changes:
- Updated copyright header as per LTP format.
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_file_ops01.c | 302 +++++++++++++++++++++++ 3 files changed, 304 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_file_ops01.c
runtest/fs +1 -0
@@ -93,3 +93,4 @@ acl_user_obj01 acl_user_obj01 acl_mask01 acl_mask01 acl_other01 acl_other01 acl_inherit01 acl_inherit01 +acl_file_ops01 acl_file_ops01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -2,3 +2,4 @@ /acl_mask01 /acl_other01 /acl_inherit01 +/acl_file_ops01
testcases/kernel/fs/acl/acl_file_ops01.c new file +302 -0
302 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 4/8 fs/acl: Add default ACL inheritance test
In reply to Sachin SantAdd acl_inherit01 test to validate default ACL inheritance from parent directory to newly created files.
The test verifies that:
- Default ACLs set on a directory are inherited by new files
- New file permissions reflect the default ACL entries
- File created with umask 0 gets permissions from default ACL
This test sets default ACL with read-only permissions (r--r--r--) on the parent directory, creates a new file with umask 0, and verifies the file has 0444 permissions inherited from the default ACL.
---
V3 changes:
- Remove unused acl_get_file() block
- keep mode-bit validation with explanatory comment
- v2 link https://lore.kernel.org/ltp/[email protected]/T/#t
V2 changes:
- Updated copyright header as per LTP format.
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_inherit01.c | 116 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_inherit01.c
runtest/fs +1 -0
@@ -92,3 +92,4 @@ squashfs01 squashfs01 acl_user_obj01 acl_user_obj01 acl_mask01 acl_mask01 acl_other01 acl_other01 +acl_inherit01 acl_inherit01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -1,3 +1,4 @@ /acl_user_obj01 /acl_mask01 /acl_other01 +/acl_inherit01
testcases/kernel/fs/acl/acl_inherit01.c new file +116 -0
116 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 6/8 fs/acl: Add symlink ACL operations test
In reply to Sachin SantAdd acl_link01 test to verify that ACL operations on symlinks follow the symlink to the target file. The test validates that setting and getting ACLs through a symlink path affects the target file, not the symlink itself.
Test coverage:
- Create regular file with mode 0600 (rw-------)
- Set distinct ACL (rwxrw----) through symlink path
- Verify ACL was set on target file by reading directly
- Get ACL through symlink path
- Verify both ACLs match and differ from initial 0600 mode
The test uses distinct permissions to ensure it can detect if symlink-following fails.
Test returns TCONF if ACL is not supported by the filesystem.
---
V4 changes:
- Rewrite test logic to use distinct ACL (rwxrw----) that
differs from initial mode.
- Update commit message to reflect the implementation.
- v3 link https://lore.kernel.org/ltp/[email protected]/T/#t
V3 changes:
- Updated the test to read the ACL from both TESTSYMLINK
and TESTFILE, and verify the expected entries/permissions match.
- Updated commit message to reflect this change.
- Updated copyright header as per LTP format.
- v2 link https://lore.kernel.org/ltp/[email protected]/T/#t
V2 changes:
- Updated incorrect TCONF message and description text
- Updated commit message to remove incorrect symlinks wording
- Use reset_test_path_no_chown variant to skip chown step
and removed needs_cmd tag to avoid useradd/userdel dependency
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_link01.c | 148 +++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_link01.c
runtest/fs +1 -0
@@ -94,3 +94,4 @@ acl_mask01 acl_mask01 acl_other01 acl_other01 acl_inherit01 acl_inherit01 acl_file_ops01 acl_file_ops01 +acl_link01 acl_link01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -3,3 +3,4 @@ /acl_other01 /acl_inherit01 /acl_file_ops01 +/acl_link01
testcases/kernel/fs/acl/acl_link01.c new file +148 -0
148 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 7/8 fs/acl: Add extended attributes test
In reply to Sachin SantAdd xattr_test01 implementing extended attributes testing
- Test xattr set/get/remove operations on files and directories
- Test xattr backup and restore functionality
- Support multiple filesystems (ext2/3/4, xfs, btrfs)
---
V3 changes:
- Updated copyright header as per LTP format.
- Updated commit message as per review comments.
- v2 link https://lore.kernel.org/ltp/[email protected]/T/#t
V2 changes:
- Use reset_test_path_no_chown variant to skip chown step
and removed needs_cmd tag to avoid useradd/userdel dependency
- v1 link https://lore.kernel.org/ltp/[email protected]/T/#t
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/xattr_test01.c | 336 +++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 testcases/kernel/fs/acl/xattr_test01.c
runtest/fs +1 -0
@@ -95,3 +95,4 @@ acl_other01 acl_other01 acl_inherit01 acl_inherit01 acl_file_ops01 acl_file_ops01 acl_link01 acl_link01 +xattr_test01 xattr_test01
testcases/kernel/fs/acl/.gitignore +1 -0
@@ -4,3 +4,4 @@ /acl_inherit01 /acl_file_ops01 /acl_link01 +/xattr_test01
testcases/kernel/fs/acl/xattr_test01.c new file +336 -0
336 lines not on this page · raw message
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 8/8 fs/acl: Remove old shell-based ACL test
In reply to Sachin SantRemove tacl_xattr.sh, the old shell-based ACL and extended attribute test script. This test has been replaced by the new modular C-based test suite:
- acl_user_obj01: ACL_USER_OBJ permissions
- acl_mask01: ACL mask interactions (3 tests)
- acl_other01: ACL_OTHER permissions
- acl_inherit01: Default ACL inheritance
- acl_file_ops01: chmod/chown interactions (2 tests)
- acl_link01: Symlink ACL operations
- xattr_test01: Extended attributes (2 tests)
---
V1 changes:
- Updated commit message to reflect correct number of
test scenario in xattr_test01
- rfc link https://lore.kernel.org/ltp/[email protected]/T/#t
--- testcases/kernel/fs/acl/tacl_xattr.sh | 807 -------------------------- 1 file changed, 807 deletions(-) delete mode 100755 testcases/kernel/fs/acl/tacl_xattr.sh
testcases/kernel/fs/acl/tacl_xattr.sh deleted +0 -807
@@ -1,807 +0,0 @@ -#!/bin/bash -############################################################## -# -# Copyright (c) International Business Machines Corp., 2003 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, -# -# FILE : tacl_xattr.sh -# USAGE : ./tacl_xattr.sh -# -# DESCRIPTION : A script that will test ACL and Extend Attribute on Linux system. -# REQUIREMENTS: -# 1) Kernel with loop device support -# 2) A spare (scratch) disk partition of 100MB or larger. -# 3) Kernel with ACL and Extend Attribute function support -# -# HISTORY : -# 10/23/2003 Kai Zhao ([email protected]) -# 07/06/2004 Jacky Malcles enable ext3 & clean users home dir. -# -# CODE COVERAGE: -# 76.3% - fs/posix_acl.c -# 80.9% - xattr_acl.c -# 73.0% - xattr.c -# -############################################################## - -CUR_PATH="" -CONTENT="" -RES="" -USER_PERMISSION="" -GROUP_PERMISSION="" -OTHER_PERMISSION="" -ITEM_OWNER="" -ITEM_GROUP="" - -################################################################ -# -# Make sure that uid=root is running this script. -# Make sure that loop device is built into the kernel -# Make sure that ACL(Access Control List) and Extended Attribute are -# built into the kernel -# -################################################################ - -if [ $UID != 0 ] -then - echo "FAILED: Must have root access to execute this script" - exit 1 -fi - -################################################################# -# -# Prepare Ext2 file system for ACL and Extended Attribute test -# Make some directory , file and symlink for the test -# Add three users for the test -# -################################################################# - -if [ ! -e tacl ] -then - mkdir -m 777 tacl -else - echo "FAILED: Directory tacl are exist" - exit 1 -fi - -dd if=/dev/zero of=tacl/blkext2 bs=1k count=10240 -chmod 777 tacl/blkext2 - -losetup /dev/loop0 tacl/blkext2 >/dev/null 2>&1 -if [ $? != 0 ] -then - printf "\nFAILED: [ losetup ] Must have loop device support by kernel\n" - printf "\t to execute this script\n" - exit 1 -fi - -mount | grep ext2 -if [ $? != 0 ] -then - mkfs -t ext3 /dev/loop0 - mkdir -m 777 tacl/mount-ext2 - mount -t ext3 -o defaults,acl,user_xattr /dev/loop0 tacl/mount-ext2 - if [ $? != 0 ] - then - printf "\nFAILED: [ mount ] Make sure that ACL (Access Control List)\n" - printf "\t and Extended Attribute are built into the kernel\n" - printf "\t Can not mount ext2 file system with acl and user_xattr options\n" - exit 1 - fi - -else - mkfs -t ext2 /dev/loop0 - mkdir -m 777 tacl/mount-ext2 - mount -t ext2 -o defaults,acl,user_xattr /dev/loop0 tacl/mount-ext2 - if [ $? != 0 ] - then - printf "\nFAILED: [ mount ] Make sure that ACL (Access Control List)\n" - printf "\t and Extended Attribute are built into the kernel\n" - printf "\t Can not mount ext2 file system with acl and user_xattr options\n" - exit 1 - fi -fi - -chmod 777 tacl/mount-ext2 - -useradd -d `pwd`/tacl/tacluser1 tacluser1 -useradd -d `pwd`/tacl/tacluser2 tacluser2 -useradd -d `pwd`/tacl/tacluser3 tacluser3 -useradd -d `pwd`/tacl/tacluser4 tacluser4 - -if [ ! -e tacl/mount-ext2/shared ] -then - mkdir -p -m 777 tacl/mount-ext2/shared -fi - -CUR_PATH=`pwd` - -su - tacluser1 << TACL_USER1 - - mkdir $CUR_PATH/tacl/mount-ext2/shared/team1 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/file1 - - cd $CUR_PATH/tacl/mount-ext2/shared/team1 - ln -sf file1 symlinkfile1 - cd $CUR_PATH - - cd $CUR_PATH/tacl/mount-ext2/shared - ln -sf team1 symlinkdir1 - cd $CUR_PATH - -TACL_USER1 - -su - tacluser2 << TACL_USER2 - - mkdir $CUR_PATH/tacl/mount-ext2/shared/team2 - touch $CUR_PATH/tacl/mount-ext2/shared/team2/file1 - - cd $CUR_PATH/tacl/mount-ext2/shared/team2 - ln -sf file1 symlinkfile1 - cd $CUR_PATH - - cd $CUR_PATH/tacl/mount-ext2/shared - ln -sf team2 symlinkdir2 - cd $CUR_PATH - -TACL_USER2 - -############################################################################################# -# -# The permissions bit limit user's act -# lrwxrwxrwx 1 tacluser1 tacluser1 5 Jun 23 13:39 symlinkdir1 -> team1 -# lrwxrwxrwx 1 tacluser2 tacluser2 5 Jun 23 13:39 symlinkdir2 -> team2 -# dr-x------ 2 tacluser1 tacluser1 1024 Jun 23 13:39 team1 -# drwxrwxr-x 2 tacluser2 tacluser2 1024 Jun 23 13:39 team2 -# -############################################################################################# - -chmod 500 tacl/mount-ext2/shared/team1 - -su - tacluser1 << TACL_USER1 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfil1 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile1 ] - then - printf "\nFAILED: [ touch ] Create file must be denied by file permission bits\n" - printf "\t [ Physical Directory ]\n" - else - printf "\nSUCCESS: Create file denied by file permission bits [ Physical directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfil2 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile2 ] - then - printf "\nFAILED: [ touch ] Create file must be denied by file permission bits\n" - printf "\t [ Symlink Directory ]\n" - else - printf "\nSUCCESS: Create file denied by file permission bits [ Symlink directory ]\n" - fi - -TACL_USER1 - -################################################################# -# -# ACL_USER_OBJ are a superset of the permissions specified -# by the file permission bits. -# The effective user ID of the process matches the user ID of -# the file object owner. -# Owner's act are based ACL_USER_OBJ -# -################################################################# - -setfacl -m u::rx tacl/mount-ext2/shared/team1 -su - tacluser1 << TACL_USER1 - - cd $CUR_PATH/tacl/mount-ext2/shared/team1/ 2> /dev/null - if [ $? != 0 ] - then - printf "\nFAILED: [ touch ] ACL_USER_OBJ entry already contains the owner execute\n" - printf "\t permissions, but operation failed [ Physical Directory ]\n" - else - printf "\nSUCCESS: ACL_USER_OBJ entry contains the owner execute permissions,\n" - printf "\t operation success [ Physical Directory ]\n" - fi - - cd $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/ 2> /dev/null - if [ $? != 0 ] - then - printf "\nFAILED: [ touch ] ACL_USER_OBJ entry already contains the owner execute\n" - printf "\t permissions, but operation failed [ Symlink Directory ]\n" - else - printf "\nSUCCESS: ACL_USER_OBJ entry contains the owner execute permissions,\n" - printf "\t operation success [ Symlink Directory ]\n" - fi - -TACL_USER1 - -setfacl -m u::rwx tacl/mount-ext2/shared/team1 - -su - tacluser1 << TACL_USER1 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfil1 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile1 ] - then - printf "\nFAILED: [ touch ] ACL_USER_OBJ entry already contains the owner write \n" - printf "\t permissions, but operation failed [ Physical Directory ]\n" - else - printf "\nSUCCESS: ACL_USER_OBJ entry contains the owner write permissions,\n" - printf "\t operation success [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfil2 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile2 ] - then - printf "\nFAILED: [ touch ] ACL_USER_OBJ entry already contains the owner write \n" - printf "\t permissions, but operation failed [ Symlink Directory ]\n" - else - printf "\nSUCCESS: ACL_USER_OBJ entry contains the owner write permissions,\n" - printf "\t operation success [ Symlink Directory ]\n" - fi - -TACL_USER1 - -################################################################# -# -# The effective user ID of the process matches the qualifier of -# any entry of type ACL_USER -# IF the matching ACL_USER entry and the ACL_MASK -# entry contain the requested permissions,# access is granted, -# ELSE access is denied. -# -################################################################# - -setfacl -m u:tacluser3:rwx tacl/mount-ext2/shared/team1 - -su - tacluser3 << TACL_USER3 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile3 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile3 ] - then - printf "\nSUCCESS: ACL_USER entry contains the user permissions,\n" - printf "\t operation success [ Physical Directory ]\n" - else - printf "\nFAILED: ACL_USER entry contains the user permissions,\n" - printf "\t but operation denied [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile4 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile4 ] - then - printf "\nSUCCESS: ACL_USER entry contains the user permissions,\n" - printf "\t operation success [ Symlink Directory ]\n" - else - printf "\nFAILED: ACL_USER entry contains the user permissions,\n" - printf "\t but operation denied [ Symlink Directory ]\n" - fi - -TACL_USER3 - -setfacl -m mask:--- tacl/mount-ext2/shared/team1 - -su - tacluser3 << TACL_USER3 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile5 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile5 ] - then - printf "\nFAILED: [ touch ] ACL_USER entry contains the user permissions\n" - printf "\t but ACL_MASK are set --- ,\n" - printf "\t operation must be denied [ Physical Directory ]\n" - else - printf "\nSUCCESS: ACL_USER entry contains the user permissions,\n" - printf "\t but ACL_MASK are set ___ ,\n" - printf "\t operation success [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile6 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile6 ] - then - printf "\nFAILED: [ touch ] ACL_USER entry contains the user permissions\n" - printf "\t but ACL_MASK are set --- ,\n" - printf "\t operation must be denied [ Symlink Directory ]\n" - else - printf "\nSUCCESS: ACL_USER entry contains the user permissions,\n" - printf "\t but ACL_MASK are set ___ ,\n" - printf "\t operation success [ Symlink Directory ]\n" - fi - -TACL_USER3 - -########################################################################################### -# -# The effective group ID or any of the supplementary group IDs of the process match the -# qualifier of the entry of type ACL_GROUP_OBJ, or the qualifier of any entry of type -# ACL_GROUP -# -# IF the ACL contains an ACL_MASK entry, THEN -# if the ACL_MASK entry and any of the matching ACL_GROUP_OBJ -# or ACL_GROUP entries contain the requested permissions, -# access is granted, -# -# else access is denied. -# -# ELSE (note that there can be no ACL_GROUP entries without an ACL_MASK entry) -# if the ACL_GROUP_OBJ entry contains the requested permis- -# sions, access is granted, -# -# else access is denied. -# -########################################################################################### - -setfacl -m g:tacluser2:rwx tacl/mount-ext2/shared/team1 - -su - tacluser2 << TACL_USER2 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile7 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile7 ] - then - printf "\nSUCCESS: ACL_GROUP entry contains the group permissions,\n" - printf "\t option success [ Physical Directory ]\n" - else - printf "\nFAILED: [ touch ] ACL_GROUP entry already contains the group permissions,\n" - printf "\t but option success [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile8 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile8 ] - then - printf "\nSUCCESS: ACL_GROUP entry contains the group permissions,\n" - printf "\t option success [ Symlink Directory ]\n" - else - printf "\nFAILED: [ touch ] ACL_GROUP entry already contains the group permissions,\n" - printf "\t but option success [ Symlink Directory ]\n" - fi - -TACL_USER2 - -setfacl -m mask:--- tacl/mount-ext2/shared/team1 - -su - tacluser2 << TACL_USER2 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile9 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile9 ] - then - printf "\nFAILED: [ touch ] ACL_GROUP entry contains the group permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option must no be success [ Physical Directory ]\n" - else - printf "\nSUCCESS: ACL_GROUP entry already contains the group permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option success [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile10 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile10 ] - then - printf "\nFAILED: [ touch ] ACL_GROUP entry contains the group permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option must no be success [ Symlink Directory ]\n" - else - printf "\nSUCCESS: ACL_GROUP entry already contains the group permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option success [ Symlink Directory ]\n" - fi - -TACL_USER2 - -setfacl -m g::rwx tacl/mount-ext2/shared/team1 -usermod -g tacluser1 tacluser2 - -su - tacluser2 << TACL_USER2 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile11 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile11 ] - then - printf "\nSUCCESS: ACL_GROUP_OBJ entry contains the group owner permissions,\n" - printf "\t option success [ Physical Directory ]\n" - else - printf "\nFAILED: [ touch ] ACL_GROUP_OBJ entry already contains the group owner,\n" - printf "\t but option denied [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile12 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile12 ] - then - printf "\nSUCCESS: ACL_GROUP_OBJ entry contains the group owner permissions,\n" - printf "\t option success [ Symlink Directory ]\n" - else - printf "\nFAILED: [ touch ] ACL_GROUP_OBJ entry already contains the group owner,\n" - printf "\t but option denied [ Symlink Directory ]\n" - fi - -TACL_USER2 - -setfacl -m mask:--- tacl/mount-ext2/shared/team1 - -su - tacluser2 << TACL_USER2 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile13 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile13 ] - then - printf "\nFAILED: [ touch ] ACL_GROUP_OBJ entry contains the group owner permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option must no be success [ Physical Directory ]\n" - else - printf "\nSUCCESS: ACL_GROUP_OBJ entry already contains the group owner permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option success [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile14 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile14 ] - then - printf "\nFAILED: [ touch ] ACL_GROUP_OBJ entry contains the group owner permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option must no be success [ Symlink Directory ]\n" - else - printf "\nSUCCESS: ACL_GROUP_OBJ entry already contains the group owner permissions\n" - printf "\t and ACL_MASK entry are set ---,\n" - printf "\t option success [ Symlink Directory ]\n" - fi - -TACL_USER2 - -usermod -g tacluser2 tacluser2 - -################################################################################### -# -# IF the ACL_OTHER entry contains the requested permissions, access is granted -# -################################################################################### - -setfacl -m o::rwx tacl/mount-ext2/shared/team1 - -su - tacluser4 << TACL_USER4 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile15 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile15 ] - then - printf "\nSUCCESS: ACL_OTHER entry contains the user permissions,\n" - printf "\t operation success [ Physical Directory ]\n" - else - printf "\nFAILED: ACL_OTHER entry contains the user permissions,\n" - printf "\t but operation denied [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile16 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile16 ] - then - printf "\nSUCCESS: ACL_OTHER entry contains the user permissions,\n" - printf "\t operation success [ Symlink Directory ]\n" - else - printf "\nFAILED: ACL_OTHER entry contains the user permissions,\n" - printf "\t but operation denied [ Symlink Directory ]\n" - fi - -TACL_USER4 - -setfacl -m mask:--- tacl/mount-ext2/shared/team1 - -su - tacluser4 << TACL_USER4 - - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile17 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/team1/newfile17 ] - then - printf "\nSUCCESS: [ touch ] ACL_OTHER do not strick by ACL_MASK [ Physical Directory ]\n" - else - printf "\nFAILED: ACL_OTHER do not strick by ACL_MASK [ Physical Directory ]\n" - fi - - touch $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile18 2> /dev/null - if [ -e $CUR_PATH/tacl/mount-ext2/shared/symlinkdir1/newfile18 ] - then - printf "\nSUCCESS: [ touch ] ACL_OTHER do not strick by ACL_MASK [ Symlink Directory ]\n" - else - printf "\nFAILED: ACL_OTHER do not strick by ACL_MASK [ Symlink Directory ]\n" - fi - -TACL_USER4 - -############################################################################ -# -# OBJECT CREATION AND DEFAULT ACLs -# The new object inherits the default ACL of the containing directory as its access ACL. -# -############################################################################ - -rm -f tacl/mount-ext2/shared/team1/newfil* - -# -# Test ACL_USER_OBJ default ACLs -# -setfacl -m d:u::r -m d:g::r -m d:o::r tacl/mount-ext2/shared/team1 - -su - tacluser1 << TACL_USER1 - - MASK=`umask` - umask 0 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile1 - umask $MASK > /dev/null - -TACL_USER1 - -CONTENT="" -CONTENT=`ls -l tacl/mount-ext2/shared/team1/newfile1` -RES=`echo $CONTENT | grep ".r--r--r--" | awk '{print $1}'` - -if [ $RES != "" ] -then - printf "\nSUCCESS: With default ACLs set, new file permission set correct.\n" -else - printf "\nFAILED: With default ACLs set, new file permission set not correct\n" -fi - - - -# -# Test ACL_USER and ACL_GROUP defaults ACLs -# -setfacl -m d:u:tacluser3:rw -m d:g:tacluser3:rw tacl/mount-ext2/shared/team1 -su - tacluser3 << TACL_USER3 - - MASK=`umask` - umask 0 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile2 - umask $MASK > /dev/null - -TACL_USER3 - -CONTENT="" -CONTENT=`ls -l tacl/mount-ext2/shared/team1/newfile2` -RES=`echo $CONTENT | grep ".r--rw-r--" | awk '{print $1}'` - -if [ $RES != "" ] -then - printf "\nSUCCESS: With default ACLs set, new file permission set correct.\n" -else - printf "\nFAILED: With default ACLs set, new file permission set not correct\n" -fi - -# -# Test ACL_GROUP default ACLs -# - -setfacl -m d:u::rwx -m d:g::rwx -m d:o::rwx tacl/mount-ext2/shared/team1 -su - tacluser3 << TACL_USER3 - - MASK=`umask` - umask 0 - touch $CUR_PATH/tacl/mount-ext2/shared/team1/newfile3 - umask $MASK > /dev/null - -TACL_USER3 - -CONTENT="" -CONTENT=`ls -l tacl/mount-ext2/shared/team1/newfile3` -RES=`echo $CONTENT | grep ".rw-rw-rw-" | awk '{print \$1}'` - -if [ $RES != "" ] -then - printf "\nSUCCESS: With default ACLs set, new file permission set correct.\n" -else - printf "\nFAILED: With default ACLs set, new file permission set not correct\n" -fi - - -################################################################################# -# -# Chmod also change ACL_USER_OBJ ACL_GROUP_OBJ and ACL_OTHER permissions -# -################################################################################# -su - tacluser3 << TACL_USER3 - MASK=`umask` - umask 0 - - chmod 777 $CUR_PATH/tacl/mount-ext2/shared/team1/newfile3 - umask $MASK > /dev/null -TACL_USER3 - -CONTENT="" -CONTENT=`getfacl tacl/mount-ext2/shared/team1/newfile3` - -USER_PERMISSION=`echo $CONTENT | awk '{print \$10}'` - -GROUP_PERMISSION=`echo $CONTENT | awk '{print \$12}'` -OTHER_PERMISSION=`echo $CONTENT | awk '{print \$15}'` - -if [ $USER_PERMISSION = "user::rwx" ] -then - if [ $GROUP_PERMISSION = "group::rwx" ] - then - if [ $OTHER_PERMISSION = "other::rwx" ] - then - printf "\nSUCCESS: Chmod with ACL_USER_OBJ ACL_GROUP_OBJ and ACL_OTHER are correct\n" - else - printf "\nFAILED: Chmod with ACL_USER_OBJ ACL_GROUP_OBJ and ACL_OTHER are not correct\n" - fi - else - printf "\nFAILED: Chmod with ACL_USER_OBJ ACL_GROUP_OBJ and ACL_OTHER are not correct\n" - fi -else - printf "\nFAILED: Chmod with ACL_USER_OBJ ACL_GROUP_OBJ and ACL_OTHER are not correct\n" -fi - - -##################################################################################### -# -# Chown only change object owner and group -# -##################################################################################### - -chown tacluser2.tacluser2 tacl/mount-ext2/shared/team1/newfile2 -CONTENT="" -CONTENT=`getfacl tacl/mount-ext2/shared/team1/newfile2` - -ITEM_OWNER=`echo $CONTENT | awk '{print \$6}'` -ITEM_GROUP=`echo $CONTENT | awk '{print \$9}'` - -if [ $ITEM_OWNER = "tacluser2" ] -then - if [ $ITEM_GROUP = "tacluser2" ] - then - printf "\nSUCCESS: Chown correct\n" - else - printf "\nFAILED: Chown are not correct\n" - fi -else - echo "FAILED: Chown are not correct" -fi - -##################################################### -# -# Test ACLs backup and restore -# -##################################################### - -getfacl -RL tacl/mount-ext2/ > tacl/tmp1 -setfacl -m u::--- -m g::--- -m o::--- tacl/mount-ext2/shared/team1 -setfacl --restore tacl/tmp1 -getfacl -RL tacl/mount-ext2/ > tacl/tmp2 - -if [ `diff tacl/tmp1 tacl/tmp2` ] -then - printf "\nFAILED: ACLs backup and restore are not correct\n" -else - printf "\nSUCCESS: ACLs backup and restore are correct\n" -fi - -printf "\n\tEnd ACLs Test\n" - -##################################################### -# -# Now begin Extend Attribute test -# -##################################################### - -printf "\nNow begin Extend Attribute Test\n" - -# dir -printf "\nAttach name:value pair to object dir\n\n" -attr -s attrname1 -V attrvalue1 tacl/mount-ext2/shared/team2 -if [ $? != 0 ] -then - echo "FAILED: Attach name:value pair to object dir" -fi - -#file -echo -echo "Attach name:value pair to object file " -echo "" -attr -s attrname2 -V attrvalue2 tacl/mount-ext2/shared/team2/file1 -if [ $? != 0 ] -then - echo "FAILED: Attach name:value pair to object file" -fi - -#symlink file -echo -echo "Attach name:value pair to object symlink file" -echo "" -attr -s attrname3 -V attrvalue3 tacl/mount-ext2/shared/team2/symlinkfile1 -if [ $? != 0 ] -then - echo "INFO: Can't attach name:value pair to object symlink file" -fi - -echo "" -ls -lRt tacl/mount-ext2/shared/team2 - -echo -echo "get extended attributes of filesystem objects" -echo "" - -echo "Dump the values" -getfattr -d tacl/mount-ext2/shared/team2 -if [ $? != 0 ] -then - echo "FAILED: getfattr: Dump the values" -fi - -echo "Recursively dump the values" -getfattr -dR tacl/mount-ext2/* -if [ $? != 0 ] -then - echo "FAILED: getfattr: Recursively Dump the values" -fi - -echo "Do not follow symlinks." -echo "but extended user attributes are disallowed for symbolic links" -getfattr -h --no-dereference tacl/mount-ext2/shared/team2/symlinkfile1 -if [ $? != 0 ] -then - echo "FAILED: getfattr: Do not follow symlinks." -fi -echo - -echo "Logical walk, follow symbolic links" -getfattr -L tacl/mount-ext2/shared/team2/* -if [ $? != 0 ] -then - echo "FAILED: getfattr: Logical walk" -fi - -echo "Physical walk, skip all symbolic links" -getfattr -P tacl/mount-ext2/shared/team2/* -if [ $? != 0 ] -then - echo "FAILED: getfattr: Physical walk" -fi - -echo "attr -g to search the named object" -attr -g attrname1 tacl/mount-ext2/shared/team2 -if [ $? != 0 ] -then - echo "FAILED: attr: to search the named object" -fi -echo - -echo "attr -r to remove the named object" -attr -r attrname2 tacl/mount-ext2/shared/team2/file1 -if [ $? != 0 ] -then - echo "FAILED: attr: to remove the named object" -fi - - -################################# -# -# Backup and Restore -# -################################# -getfattr -dhR -m- -e hex tacl/mount-ext2 > tacl/backup.ea -setfattr -h --restore=tacl/backup.ea - -getfattr -dhR -m- -e hex tacl/mount-ext2 > tacl/backup.ea1 -if [ `diff tacl/backup.ea1 tacl/backup.ea` ] -then - printf "\nFAILED: EAs backup and restore are not correct\n" -else - printf "\nSUCCESS: EAs backup and restore are correct\n" -fi - -printf "\n\tEnd EAs Test\n" - - - -##################################################### -# -# Clean up -# -##################################################### - -userdel tacluser1 -userdel tacluser2 -userdel tacluser3 -userdel tacluser4 -umount -d tacl/mount-ext2 -rm -rf tacl
Signature · 5 lines
2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp