1*e4a36f41SAndroid Build Coastguard Worker// Copyright (C) 2021 The Android Open Source Project 2*e4a36f41SAndroid Build Coastguard Worker// 3*e4a36f41SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*e4a36f41SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*e4a36f41SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*e4a36f41SAndroid Build Coastguard Worker// 7*e4a36f41SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*e4a36f41SAndroid Build Coastguard Worker// 9*e4a36f41SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*e4a36f41SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*e4a36f41SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*e4a36f41SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*e4a36f41SAndroid Build Coastguard Worker// limitations under the License. 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Workerpackage selinux 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Workerimport ( 18*e4a36f41SAndroid Build Coastguard Worker "os" 19*e4a36f41SAndroid Build Coastguard Worker "sort" 20*e4a36f41SAndroid Build Coastguard Worker "strconv" 21*e4a36f41SAndroid Build Coastguard Worker "strings" 22*e4a36f41SAndroid Build Coastguard Worker 23*e4a36f41SAndroid Build Coastguard Worker "github.com/google/blueprint/proptools" 24*e4a36f41SAndroid Build Coastguard Worker 25*e4a36f41SAndroid Build Coastguard Worker "android/soong/android" 26*e4a36f41SAndroid Build Coastguard Worker) 27*e4a36f41SAndroid Build Coastguard Worker 28*e4a36f41SAndroid Build Coastguard Workerconst ( 29*e4a36f41SAndroid Build Coastguard Worker MlsSens = 1 30*e4a36f41SAndroid Build Coastguard Worker MlsCats = 1024 31*e4a36f41SAndroid Build Coastguard Worker PolicyVers = 30 32*e4a36f41SAndroid Build Coastguard Worker) 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Worker// This order should be kept. checkpolicy syntax requires it. 35*e4a36f41SAndroid Build Coastguard Workervar policyConfOrder = []string{ 36*e4a36f41SAndroid Build Coastguard Worker "flagging_macros", 37*e4a36f41SAndroid Build Coastguard Worker "security_classes", 38*e4a36f41SAndroid Build Coastguard Worker "initial_sids", 39*e4a36f41SAndroid Build Coastguard Worker "access_vectors", 40*e4a36f41SAndroid Build Coastguard Worker "global_macros", 41*e4a36f41SAndroid Build Coastguard Worker "neverallow_macros", 42*e4a36f41SAndroid Build Coastguard Worker "mls_macros", 43*e4a36f41SAndroid Build Coastguard Worker "mls_decl", 44*e4a36f41SAndroid Build Coastguard Worker "mls", 45*e4a36f41SAndroid Build Coastguard Worker "policy_capabilities", 46*e4a36f41SAndroid Build Coastguard Worker "te_macros", 47*e4a36f41SAndroid Build Coastguard Worker "ioctl_defines", 48*e4a36f41SAndroid Build Coastguard Worker "ioctl_macros", 49*e4a36f41SAndroid Build Coastguard Worker "attributes|*.te", 50*e4a36f41SAndroid Build Coastguard Worker "roles_decl", 51*e4a36f41SAndroid Build Coastguard Worker "roles", 52*e4a36f41SAndroid Build Coastguard Worker "users", 53*e4a36f41SAndroid Build Coastguard Worker "initial_sid_contexts", 54*e4a36f41SAndroid Build Coastguard Worker "fs_use", 55*e4a36f41SAndroid Build Coastguard Worker "genfs_contexts", 56*e4a36f41SAndroid Build Coastguard Worker "port_contexts", 57*e4a36f41SAndroid Build Coastguard Worker} 58*e4a36f41SAndroid Build Coastguard Worker 59*e4a36f41SAndroid Build Coastguard Workerfunc init() { 60*e4a36f41SAndroid Build Coastguard Worker android.RegisterModuleType("se_policy_conf", policyConfFactory) 61*e4a36f41SAndroid Build Coastguard Worker android.RegisterModuleType("se_policy_conf_defaults", policyConfDefaultFactory) 62*e4a36f41SAndroid Build Coastguard Worker android.RegisterModuleType("se_policy_cil", policyCilFactory) 63*e4a36f41SAndroid Build Coastguard Worker android.RegisterModuleType("se_policy_binary", policyBinaryFactory) 64*e4a36f41SAndroid Build Coastguard Worker} 65*e4a36f41SAndroid Build Coastguard Worker 66*e4a36f41SAndroid Build Coastguard Workertype policyConfProperties struct { 67*e4a36f41SAndroid Build Coastguard Worker // Name of the output. Default is {module_name} 68*e4a36f41SAndroid Build Coastguard Worker Stem *string 69*e4a36f41SAndroid Build Coastguard Worker 70*e4a36f41SAndroid Build Coastguard Worker // Policy files to be compiled to cil file. 71*e4a36f41SAndroid Build Coastguard Worker Srcs []string `android:"path"` 72*e4a36f41SAndroid Build Coastguard Worker 73*e4a36f41SAndroid Build Coastguard Worker // Target build variant (user / userdebug / eng). Default follows the current lunch target 74*e4a36f41SAndroid Build Coastguard Worker Build_variant *string 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker // Whether to exclude build test or not. Default is false 77*e4a36f41SAndroid Build Coastguard Worker Exclude_build_test *bool 78*e4a36f41SAndroid Build Coastguard Worker 79*e4a36f41SAndroid Build Coastguard Worker // Whether to include asan specific policies or not. Default follows the current lunch target 80*e4a36f41SAndroid Build Coastguard Worker With_asan *bool 81*e4a36f41SAndroid Build Coastguard Worker 82*e4a36f41SAndroid Build Coastguard Worker // Whether to build CTS specific policy or not. Default is false 83*e4a36f41SAndroid Build Coastguard Worker Cts *bool 84*e4a36f41SAndroid Build Coastguard Worker 85*e4a36f41SAndroid Build Coastguard Worker // Whether to build recovery specific policy or not. Default is false 86*e4a36f41SAndroid Build Coastguard Worker Target_recovery *bool 87*e4a36f41SAndroid Build Coastguard Worker 88*e4a36f41SAndroid Build Coastguard Worker // Whether this module is directly installable to one of the partitions. Default is true 89*e4a36f41SAndroid Build Coastguard Worker Installable *bool 90*e4a36f41SAndroid Build Coastguard Worker 91*e4a36f41SAndroid Build Coastguard Worker // Desired number of MLS categories. Defaults to 1024 92*e4a36f41SAndroid Build Coastguard Worker Mls_cats *int64 93*e4a36f41SAndroid Build Coastguard Worker 94*e4a36f41SAndroid Build Coastguard Worker // Board api level of policy files. Set "current" for RELEASE_BOARD_API_LEVEL, or a direct 95*e4a36f41SAndroid Build Coastguard Worker // version string (e.g. "202404"). Defaults to "current" 96*e4a36f41SAndroid Build Coastguard Worker Board_api_level *string 97*e4a36f41SAndroid Build Coastguard Worker} 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Workertype policyConf struct { 100*e4a36f41SAndroid Build Coastguard Worker android.ModuleBase 101*e4a36f41SAndroid Build Coastguard Worker android.DefaultableModuleBase 102*e4a36f41SAndroid Build Coastguard Worker flaggableModuleBase 103*e4a36f41SAndroid Build Coastguard Worker 104*e4a36f41SAndroid Build Coastguard Worker properties policyConfProperties 105*e4a36f41SAndroid Build Coastguard Worker 106*e4a36f41SAndroid Build Coastguard Worker installSource android.Path 107*e4a36f41SAndroid Build Coastguard Worker installPath android.InstallPath 108*e4a36f41SAndroid Build Coastguard Worker} 109*e4a36f41SAndroid Build Coastguard Worker 110*e4a36f41SAndroid Build Coastguard Workervar _ flaggableModule = (*policyConf)(nil) 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker// se_policy_conf merges collection of policy files into a policy.conf file to be processed by 113*e4a36f41SAndroid Build Coastguard Worker// checkpolicy. 114*e4a36f41SAndroid Build Coastguard Workerfunc policyConfFactory() android.Module { 115*e4a36f41SAndroid Build Coastguard Worker c := &policyConf{} 116*e4a36f41SAndroid Build Coastguard Worker c.AddProperties(&c.properties) 117*e4a36f41SAndroid Build Coastguard Worker initFlaggableModule(c) 118*e4a36f41SAndroid Build Coastguard Worker android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon) 119*e4a36f41SAndroid Build Coastguard Worker android.InitDefaultableModule(c) 120*e4a36f41SAndroid Build Coastguard Worker return c 121*e4a36f41SAndroid Build Coastguard Worker} 122*e4a36f41SAndroid Build Coastguard Worker 123*e4a36f41SAndroid Build Coastguard Workertype policyConfDefaults struct { 124*e4a36f41SAndroid Build Coastguard Worker android.ModuleBase 125*e4a36f41SAndroid Build Coastguard Worker android.DefaultsModuleBase 126*e4a36f41SAndroid Build Coastguard Worker} 127*e4a36f41SAndroid Build Coastguard Worker 128*e4a36f41SAndroid Build Coastguard Worker// se_policy_conf_defaults provides a set of properties that can be inherited by other 129*e4a36f41SAndroid Build Coastguard Worker// se_policy_conf_defaults modules. A module can use the properties from a se_policy_conf_defaults 130*e4a36f41SAndroid Build Coastguard Worker// using `defaults: ["<:default_module_name>"]`. Properties of both modules are merged (when 131*e4a36f41SAndroid Build Coastguard Worker// possible) by prepending the default module's values to the depending module's values. 132*e4a36f41SAndroid Build Coastguard Workerfunc policyConfDefaultFactory() android.Module { 133*e4a36f41SAndroid Build Coastguard Worker c := &policyConfDefaults{} 134*e4a36f41SAndroid Build Coastguard Worker c.AddProperties( 135*e4a36f41SAndroid Build Coastguard Worker &policyConfProperties{}, 136*e4a36f41SAndroid Build Coastguard Worker &flaggableModuleProperties{}, 137*e4a36f41SAndroid Build Coastguard Worker ) 138*e4a36f41SAndroid Build Coastguard Worker android.InitDefaultsModule(c) 139*e4a36f41SAndroid Build Coastguard Worker return c 140*e4a36f41SAndroid Build Coastguard Worker} 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) installable() bool { 143*e4a36f41SAndroid Build Coastguard Worker return proptools.BoolDefault(c.properties.Installable, true) 144*e4a36f41SAndroid Build Coastguard Worker} 145*e4a36f41SAndroid Build Coastguard Worker 146*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) stem() string { 147*e4a36f41SAndroid Build Coastguard Worker return proptools.StringDefault(c.properties.Stem, c.Name()) 148*e4a36f41SAndroid Build Coastguard Worker} 149*e4a36f41SAndroid Build Coastguard Worker 150*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) buildVariant(ctx android.ModuleContext) string { 151*e4a36f41SAndroid Build Coastguard Worker if variant := proptools.String(c.properties.Build_variant); variant != "" { 152*e4a36f41SAndroid Build Coastguard Worker return variant 153*e4a36f41SAndroid Build Coastguard Worker } 154*e4a36f41SAndroid Build Coastguard Worker if ctx.Config().Eng() { 155*e4a36f41SAndroid Build Coastguard Worker return "eng" 156*e4a36f41SAndroid Build Coastguard Worker } 157*e4a36f41SAndroid Build Coastguard Worker if ctx.Config().Debuggable() { 158*e4a36f41SAndroid Build Coastguard Worker return "userdebug" 159*e4a36f41SAndroid Build Coastguard Worker } 160*e4a36f41SAndroid Build Coastguard Worker return "user" 161*e4a36f41SAndroid Build Coastguard Worker} 162*e4a36f41SAndroid Build Coastguard Worker 163*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) cts() bool { 164*e4a36f41SAndroid Build Coastguard Worker return proptools.Bool(c.properties.Cts) 165*e4a36f41SAndroid Build Coastguard Worker} 166*e4a36f41SAndroid Build Coastguard Worker 167*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) isTargetRecovery() bool { 168*e4a36f41SAndroid Build Coastguard Worker return proptools.Bool(c.properties.Target_recovery) 169*e4a36f41SAndroid Build Coastguard Worker} 170*e4a36f41SAndroid Build Coastguard Worker 171*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) withAsan(ctx android.ModuleContext) string { 172*e4a36f41SAndroid Build Coastguard Worker isAsanDevice := android.InList("address", ctx.Config().SanitizeDevice()) 173*e4a36f41SAndroid Build Coastguard Worker return strconv.FormatBool(proptools.BoolDefault(c.properties.With_asan, isAsanDevice)) 174*e4a36f41SAndroid Build Coastguard Worker} 175*e4a36f41SAndroid Build Coastguard Worker 176*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) sepolicySplit(ctx android.ModuleContext) string { 177*e4a36f41SAndroid Build Coastguard Worker if c.cts() { 178*e4a36f41SAndroid Build Coastguard Worker return "cts" 179*e4a36f41SAndroid Build Coastguard Worker } 180*e4a36f41SAndroid Build Coastguard Worker if c.isTargetRecovery() { 181*e4a36f41SAndroid Build Coastguard Worker return "false" 182*e4a36f41SAndroid Build Coastguard Worker } 183*e4a36f41SAndroid Build Coastguard Worker return strconv.FormatBool(true) 184*e4a36f41SAndroid Build Coastguard Worker} 185*e4a36f41SAndroid Build Coastguard Worker 186*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) compatibleProperty(ctx android.ModuleContext) string { 187*e4a36f41SAndroid Build Coastguard Worker if c.cts() { 188*e4a36f41SAndroid Build Coastguard Worker return "cts" 189*e4a36f41SAndroid Build Coastguard Worker } 190*e4a36f41SAndroid Build Coastguard Worker if c.isTargetRecovery() { 191*e4a36f41SAndroid Build Coastguard Worker return "false" 192*e4a36f41SAndroid Build Coastguard Worker } 193*e4a36f41SAndroid Build Coastguard Worker return "true" 194*e4a36f41SAndroid Build Coastguard Worker} 195*e4a36f41SAndroid Build Coastguard Worker 196*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) trebleSyspropNeverallow(ctx android.ModuleContext) string { 197*e4a36f41SAndroid Build Coastguard Worker if c.cts() { 198*e4a36f41SAndroid Build Coastguard Worker return "cts" 199*e4a36f41SAndroid Build Coastguard Worker } 200*e4a36f41SAndroid Build Coastguard Worker if c.isTargetRecovery() { 201*e4a36f41SAndroid Build Coastguard Worker return "false" 202*e4a36f41SAndroid Build Coastguard Worker } 203*e4a36f41SAndroid Build Coastguard Worker return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenTrebleSyspropNeverallow()) 204*e4a36f41SAndroid Build Coastguard Worker} 205*e4a36f41SAndroid Build Coastguard Worker 206*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) enforceSyspropOwner(ctx android.ModuleContext) string { 207*e4a36f41SAndroid Build Coastguard Worker if c.cts() { 208*e4a36f41SAndroid Build Coastguard Worker return "cts" 209*e4a36f41SAndroid Build Coastguard Worker } 210*e4a36f41SAndroid Build Coastguard Worker if c.isTargetRecovery() { 211*e4a36f41SAndroid Build Coastguard Worker return "false" 212*e4a36f41SAndroid Build Coastguard Worker } 213*e4a36f41SAndroid Build Coastguard Worker return strconv.FormatBool(!ctx.DeviceConfig().BuildBrokenEnforceSyspropOwner()) 214*e4a36f41SAndroid Build Coastguard Worker} 215*e4a36f41SAndroid Build Coastguard Worker 216*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) enforceDebugfsRestrictions(ctx android.ModuleContext) string { 217*e4a36f41SAndroid Build Coastguard Worker if c.cts() { 218*e4a36f41SAndroid Build Coastguard Worker return "cts" 219*e4a36f41SAndroid Build Coastguard Worker } 220*e4a36f41SAndroid Build Coastguard Worker return strconv.FormatBool(ctx.DeviceConfig().BuildDebugfsRestrictionsEnabled()) 221*e4a36f41SAndroid Build Coastguard Worker} 222*e4a36f41SAndroid Build Coastguard Worker 223*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) mlsCats() int { 224*e4a36f41SAndroid Build Coastguard Worker return proptools.IntDefault(c.properties.Mls_cats, MlsCats) 225*e4a36f41SAndroid Build Coastguard Worker} 226*e4a36f41SAndroid Build Coastguard Worker 227*e4a36f41SAndroid Build Coastguard Workerfunc findPolicyConfOrder(name string) int { 228*e4a36f41SAndroid Build Coastguard Worker for idx, pattern := range policyConfOrder { 229*e4a36f41SAndroid Build Coastguard Worker // We could use regexp but it seems like an overkill 230*e4a36f41SAndroid Build Coastguard Worker if pattern == "attributes|*.te" && (name == "attributes" || strings.HasSuffix(name, ".te")) { 231*e4a36f41SAndroid Build Coastguard Worker return idx 232*e4a36f41SAndroid Build Coastguard Worker } else if pattern == name { 233*e4a36f41SAndroid Build Coastguard Worker return idx 234*e4a36f41SAndroid Build Coastguard Worker } 235*e4a36f41SAndroid Build Coastguard Worker } 236*e4a36f41SAndroid Build Coastguard Worker // name is not matched 237*e4a36f41SAndroid Build Coastguard Worker return len(policyConfOrder) 238*e4a36f41SAndroid Build Coastguard Worker} 239*e4a36f41SAndroid Build Coastguard Worker 240*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) transformPolicyToConf(ctx android.ModuleContext) android.OutputPath { 241*e4a36f41SAndroid Build Coastguard Worker conf := pathForModuleOut(ctx, c.stem()) 242*e4a36f41SAndroid Build Coastguard Worker rule := android.NewRuleBuilder(pctx, ctx) 243*e4a36f41SAndroid Build Coastguard Worker 244*e4a36f41SAndroid Build Coastguard Worker srcs := android.PathsForModuleSrc(ctx, c.properties.Srcs) 245*e4a36f41SAndroid Build Coastguard Worker sort.SliceStable(srcs, func(x, y int) bool { 246*e4a36f41SAndroid Build Coastguard Worker return findPolicyConfOrder(srcs[x].Base()) < findPolicyConfOrder(srcs[y].Base()) 247*e4a36f41SAndroid Build Coastguard Worker }) 248*e4a36f41SAndroid Build Coastguard Worker 249*e4a36f41SAndroid Build Coastguard Worker flags := c.getBuildFlags(ctx) 250*e4a36f41SAndroid Build Coastguard Worker rule.Command().Tool(ctx.Config().PrebuiltBuildTool(ctx, "m4")). 251*e4a36f41SAndroid Build Coastguard Worker Flag("--fatal-warnings"). 252*e4a36f41SAndroid Build Coastguard Worker FlagForEachArg("-D ", ctx.DeviceConfig().SepolicyM4Defs()). 253*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D mls_num_sens=", strconv.Itoa(MlsSens)). 254*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D mls_num_cats=", strconv.Itoa(c.mlsCats())). 255*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_arch=", ctx.DeviceConfig().DeviceArch()). 256*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_with_asan=", c.withAsan(ctx)). 257*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_with_dexpreopt=", strconv.FormatBool(ctx.DeviceConfig().WithDexpreopt())). 258*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_with_native_coverage=", strconv.FormatBool(ctx.DeviceConfig().ClangCoverageEnabled() || ctx.DeviceConfig().GcovCoverageEnabled())). 259*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_build_variant=", c.buildVariant(ctx)). 260*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_full_treble=", c.sepolicySplit(ctx)). 261*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_compatible_property=", c.compatibleProperty(ctx)). 262*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_treble_sysprop_neverallow=", c.trebleSyspropNeverallow(ctx)). 263*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_enforce_sysprop_owner=", c.enforceSyspropOwner(ctx)). 264*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_exclude_build_test=", strconv.FormatBool(proptools.Bool(c.properties.Exclude_build_test))). 265*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_requires_insecure_execmem_for_swiftshader=", strconv.FormatBool(ctx.DeviceConfig().RequiresInsecureExecmemForSwiftshader())). 266*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_enforce_debugfs_restriction=", c.enforceDebugfsRestrictions(ctx)). 267*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-D target_recovery=", strconv.FormatBool(c.isTargetRecovery())). 268*e4a36f41SAndroid Build Coastguard Worker Flag(boardApiLevelToM4Macro(ctx, c.properties.Board_api_level)). 269*e4a36f41SAndroid Build Coastguard Worker Flags(flagsToM4Macros(flags)). 270*e4a36f41SAndroid Build Coastguard Worker Flag("-s"). 271*e4a36f41SAndroid Build Coastguard Worker Inputs(srcs). 272*e4a36f41SAndroid Build Coastguard Worker Text("> ").Output(conf) 273*e4a36f41SAndroid Build Coastguard Worker 274*e4a36f41SAndroid Build Coastguard Worker rule.Build("conf", "Transform policy to conf: "+ctx.ModuleName()) 275*e4a36f41SAndroid Build Coastguard Worker return conf 276*e4a36f41SAndroid Build Coastguard Worker} 277*e4a36f41SAndroid Build Coastguard Worker 278*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) DepsMutator(ctx android.BottomUpMutatorContext) { 279*e4a36f41SAndroid Build Coastguard Worker c.flagDeps(ctx) 280*e4a36f41SAndroid Build Coastguard Worker} 281*e4a36f41SAndroid Build Coastguard Worker 282*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) GenerateAndroidBuildActions(ctx android.ModuleContext) { 283*e4a36f41SAndroid Build Coastguard Worker if !c.installable() { 284*e4a36f41SAndroid Build Coastguard Worker c.SkipInstall() 285*e4a36f41SAndroid Build Coastguard Worker } 286*e4a36f41SAndroid Build Coastguard Worker 287*e4a36f41SAndroid Build Coastguard Worker c.installSource = c.transformPolicyToConf(ctx) 288*e4a36f41SAndroid Build Coastguard Worker c.installPath = android.PathForModuleInstall(ctx, "etc") 289*e4a36f41SAndroid Build Coastguard Worker ctx.InstallFile(c.installPath, c.stem(), c.installSource) 290*e4a36f41SAndroid Build Coastguard Worker 291*e4a36f41SAndroid Build Coastguard Worker ctx.SetOutputFiles(android.Paths{c.installSource}, "") 292*e4a36f41SAndroid Build Coastguard Worker} 293*e4a36f41SAndroid Build Coastguard Worker 294*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyConf) AndroidMkEntries() []android.AndroidMkEntries { 295*e4a36f41SAndroid Build Coastguard Worker return []android.AndroidMkEntries{android.AndroidMkEntries{ 296*e4a36f41SAndroid Build Coastguard Worker OutputFile: android.OptionalPathForPath(c.installSource), 297*e4a36f41SAndroid Build Coastguard Worker Class: "ETC", 298*e4a36f41SAndroid Build Coastguard Worker ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 299*e4a36f41SAndroid Build Coastguard Worker func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 300*e4a36f41SAndroid Build Coastguard Worker entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.installable()) 301*e4a36f41SAndroid Build Coastguard Worker entries.SetPath("LOCAL_MODULE_PATH", c.installPath) 302*e4a36f41SAndroid Build Coastguard Worker entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem()) 303*e4a36f41SAndroid Build Coastguard Worker }, 304*e4a36f41SAndroid Build Coastguard Worker }, 305*e4a36f41SAndroid Build Coastguard Worker }} 306*e4a36f41SAndroid Build Coastguard Worker} 307*e4a36f41SAndroid Build Coastguard Worker 308*e4a36f41SAndroid Build Coastguard Workertype policyCilProperties struct { 309*e4a36f41SAndroid Build Coastguard Worker // Name of the output. Default is {module_name} 310*e4a36f41SAndroid Build Coastguard Worker Stem *string 311*e4a36f41SAndroid Build Coastguard Worker 312*e4a36f41SAndroid Build Coastguard Worker // Policy file to be compiled to cil file. 313*e4a36f41SAndroid Build Coastguard Worker Src *string `android:"path"` 314*e4a36f41SAndroid Build Coastguard Worker 315*e4a36f41SAndroid Build Coastguard Worker // If true, the input policy file is a binary policy that will be decompiled to a cil file. 316*e4a36f41SAndroid Build Coastguard Worker // Defaults to false. 317*e4a36f41SAndroid Build Coastguard Worker Decompile_binary *bool 318*e4a36f41SAndroid Build Coastguard Worker 319*e4a36f41SAndroid Build Coastguard Worker // Additional cil files to be added in the end of the output. This is to support workarounds 320*e4a36f41SAndroid Build Coastguard Worker // which are not supported by the policy language. 321*e4a36f41SAndroid Build Coastguard Worker Additional_cil_files []string `android:"path"` 322*e4a36f41SAndroid Build Coastguard Worker 323*e4a36f41SAndroid Build Coastguard Worker // Cil files to be filtered out by the filter_out tool of "build_sepolicy". Used to build 324*e4a36f41SAndroid Build Coastguard Worker // exported policies 325*e4a36f41SAndroid Build Coastguard Worker Filter_out []string `android:"path"` 326*e4a36f41SAndroid Build Coastguard Worker 327*e4a36f41SAndroid Build Coastguard Worker // Whether to remove line markers (denoted by ;;) out of compiled cil files. Defaults to false 328*e4a36f41SAndroid Build Coastguard Worker Remove_line_marker *bool 329*e4a36f41SAndroid Build Coastguard Worker 330*e4a36f41SAndroid Build Coastguard Worker // Whether to run secilc to check compiled policy or not. Defaults to true 331*e4a36f41SAndroid Build Coastguard Worker Secilc_check *bool 332*e4a36f41SAndroid Build Coastguard Worker 333*e4a36f41SAndroid Build Coastguard Worker // Whether to ignore neverallow when running secilc check. Defaults to 334*e4a36f41SAndroid Build Coastguard Worker // SELINUX_IGNORE_NEVERALLOWS. 335*e4a36f41SAndroid Build Coastguard Worker Ignore_neverallow *bool 336*e4a36f41SAndroid Build Coastguard Worker 337*e4a36f41SAndroid Build Coastguard Worker // Whether this module is directly installable to one of the partitions. Default is true 338*e4a36f41SAndroid Build Coastguard Worker Installable *bool 339*e4a36f41SAndroid Build Coastguard Worker} 340*e4a36f41SAndroid Build Coastguard Worker 341*e4a36f41SAndroid Build Coastguard Workertype policyCil struct { 342*e4a36f41SAndroid Build Coastguard Worker android.ModuleBase 343*e4a36f41SAndroid Build Coastguard Worker 344*e4a36f41SAndroid Build Coastguard Worker properties policyCilProperties 345*e4a36f41SAndroid Build Coastguard Worker 346*e4a36f41SAndroid Build Coastguard Worker installSource android.Path 347*e4a36f41SAndroid Build Coastguard Worker installPath android.InstallPath 348*e4a36f41SAndroid Build Coastguard Worker} 349*e4a36f41SAndroid Build Coastguard Worker 350*e4a36f41SAndroid Build Coastguard Worker// se_policy_cil compiles a policy.conf file to a cil file with checkpolicy, and optionally runs 351*e4a36f41SAndroid Build Coastguard Worker// secilc to check the output cil file. Affected by SELINUX_IGNORE_NEVERALLOWS. 352*e4a36f41SAndroid Build Coastguard Workerfunc policyCilFactory() android.Module { 353*e4a36f41SAndroid Build Coastguard Worker c := &policyCil{} 354*e4a36f41SAndroid Build Coastguard Worker c.AddProperties(&c.properties) 355*e4a36f41SAndroid Build Coastguard Worker android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon) 356*e4a36f41SAndroid Build Coastguard Worker return c 357*e4a36f41SAndroid Build Coastguard Worker} 358*e4a36f41SAndroid Build Coastguard Worker 359*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyCil) Installable() bool { 360*e4a36f41SAndroid Build Coastguard Worker return proptools.BoolDefault(c.properties.Installable, true) 361*e4a36f41SAndroid Build Coastguard Worker} 362*e4a36f41SAndroid Build Coastguard Worker 363*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyCil) stem() string { 364*e4a36f41SAndroid Build Coastguard Worker return proptools.StringDefault(c.properties.Stem, c.Name()) 365*e4a36f41SAndroid Build Coastguard Worker} 366*e4a36f41SAndroid Build Coastguard Worker 367*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyCil) compileConfToCil(ctx android.ModuleContext, conf android.Path) android.OutputPath { 368*e4a36f41SAndroid Build Coastguard Worker cil := pathForModuleOut(ctx, c.stem()) 369*e4a36f41SAndroid Build Coastguard Worker rule := android.NewRuleBuilder(pctx, ctx) 370*e4a36f41SAndroid Build Coastguard Worker checkpolicyCmd := rule.Command().BuiltTool("checkpolicy"). 371*e4a36f41SAndroid Build Coastguard Worker Flag("-C"). // Write CIL 372*e4a36f41SAndroid Build Coastguard Worker Flag("-M"). // Enable MLS 373*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-c ", strconv.Itoa(PolicyVers)). 374*e4a36f41SAndroid Build Coastguard Worker FlagWithOutput("-o ", cil). 375*e4a36f41SAndroid Build Coastguard Worker Input(conf) 376*e4a36f41SAndroid Build Coastguard Worker 377*e4a36f41SAndroid Build Coastguard Worker if proptools.Bool(c.properties.Decompile_binary) { 378*e4a36f41SAndroid Build Coastguard Worker checkpolicyCmd.Flag("-b") // Read binary 379*e4a36f41SAndroid Build Coastguard Worker } 380*e4a36f41SAndroid Build Coastguard Worker 381*e4a36f41SAndroid Build Coastguard Worker if len(c.properties.Filter_out) > 0 { 382*e4a36f41SAndroid Build Coastguard Worker rule.Command().BuiltTool("build_sepolicy"). 383*e4a36f41SAndroid Build Coastguard Worker Text("filter_out"). 384*e4a36f41SAndroid Build Coastguard Worker Flag("-f"). 385*e4a36f41SAndroid Build Coastguard Worker Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)). 386*e4a36f41SAndroid Build Coastguard Worker FlagWithOutput("-t ", cil) 387*e4a36f41SAndroid Build Coastguard Worker } 388*e4a36f41SAndroid Build Coastguard Worker 389*e4a36f41SAndroid Build Coastguard Worker if len(c.properties.Additional_cil_files) > 0 { 390*e4a36f41SAndroid Build Coastguard Worker rule.Command().Text("cat"). 391*e4a36f41SAndroid Build Coastguard Worker Inputs(android.PathsForModuleSrc(ctx, c.properties.Additional_cil_files)). 392*e4a36f41SAndroid Build Coastguard Worker Text(">> ").Output(cil) 393*e4a36f41SAndroid Build Coastguard Worker } 394*e4a36f41SAndroid Build Coastguard Worker 395*e4a36f41SAndroid Build Coastguard Worker if proptools.Bool(c.properties.Remove_line_marker) { 396*e4a36f41SAndroid Build Coastguard Worker rule.Command().Text("grep -v"). 397*e4a36f41SAndroid Build Coastguard Worker Text(proptools.ShellEscape(";;")). 398*e4a36f41SAndroid Build Coastguard Worker Text(cil.String()). 399*e4a36f41SAndroid Build Coastguard Worker Text(">"). 400*e4a36f41SAndroid Build Coastguard Worker Text(cil.String() + ".tmp"). 401*e4a36f41SAndroid Build Coastguard Worker Text("&& mv"). 402*e4a36f41SAndroid Build Coastguard Worker Text(cil.String() + ".tmp"). 403*e4a36f41SAndroid Build Coastguard Worker Text(cil.String()) 404*e4a36f41SAndroid Build Coastguard Worker } 405*e4a36f41SAndroid Build Coastguard Worker 406*e4a36f41SAndroid Build Coastguard Worker if proptools.BoolDefault(c.properties.Secilc_check, true) { 407*e4a36f41SAndroid Build Coastguard Worker secilcCmd := rule.Command().BuiltTool("secilc"). 408*e4a36f41SAndroid Build Coastguard Worker Flag("-m"). // Multiple decls 409*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-M ", "true"). // Enable MLS 410*e4a36f41SAndroid Build Coastguard Worker Flag("-G"). // expand and remove auto generated attributes 411*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-c ", strconv.Itoa(PolicyVers)). 412*e4a36f41SAndroid Build Coastguard Worker Inputs(android.PathsForModuleSrc(ctx, c.properties.Filter_out)). // Also add cil files which are filtered out 413*e4a36f41SAndroid Build Coastguard Worker Text(cil.String()). 414*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-o ", os.DevNull). 415*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-f ", os.DevNull) 416*e4a36f41SAndroid Build Coastguard Worker 417*e4a36f41SAndroid Build Coastguard Worker if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) { 418*e4a36f41SAndroid Build Coastguard Worker secilcCmd.Flag("-N") 419*e4a36f41SAndroid Build Coastguard Worker } 420*e4a36f41SAndroid Build Coastguard Worker } 421*e4a36f41SAndroid Build Coastguard Worker 422*e4a36f41SAndroid Build Coastguard Worker rule.Build("cil", "Building cil for "+ctx.ModuleName()) 423*e4a36f41SAndroid Build Coastguard Worker return cil 424*e4a36f41SAndroid Build Coastguard Worker} 425*e4a36f41SAndroid Build Coastguard Worker 426*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyCil) GenerateAndroidBuildActions(ctx android.ModuleContext) { 427*e4a36f41SAndroid Build Coastguard Worker if proptools.String(c.properties.Src) == "" { 428*e4a36f41SAndroid Build Coastguard Worker ctx.PropertyErrorf("src", "must be specified") 429*e4a36f41SAndroid Build Coastguard Worker return 430*e4a36f41SAndroid Build Coastguard Worker } 431*e4a36f41SAndroid Build Coastguard Worker conf := android.PathForModuleSrc(ctx, *c.properties.Src) 432*e4a36f41SAndroid Build Coastguard Worker cil := c.compileConfToCil(ctx, conf) 433*e4a36f41SAndroid Build Coastguard Worker 434*e4a36f41SAndroid Build Coastguard Worker if !c.Installable() { 435*e4a36f41SAndroid Build Coastguard Worker c.SkipInstall() 436*e4a36f41SAndroid Build Coastguard Worker } 437*e4a36f41SAndroid Build Coastguard Worker 438*e4a36f41SAndroid Build Coastguard Worker if c.InstallInDebugRamdisk() { 439*e4a36f41SAndroid Build Coastguard Worker // for userdebug_plat_sepolicy.cil 440*e4a36f41SAndroid Build Coastguard Worker c.installPath = android.PathForModuleInstall(ctx) 441*e4a36f41SAndroid Build Coastguard Worker } else { 442*e4a36f41SAndroid Build Coastguard Worker c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux") 443*e4a36f41SAndroid Build Coastguard Worker } 444*e4a36f41SAndroid Build Coastguard Worker c.installSource = cil 445*e4a36f41SAndroid Build Coastguard Worker ctx.InstallFile(c.installPath, c.stem(), c.installSource) 446*e4a36f41SAndroid Build Coastguard Worker 447*e4a36f41SAndroid Build Coastguard Worker ctx.SetOutputFiles(android.Paths{c.installSource}, "") 448*e4a36f41SAndroid Build Coastguard Worker} 449*e4a36f41SAndroid Build Coastguard Worker 450*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyCil) AndroidMkEntries() []android.AndroidMkEntries { 451*e4a36f41SAndroid Build Coastguard Worker return []android.AndroidMkEntries{android.AndroidMkEntries{ 452*e4a36f41SAndroid Build Coastguard Worker OutputFile: android.OptionalPathForPath(c.installSource), 453*e4a36f41SAndroid Build Coastguard Worker Class: "ETC", 454*e4a36f41SAndroid Build Coastguard Worker ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 455*e4a36f41SAndroid Build Coastguard Worker func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 456*e4a36f41SAndroid Build Coastguard Worker entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable()) 457*e4a36f41SAndroid Build Coastguard Worker entries.SetPath("LOCAL_MODULE_PATH", c.installPath) 458*e4a36f41SAndroid Build Coastguard Worker entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem()) 459*e4a36f41SAndroid Build Coastguard Worker }, 460*e4a36f41SAndroid Build Coastguard Worker }, 461*e4a36f41SAndroid Build Coastguard Worker }} 462*e4a36f41SAndroid Build Coastguard Worker} 463*e4a36f41SAndroid Build Coastguard Worker 464*e4a36f41SAndroid Build Coastguard Workertype policyBinaryProperties struct { 465*e4a36f41SAndroid Build Coastguard Worker // Name of the output. Default is {module_name} 466*e4a36f41SAndroid Build Coastguard Worker Stem *string 467*e4a36f41SAndroid Build Coastguard Worker 468*e4a36f41SAndroid Build Coastguard Worker // Cil files to be compiled. 469*e4a36f41SAndroid Build Coastguard Worker Srcs []string `android:"path"` 470*e4a36f41SAndroid Build Coastguard Worker 471*e4a36f41SAndroid Build Coastguard Worker // Whether to ignore neverallow when running secilc check. Defaults to 472*e4a36f41SAndroid Build Coastguard Worker // SELINUX_IGNORE_NEVERALLOWS. 473*e4a36f41SAndroid Build Coastguard Worker Ignore_neverallow *bool 474*e4a36f41SAndroid Build Coastguard Worker 475*e4a36f41SAndroid Build Coastguard Worker // Whether this module is directly installable to one of the partitions. Default is true 476*e4a36f41SAndroid Build Coastguard Worker Installable *bool 477*e4a36f41SAndroid Build Coastguard Worker 478*e4a36f41SAndroid Build Coastguard Worker // List of domains that are allowed to be in permissive mode on user builds. 479*e4a36f41SAndroid Build Coastguard Worker Permissive_domains_on_user_builds []string 480*e4a36f41SAndroid Build Coastguard Worker} 481*e4a36f41SAndroid Build Coastguard Worker 482*e4a36f41SAndroid Build Coastguard Workertype policyBinary struct { 483*e4a36f41SAndroid Build Coastguard Worker android.ModuleBase 484*e4a36f41SAndroid Build Coastguard Worker 485*e4a36f41SAndroid Build Coastguard Worker properties policyBinaryProperties 486*e4a36f41SAndroid Build Coastguard Worker 487*e4a36f41SAndroid Build Coastguard Worker installSource android.Path 488*e4a36f41SAndroid Build Coastguard Worker installPath android.InstallPath 489*e4a36f41SAndroid Build Coastguard Worker} 490*e4a36f41SAndroid Build Coastguard Worker 491*e4a36f41SAndroid Build Coastguard Worker// se_policy_binary compiles cil files to a binary sepolicy file with secilc. Usually sources of 492*e4a36f41SAndroid Build Coastguard Worker// se_policy_binary come from outputs of se_policy_cil modules. 493*e4a36f41SAndroid Build Coastguard Workerfunc policyBinaryFactory() android.Module { 494*e4a36f41SAndroid Build Coastguard Worker c := &policyBinary{} 495*e4a36f41SAndroid Build Coastguard Worker c.AddProperties(&c.properties) 496*e4a36f41SAndroid Build Coastguard Worker android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon) 497*e4a36f41SAndroid Build Coastguard Worker return c 498*e4a36f41SAndroid Build Coastguard Worker} 499*e4a36f41SAndroid Build Coastguard Worker 500*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyBinary) InstallInRoot() bool { 501*e4a36f41SAndroid Build Coastguard Worker return c.InstallInRecovery() 502*e4a36f41SAndroid Build Coastguard Worker} 503*e4a36f41SAndroid Build Coastguard Worker 504*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyBinary) Installable() bool { 505*e4a36f41SAndroid Build Coastguard Worker return proptools.BoolDefault(c.properties.Installable, true) 506*e4a36f41SAndroid Build Coastguard Worker} 507*e4a36f41SAndroid Build Coastguard Worker 508*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyBinary) stem() string { 509*e4a36f41SAndroid Build Coastguard Worker return proptools.StringDefault(c.properties.Stem, c.Name()) 510*e4a36f41SAndroid Build Coastguard Worker} 511*e4a36f41SAndroid Build Coastguard Worker 512*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) { 513*e4a36f41SAndroid Build Coastguard Worker if len(c.properties.Srcs) == 0 { 514*e4a36f41SAndroid Build Coastguard Worker ctx.PropertyErrorf("srcs", "must be specified") 515*e4a36f41SAndroid Build Coastguard Worker return 516*e4a36f41SAndroid Build Coastguard Worker } 517*e4a36f41SAndroid Build Coastguard Worker bin := pathForModuleOut(ctx, c.stem()+"_policy") 518*e4a36f41SAndroid Build Coastguard Worker rule := android.NewRuleBuilder(pctx, ctx) 519*e4a36f41SAndroid Build Coastguard Worker secilcCmd := rule.Command().BuiltTool("secilc"). 520*e4a36f41SAndroid Build Coastguard Worker Flag("-m"). // Multiple decls 521*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-M ", "true"). // Enable MLS 522*e4a36f41SAndroid Build Coastguard Worker Flag("-G"). // expand and remove auto generated attributes 523*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-c ", strconv.Itoa(PolicyVers)). 524*e4a36f41SAndroid Build Coastguard Worker Inputs(android.PathsForModuleSrc(ctx, c.properties.Srcs)). 525*e4a36f41SAndroid Build Coastguard Worker FlagWithOutput("-o ", bin). 526*e4a36f41SAndroid Build Coastguard Worker FlagWithArg("-f ", os.DevNull) 527*e4a36f41SAndroid Build Coastguard Worker 528*e4a36f41SAndroid Build Coastguard Worker if proptools.BoolDefault(c.properties.Ignore_neverallow, ctx.Config().SelinuxIgnoreNeverallows()) { 529*e4a36f41SAndroid Build Coastguard Worker secilcCmd.Flag("-N") 530*e4a36f41SAndroid Build Coastguard Worker } 531*e4a36f41SAndroid Build Coastguard Worker rule.Temporary(bin) 532*e4a36f41SAndroid Build Coastguard Worker 533*e4a36f41SAndroid Build Coastguard Worker // permissive check is performed only in user build (not debuggable). 534*e4a36f41SAndroid Build Coastguard Worker if !ctx.Config().Debuggable() { 535*e4a36f41SAndroid Build Coastguard Worker permissiveDomains := pathForModuleOut(ctx, c.stem()+"_permissive") 536*e4a36f41SAndroid Build Coastguard Worker cmd := rule.Command().BuiltTool("sepolicy-analyze"). 537*e4a36f41SAndroid Build Coastguard Worker Input(bin). 538*e4a36f41SAndroid Build Coastguard Worker Text("permissive") 539*e4a36f41SAndroid Build Coastguard Worker // Filter-out domains listed in permissive_domains_on_user_builds 540*e4a36f41SAndroid Build Coastguard Worker allowedDomains := c.properties.Permissive_domains_on_user_builds 541*e4a36f41SAndroid Build Coastguard Worker if len(allowedDomains) != 0 { 542*e4a36f41SAndroid Build Coastguard Worker cmd.Text("| { grep -Fxv") 543*e4a36f41SAndroid Build Coastguard Worker for _, d := range allowedDomains { 544*e4a36f41SAndroid Build Coastguard Worker cmd.FlagWithArg("-e ", proptools.ShellEscape(d)) 545*e4a36f41SAndroid Build Coastguard Worker } 546*e4a36f41SAndroid Build Coastguard Worker cmd.Text(" || true; }") // no match doesn't fail the cmd 547*e4a36f41SAndroid Build Coastguard Worker } 548*e4a36f41SAndroid Build Coastguard Worker cmd.Text(" > ").Output(permissiveDomains) 549*e4a36f41SAndroid Build Coastguard Worker rule.Temporary(permissiveDomains) 550*e4a36f41SAndroid Build Coastguard Worker 551*e4a36f41SAndroid Build Coastguard Worker msg := `==========\n` + 552*e4a36f41SAndroid Build Coastguard Worker `ERROR: permissive domains not allowed in user builds\n` + 553*e4a36f41SAndroid Build Coastguard Worker `List of invalid domains:` 554*e4a36f41SAndroid Build Coastguard Worker 555*e4a36f41SAndroid Build Coastguard Worker rule.Command().Text("if test"). 556*e4a36f41SAndroid Build Coastguard Worker FlagWithInput("-s ", permissiveDomains). 557*e4a36f41SAndroid Build Coastguard Worker Text("; then echo"). 558*e4a36f41SAndroid Build Coastguard Worker Flag("-e"). 559*e4a36f41SAndroid Build Coastguard Worker Text(`"` + msg + `"`). 560*e4a36f41SAndroid Build Coastguard Worker Text("&& cat "). 561*e4a36f41SAndroid Build Coastguard Worker Input(permissiveDomains). 562*e4a36f41SAndroid Build Coastguard Worker Text("; exit 1; fi") 563*e4a36f41SAndroid Build Coastguard Worker } 564*e4a36f41SAndroid Build Coastguard Worker 565*e4a36f41SAndroid Build Coastguard Worker out := pathForModuleOut(ctx, c.stem()) 566*e4a36f41SAndroid Build Coastguard Worker rule.Command().Text("cp"). 567*e4a36f41SAndroid Build Coastguard Worker Flag("-f"). 568*e4a36f41SAndroid Build Coastguard Worker Input(bin). 569*e4a36f41SAndroid Build Coastguard Worker Output(out) 570*e4a36f41SAndroid Build Coastguard Worker 571*e4a36f41SAndroid Build Coastguard Worker rule.DeleteTemporaryFiles() 572*e4a36f41SAndroid Build Coastguard Worker rule.Build("secilc", "Compiling cil files for "+ctx.ModuleName()) 573*e4a36f41SAndroid Build Coastguard Worker 574*e4a36f41SAndroid Build Coastguard Worker if !c.Installable() { 575*e4a36f41SAndroid Build Coastguard Worker c.SkipInstall() 576*e4a36f41SAndroid Build Coastguard Worker } 577*e4a36f41SAndroid Build Coastguard Worker 578*e4a36f41SAndroid Build Coastguard Worker if c.InstallInRecovery() { 579*e4a36f41SAndroid Build Coastguard Worker // install in root 580*e4a36f41SAndroid Build Coastguard Worker c.installPath = android.PathForModuleInstall(ctx) 581*e4a36f41SAndroid Build Coastguard Worker } else { 582*e4a36f41SAndroid Build Coastguard Worker c.installPath = android.PathForModuleInstall(ctx, "etc", "selinux") 583*e4a36f41SAndroid Build Coastguard Worker } 584*e4a36f41SAndroid Build Coastguard Worker c.installSource = out 585*e4a36f41SAndroid Build Coastguard Worker ctx.InstallFile(c.installPath, c.stem(), c.installSource) 586*e4a36f41SAndroid Build Coastguard Worker 587*e4a36f41SAndroid Build Coastguard Worker ctx.SetOutputFiles(android.Paths{c.installSource}, "") 588*e4a36f41SAndroid Build Coastguard Worker} 589*e4a36f41SAndroid Build Coastguard Worker 590*e4a36f41SAndroid Build Coastguard Workerfunc (c *policyBinary) AndroidMkEntries() []android.AndroidMkEntries { 591*e4a36f41SAndroid Build Coastguard Worker return []android.AndroidMkEntries{android.AndroidMkEntries{ 592*e4a36f41SAndroid Build Coastguard Worker OutputFile: android.OptionalPathForPath(c.installSource), 593*e4a36f41SAndroid Build Coastguard Worker Class: "ETC", 594*e4a36f41SAndroid Build Coastguard Worker ExtraEntries: []android.AndroidMkExtraEntriesFunc{ 595*e4a36f41SAndroid Build Coastguard Worker func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { 596*e4a36f41SAndroid Build Coastguard Worker entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", !c.Installable()) 597*e4a36f41SAndroid Build Coastguard Worker entries.SetPath("LOCAL_MODULE_PATH", c.installPath) 598*e4a36f41SAndroid Build Coastguard Worker entries.SetString("LOCAL_INSTALLED_MODULE_STEM", c.stem()) 599*e4a36f41SAndroid Build Coastguard Worker }, 600*e4a36f41SAndroid Build Coastguard Worker }, 601*e4a36f41SAndroid Build Coastguard Worker }} 602*e4a36f41SAndroid Build Coastguard Worker} 603