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