]>
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
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 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)",
97 static void test_create_file_prepare(const char* fname
) {
100 log_info("============ %s ==========", __func__
);
102 r
= mac_selinux_create_file_prepare(fname
, S_IRWXU
);
103 log_info_errno(r
, "mac_selinux_create_file_prepare → %d (%m)", r
);
105 mac_selinux_create_file_clear();
108 int main(int argc
, char **argv
) {
109 const char *path
= SYSTEMD_BINARY_PATH
;
113 log_set_max_level(LOG_DEBUG
);
114 log_parse_environment();
119 test_create_file_prepare(path
);