1 Star 0 Fork 1.6K

王洪涛/security_selinux

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BUILD.gn 17.68 KB
一键复制 编辑 原始数据 按行查看 历史
qy136 提交于 2023-05-15 13:37 . add
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
# Copyright (c) 2021-2023 北京万里红科技有限公司
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/startup/init/begetd.gni")
import("//build/ohos.gni")
import("selinux.gni")
config("selinux_core_config") {
include_dirs = [
"interfaces/policycoreutils/include",
"$THIRD_PARTY_DIR/selinux/libselinux/include",
]
}
ohos_shared_library("libload_policy") {
output_name = "libload_policy"
sources = [ "interfaces/policycoreutils/src/load_policy.cpp" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [
":libselinux_klog_static",
"$THIRD_PARTY_DIR/selinux:libselinux",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
install_enable = true
install_images = [
"system",
"ramdisk",
"updater",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
ohos_shared_library("librestorecon") {
output_name = "librestorecon"
sources = [ "interfaces/policycoreutils/src/selinux_restorecon.c" ]
public_configs = [ ":selinux_core_config" ]
deps = [ "$THIRD_PARTY_DIR/selinux:libselinux" ]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
install_enable = true
install_images = [
"system",
"ramdisk",
"updater",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
ohos_shared_library("libhap_restorecon") {
output_name = "libhap_restorecon"
sources = [
"interfaces/policycoreutils/src/hap_restorecon.cpp",
"interfaces/policycoreutils/src/sehap_contexts_trie.cpp",
]
public_configs = [ ":selinux_core_config" ]
deps = [
":libselinux_error_static",
":libselinux_hilog_static",
"$THIRD_PARTY_DIR/selinux:libselinux",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
install_enable = true
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
ohos_static_library("libselinux_error_static") {
output_name = "libselinux_error_static"
sources = [ "interfaces/policycoreutils/src/selinux_error.cpp" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
cflags = [
"-D_GNU_SOURCE",
"-w",
]
part_name = "selinux"
subsystem_name = "security"
}
ohos_static_library("libselinux_klog_static") {
output_name = "libselinux_klog_static"
sources = [ "interfaces/policycoreutils/src/selinux_klog.c" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [ "$THIRD_PARTY_DIR/bounds_checking_function:libsec_shared" ]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
part_name = "selinux"
subsystem_name = "security"
}
ohos_static_library("libselinux_hilog_static") {
output_name = "libselinux_hilog_static"
sources = [ "interfaces/policycoreutils/src/selinux_log.c" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [ "$THIRD_PARTY_DIR/bounds_checking_function:libsec_shared" ]
external_deps = [ "hilog_native:libhilog" ]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
part_name = "selinux"
subsystem_name = "security"
}
if (!startup_init_with_param_base) {
inherited_configs = [
"$BUILD_CONFIG_DIR/compiler:afdo",
"$BUILD_CONFIG_DIR/compiler:afdo_optimize_size",
"$BUILD_CONFIG_DIR/compiler:compiler",
"$BUILD_CONFIG_DIR/compiler:compiler_arm_fpu",
"$BUILD_CONFIG_DIR/compiler:compiler_arm_thumb",
"$BUILD_CONFIG_DIR/compiler:chromium_code",
"$BUILD_CONFIG_DIR/compiler:default_include_dirs",
"$BUILD_CONFIG_DIR/compiler:default_optimization",
"$BUILD_CONFIG_DIR/compiler:default_stack_frames",
"$BUILD_CONFIG_DIR/compiler:default_symbols",
"$BUILD_CONFIG_DIR/compiler:export_dynamic",
"$BUILD_CONFIG_DIR/compiler:no_exceptions",
"$BUILD_CONFIG_DIR/compiler:no_rtti",
"$BUILD_CONFIG_DIR/compiler:runtime_library",
"$BUILD_CONFIG_DIR/compiler:thin_archive",
"$BUILD_CONFIG_DIR/sanitizers:default_sanitizer_flags",
]
}
source_set("libselinux_parameter_static") {
output_name = "libselinux_parameter_static"
sources = [
"interfaces/policycoreutils/src/contexts_trie.c",
"interfaces/policycoreutils/src/selinux_map.c",
"interfaces/policycoreutils/src/selinux_parameter.c",
"interfaces/policycoreutils/src/selinux_share_mem.c",
]
include_dirs = [ "interfaces/policycoreutils/include" ]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
if (!startup_init_with_param_base) {
ldflags = [ "-nostdlib" ]
configs -= inherited_configs
configs += [ "$BUILD_CONFIG_DIR/compiler:compiler" ]
}
}
ohos_shared_library("libparaperm_checker") {
output_name = "libparaperm_checker"
sources = [ "interfaces/policycoreutils/src/param_checker.c" ]
public_configs = [ ":selinux_core_config" ]
deps = [
":libselinux_klog_static",
"$THIRD_PARTY_DIR/bounds_checking_function:libsec_shared",
"$THIRD_PARTY_DIR/selinux:libselinux",
]
if (startup_init_with_param_base) {
deps += [ ":libselinux_parameter_static" ]
}
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
install_images = [
"system",
"updater",
]
part_name = "selinux"
subsystem_name = "security"
}
ohos_shared_library("libservice_checker") {
output_name = "libservice_checker"
sources = [ "interfaces/policycoreutils/src/service_checker.cpp" ]
public_configs = [ ":selinux_core_config" ]
deps = [
":libselinux_error_static",
":libselinux_hilog_static",
"$THIRD_PARTY_DIR/bounds_checking_function:libsec_shared",
"$THIRD_PARTY_DIR/selinux:libselinux",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
part_name = "selinux"
subsystem_name = "security"
}
ohos_executable("load_policy") {
install_enable = true
sources = [ "interfaces/tools/load_policy/load_policy.c" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [ ":libload_policy" ]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
install_images = [
"system",
"updater",
]
}
ohos_executable("restorecon") {
install_enable = true
sources = [ "interfaces/tools/restorecon/restorecon.c" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [
":librestorecon",
"$THIRD_PARTY_DIR/bounds_checking_function:libsec_shared",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
install_images = [
"system",
"updater",
]
}
ohos_executable("hap_restorecon") {
install_enable = false
sources = [ "interfaces/tools/hap_restorecon/test.cpp" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [
":libhap_restorecon",
":libselinux_error_static",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
ohos_executable("param_check") {
install_enable = false
sources = [ "interfaces/tools/param_check/test.cpp" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [
":libparaperm_checker",
":libselinux_error_static",
":libselinux_parameter_static",
"$THIRD_PARTY_DIR/selinux:libselinux",
]
if (startup_init_with_param_base) {
deps += [ ":libselinux_parameter_static" ]
}
cflags = [
"-D_GNU_SOURCE",
"-DTIME_DISPLAY",
"-Wall",
"-Werror",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
ohos_executable("service_check") {
install_enable = false
sources = [ "interfaces/tools/service_check/test.cpp" ]
include_dirs = [ "interfaces/policycoreutils/include" ]
deps = [
":libselinux_error_static",
":libservice_checker",
]
cflags = [
"-D_GNU_SOURCE",
"-Wall",
"-Werror",
]
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
}
debug_version = "disable"
updater_version = "disable"
action("build_policy") {
if (build_variant == "user") {
debug_version = "disable"
} else if (build_variant == "root") {
debug_version = "enable"
} else {
debug_version = "enable"
}
updater_version = "disable"
inputs = exec_script("//build/scripts/find.py",
[ rebase_path("sepolicy") ],
"list lines")
if (selinux_build_path != "default") {
foreach(src, string_split(selinux_build_path, ":")) {
src = "//" + src
inputs += exec_script("//build/scripts/find.py",
[ rebase_path(src) ],
"list lines")
}
}
if (special_build_policy_script != "default") {
script = special_build_policy_script
} else {
script = "scripts/build_policy.py"
}
args = [
"--dst-file",
rebase_path(target_out_dir + "/policy.31"),
"--tool-path",
rebase_path(root_build_dir + "/clang_x64/security/selinux/"),
"--source-root-dir",
rebase_path("//"),
"--policy_dir_list",
selinux_build_path,
"--debug-version",
debug_version,
"--updater-version",
updater_version,
"--components",
components,
]
deps = [
"$THIRD_PARTY_DIR/selinux:checkpolicy($host_toolchain)",
"$THIRD_PARTY_DIR/selinux:secilc($host_toolchain)",
]
outputs = [
target_out_dir + "/policy.31",
target_out_dir + "/vendor.cil",
target_out_dir + "/prebuild_sepolicy.system.cil.sha256",
target_out_dir + "/system.cil",
target_out_dir + "/system.cil.sha256",
]
}
action("build_update_policy") {
if (build_variant == "user") {
debug_version = "disable"
} else if (build_variant == "root") {
debug_version = "enable"
} else {
debug_version = "enable"
}
updater_version = "enable"
components = "default"
inputs = exec_script("//build/scripts/find.py",
[ rebase_path("sepolicy") ],
"list lines")
if (selinux_build_path != "default") {
foreach(src, string_split(selinux_build_path, ":")) {
src = "//" + src
inputs += exec_script("//build/scripts/find.py",
[ rebase_path(src) ],
"list lines")
}
}
script = "scripts/build_policy.py"
args = [
"--dst-file",
rebase_path(target_out_dir + "/updater/policy.31"),
"--tool-path",
rebase_path(root_build_dir + "/clang_x64/security/selinux/"),
"--source-root-dir",
rebase_path("//"),
"--policy_dir_list",
selinux_build_path,
"--debug-version",
debug_version,
"--updater-version",
updater_version,
"--components",
components,
]
deps = [
"$THIRD_PARTY_DIR/selinux:checkpolicy($host_toolchain)",
"$THIRD_PARTY_DIR/selinux:secilc($host_toolchain)",
]
outputs = [ target_out_dir + "/updater/policy.31" ]
}
action("build_contexts") {
inputs = exec_script("//build/scripts/find.py",
[ rebase_path("sepolicy") ],
"list lines")
if (selinux_build_path != "default") {
foreach(src, string_split(selinux_build_path, ":")) {
src = "//" + src
inputs += exec_script("//build/scripts/find.py",
[ rebase_path(src) ],
"list lines")
}
}
script = "scripts/build_contexts.py"
args = [
"--dst-dir",
rebase_path(target_out_dir + "/"),
"--tool-path",
rebase_path(root_build_dir + "/clang_x64/security/selinux/"),
"--policy-file",
rebase_path(target_out_dir + "/policy.31"),
"--source-root-dir",
rebase_path("//"),
"--policy_dir_list",
selinux_build_path,
"--components",
components,
]
deps = [
":build_policy",
"$THIRD_PARTY_DIR/selinux:sefcontext_compile($host_toolchain)",
]
outputs = [
target_out_dir + "/file_contexts.bin",
target_out_dir + "/file_contexts",
target_out_dir + "/sehap_contexts",
target_out_dir + "/service_contexts",
target_out_dir + "/hdf_service_contexts",
target_out_dir + "/parameter_contexts",
]
}
copy("selinux_config") {
if (selinux_enforce) {
sources = [ "config/config.enforce" ]
} else {
sources = [ "config/config.permissive" ]
}
outputs = [ "$target_out_dir/config" ]
}
copy("updater_selinux_config") {
sources = [ "config/config.enforce" ]
outputs = [ "$target_out_dir/updater/config" ]
}
ohos_prebuilt_etc("build_sepolicy") {
deps = [ ":build_policy" ]
source = target_out_dir + "/policy.31"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
if (components == "vendor") {
relative_install_dir = "selinux/prebuild_sepolicy/"
install_images = [ "vendor" ]
} else if (components == "default") {
relative_install_dir = "selinux/targeted/policy/"
install_images = [ "system" ]
}
}
ohos_prebuilt_etc("build_updater_sepolicy") {
deps = [ ":build_update_policy" ]
source = target_out_dir + "/updater/policy.31"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/policy/"
install_images = [ "updater" ]
}
ohos_prebuilt_etc("config") {
deps = [ ":selinux_config" ]
source = target_out_dir + "/config"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "system" ]
}
ohos_prebuilt_etc("updater_config") {
deps = [ ":updater_selinux_config" ]
source = target_out_dir + "/updater/config"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "updater" ]
}
ohos_prebuilt_etc("sehap_contexts") {
deps = [ ":build_contexts" ]
source = target_out_dir + "/sehap_contexts"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/contexts/"
}
ohos_prebuilt_etc("parameter_contexts") {
deps = [ ":build_contexts" ]
source = target_out_dir + "/parameter_contexts"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/contexts/"
install_images = [
"system",
"updater",
]
}
ohos_prebuilt_etc("service_contexts") {
deps = [ ":build_contexts" ]
source = target_out_dir + "/service_contexts"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/contexts/"
}
ohos_prebuilt_etc("hdf_service_contexts") {
deps = [ ":build_contexts" ]
source = target_out_dir + "/hdf_service_contexts"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/contexts/"
}
ohos_prebuilt_etc("file_contexts") {
deps = [ ":build_contexts" ]
source = target_out_dir + "/file_contexts"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/targeted/contexts/"
if (components == "vendor") {
install_images = [ "vendor" ]
} else {
install_images = [
"system",
"updater",
]
}
}
ohos_prebuilt_etc("vendor_cil") {
deps = [ ":build_policy" ]
source = target_out_dir + "/vendor.cil"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "vendor" ]
}
ohos_prebuilt_etc("prebuild_sepolicy_system_cil_sha256") {
deps = [ ":build_policy" ]
source = target_out_dir + "/prebuild_sepolicy.system.cil.sha256"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "vendor" ]
}
ohos_prebuilt_etc("system_cil") {
deps = [ ":build_policy" ]
source = target_out_dir + "/system.cil"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "system" ]
}
ohos_prebuilt_etc("system_cil_sha256") {
deps = [ ":build_policy" ]
source = target_out_dir + "/system.cil.sha256"
license_file = "LICENSE"
part_name = "selinux"
subsystem_name = "security"
relative_install_dir = "selinux/"
install_images = [ "system" ]
}
group("selinux_group") {
if (build_selinux) {
deps = [
":build_updater_sepolicy",
":config",
":file_contexts",
":hap_restorecon",
":hdf_service_contexts",
":load_policy",
":param_check",
":parameter_contexts",
":restorecon",
":sehap_contexts",
":service_check",
":service_contexts",
":updater_config",
"$THIRD_PARTY_DIR/selinux:checkpolicy($host_toolchain)",
"$THIRD_PARTY_DIR/selinux:chkcon",
"$THIRD_PARTY_DIR/selinux:getenforce",
"$THIRD_PARTY_DIR/selinux:getfilecon",
"$THIRD_PARTY_DIR/selinux:getpidcon",
"$THIRD_PARTY_DIR/selinux:secilc",
"$THIRD_PARTY_DIR/selinux:secilc($host_toolchain)",
"$THIRD_PARTY_DIR/selinux:sefcontext_compile($host_toolchain)",
"$THIRD_PARTY_DIR/selinux:selinux_check_access",
"$THIRD_PARTY_DIR/selinux:selinuxexeccon",
"$THIRD_PARTY_DIR/selinux:setenforce",
"$THIRD_PARTY_DIR/selinux:setfilecon",
]
if (components == "system") {
deps += [
":system_cil",
":system_cil_sha256",
]
} else if (components == "vendor") {
deps += [
":build_sepolicy",
":prebuild_sepolicy_system_cil_sha256",
":vendor_cil",
]
} else {
deps += [ ":build_sepolicy" ]
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/htwangq/security_selinux.git
git@gitee.com:htwangq/security_selinux.git
htwangq
security_selinux
security_selinux
master

搜索帮助