]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-dev-setup.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / test / test-dev-setup.c
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 int main(int argc, char *argv[]) {
11 _cleanup_(rm_rf_physical_and_freep) char *p = NULL;
12 const char *f;
13 struct stat st;
14
15 if (have_effective_cap(CAP_DAC_OVERRIDE) <= 0)
16 return EXIT_TEST_SKIP;
17
18 assert_se(mkdtemp_malloc("/tmp/test-dev-setupXXXXXX", &p) >= 0);
19
20 f = prefix_roota(p, "/run");
21 assert_se(mkdir(f, 0755) >= 0);
22
23 assert_se(make_inaccessible_nodes(p, 1, 1) >= 0);
24
25 f = prefix_roota(p, "/run/systemd/inaccessible/reg");
26 assert_se(stat(f, &st) >= 0);
27 assert_se(S_ISREG(st.st_mode));
28 assert_se((st.st_mode & 07777) == 0000);
29
30 f = prefix_roota(p, "/run/systemd/inaccessible/dir");
31 assert_se(stat(f, &st) >= 0);
32 assert_se(S_ISDIR(st.st_mode));
33 assert_se((st.st_mode & 07777) == 0000);
34
35 f = prefix_roota(p, "/run/systemd/inaccessible/fifo");
36 assert_se(stat(f, &st) >= 0);
37 assert_se(S_ISFIFO(st.st_mode));
38 assert_se((st.st_mode & 07777) == 0000);
39
40 f = prefix_roota(p, "/run/systemd/inaccessible/sock");
41 assert_se(stat(f, &st) >= 0);
42 assert_se(S_ISSOCK(st.st_mode));
43 assert_se((st.st_mode & 07777) == 0000);
44
45 f = prefix_roota(p, "/run/systemd/inaccessible/chr");
46 if (stat(f, &st) < 0)
47 assert_se(errno == ENOENT);
48 else {
49 assert_se(S_ISCHR(st.st_mode));
50 assert_se((st.st_mode & 07777) == 0000);
51 }
52
53 f = prefix_roota(p, "/run/systemd/inaccessible/blk");
54 if (stat(f, &st) < 0)
55 assert_se(errno == ENOENT);
56 else {
57 assert_se(S_ISBLK(st.st_mode));
58 assert_se((st.st_mode & 07777) == 0000);
59 }
60
61 return EXIT_SUCCESS;
62 }