]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-selinux.c
aae818068ac52c666444722733aa431b9a585f94
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2016 Zbigniew Jędrzejewski-Szmek
8 #include "alloc-util.h"
11 #include "selinux-util.h"
12 #include "string-util.h"
13 #include "time-util.h"
16 static void test_testing(void) {
19 log_info("============ %s ==========", __func__
);
21 b
= mac_selinux_use();
22 log_info("mac_selinux_use → %s", yes_no(b
));
24 b
= mac_selinux_use();
25 log_info("mac_selinux_use → %s", yes_no(b
));
29 b
= mac_selinux_use();
30 log_info("mac_selinux_use → %s", yes_no(b
));
32 b
= mac_selinux_use();
33 log_info("mac_selinux_use → %s", yes_no(b
));
36 static void test_loading(void) {
40 log_info("============ %s ==========", __func__
);
42 n1
= now(CLOCK_MONOTONIC
);
43 r
= mac_selinux_init();
44 n2
= now(CLOCK_MONOTONIC
);
45 log_info_errno(r
, "mac_selinux_init → %d %.2fs (%m)", r
, (n2
- n1
)/1e6
);
48 static void test_cleanup(void) {
51 log_info("============ %s ==========", __func__
);
53 n1
= now(CLOCK_MONOTONIC
);
55 n2
= now(CLOCK_MONOTONIC
);
56 log_info("mac_selinux_finish → %.2fs", (n2
- n1
)/1e6
);
59 static void test_misc(const char* fname
) {
60 _cleanup_(mac_selinux_freep
) char *label
= NULL
, *label2
= NULL
, *label3
= NULL
;
62 _cleanup_close_
int fd
= -1;
64 log_info("============ %s ==========", __func__
);
66 r
= mac_selinux_get_our_label(&label
);
67 log_info_errno(r
, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
70 r
= mac_selinux_get_create_label_from_exe(fname
, &label2
);
71 log_info_errno(r
, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
74 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
77 r
= mac_selinux_get_child_mls_label(fd
, fname
, label2
, &label3
);
78 log_info_errno(r
, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
82 static void test_create_file_prepare(const char* fname
) {
85 log_info("============ %s ==========", __func__
);
87 r
= mac_selinux_create_file_prepare(fname
, S_IRWXU
);
88 log_info_errno(r
, "mac_selinux_create_file_prepare → %d (%m)", r
);
90 mac_selinux_create_file_clear();
93 int main(int argc
, char **argv
) {
94 const char *path
= SYSTEMD_BINARY_PATH
;
98 log_set_max_level(LOG_DEBUG
);
99 log_parse_environment();
104 test_create_file_prepare(path
);