1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2016 Zbigniew Jędrzejewski-Szmek
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "alloc-util.h"
26 #include "selinux-util.h"
27 #include "string-util.h"
28 #include "time-util.h"
31 static void test_testing(void) {
34 log_info("============ %s ==========", __func__);
36 b = mac_selinux_use();
37 log_info("mac_selinux_use → %s", yes_no(b));
39 b = mac_selinux_use();
40 log_info("mac_selinux_use → %s", yes_no(b));
44 b = mac_selinux_use();
45 log_info("mac_selinux_use → %s", yes_no(b));
47 b = mac_selinux_use();
48 log_info("mac_selinux_use → %s", yes_no(b));
51 static void test_loading(void) {
55 log_info("============ %s ==========", __func__);
57 n1 = now(CLOCK_MONOTONIC);
58 r = mac_selinux_init();
59 n2 = now(CLOCK_MONOTONIC);
60 log_info_errno(r, "mac_selinux_init → %d %.2fs (%m)", r, (n2 - n1)/1e6);
63 static void test_cleanup(void) {
66 log_info("============ %s ==========", __func__);
68 n1 = now(CLOCK_MONOTONIC);
70 n2 = now(CLOCK_MONOTONIC);
71 log_info("mac_selinux_finish → %.2fs", (n2 - n1)/1e6);
74 #if 0 /// UNNEEDED by elogind
75 static void test_misc(const char* fname) {
76 _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
78 _cleanup_close_ int fd = -1;
80 log_info("============ %s ==========", __func__);
82 r = mac_selinux_get_our_label(&label);
83 log_info_errno(r, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
86 r = mac_selinux_get_create_label_from_exe(fname, &label2);
87 log_info_errno(r, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
90 fd = socket(AF_INET, SOCK_DGRAM, 0);
93 r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3);
94 log_info_errno(r, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
99 static void test_create_file_prepare(const char* fname) {
102 log_info("============ %s ==========", __func__);
104 r = mac_selinux_create_file_prepare(fname, S_IRWXU);
105 log_info_errno(r, "mac_selinux_create_file_prepare → %d (%m)", r);
107 mac_selinux_create_file_clear();
110 int main(int argc, char **argv) {
111 const char *path = SYSTEMD_BINARY_PATH;
115 log_set_max_level(LOG_DEBUG);
116 log_parse_environment();
120 #if 0 /// UNNEEDED by elogind
123 test_create_file_prepare(path);