]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-selinux.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2016 Zbigniew Jędrzejewski-Szmek
10 #include "alloc-util.h"
13 #include "selinux-util.h"
14 #include "string-util.h"
15 #include "time-util.h"
18 static void test_testing(void) {
21 log_info("============ %s ==========", __func__
);
23 b
= mac_selinux_use();
24 log_info("mac_selinux_use → %s", yes_no(b
));
26 b
= mac_selinux_use();
27 log_info("mac_selinux_use → %s", yes_no(b
));
31 b
= mac_selinux_use();
32 log_info("mac_selinux_use → %s", yes_no(b
));
34 b
= mac_selinux_use();
35 log_info("mac_selinux_use → %s", yes_no(b
));
38 static void test_loading(void) {
42 log_info("============ %s ==========", __func__
);
44 n1
= now(CLOCK_MONOTONIC
);
45 r
= mac_selinux_init();
46 n2
= now(CLOCK_MONOTONIC
);
47 log_info_errno(r
, "mac_selinux_init → %d %.2fs (%m)", r
, (n2
- n1
)/1e6
);
50 static void test_cleanup(void) {
53 log_info("============ %s ==========", __func__
);
55 n1
= now(CLOCK_MONOTONIC
);
57 n2
= now(CLOCK_MONOTONIC
);
58 log_info("mac_selinux_finish → %.2fs", (n2
- n1
)/1e6
);
61 static void test_misc(const char* fname
) {
62 _cleanup_(mac_selinux_freep
) char *label
= NULL
, *label2
= NULL
, *label3
= NULL
;
64 _cleanup_close_
int fd
= -1;
66 log_info("============ %s ==========", __func__
);
68 r
= mac_selinux_get_our_label(&label
);
69 log_info_errno(r
, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
72 r
= mac_selinux_get_create_label_from_exe(fname
, &label2
);
73 log_info_errno(r
, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
76 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
79 r
= mac_selinux_get_child_mls_label(fd
, fname
, label2
, &label3
);
80 log_info_errno(r
, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
84 static void test_create_file_prepare(const char* fname
) {
87 log_info("============ %s ==========", __func__
);
89 r
= mac_selinux_create_file_prepare(fname
, S_IRWXU
);
90 log_info_errno(r
, "mac_selinux_create_file_prepare → %d (%m)", r
);
92 mac_selinux_create_file_clear();
95 int main(int argc
, char **argv
) {
96 const char *path
= SYSTEMD_BINARY_PATH
;
100 log_set_max_level(LOG_DEBUG
);
101 log_parse_environment();
106 test_create_file_prepare(path
);