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