]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-acl-util.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 #include "errno-util.h"
11 #include "format-util.h"
12 #include "string-util.h"
14 #include "tmpfile-util.h"
15 #include "user-util.h"
17 static int test_add_acls_for_user(void) {
18 char fn
[] = "/tmp/test-empty.XXXXXX";
19 _cleanup_close_
int fd
= -1;
24 log_info("/* %s */", __func__
);
26 fd
= mkostemp_safe(fn
);
29 /* Use the mode that user journal files use */
30 assert_se(fchmod(fd
, 0640) == 0);
32 cmd
= strjoina("ls -l ", fn
);
33 assert_se(system(cmd
) == 0);
35 cmd
= strjoina("getfacl -p ", fn
);
36 assert_se(system(cmd
) == 0);
39 const char *nobody
= NOBODY_USER_NAME
;
40 r
= get_user_creds(&nobody
, &uid
, NULL
, NULL
, NULL
, 0);
46 r
= fd_add_uid_acl_permission(fd
, uid
, ACL_READ
);
47 if (ERRNO_IS_NOT_SUPPORTED(r
))
48 return log_tests_skipped("no ACL support on /tmp");
50 log_info_errno(r
, "fd_add_uid_acl_permission(%i, "UID_FMT
", ACL_READ): %m", fd
, uid
);
53 cmd
= strjoina("ls -l ", fn
);
54 assert_se(system(cmd
) == 0);
56 cmd
= strjoina("getfacl -p ", fn
);
57 assert_se(system(cmd
) == 0);
59 /* set the acls again */
61 r
= fd_add_uid_acl_permission(fd
, uid
, ACL_READ
);
64 cmd
= strjoina("ls -l ", fn
);
65 assert_se(system(cmd
) == 0);
67 cmd
= strjoina("getfacl -p ", fn
);
68 assert_se(system(cmd
) == 0);
74 int main(int argc
, char **argv
) {
75 return test_add_acls_for_user();