]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-selinux.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
8 #include "selinux-util.h"
9 #include "string-util.h"
11 #include "time-util.h"
14 static void test_testing(void) {
17 log_info("============ %s ==========", __func__
);
19 b
= mac_selinux_use();
20 log_info("mac_selinux_use → %s", yes_no(b
));
22 b
= mac_selinux_use();
23 log_info("mac_selinux_use → %s", yes_no(b
));
27 b
= mac_selinux_use();
28 log_info("mac_selinux_use → %s", yes_no(b
));
30 b
= mac_selinux_use();
31 log_info("mac_selinux_use → %s", yes_no(b
));
34 static void test_loading(void) {
38 log_info("============ %s ==========", __func__
);
40 n1
= now(CLOCK_MONOTONIC
);
41 r
= mac_selinux_init();
42 n2
= now(CLOCK_MONOTONIC
);
43 log_info_errno(r
, "mac_selinux_init → %d %.2fs (%m)", r
, (n2
- n1
)/1e6
);
46 static void test_cleanup(void) {
49 log_info("============ %s ==========", __func__
);
51 n1
= now(CLOCK_MONOTONIC
);
53 n2
= now(CLOCK_MONOTONIC
);
54 log_info("mac_selinux_finish → %.2fs", (n2
- n1
)/1e6
);
57 static void test_misc(const char* fname
) {
58 _cleanup_(mac_selinux_freep
) char *label
= NULL
, *label2
= NULL
, *label3
= NULL
;
60 _cleanup_close_
int fd
= -1;
62 log_info("============ %s ==========", __func__
);
64 r
= mac_selinux_get_our_label(&label
);
65 log_info_errno(r
, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
68 r
= mac_selinux_get_create_label_from_exe(fname
, &label2
);
69 log_info_errno(r
, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
72 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
75 r
= mac_selinux_get_child_mls_label(fd
, fname
, label2
, &label3
);
76 log_info_errno(r
, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
80 static void test_create_file_prepare(const char* fname
) {
83 log_info("============ %s ==========", __func__
);
85 r
= mac_selinux_create_file_prepare(fname
, S_IRWXU
);
86 log_info_errno(r
, "mac_selinux_create_file_prepare → %d (%m)", r
);
88 mac_selinux_create_file_clear();
91 int main(int argc
, char **argv
) {
92 const char *path
= SYSTEMD_BINARY_PATH
;
96 test_setup_logging(LOG_DEBUG
);
101 test_create_file_prepare(path
);