]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-selinux.c
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 "time-util.h"
28 static void test_testing(void) {
31 log_info("============ %s ==========", __func__
);
33 b
= mac_selinux_use();
34 log_info("mac_selinux_use → %d", b
);
36 b
= mac_selinux_have();
37 log_info("mac_selinux_have → %d", b
);
41 b
= mac_selinux_use();
42 log_info("mac_selinux_use → %d", b
);
44 b
= mac_selinux_have();
45 log_info("mac_selinux_have → %d", b
);
48 static void test_loading(void) {
52 log_info("============ %s ==========", __func__
);
54 n1
= now(CLOCK_MONOTONIC
);
55 r
= mac_selinux_init();
56 n2
= now(CLOCK_MONOTONIC
);
57 log_info_errno(r
, "mac_selinux_init → %d (%m) %.2fs", r
, (n2
- n1
)/1e6
);
60 static void test_cleanup(void) {
63 log_info("============ %s ==========", __func__
);
65 n1
= now(CLOCK_MONOTONIC
);
67 n2
= now(CLOCK_MONOTONIC
);
68 log_info("mac_selinux_finish → %.2fs", (n2
- n1
)/1e6
);
71 static void test_misc(const char* fname
) {
72 _cleanup_(mac_selinux_freep
) char *label
= NULL
, *label2
= NULL
, *label3
= NULL
;
74 _cleanup_close_
int fd
= -1;
76 log_info("============ %s ==========", __func__
);
78 r
= mac_selinux_get_our_label(&label
);
79 log_info_errno(r
, "mac_selinux_get_our_label → %d (%m), \"%s\"", r
, label
);
81 r
= mac_selinux_get_create_label_from_exe(fname
, &label2
);
82 log_info_errno(r
, "mac_selinux_create_label_from_exe → %d (%m), \"%s\"", r
, label2
);
84 fd
= socket(AF_INET
, SOCK_DGRAM
, 0);
87 r
= mac_selinux_get_child_mls_label(fd
, fname
, label2
, &label3
);
88 log_info_errno(r
, "mac_selinux_get_child_mls_label → %d (%m), \"%s\"", r
, label3
);
91 static void test_create_file_prepare(const char* fname
) {
94 log_info("============ %s ==========", __func__
);
96 r
= mac_selinux_create_file_prepare(fname
, S_IRWXU
);
97 log_info_errno(r
, "mac_selinux_create_file_prepare → %d (%m)", r
);
99 mac_selinux_create_file_clear();
102 int main(int argc
, char **argv
) {
103 const char *path
= SYSTEMD_BINARY_PATH
;
107 log_set_max_level(LOG_DEBUG
);
108 log_parse_environment();
113 test_create_file_prepare(path
);