]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5bb5b236 ZJS |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2015 Zbigniew Jędrzejewski-Szmek | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <fcntl.h> | |
22 | #include <stdlib.h> | |
23 | #include <sys/stat.h> | |
24 | #include <unistd.h> | |
25 | ||
26 | #include "acl-util.h" | |
27 | #include "fd-util.h" | |
28 | #include "fileio.h" | |
29 | #include "string-util.h" | |
30 | #include "user-util.h" | |
31 | ||
32 | static void test_add_acls_for_user(void) { | |
33 | char fn[] = "/tmp/test-empty.XXXXXX"; | |
34 | _cleanup_close_ int fd = -1; | |
35 | char *cmd; | |
36 | uid_t uid; | |
37 | int r; | |
38 | ||
646853bd | 39 | fd = mkostemp_safe(fn); |
5bb5b236 ZJS |
40 | assert_se(fd >= 0); |
41 | ||
42 | /* Use the mode that user journal files use */ | |
d879fca6 | 43 | assert_se(fchmod(fd, 0640) == 0); |
5bb5b236 ZJS |
44 | |
45 | cmd = strjoina("ls -l ", fn); | |
46 | assert_se(system(cmd) == 0); | |
47 | ||
48 | cmd = strjoina("getfacl -p ", fn); | |
49 | assert_se(system(cmd) == 0); | |
50 | ||
51 | if (getuid() == 0) { | |
52 | const char *nobody = "nobody"; | |
53 | r = get_user_creds(&nobody, &uid, NULL, NULL, NULL); | |
54 | if (r < 0) | |
55 | uid = 0; | |
56 | } else | |
57 | uid = getuid(); | |
58 | ||
59 | r = add_acls_for_user(fd, uid); | |
60 | assert_se(r >= 0); | |
61 | ||
62 | cmd = strjoina("ls -l ", fn); | |
63 | assert_se(system(cmd) == 0); | |
64 | ||
65 | cmd = strjoina("getfacl -p ", fn); | |
66 | assert_se(system(cmd) == 0); | |
67 | ||
68 | /* set the acls again */ | |
69 | ||
70 | r = add_acls_for_user(fd, uid); | |
71 | assert_se(r >= 0); | |
72 | ||
73 | cmd = strjoina("ls -l ", fn); | |
74 | assert_se(system(cmd) == 0); | |
75 | ||
76 | cmd = strjoina("getfacl -p ", fn); | |
77 | assert_se(system(cmd) == 0); | |
78 | ||
79 | unlink(fn); | |
80 | } | |
81 | ||
82 | int main(int argc, char **argv) { | |
83 | test_add_acls_for_user(); | |
d879fca6 ZJS |
84 | |
85 | return 0; | |
5bb5b236 | 86 | } |