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