Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 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 paths |
| 16 | |
| 17 | import "runtime" |
| 18 | |
| 19 | type PathConfig struct { |
| 20 | // Whether to create the symlink in the new PATH for this tool. |
| 21 | Symlink bool |
| 22 | |
| 23 | // Whether to log about usages of this tool to the soong.log |
| 24 | Log bool |
| 25 | |
| 26 | // Whether to exit with an error instead of invoking the underlying tool. |
| 27 | Error bool |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 28 | |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 29 | // Whether we use a linux-specific prebuilt for this tool. On Darwin, |
| 30 | // we'll allow the host executable instead. |
| 31 | LinuxOnlyPrebuilt bool |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 34 | // These binaries can be run from $PATH, nonhermetically. There should be as |
| 35 | // few as possible of these, since this means that the build depends on tools |
| 36 | // that are not shipped in the source tree and whose behavior is therefore |
| 37 | // unpredictable. |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 38 | var Allowed = PathConfig{ |
| 39 | Symlink: true, |
| 40 | Log: false, |
| 41 | Error: false, |
| 42 | } |
| 43 | |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 44 | // This tool is specifically disallowed and calling it will result in an |
| 45 | // "executable no found" error. |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 46 | var Forbidden = PathConfig{ |
| 47 | Symlink: false, |
| 48 | Log: true, |
| 49 | Error: true, |
| 50 | } |
| 51 | |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 52 | // This tool is allowed, but access to it will be logged. |
Dan Willemsen | 3eec9c5 | 2018-10-04 23:21:40 +0000 | [diff] [blame] | 53 | var Log = PathConfig{ |
| 54 | Symlink: true, |
Dan Willemsen | e9e20dd | 2018-10-09 23:23:19 +0000 | [diff] [blame] | 55 | Log: true, |
| 56 | Error: false, |
Dan Willemsen | 3eec9c5 | 2018-10-04 23:21:40 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 59 | // The configuration used if the tool is not listed in the config below. |
Dan Willemsen | 8125d2a | 2018-08-15 15:26:39 -0700 | [diff] [blame] | 60 | // Currently this will create the symlink, but log and error when it's used. In |
| 61 | // the future, I expect the symlink to be removed, and this will be equivalent |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 62 | // to Forbidden. This applies to every tool not specifically mentioned in the |
| 63 | // configuration. |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 64 | var Missing = PathConfig{ |
| 65 | Symlink: true, |
| 66 | Log: true, |
Dan Willemsen | 8125d2a | 2018-08-15 15:26:39 -0700 | [diff] [blame] | 67 | Error: true, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 70 | // This is used for binaries for which we have prebuilt versions, but only for |
| 71 | // Linux. Thus, their execution from $PATH is only allowed on Mac OS. |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 72 | var LinuxOnlyPrebuilt = PathConfig{ |
| 73 | Symlink: false, |
| 74 | Log: true, |
| 75 | Error: true, |
| 76 | LinuxOnlyPrebuilt: true, |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 79 | func GetConfig(name string) PathConfig { |
| 80 | if config, ok := Configuration[name]; ok { |
| 81 | return config |
| 82 | } |
| 83 | return Missing |
| 84 | } |
| 85 | |
Lukacs T. Berki | 2388f64 | 2022-05-06 12:42:05 +0200 | [diff] [blame] | 86 | // This list specifies whether a particular binary from $PATH is allowed to be |
| 87 | // run during the build. For more documentation, see path_interposer.go . |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 88 | var Configuration = map[string]PathConfig{ |
Kousik Kumar | 5c5c57d | 2023-06-05 10:57:07 -0400 | [diff] [blame] | 89 | "bash": Allowed, |
Kousik Kumar | 5c5c57d | 2023-06-05 10:57:07 -0400 | [diff] [blame] | 90 | "diff": Allowed, |
| 91 | "dlv": Allowed, |
| 92 | "expr": Allowed, |
| 93 | "fuser": Allowed, |
| 94 | "gcert": Allowed, |
| 95 | "getopt": Allowed, |
| 96 | "git": Allowed, |
| 97 | "hexdump": Allowed, |
| 98 | "jar": Allowed, |
| 99 | "java": Allowed, |
| 100 | "javap": Allowed, |
| 101 | "lsof": Allowed, |
| 102 | "openssl": Allowed, |
| 103 | "prodcertstatus": Allowed, |
| 104 | "pstree": Allowed, |
| 105 | "rsync": Allowed, |
| 106 | "sh": Allowed, |
| 107 | "stubby": Allowed, |
| 108 | "tr": Allowed, |
| 109 | "unzip": Allowed, |
| 110 | "zip": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 111 | |
| 112 | // Host toolchain is removed. In-tree toolchain should be used instead. |
| 113 | // GCC also can't find cc1 with this implementation. |
| 114 | "ar": Forbidden, |
| 115 | "as": Forbidden, |
| 116 | "cc": Forbidden, |
| 117 | "clang": Forbidden, |
| 118 | "clang++": Forbidden, |
| 119 | "gcc": Forbidden, |
| 120 | "g++": Forbidden, |
| 121 | "ld": Forbidden, |
| 122 | "ld.bfd": Forbidden, |
| 123 | "ld.gold": Forbidden, |
| 124 | "pkg-config": Forbidden, |
| 125 | |
Elliott Hughes | f1ff226 | 2019-08-27 15:17:32 -0700 | [diff] [blame] | 126 | // These are toybox tools that only work on Linux. |
| 127 | "pgrep": LinuxOnlyPrebuilt, |
| 128 | "pkill": LinuxOnlyPrebuilt, |
| 129 | "ps": LinuxOnlyPrebuilt, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | func init() { |
| 133 | if runtime.GOOS == "darwin" { |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 134 | Configuration["sw_vers"] = Allowed |
| 135 | Configuration["xcrun"] = Allowed |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 136 | |
Elliott Hughes | 34b49d1 | 2019-09-06 14:42:24 -0700 | [diff] [blame] | 137 | // We don't have darwin prebuilts for some tools, |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 138 | // so allow the host versions. |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 139 | for name, config := range Configuration { |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 140 | if config.LinuxOnlyPrebuilt { |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 141 | Configuration[name] = Allowed |
| 142 | } |
| 143 | } |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 144 | } |
| 145 | } |