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