android_filesystem_config.h revision 50458cf76ea7b0b03598c785acb1481ed0ae5b1d
1/*
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
29/* This is the master Users and Groups config for the platform.
30** DO NOT EVER RENUMBER.
31*/
32
33#define AID_ROOT             0  /* traditional unix root user */
34
35#define AID_SYSTEM        1000  /* system server */
36
37#define AID_RADIO         1001  /* telephony subsystem, RIL */
38#define AID_BLUETOOTH     1002  /* bluetooth subsystem */
39#define AID_GRAPHICS      1003  /* graphics devices */
40#define AID_INPUT         1004  /* input devices */
41#define AID_AUDIO         1005  /* audio devices */
42#define AID_CAMERA        1006  /* camera devices */
43#define AID_LOG           1007  /* log devices */
44#define AID_COMPASS       1008  /* compass device */
45#define AID_MOUNT         1009  /* mountd socket */
46#define AID_WIFI          1010  /* wifi subsystem */
47#define AID_ADB           1011  /* android debug bridge (adbd) */
48#define AID_INSTALL       1012  /* group for installing packages */
49#define AID_MEDIA         1013  /* mediaserver process */
50#define AID_DHCP          1014  /* dhcp client */
51#define AID_SDCARD_RW     1015  /* external storage write access */
52#define AID_VPN           1016  /* vpn system */
53#define AID_KEYSTORE      1017  /* keystore subsystem */
54#define AID_USB           1018  /* USB devices */
55#define AID_DRM           1019  /* DRM server */
56#define AID_AVAILABLE     1020  /* available for use */
57#define AID_GPS           1021  /* GPS daemon */
58#define AID_UNUSED1       1022  /* deprecated, DO NOT USE */
59#define AID_MEDIA_RW      1023  /* internal media storage write access */
60#define AID_MTP           1024  /* MTP USB driver access */
61#define AID_UNUSED2       1025  /* deprecated, DO NOT USE */
62#define AID_DRMRPC        1026  /* group for drm rpc */
63#define AID_NFC           1027  /* nfc subsystem */
64#define AID_SDCARD_R      1028  /* external storage read access */
65
66#define AID_SHELL         2000  /* adb and debug shell user */
67#define AID_CACHE         2001  /* cache access */
68#define AID_DIAG          2002  /* access to diagnostic resources */
69
70/* The 3000 series are intended for use as supplemental group id's only.
71 * They indicate special Android capabilities that the kernel is aware of. */
72#define AID_NET_BT_ADMIN  3001  /* bluetooth: create any socket */
73#define AID_NET_BT        3002  /* bluetooth: create sco, rfcomm or l2cap sockets */
74#define AID_INET          3003  /* can create AF_INET and AF_INET6 sockets */
75#define AID_NET_RAW       3004  /* can create raw INET sockets */
76#define AID_NET_ADMIN     3005  /* can configure interfaces and routing tables. */
77#define AID_NET_BW_STATS  3006  /* read bandwidth statistics */
78#define AID_NET_BW_ACCT   3007  /* change bandwidth statistics accounting */
79
80#define AID_MISC          9998  /* access to misc storage */
81#define AID_NOBODY        9999
82
83#define AID_APP          10000  /* first app user */
84
85#define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
86#define AID_ISOLATED_END   99999 /* end of uids for fully isolated sandboxed processes */
87
88#define AID_USER        100000  /* offset for uid ranges for each user */
89
90#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
91struct android_id_info {
92    const char *name;
93    unsigned aid;
94};
95
96static const struct android_id_info android_ids[] = {
97    { "root",      AID_ROOT, },
98    { "system",    AID_SYSTEM, },
99    { "radio",     AID_RADIO, },
100    { "bluetooth", AID_BLUETOOTH, },
101    { "graphics",  AID_GRAPHICS, },
102    { "input",     AID_INPUT, },
103    { "audio",     AID_AUDIO, },
104    { "camera",    AID_CAMERA, },
105    { "log",       AID_LOG, },
106    { "compass",   AID_COMPASS, },
107    { "mount",     AID_MOUNT, },
108    { "wifi",      AID_WIFI, },
109    { "dhcp",      AID_DHCP, },
110    { "adb",       AID_ADB, },
111    { "install",   AID_INSTALL, },
112    { "media",     AID_MEDIA, },
113    { "drm",       AID_DRM, },
114    { "available", AID_AVAILABLE, },
115    { "nfc",       AID_NFC, },
116    { "drmrpc",    AID_DRMRPC, },
117    { "shell",     AID_SHELL, },
118    { "cache",     AID_CACHE, },
119    { "diag",      AID_DIAG, },
120    { "net_bt_admin", AID_NET_BT_ADMIN, },
121    { "net_bt",    AID_NET_BT, },
122    { "sdcard_rw", AID_SDCARD_RW, },
123    { "media_rw",  AID_MEDIA_RW, },
124    { "vpn",       AID_VPN, },
125    { "keystore",  AID_KEYSTORE, },
126    { "usb",       AID_USB, },
127    { "mtp",       AID_MTP, },
128    { "gps",       AID_GPS, },
129    { "inet",      AID_INET, },
130    { "net_raw",   AID_NET_RAW, },
131    { "net_admin", AID_NET_ADMIN, },
132    { "net_bw_stats", AID_NET_BW_STATS, },
133    { "net_bw_acct", AID_NET_BW_ACCT, },
134    { "misc",      AID_MISC, },
135    { "nobody",    AID_NOBODY, },
136};
137
138#define android_id_count \
139    (sizeof(android_ids) / sizeof(android_ids[0]))
140
141struct fs_path_config {
142    unsigned mode;
143    unsigned uid;
144    unsigned gid;
145    const char *prefix;
146};
147
148/* Rules for directories.
149** These rules are applied based on "first match", so they
150** should start with the most specific path and work their
151** way up to the root.
152*/
153
154static struct fs_path_config android_dirs[] = {
155    { 00770, AID_SYSTEM, AID_CACHE,  "cache" },
156    { 00771, AID_SYSTEM, AID_SYSTEM, "data/app" },
157    { 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" },
158    { 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" },
159    { 00771, AID_SYSTEM, AID_SYSTEM, "data/data" },
160    { 00771, AID_SHELL,  AID_SHELL,  "data/local/tmp" },
161    { 00771, AID_SHELL,  AID_SHELL,  "data/local" },
162    { 01771, AID_SYSTEM, AID_MISC,   "data/misc" },
163    { 00770, AID_DHCP,   AID_DHCP,   "data/misc/dhcp" },
164    { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media" },
165    { 00775, AID_MEDIA_RW, AID_MEDIA_RW, "data/media/Music" },
166    { 00771, AID_SYSTEM, AID_SYSTEM, "data" },
167    { 00750, AID_ROOT,   AID_SHELL,  "sbin" },
168    { 00755, AID_ROOT,   AID_SHELL,  "system/bin" },
169    { 00755, AID_ROOT,   AID_SHELL,  "system/vendor" },
170    { 00755, AID_ROOT,   AID_SHELL,  "system/xbin" },
171    { 00755, AID_ROOT,   AID_ROOT,   "system/etc/ppp" },
172    { 00777, AID_ROOT,   AID_ROOT,   "sdcard" },
173    { 00755, AID_ROOT,   AID_ROOT,   0 },
174};
175
176/* Rules for files.
177** These rules are applied based on "first match", so they
178** should start with the most specific path and work their
179** way up to the root. Prefixes ending in * denotes wildcard
180** and will allow partial matches.
181*/
182static struct fs_path_config android_files[] = {
183    { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.rc" },
184    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.sh" },
185    { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.trout.rc" },
186    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.ril" },
187    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.testmenu" },
188    { 00550, AID_DHCP,      AID_SHELL,     "system/etc/dhcpcd/dhcpcd-run-hooks" },
189    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
190    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/main.conf" },
191    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/input.conf" },
192    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/audio.conf" },
193    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/network.conf" },
194    { 00444, AID_NET_BT,    AID_NET_BT,    "system/etc/bluetooth/blacklist.conf" },
195    { 00640, AID_SYSTEM,    AID_SYSTEM,    "system/etc/bluetooth/auto_pairing.conf" },
196    { 00444, AID_RADIO,     AID_AUDIO,     "system/etc/AudioPara4.csv" },
197    { 00555, AID_ROOT,      AID_ROOT,      "system/etc/ppp/*" },
198    { 00555, AID_ROOT,      AID_ROOT,      "system/etc/rc.*" },
199    { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app/*" },
200    { 00644, AID_MEDIA_RW,  AID_MEDIA_RW,  "data/media/*" },
201    { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app-private/*" },
202    { 00644, AID_APP,       AID_APP,       "data/data/*" },
203        /* the following two files are INTENTIONALLY set-gid and not set-uid.
204         * Do not change. */
205    { 02755, AID_ROOT,      AID_NET_RAW,   "system/bin/ping" },
206    { 02750, AID_ROOT,      AID_INET,      "system/bin/netcfg" },
207    	/* the following five files are INTENTIONALLY set-uid, but they
208	 * are NOT included on user builds. */
209    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/su" },
210    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/librank" },
211    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/procrank" },
212    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/procmem" },
213    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/tcpdump" },
214    { 04770, AID_ROOT,      AID_RADIO,     "system/bin/pppd-ril" },
215		/* the following file is INTENTIONALLY set-uid, and IS included
216		 * in user builds. */
217    { 06750, AID_ROOT,      AID_SHELL,     "system/bin/run-as" },
218    { 00755, AID_ROOT,      AID_SHELL,     "system/bin/*" },
219    { 00755, AID_ROOT,      AID_ROOT,      "system/lib/valgrind/*" },
220    { 00755, AID_ROOT,      AID_SHELL,     "system/xbin/*" },
221    { 00755, AID_ROOT,      AID_SHELL,     "system/vendor/bin/*" },
222    { 00750, AID_ROOT,      AID_SHELL,     "sbin/*" },
223    { 00755, AID_ROOT,      AID_ROOT,      "bin/*" },
224    { 00750, AID_ROOT,      AID_SHELL,     "init*" },
225    { 00750, AID_ROOT,      AID_SHELL,     "charger*" },
226    { 00644, AID_ROOT,      AID_ROOT,       0 },
227};
228
229static inline void fs_config(const char *path, int dir,
230                             unsigned *uid, unsigned *gid, unsigned *mode)
231{
232    struct fs_path_config *pc;
233    int plen;
234
235    pc = dir ? android_dirs : android_files;
236    plen = strlen(path);
237    for(; pc->prefix; pc++){
238        int len = strlen(pc->prefix);
239        if (dir) {
240            if(plen < len) continue;
241            if(!strncmp(pc->prefix, path, len)) break;
242            continue;
243        }
244        /* If name ends in * then allow partial matches. */
245        if (pc->prefix[len -1] == '*') {
246            if(!strncmp(pc->prefix, path, len - 1)) break;
247        } else if (plen == len){
248            if(!strncmp(pc->prefix, path, len)) break;
249        }
250    }
251    *uid = pc->uid;
252    *gid = pc->gid;
253    *mode = (*mode & (~07777)) | pc->mode;
254
255#if 0
256    fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
257            path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);
258#endif
259}
260#endif
261#endif
262