Yi-Yo Chiang | 2c18965 | 2021-11-08 19:30:04 +0800 | [diff] [blame] | 1 | // Copyright 2021 The Android Open Source Project |
| 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 | package selinux |
| 16 | |
| 17 | import ( |
| 18 | "github.com/google/blueprint/proptools" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | android.RegisterModuleType("se_bug_map", bugMapFactory) |
| 25 | } |
| 26 | |
| 27 | // se_bug_map collects and installs selinux denial bug tracking information to be loaded by auditd. |
| 28 | func bugMapFactory() android.Module { |
| 29 | c := &bugMap{} |
| 30 | c.AddProperties(&c.properties) |
| 31 | android.InitAndroidArchModule(c, android.DeviceSupported, android.MultilibCommon) |
| 32 | return c |
| 33 | } |
| 34 | |
| 35 | type bugMap struct { |
| 36 | android.ModuleBase |
| 37 | properties bugMapProperties |
| 38 | installSource android.Path |
| 39 | installPath android.InstallPath |
| 40 | } |
| 41 | |
| 42 | type bugMapProperties struct { |
Inseob Kim | 4196403 | 2022-04-22 07:50:22 +0900 | [diff] [blame] | 43 | // List of source files or se_build_files modules. |
Yi-Yo Chiang | 2c18965 | 2021-11-08 19:30:04 +0800 | [diff] [blame] | 44 | Srcs []string `android:"path"` |
| 45 | |
| 46 | // Output file name. Defaults to module name if unspecified. |
| 47 | Stem *string |
| 48 | } |
| 49 | |
| 50 | func (b *bugMap) stem() string { |
| 51 | return proptools.StringDefault(b.properties.Stem, b.Name()) |
| 52 | } |
| 53 | |
| 54 | func (b *bugMap) expandSeSources(ctx android.ModuleContext) android.Paths { |
Inseob Kim | 4196403 | 2022-04-22 07:50:22 +0900 | [diff] [blame] | 55 | return android.PathsForModuleSrc(ctx, b.properties.Srcs) |
Yi-Yo Chiang | 2c18965 | 2021-11-08 19:30:04 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | func (b *bugMap) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 59 | if !b.SocSpecific() && !b.SystemExtSpecific() && !b.Platform() { |
| 60 | ctx.ModuleErrorf("Selinux bug_map can only be installed in system, system_ext and vendor partitions") |
| 61 | } |
| 62 | |
| 63 | srcPaths := b.expandSeSources(ctx) |
| 64 | out := android.PathForModuleGen(ctx, b.Name()) |
| 65 | ctx.Build(pctx, android.BuildParams{ |
| 66 | Rule: android.Cat, |
| 67 | Inputs: srcPaths, |
| 68 | Output: out, |
| 69 | Description: "Combining bug_map for " + b.Name(), |
| 70 | }) |
| 71 | |
| 72 | b.installPath = android.PathForModuleInstall(ctx, "etc", "selinux") |
| 73 | b.installSource = out |
| 74 | ctx.InstallFile(b.installPath, b.stem(), b.installSource) |
| 75 | } |
| 76 | |
| 77 | func (b *bugMap) AndroidMkEntries() []android.AndroidMkEntries { |
| 78 | return []android.AndroidMkEntries{android.AndroidMkEntries{ |
| 79 | Class: "ETC", |
| 80 | OutputFile: android.OptionalPathForPath(b.installSource), |
| 81 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 82 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
Colin Cross | 6c7f937 | 2022-01-11 19:35:43 -0800 | [diff] [blame] | 83 | entries.SetPath("LOCAL_MODULE_PATH", b.installPath) |
Yi-Yo Chiang | 2c18965 | 2021-11-08 19:30:04 +0800 | [diff] [blame] | 84 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", b.stem()) |
| 85 | }, |
| 86 | }, |
| 87 | }} |
| 88 | } |