]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-acl-util.c
9a3db3c8e3c179f3b883bd9e05f2e65edfde9dad
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "format-util.h"
11 #include "string-util.h"
12 #include "tmpfile-util.h"
13 #include "user-util.h"
15 static void test_add_acls_for_user(void) {
16 char fn
[] = "/tmp/test-empty.XXXXXX";
17 _cleanup_close_
int fd
= -1;
22 log_info("/* %s */", __func__
);
24 fd
= mkostemp_safe(fn
);
27 /* Use the mode that user journal files use */
28 assert_se(fchmod(fd
, 0640) == 0);
30 cmd
= strjoina("ls -l ", fn
);
31 assert_se(system(cmd
) == 0);
33 cmd
= strjoina("getfacl -p ", fn
);
34 assert_se(system(cmd
) == 0);
37 const char *nobody
= NOBODY_USER_NAME
;
38 r
= get_user_creds(&nobody
, &uid
, NULL
, NULL
, NULL
, 0);
44 r
= fd_add_uid_acl_permission(fd
, uid
, true, false, false);
45 log_info_errno(r
, "fd_add_uid_acl_permission(%i, "UID_FMT
", true, false, false): %m", fd
, uid
);
48 cmd
= strjoina("ls -l ", fn
);
49 assert_se(system(cmd
) == 0);
51 cmd
= strjoina("getfacl -p ", fn
);
52 assert_se(system(cmd
) == 0);
54 /* set the acls again */
56 r
= fd_add_uid_acl_permission(fd
, uid
, true, false, false);
59 cmd
= strjoina("ls -l ", fn
);
60 assert_se(system(cmd
) == 0);
62 cmd
= strjoina("getfacl -p ", fn
);
63 assert_se(system(cmd
) == 0);
68 int main(int argc
, char **argv
) {
69 test_add_acls_for_user();