]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5bb5b236 ZJS |
2 | |
3 | #include <fcntl.h> | |
4 | #include <stdlib.h> | |
5 | #include <sys/stat.h> | |
6 | #include <unistd.h> | |
7 | ||
8 | #include "acl-util.h" | |
9 | #include "fd-util.h" | |
5bb5b236 | 10 | #include "string-util.h" |
e4de7287 | 11 | #include "tmpfile-util.h" |
5bb5b236 ZJS |
12 | #include "user-util.h" |
13 | ||
14 | static void test_add_acls_for_user(void) { | |
15 | char fn[] = "/tmp/test-empty.XXXXXX"; | |
16 | _cleanup_close_ int fd = -1; | |
17 | char *cmd; | |
18 | uid_t uid; | |
19 | int r; | |
20 | ||
646853bd | 21 | fd = mkostemp_safe(fn); |
5bb5b236 ZJS |
22 | assert_se(fd >= 0); |
23 | ||
24 | /* Use the mode that user journal files use */ | |
d879fca6 | 25 | assert_se(fchmod(fd, 0640) == 0); |
5bb5b236 ZJS |
26 | |
27 | cmd = strjoina("ls -l ", fn); | |
28 | assert_se(system(cmd) == 0); | |
29 | ||
30 | cmd = strjoina("getfacl -p ", fn); | |
31 | assert_se(system(cmd) == 0); | |
32 | ||
33 | if (getuid() == 0) { | |
a3d37fe9 | 34 | const char *nobody = NOBODY_USER_NAME; |
fafff8f1 | 35 | r = get_user_creds(&nobody, &uid, NULL, NULL, NULL, 0); |
5bb5b236 ZJS |
36 | if (r < 0) |
37 | uid = 0; | |
38 | } else | |
39 | uid = getuid(); | |
40 | ||
41 | r = add_acls_for_user(fd, uid); | |
42 | assert_se(r >= 0); | |
43 | ||
44 | cmd = strjoina("ls -l ", fn); | |
45 | assert_se(system(cmd) == 0); | |
46 | ||
47 | cmd = strjoina("getfacl -p ", fn); | |
48 | assert_se(system(cmd) == 0); | |
49 | ||
50 | /* set the acls again */ | |
51 | ||
52 | r = add_acls_for_user(fd, uid); | |
53 | assert_se(r >= 0); | |
54 | ||
55 | cmd = strjoina("ls -l ", fn); | |
56 | assert_se(system(cmd) == 0); | |
57 | ||
58 | cmd = strjoina("getfacl -p ", fn); | |
59 | assert_se(system(cmd) == 0); | |
60 | ||
61 | unlink(fn); | |
62 | } | |
63 | ||
64 | int main(int argc, char **argv) { | |
65 | test_add_acls_for_user(); | |
d879fca6 ZJS |
66 | |
67 | return 0; | |
5bb5b236 | 68 | } |