blob: 540318fd59e736dfd0c25a661d64cea58db2f304 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -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>
Nick Kraleviche9e74f32013-02-07 14:22:12 -080028#include <stdint.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080029
Nick Kralevichfe813572013-02-11 15:14:55 -080030#ifdef HAVE_ANDROID_OS
31#include <linux/capability.h>
32#else
33#include "android_filesystem_capability.h"
34#endif
35
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080036/* 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 */
San Mehat6e1f2152009-04-23 09:15:08 -070058#define AID_SDCARD_RW 1015 /* external storage write access */
San Mehat4a6f2322009-05-14 19:44:59 -070059#define AID_VPN 1016 /* vpn system */
Chung-yih Wang1f75d702009-06-01 19:04:05 +080060#define AID_KEYSTORE 1017 /* keystore subsystem */
Mike Lockwood93ac1552010-05-06 13:30:09 -040061#define AID_USB 1018 /* USB devices */
aimitakeshie572d592010-07-27 08:38:35 +090062#define AID_DRM 1019 /* DRM server */
Robert Greenwalt1d91fcf2012-03-27 16:59:27 -070063#define AID_MDNSR 1020 /* MulticastDNSResponder (service discovery) */
Mike Lockwoodc29919c2010-09-27 08:01:58 -040064#define AID_GPS 1021 /* GPS daemon */
Jeff Hamiltona6a36c02011-03-24 21:40:43 -050065#define AID_UNUSED1 1022 /* deprecated, DO NOT USE */
Mike Lockwood2e0047b2010-10-29 10:55:54 -040066#define AID_MEDIA_RW 1023 /* internal media storage write access */
Mike Lockwoodaf7bdc62011-01-10 08:22:30 -050067#define AID_MTP 1024 /* MTP USB driver access */
Nick Pelly097b4ed2011-11-21 14:55:59 -080068#define AID_UNUSED2 1025 /* deprecated, DO NOT USE */
Jeffrey Tinker7005c032011-09-30 12:40:25 -070069#define AID_DRMRPC 1026 /* group for drm rpc */
Nick Pelly097b4ed2011-11-21 14:55:59 -080070#define AID_NFC 1027 /* nfc subsystem */
Dianne Hackborn50458cf2012-03-07 12:57:14 -080071#define AID_SDCARD_R 1028 /* external storage read access */
Daniel Drownb49183f2012-02-16 10:00:24 -060072#define AID_CLAT 1029 /* clat part of nat464 */
Doug Zongker8cc97302013-01-29 10:50:22 -080073#define AID_LOOP_RADIO 1030 /* loop radio devices */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080074
75#define AID_SHELL 2000 /* adb and debug shell user */
76#define AID_CACHE 2001 /* cache access */
77#define AID_DIAG 2002 /* access to diagnostic resources */
78
79/* The 3000 series are intended for use as supplemental group id's only.
80 * They indicate special Android capabilities that the kernel is aware of. */
81#define AID_NET_BT_ADMIN 3001 /* bluetooth: create any socket */
82#define AID_NET_BT 3002 /* bluetooth: create sco, rfcomm or l2cap sockets */
83#define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
84#define AID_NET_RAW 3004 /* can create raw INET sockets */
Chia-chi Yeh88dc6572009-06-19 14:59:08 +080085#define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */
Jeff Sharkey4f1df182011-05-02 17:52:03 -070086#define AID_NET_BW_STATS 3006 /* read bandwidth statistics */
87#define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */
Matthew Xie971153a2012-10-04 12:35:27 -070088#define AID_NET_BT_STACK 3008 /* bluetooth: access config files */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080089
90#define AID_MISC 9998 /* access to misc storage */
91#define AID_NOBODY 9999
92
Dianne Hackbornca185ab2012-02-09 11:19:00 -080093#define AID_APP 10000 /* first app user */
94
95#define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
96#define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
97
98#define AID_USER 100000 /* offset for uid ranges for each user */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080099
Kenny Root7e41c842012-09-11 15:03:45 -0700100#define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
101#define AID_SHARED_GID_END 59999 /* start of gids for apps in each user to share */
102
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800103#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
104struct android_id_info {
105 const char *name;
106 unsigned aid;
107};
108
Nick Kralevich4688ac52010-08-31 09:44:43 -0700109static const struct android_id_info android_ids[] = {
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800110 { "root", AID_ROOT, },
111 { "system", AID_SYSTEM, },
112 { "radio", AID_RADIO, },
113 { "bluetooth", AID_BLUETOOTH, },
114 { "graphics", AID_GRAPHICS, },
115 { "input", AID_INPUT, },
116 { "audio", AID_AUDIO, },
117 { "camera", AID_CAMERA, },
118 { "log", AID_LOG, },
119 { "compass", AID_COMPASS, },
120 { "mount", AID_MOUNT, },
121 { "wifi", AID_WIFI, },
122 { "dhcp", AID_DHCP, },
123 { "adb", AID_ADB, },
124 { "install", AID_INSTALL, },
125 { "media", AID_MEDIA, },
aimitakeshie572d592010-07-27 08:38:35 +0900126 { "drm", AID_DRM, },
Robert Greenwalt1d91fcf2012-03-27 16:59:27 -0700127 { "mdnsr", AID_MDNSR, },
Nick Pelly85905a62010-10-14 23:30:51 -0700128 { "nfc", AID_NFC, },
Jeffrey Tinker7005c032011-09-30 12:40:25 -0700129 { "drmrpc", AID_DRMRPC, },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800130 { "shell", AID_SHELL, },
131 { "cache", AID_CACHE, },
132 { "diag", AID_DIAG, },
133 { "net_bt_admin", AID_NET_BT_ADMIN, },
134 { "net_bt", AID_NET_BT, },
Matthew Xie971153a2012-10-04 12:35:27 -0700135 { "net_bt_stack", AID_NET_BT_STACK, },
Dianne Hackborn5d3aadb2012-03-12 10:54:11 -0700136 { "sdcard_r", AID_SDCARD_R, },
San Mehat6e1f2152009-04-23 09:15:08 -0700137 { "sdcard_rw", AID_SDCARD_RW, },
Mike Lockwood2e0047b2010-10-29 10:55:54 -0400138 { "media_rw", AID_MEDIA_RW, },
San Mehat4a6f2322009-05-14 19:44:59 -0700139 { "vpn", AID_VPN, },
Chung-yih Wang1f75d702009-06-01 19:04:05 +0800140 { "keystore", AID_KEYSTORE, },
Mike Lockwood93ac1552010-05-06 13:30:09 -0400141 { "usb", AID_USB, },
Mike Lockwoodaf7bdc62011-01-10 08:22:30 -0500142 { "mtp", AID_MTP, },
Mike Lockwoodc29919c2010-09-27 08:01:58 -0400143 { "gps", AID_GPS, },
Chung-yih Wang1f75d702009-06-01 19:04:05 +0800144 { "inet", AID_INET, },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800145 { "net_raw", AID_NET_RAW, },
Chia-chi Yeh88dc6572009-06-19 14:59:08 +0800146 { "net_admin", AID_NET_ADMIN, },
Jeff Sharkey4f1df182011-05-02 17:52:03 -0700147 { "net_bw_stats", AID_NET_BW_STATS, },
148 { "net_bw_acct", AID_NET_BW_ACCT, },
Doug Zongker0fe97422013-01-29 09:04:53 -0800149 { "loop_radio", AID_LOOP_RADIO, },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800150 { "misc", AID_MISC, },
151 { "nobody", AID_NOBODY, },
Daniel Drownb49183f2012-02-16 10:00:24 -0600152 { "clat", AID_CLAT, },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800153};
154
155#define android_id_count \
156 (sizeof(android_ids) / sizeof(android_ids[0]))
Doug Zongker08c370c2012-05-03 14:16:54 -0700157
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800158struct fs_path_config {
159 unsigned mode;
160 unsigned uid;
161 unsigned gid;
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800162 uint64_t capabilities;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800163 const char *prefix;
164};
165
166/* Rules for directories.
167** These rules are applied based on "first match", so they
168** should start with the most specific path and work their
169** way up to the root.
170*/
171
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800172static const struct fs_path_config android_dirs[] = {
173 { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
174 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
175 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
176 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/dalvik-cache" },
177 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
178 { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
179 { 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
180 { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
181 { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
182 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
183 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
184 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
185 { 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
186 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
187 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
188 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
189 { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
Colin Cross0b56fc72013-03-20 11:58:19 -0700190 { 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800191 { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
192 { 00755, AID_ROOT, AID_ROOT, 0, 0 },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800193};
194
195/* Rules for files.
196** These rules are applied based on "first match", so they
197** should start with the most specific path and work their
198** way up to the root. Prefixes ending in * denotes wildcard
199** and will allow partial matches.
200*/
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800201static const struct fs_path_config android_files[] = {
202 { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
203 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
204 { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.trout.rc" },
205 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
206 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.testmenu" },
207 { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
208 { 00440, AID_BLUETOOTH, AID_BLUETOOTH, 0, "system/etc/dbus.conf" },
209 { 00444, AID_RADIO, AID_AUDIO, 0, "system/etc/AudioPara4.csv" },
210 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
211 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
212 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
213 { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
214 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
215 { 00644, AID_APP, AID_APP, 0, "data/data/*" },
Nick Kralevichfe813572013-02-11 15:14:55 -0800216 { 00755, AID_ROOT, AID_ROOT, 0, "system/bin/ping" },
217
218 /* the following file is INTENTIONALLY set-gid and not set-uid.
219 * Do not change. */
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800220 { 02750, AID_ROOT, AID_INET, 0, "system/bin/netcfg" },
Nick Kralevichfe813572013-02-11 15:14:55 -0800221
222 /* the following five files are INTENTIONALLY set-uid, but they
223 * are NOT included on user builds. */
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800224 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/su" },
225 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" },
226 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" },
227 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
228 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/tcpdump" },
229 { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" },
Nick Kralevichfe813572013-02-11 15:14:55 -0800230
231 /* the following file has enhanced capabilities and IS included in user builds. */
232 { 00750, AID_ROOT, AID_SHELL, (1 << CAP_SETUID) | (1 << CAP_SETGID), "system/bin/run-as" },
233
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800234 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
235 { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
236 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
237 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },
Colin Cross0b56fc72013-03-20 11:58:19 -0700238 { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800239 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
240 { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
241 { 00750, AID_ROOT, AID_SHELL, 0, "init*" },
242 { 00750, AID_ROOT, AID_SHELL, 0, "charger*" },
243 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
244 { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
245 { 00644, AID_ROOT, AID_ROOT, 0, 0 },
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800246};
247
248static inline void fs_config(const char *path, int dir,
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800249 unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800250{
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800251 const struct fs_path_config *pc;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800252 int plen;
Doug Zongker08c370c2012-05-03 14:16:54 -0700253
Colin Cross04aaf5a2012-12-21 12:50:29 -0800254 if (path[0] == '/') {
255 path++;
256 }
257
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800258 pc = dir ? android_dirs : android_files;
259 plen = strlen(path);
260 for(; pc->prefix; pc++){
261 int len = strlen(pc->prefix);
262 if (dir) {
263 if(plen < len) continue;
264 if(!strncmp(pc->prefix, path, len)) break;
265 continue;
266 }
267 /* If name ends in * then allow partial matches. */
268 if (pc->prefix[len -1] == '*') {
269 if(!strncmp(pc->prefix, path, len - 1)) break;
270 } else if (plen == len){
271 if(!strncmp(pc->prefix, path, len)) break;
272 }
273 }
274 *uid = pc->uid;
275 *gid = pc->gid;
276 *mode = (*mode & (~07777)) | pc->mode;
Nick Kraleviche9e74f32013-02-07 14:22:12 -0800277 *capabilities = pc->capabilities;
Doug Zongker08c370c2012-05-03 14:16:54 -0700278
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800279#if 0
Doug Zongker08c370c2012-05-03 14:16:54 -0700280 fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800281 path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);
282#endif
283}
284#endif
285#endif