Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : :
3 : : #include "capability-util.h"
4 : : #include "dev-setup.h"
5 : : #include "fs-util.h"
6 : : #include "path-util.h"
7 : : #include "rm-rf.h"
8 : : #include "tmpfile-util.h"
9 : :
10 : 4 : int main(int argc, char *argv[]) {
11 : 4 : _cleanup_(rm_rf_physical_and_freep) char *p = NULL;
12 : : const char *f;
13 : : struct stat st;
14 : :
15 [ + - ]: 4 : if (have_effective_cap(CAP_DAC_OVERRIDE) <= 0)
16 : 4 : return EXIT_TEST_SKIP;
17 : :
18 [ # # ]: 0 : assert_se(mkdtemp_malloc("/tmp/test-dev-setupXXXXXX", &p) >= 0);
19 : :
20 [ # # # # : 0 : f = prefix_roota(p, "/run");
# # # # #
# # # # #
# # ]
21 [ # # ]: 0 : assert_se(mkdir(f, 0755) >= 0);
22 : :
23 [ # # ]: 0 : assert_se(make_inaccessible_nodes(p, 1, 1) >= 0);
24 : :
25 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/reg");
# # # # #
# # # # #
# # ]
26 [ # # ]: 0 : assert_se(stat(f, &st) >= 0);
27 [ # # ]: 0 : assert_se(S_ISREG(st.st_mode));
28 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
29 : :
30 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/dir");
# # # # #
# # # # #
# # ]
31 [ # # ]: 0 : assert_se(stat(f, &st) >= 0);
32 [ # # ]: 0 : assert_se(S_ISDIR(st.st_mode));
33 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
34 : :
35 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/fifo");
# # # # #
# # # # #
# # ]
36 [ # # ]: 0 : assert_se(stat(f, &st) >= 0);
37 [ # # ]: 0 : assert_se(S_ISFIFO(st.st_mode));
38 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
39 : :
40 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/sock");
# # # # #
# # # # #
# # ]
41 [ # # ]: 0 : assert_se(stat(f, &st) >= 0);
42 [ # # ]: 0 : assert_se(S_ISSOCK(st.st_mode));
43 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
44 : :
45 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/chr");
# # # # #
# # # # #
# # ]
46 [ # # ]: 0 : if (stat(f, &st) < 0)
47 [ # # ]: 0 : assert_se(errno == ENOENT);
48 : : else {
49 [ # # ]: 0 : assert_se(S_ISCHR(st.st_mode));
50 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
51 : : }
52 : :
53 [ # # # # : 0 : f = prefix_roota(p, "/run/systemd/inaccessible/blk");
# # # # #
# # # # #
# # ]
54 [ # # ]: 0 : if (stat(f, &st) < 0)
55 [ # # ]: 0 : assert_se(errno == ENOENT);
56 : : else {
57 [ # # ]: 0 : assert_se(S_ISBLK(st.st_mode));
58 [ # # ]: 0 : assert_se((st.st_mode & 07777) == 0000);
59 : : }
60 : :
61 : 0 : return EXIT_SUCCESS;
62 : : }
|