2 This file is part of systemd.
4 Copyright 2016 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
25 #include "selinux-util.h"
26 #include "string-util.h"
27 #include "time-util.h"
30 static void test_testing(void) {
33 log_info("============ %s ==========", __func__);
35 b = mac_selinux_use();
36 log_info("mac_selinux_use → %s", yes_no(b));
38 b = mac_selinux_have();
39 log_info("mac_selinux_have → %s", yes_no(b));
43 b = mac_selinux_use();
44 log_info("mac_selinux_use → %s", yes_no(b));
46 b = mac_selinux_have();
47 log_info("mac_selinux_have → %s", yes_no(b));
50 static void test_loading(void) {
54 log_info("============ %s ==========", __func__);
56 n1 = now(CLOCK_MONOTONIC);
57 r = mac_selinux_init();
58 n2 = now(CLOCK_MONOTONIC);
59 log_info_errno(r, "mac_selinux_init → %d %.2fs (%m)", r, (n2 - n1)/1e6);
62 static void test_cleanup(void) {
65 log_info("============ %s ==========", __func__);
67 n1 = now(CLOCK_MONOTONIC);
69 n2 = now(CLOCK_MONOTONIC);
70 log_info("mac_selinux_finish → %.2fs", (n2 - n1)/1e6);
73 #if 0 /// UNNEEDED by elogind
74 static void test_misc(const char* fname) {
75 _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
77 _cleanup_close_ int fd = -1;
79 log_info("============ %s ==========", __func__);
81 r = mac_selinux_get_our_label(&label);
82 log_info_errno(r, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
85 r = mac_selinux_get_create_label_from_exe(fname, &label2);
86 log_info_errno(r, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
89 fd = socket(AF_INET, SOCK_DGRAM, 0);
92 r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3);
93 log_info_errno(r, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
98 static void test_create_file_prepare(const char* fname) {
101 log_info("============ %s ==========", __func__);
103 r = mac_selinux_create_file_prepare(fname, S_IRWXU);
104 log_info_errno(r, "mac_selinux_create_file_prepare → %d (%m)", r);
106 mac_selinux_create_file_clear();
109 int main(int argc, char **argv) {
110 const char *path = SYSTEMD_BINARY_PATH;
114 log_set_max_level(LOG_DEBUG);
115 log_parse_environment();
119 #if 0 /// UNNEEDED by elogind
122 test_create_file_prepare(path);