1 /* Copyright (c) 2021-2022 北京万里红科技有限公司 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <errno.h> 17 #include <stdio.h> 18 #include <string.h> 19 #include <selinux/selinux.h> 20 #include <policycoreutils.h> 21 #include "selinux_klog.h" 22 LoadPolicy(void)23int LoadPolicy(void) 24 { 25 // set selinux log callback 26 SetSelinuxKmsgLevel(SELINUX_KERROR); 27 union selinux_callback cb; 28 cb.func_log = SelinuxKmsg; 29 selinux_set_callback(SELINUX_CB_LOG, cb); 30 31 int enforce = 0; 32 int ret = selinux_init_load_policy(&enforce); 33 if (ret && enforce > 0) { 34 fprintf(stderr, "Can't load policy and enforcing mode requested: %s\n", strerror(errno)); 35 return -1; 36 } 37 return 1; 38 } 39