android_filesystem_config.h revision b29b33841bd2f5143e2705525bfc4f8a2d2b6316
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_NFC           1022  /* nfc subsystem */
59#define AID_MEDIA_RW      1023  /* internal media storage write access */
60#define AID_MTP           1024  /* MTP USB driver access */
61
62#define AID_SHELL         2000  /* adb and debug shell user */
63#define AID_CACHE         2001  /* cache access */
64#define AID_DIAG          2002  /* access to diagnostic resources */
65
66/* The 3000 series are intended for use as supplemental group id's only.
67 * They indicate special Android capabilities that the kernel is aware of. */
68#define AID_NET_BT_ADMIN  3001  /* bluetooth: create any socket */
69#define AID_NET_BT        3002  /* bluetooth: create sco, rfcomm or l2cap sockets */
70#define AID_INET          3003  /* can create AF_INET and AF_INET6 sockets */
71#define AID_NET_RAW       3004  /* can create raw INET sockets */
72#define AID_NET_ADMIN     3005  /* can configure interfaces and routing tables. */
73
74#define AID_MISC          9998  /* access to misc storage */
75#define AID_NOBODY        9999
76
77#define AID_APP          10000 /* first app user */
78
79#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
80struct android_id_info {
81    const char *name;
82    unsigned aid;
83};
84
85static const struct android_id_info android_ids[] = {
86    { "root",      AID_ROOT, },
87    { "system",    AID_SYSTEM, },
88    { "radio",     AID_RADIO, },
89    { "bluetooth", AID_BLUETOOTH, },
90    { "graphics",  AID_GRAPHICS, },
91    { "input",     AID_INPUT, },
92    { "audio",     AID_AUDIO, },
93    { "camera",    AID_CAMERA, },
94    { "log",       AID_LOG, },
95    { "compass",   AID_COMPASS, },
96    { "mount",     AID_MOUNT, },
97    { "wifi",      AID_WIFI, },
98    { "dhcp",      AID_DHCP, },
99    { "adb",       AID_ADB, },
100    { "install",   AID_INSTALL, },
101    { "media",     AID_MEDIA, },
102    { "drm",       AID_DRM, },
103    { "available", AID_AVAILABLE, },
104    { "nfc",       AID_NFC, },
105    { "shell",     AID_SHELL, },
106    { "cache",     AID_CACHE, },
107    { "diag",      AID_DIAG, },
108    { "net_bt_admin", AID_NET_BT_ADMIN, },
109    { "net_bt",    AID_NET_BT, },
110    { "sdcard_rw", AID_SDCARD_RW, },
111    { "media_rw",  AID_MEDIA_RW, },
112    { "vpn",       AID_VPN, },
113    { "keystore",  AID_KEYSTORE, },
114    { "usb",       AID_USB, },
115    { "mtp",       AID_MTP, },
116    { "gps",       AID_GPS, },
117    { "inet",      AID_INET, },
118    { "net_raw",   AID_NET_RAW, },
119    { "net_admin", AID_NET_ADMIN, },
120    { "misc",      AID_MISC, },
121    { "nobody",    AID_NOBODY, },
122};
123
124#define android_id_count \
125    (sizeof(android_ids) / sizeof(android_ids[0]))
126
127struct fs_path_config {
128    unsigned mode;
129    unsigned uid;
130    unsigned gid;
131    const char *prefix;
132};
133
134/* Rules for directories.
135** These rules are applied based on "first match", so they
136** should start with the most specific path and work their
137** way up to the root.
138*/
139
140static struct fs_path_config android_dirs[] = {
141    { 00770, AID_SYSTEM, AID_CACHE,  "cache" },
142    { 00771, AID_SYSTEM, AID_SYSTEM, "data/app" },
143    { 00771, AID_SYSTEM, AID_SYSTEM, "data/app-private" },
144    { 00771, AID_SYSTEM, AID_SYSTEM, "data/dalvik-cache" },
145    { 00771, AID_SYSTEM, AID_SYSTEM, "data/data" },
146    { 00771, AID_SHELL,  AID_SHELL,  "data/local/tmp" },
147    { 00771, AID_SHELL,  AID_SHELL,  "data/local" },
148    { 01771, AID_SYSTEM, AID_MISC,   "data/misc" },
149    { 00770, AID_DHCP,   AID_DHCP,   "data/misc/dhcp" },
150    { 00771, AID_SYSTEM, AID_SYSTEM, "data" },
151    { 00750, AID_ROOT,   AID_SHELL,  "sbin" },
152    { 00755, AID_ROOT,   AID_SHELL,  "system/bin" },
153    { 00755, AID_ROOT,   AID_SHELL,  "system/vendor" },
154    { 00755, AID_ROOT,   AID_SHELL,  "system/xbin" },
155    { 00755, AID_ROOT,   AID_ROOT,   "system/etc/ppp" },
156    { 00777, AID_ROOT,   AID_ROOT,   "sdcard" },
157    { 00755, AID_ROOT,   AID_ROOT,   0 },
158};
159
160/* Rules for files.
161** These rules are applied based on "first match", so they
162** should start with the most specific path and work their
163** way up to the root. Prefixes ending in * denotes wildcard
164** and will allow partial matches.
165*/
166static struct fs_path_config android_files[] = {
167    { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.rc" },
168    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.sh" },
169    { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.trout.rc" },
170    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.ril" },
171    { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.testmenu" },
172    { 00550, AID_DHCP,      AID_SHELL,     "system/etc/dhcpcd/dhcpcd-run-hooks" },
173    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },
174    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/main.conf" },
175    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/input.conf" },
176    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/audio.conf" },
177    { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/bluetooth/network.conf" },
178    { 00444, AID_NET_BT,    AID_NET_BT,    "system/etc/bluetooth/blacklist.conf" },
179    { 00640, AID_SYSTEM,    AID_SYSTEM,    "system/etc/bluetooth/auto_pairing.conf" },
180    { 00444, AID_RADIO,     AID_AUDIO,     "system/etc/AudioPara4.csv" },
181    { 00555, AID_ROOT,      AID_ROOT,      "system/etc/ppp/*" },
182    { 00555, AID_ROOT,      AID_ROOT,      "system/etc/rc.*" },
183    { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app/*" },
184    { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app-private/*" },
185    { 00644, AID_APP,       AID_APP,       "data/data/*" },
186        /* the following two files are INTENTIONALLY set-gid and not set-uid.
187         * Do not change. */
188    { 02755, AID_ROOT,      AID_NET_RAW,   "system/bin/ping" },
189    { 02750, AID_ROOT,      AID_INET,      "system/bin/netcfg" },
190    	/* the following five files are INTENTIONALLY set-uid, but they
191	 * are NOT included on user builds. */
192    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/su" },
193    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/librank" },
194    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/procrank" },
195    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/procmem" },
196    { 06755, AID_ROOT,      AID_ROOT,      "system/xbin/tcpdump" },
197    { 04770, AID_ROOT,      AID_RADIO,     "system/bin/pppd-ril" },
198		/* the following file is INTENTIONALLY set-uid, and IS included
199		 * in user builds. */
200    { 06750, AID_ROOT,      AID_SHELL,     "system/bin/run-as" },
201    { 00755, AID_ROOT,      AID_SHELL,     "system/bin/*" },
202    { 00755, AID_ROOT,      AID_SHELL,     "system/xbin/*" },
203    { 00755, AID_ROOT,      AID_SHELL,     "system/vendor/bin/*" },
204    { 00750, AID_ROOT,      AID_SHELL,     "sbin/*" },
205    { 00755, AID_ROOT,      AID_ROOT,      "bin/*" },
206    { 00750, AID_ROOT,      AID_SHELL,     "init*" },
207    { 00644, AID_ROOT,      AID_ROOT,       0 },
208};
209
210static inline void fs_config(const char *path, int dir,
211                             unsigned *uid, unsigned *gid, unsigned *mode)
212{
213    struct fs_path_config *pc;
214    int plen;
215
216    pc = dir ? android_dirs : android_files;
217    plen = strlen(path);
218    for(; pc->prefix; pc++){
219        int len = strlen(pc->prefix);
220        if (dir) {
221            if(plen < len) continue;
222            if(!strncmp(pc->prefix, path, len)) break;
223            continue;
224        }
225        /* If name ends in * then allow partial matches. */
226        if (pc->prefix[len -1] == '*') {
227            if(!strncmp(pc->prefix, path, len - 1)) break;
228        } else if (plen == len){
229            if(!strncmp(pc->prefix, path, len)) break;
230        }
231    }
232    *uid = pc->uid;
233    *gid = pc->gid;
234    *mode = (*mode & (~07777)) | pc->mode;
235
236#if 0
237    fprintf(stderr,"< '%s' '%s' %d %d %o >\n",
238            path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode);
239#endif
240}
241#endif
242#endif
243