1#! /bin/bash 2 3# Copyright (c) 2025 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16selinux_lib_dir=$1 17selinux_exec_name=$2 18selinux_gen_dir=$3 19 20function exec_check_md5() { 21 local output_file="$1" 22 local input_file="$2" 23 local md5_file="$3" 24 local tool="$4" 25 26 echo "exec_check_md5 $output_file $input_file $md5_file using $tool" 27 check_config_result=$(bash "$selinux_lib_dir/check_md5.sh" "$output_file" "$input_file" "$md5_file") 28 29 if [[ -n "$check_config_result" ]]; then 30 if [[ "$tool" == "flex" ]]; then 31 flex -o "$output_file" "$input_file" 32 elif [[ "$tool" == "bison" ]]; then 33 bison -y -d "$input_file" -o "$output_file" 34 fi 35 fi 36} 37 38libsepol="libsepol" 39checkpolicy="checkpolicy" 40 41case "$selinux_exec_name" in 42 "$libsepol") 43 exec_check_md5 "$selinux_gen_dir/libsepol/cil/src/cil_lexer.c" \ 44 "$selinux_lib_dir/libsepol/cil/src/cil_lexer.l" \ 45 "$selinux_lib_dir/libsepol/cil/src/cil_lexer.md5" \ 46 "flex" 47 ;; 48 "$checkpolicy") 49 exec_check_md5 "$selinux_gen_dir/checkpolicy/y.tab.c" \ 50 "$selinux_lib_dir/checkpolicy/policy_parse.y" \ 51 "$selinux_lib_dir/checkpolicy/y.tab.md5" \ 52 "bison" 53 54 exec_check_md5 "$selinux_gen_dir/checkpolicy/policy_scan.c" \ 55 "$selinux_lib_dir/checkpolicy/policy_scan.l" \ 56 "$selinux_lib_dir/checkpolicy/policy_scan.md5" \ 57 "flex" 58 ;; 59 *) 60 echo "Unknown exec_name: $selinux_exec_name" 61 ;; 62esac 63