]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
ada94e69 ZJS |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2016 Zbigniew Jędrzejewski-Szmek | |
ada94e69 ZJS |
6 | ***/ |
7 | ||
8 | #include <sys/stat.h> | |
9 | ||
10 | #include "alloc-util.h" | |
11 | #include "fd-util.h" | |
12 | #include "log.h" | |
13 | #include "selinux-util.h" | |
b5ec6ada | 14 | #include "string-util.h" |
ada94e69 | 15 | #include "time-util.h" |
b5ec6ada | 16 | #include "util.h" |
ada94e69 ZJS |
17 | |
18 | static void test_testing(void) { | |
19 | bool b; | |
20 | ||
21 | log_info("============ %s ==========", __func__); | |
22 | ||
23 | b = mac_selinux_use(); | |
b5ec6ada | 24 | log_info("mac_selinux_use → %s", yes_no(b)); |
ada94e69 | 25 | |
6d395665 GT |
26 | b = mac_selinux_use(); |
27 | log_info("mac_selinux_use → %s", yes_no(b)); | |
ada94e69 ZJS |
28 | |
29 | mac_selinux_retest(); | |
30 | ||
31 | b = mac_selinux_use(); | |
b5ec6ada | 32 | log_info("mac_selinux_use → %s", yes_no(b)); |
ada94e69 | 33 | |
6d395665 GT |
34 | b = mac_selinux_use(); |
35 | log_info("mac_selinux_use → %s", yes_no(b)); | |
ada94e69 ZJS |
36 | } |
37 | ||
38 | static void test_loading(void) { | |
39 | usec_t n1, n2; | |
40 | int r; | |
41 | ||
42 | log_info("============ %s ==========", __func__); | |
43 | ||
44 | n1 = now(CLOCK_MONOTONIC); | |
45 | r = mac_selinux_init(); | |
46 | n2 = now(CLOCK_MONOTONIC); | |
08493e73 | 47 | log_info_errno(r, "mac_selinux_init → %d %.2fs (%m)", r, (n2 - n1)/1e6); |
ada94e69 ZJS |
48 | } |
49 | ||
50 | static void test_cleanup(void) { | |
51 | usec_t n1, n2; | |
52 | ||
53 | log_info("============ %s ==========", __func__); | |
54 | ||
55 | n1 = now(CLOCK_MONOTONIC); | |
56 | mac_selinux_finish(); | |
57 | n2 = now(CLOCK_MONOTONIC); | |
58 | log_info("mac_selinux_finish → %.2fs", (n2 - n1)/1e6); | |
59 | } | |
60 | ||
61 | static void test_misc(const char* fname) { | |
62 | _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL; | |
63 | int r; | |
64 | _cleanup_close_ int fd = -1; | |
65 | ||
66 | log_info("============ %s ==========", __func__); | |
67 | ||
68 | r = mac_selinux_get_our_label(&label); | |
08493e73 | 69 | log_info_errno(r, "mac_selinux_get_our_label → %d, \"%s\" (%m)", |
b5ec6ada | 70 | r, strnull(label)); |
ada94e69 ZJS |
71 | |
72 | r = mac_selinux_get_create_label_from_exe(fname, &label2); | |
08493e73 | 73 | log_info_errno(r, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)", |
b5ec6ada | 74 | r, strnull(label2)); |
ada94e69 ZJS |
75 | |
76 | fd = socket(AF_INET, SOCK_DGRAM, 0); | |
77 | assert_se(fd >= 0); | |
78 | ||
79 | r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3); | |
08493e73 | 80 | log_info_errno(r, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)", |
b5ec6ada | 81 | r, strnull(label3)); |
ada94e69 ZJS |
82 | } |
83 | ||
84 | static void test_create_file_prepare(const char* fname) { | |
85 | int r; | |
86 | ||
87 | log_info("============ %s ==========", __func__); | |
88 | ||
89 | r = mac_selinux_create_file_prepare(fname, S_IRWXU); | |
90 | log_info_errno(r, "mac_selinux_create_file_prepare → %d (%m)", r); | |
91 | ||
92 | mac_selinux_create_file_clear(); | |
93 | } | |
94 | ||
95 | int main(int argc, char **argv) { | |
96 | const char *path = SYSTEMD_BINARY_PATH; | |
97 | if (argc >= 2) | |
98 | path = argv[1]; | |
99 | ||
100 | log_set_max_level(LOG_DEBUG); | |
101 | log_parse_environment(); | |
102 | ||
103 | test_testing(); | |
104 | test_loading(); | |
105 | test_misc(path); | |
106 | test_create_file_prepare(path); | |
107 | test_cleanup(); | |
108 | ||
109 | return 0; | |
110 | } |