blob: b2f91a521a84e370cbcdb71f6e546f1b4c6e8e08 [file] [log] [blame]
rjw2e8229f2022-02-15 21:08:12 +08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
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 */
16
17/* This file is used to define the properties of the filesystem
18** images generated by build tools (mkbootfs and mkyaffs2image) and
19** by the device side of adb.
20*/
21
22#ifndef _ANDROID_FILESYSTEM_CONFIG_H_
23#define _ANDROID_FILESYSTEM_CONFIG_H_
24
25#include <string.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <stdint.h>
29
30#ifdef HAVE_ANDROID_OS
31#include <linux/capability.h>
32#else
33#include "android_filesystem_capability.h"
34#endif
35
36/* This is the master Users and Groups config for the platform.
37 * DO NOT EVER RENUMBER
38 */
39
40#define AID_ROOT 0 /* traditional unix root user */
41
42#define AID_SYSTEM 1000 /* system server */
43
44#define AID_RADIO 1001 /* telephony subsystem, RIL */
45#define AID_BLUETOOTH 1002 /* bluetooth subsystem */
46#define AID_GRAPHICS 1003 /* graphics devices */
47#define AID_INPUT 1004 /* input devices */
48#define AID_AUDIO 1005 /* audio devices */
49#define AID_CAMERA 1006 /* camera devices */
50#define AID_LOG 1007 /* log devices */
51#define AID_COMPASS 1008 /* compass device */
52#define AID_MOUNT 1009 /* mountd socket */
53#define AID_WIFI 1010 /* wifi subsystem */
54#define AID_ADB 1011 /* android debug bridge (adbd) */
55#define AID_INSTALL 1012 /* group for installing packages */
56#define AID_MEDIA 1013 /* mediaserver process */
57#define AID_DHCP 1014 /* dhcp client */
58#define AID_SDCARD_RW 1015 /* external storage write access */
59#define AID_VPN 1016 /* vpn system */
60#define AID_KEYSTORE 1017 /* keystore subsystem */
61#define AID_USB 1018 /* USB devices */
62#define AID_DRM 1019 /* DRM server */
63#define AID_MDNSR 1020 /* MulticastDNSResponder (service discovery) */
64#define AID_GPS 1021 /* GPS daemon */
65#define AID_UNUSED1 1022 /* deprecated, DO NOT USE */
66#define AID_MEDIA_RW 1023 /* internal media storage write access */
67#define AID_MTP 1024 /* MTP USB driver access */
68#define AID_UNUSED2 1025 /* deprecated, DO NOT USE */
69#define AID_DRMRPC 1026 /* group for drm rpc */
70#define AID_NFC 1027 /* nfc subsystem */
71#define AID_SDCARD_R 1028 /* external storage read access */
72#define AID_CLAT 1029 /* clat part of nat464 */
73#define AID_LOOP_RADIO 1030 /* loop radio devices */
74#define AID_MEDIA_DRM 1031 /* MediaDrm plugins */
75#define AID_PACKAGE_INFO 1032 /* access to installed package details */
76#define AID_SDCARD_PICS 1033 /* external storage photos access */
77#define AID_SDCARD_AV 1034 /* external storage audio/video access */
78#define AID_SDCARD_ALL 1035 /* access all users external storage */
79#define AID_LOGD 1036 /* log daemon */
80#define AID_SHARED_RELRO 1037 /* creator of shared GNU RELRO files */
81
82#define AID_SHELL 2000 /* adb and debug shell user */
83#define AID_CACHE 2001 /* cache access */
84#define AID_DIAG 2002 /* access to diagnostic resources */
85
86/* The range 2900-2999 is reserved for OEM, and must never be
87 * used here */
88#define AID_OEM_RESERVED_START 2900
89#define AID_OEM_RESERVED_END 2999
90
91/* The 3000 series are intended for use as supplemental group id's only.
92 * They indicate special Android capabilities that the kernel is aware of. */
93#define AID_NET_BT_ADMIN 3001 /* bluetooth: create any socket */
94#define AID_NET_BT 3002 /* bluetooth: create sco, rfcomm or l2cap sockets */
95#define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
96#define AID_NET_RAW 3004 /* can create raw INET sockets */
97#define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */
98#define AID_NET_BW_STATS 3006 /* read bandwidth statistics */
99#define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */
100#define AID_NET_BT_STACK 3008 /* bluetooth: access config files */
101
102#define AID_EVERYBODY 9997 /* shared between all apps in the same profile */
103#define AID_MISC 9998 /* access to misc storage */
104#define AID_NOBODY 9999
105
106#define AID_APP 10000 /* first app user */
107
108#define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
109#define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
110
111#define AID_USER 100000 /* offset for uid ranges for each user */
112
113#define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
114#define AID_SHARED_GID_END 59999 /* start of gids for apps in each user to share */
115
116#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
117struct android_id_info {
118 const char *name;
119 unsigned aid;
120};
121
122static const struct android_id_info android_ids[] = {
123 { "root", AID_ROOT, },
124
125 { "system", AID_SYSTEM, },
126
127 { "radio", AID_RADIO, },
128 { "bluetooth", AID_BLUETOOTH, },
129 { "graphics", AID_GRAPHICS, },
130 { "input", AID_INPUT, },
131 { "audio", AID_AUDIO, },
132 { "camera", AID_CAMERA, },
133 { "log", AID_LOG, },
134 { "compass", AID_COMPASS, },
135 { "mount", AID_MOUNT, },
136 { "wifi", AID_WIFI, },
137 { "adb", AID_ADB, },
138 { "install", AID_INSTALL, },
139 { "media", AID_MEDIA, },
140 { "dhcp", AID_DHCP, },
141 { "sdcard_rw", AID_SDCARD_RW, },
142 { "vpn", AID_VPN, },
143 { "keystore", AID_KEYSTORE, },
144 { "usb", AID_USB, },
145 { "drm", AID_DRM, },
146 { "mdnsr", AID_MDNSR, },
147 { "gps", AID_GPS, },
148 // AID_UNUSED1
149 { "media_rw", AID_MEDIA_RW, },
150 { "mtp", AID_MTP, },
151 // AID_UNUSED2
152 { "drmrpc", AID_DRMRPC, },
153 { "nfc", AID_NFC, },
154 { "sdcard_r", AID_SDCARD_R, },
155 { "clat", AID_CLAT, },
156 { "loop_radio", AID_LOOP_RADIO, },
157 { "mediadrm", AID_MEDIA_DRM, },
158 { "package_info", AID_PACKAGE_INFO, },
159 { "sdcard_pics", AID_SDCARD_PICS, },
160 { "sdcard_av", AID_SDCARD_AV, },
161 { "sdcard_all", AID_SDCARD_ALL, },
162 { "logd", AID_LOGD, },
163 { "shared_relro", AID_SHARED_RELRO, },
164
165 { "shell", AID_SHELL, },
166 { "cache", AID_CACHE, },
167 { "diag", AID_DIAG, },
168
169 { "net_bt_admin", AID_NET_BT_ADMIN, },
170 { "net_bt", AID_NET_BT, },
171 { "inet", AID_INET, },
172 { "net_raw", AID_NET_RAW, },
173 { "net_admin", AID_NET_ADMIN, },
174 { "net_bw_stats", AID_NET_BW_STATS, },
175 { "net_bw_acct", AID_NET_BW_ACCT, },
176 { "net_bt_stack", AID_NET_BT_STACK, },
177
178 { "everybody", AID_EVERYBODY, },
179 { "misc", AID_MISC, },
180 { "nobody", AID_NOBODY, },
181};
182
183#define android_id_count \
184 (sizeof(android_ids) / sizeof(android_ids[0]))
185
186struct fs_path_config {
187 unsigned mode;
188 unsigned uid;
189 unsigned gid;
190 uint64_t capabilities;
191 const char *prefix;
192};
193
194/* Rules for directories.
195** These rules are applied based on "first match", so they
196** should start with the most specific path and work their
197** way up to the root.
198*/
199
200static const struct fs_path_config android_dirs[] = {
201 { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
202 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
203 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
204 { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" },
205 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
206 { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
207 { 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
208 { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
209 { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
210 { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" },
211 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
212 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
213 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
214 { 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
215 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
216 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
217 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
218 { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
219 { 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
220 { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
221 { 00755, AID_ROOT, AID_ROOT, 0, 0 },
222};
223
224/* Rules for files.
225** These rules are applied based on "first match", so they
226** should start with the most specific path and work their
227** way up to the root. Prefixes ending in * denotes wildcard
228** and will allow partial matches.
229*/
230static const struct fs_path_config android_files[] = {
231 { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
232 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
233 { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.trout.rc" },
234 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
235 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.testmenu" },
236 { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
237 { 00444, AID_RADIO, AID_AUDIO, 0, "system/etc/AudioPara4.csv" },
238 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
239 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
240 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
241 { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
242 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
243 { 00644, AID_APP, AID_APP, 0, "data/data/*" },
244 { 00755, AID_ROOT, AID_ROOT, 0, "system/bin/ping" },
245
246 /* the following file is INTENTIONALLY set-gid and not set-uid.
247 * Do not change. */
248 { 02750, AID_ROOT, AID_INET, 0, "system/bin/netcfg" },
249
250 /* the following five files are INTENTIONALLY set-uid, but they
251 * are NOT included on user builds. */
252 { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
253 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" },
254 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" },
255 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
256 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/tcpdump" },
257 { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" },
258
259 /* the following files have enhanced capabilities and ARE included in user builds. */
260 { 00750, AID_ROOT, AID_SHELL, (1 << CAP_SETUID) | (1 << CAP_SETGID), "system/bin/run-as" },
261
262 { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },
263 { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },
264 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
265 { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
266 { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" },
267 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
268 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },
269 { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
270 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
271 { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
272 { 00750, AID_ROOT, AID_SHELL, 0, "init*" },
273 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
274 { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
275 { 00644, AID_ROOT, AID_ROOT, 0, 0 },
276};
277
278static inline void fs_config(const char *path, int dir,
279 unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities)
280{
281 const struct fs_path_config *pc;
282 int plen;
283
284 if (path[0] == '/') {
285 path++;
286 }
287
288 pc = dir ? android_dirs : android_files;
289 plen = strlen(path);
290 for(; pc->prefix; pc++){
291 int len = strlen(pc->prefix);
292 if (dir) {
293 if(plen < len) continue;
294 if(!strncmp(pc->prefix, path, len)) break;
295 continue;
296 }
297 /* If name ends in * then allow partial matches. */
298 if (pc->prefix[len -1] == '*') {
299 if(!strncmp(pc->prefix, path, len - 1)) break;
300 } else if (plen == len){
301 if(!strncmp(pc->prefix, path, len)) break;
302 }
303 }
304 *uid = pc->uid;
305 *gid = pc->gid;
306 *mode = (*mode & (~07777)) | pc->mode;
307 *capabilities = pc->capabilities;
308
309#if 0
310 fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
311 path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);
312#endif
313}
314#endif
315#endif