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 <sys/cdefs.h>
26 #include <sys/types.h>
27 #include <stdint.h>
28 
29 #ifdef HAVE_ANDROID_OS
30 #include <linux/capability.h>
31 #else
32 #include "android_filesystem_capability.h"
33 #endif
34 
35 /* This is the master Users and Groups config for the platform.
36  * DO NOT EVER RENUMBER
37  */
38 
39 #define AID_ROOT             0  /* traditional unix root user */
40 
41 #define AID_SYSTEM        1000  /* system server */
42 
43 #define AID_RADIO         1001  /* telephony subsystem, RIL */
44 #define AID_BLUETOOTH     1002  /* bluetooth subsystem */
45 #define AID_GRAPHICS      1003  /* graphics devices */
46 #define AID_INPUT         1004  /* input devices */
47 #define AID_AUDIO         1005  /* audio devices */
48 #define AID_CAMERA        1006  /* camera devices */
49 #define AID_LOG           1007  /* log devices */
50 #define AID_COMPASS       1008  /* compass device */
51 #define AID_MOUNT         1009  /* mountd socket */
52 #define AID_WIFI          1010  /* wifi subsystem */
53 #define AID_ADB           1011  /* android debug bridge (adbd) */
54 #define AID_INSTALL       1012  /* group for installing packages */
55 #define AID_MEDIA         1013  /* mediaserver process */
56 #define AID_DHCP          1014  /* dhcp client */
57 #define AID_SDCARD_RW     1015  /* external storage write access */
58 #define AID_VPN           1016  /* vpn system */
59 #define AID_KEYSTORE      1017  /* keystore subsystem */
60 #define AID_USB           1018  /* USB devices */
61 #define AID_DRM           1019  /* DRM server */
62 #define AID_MDNSR         1020  /* MulticastDNSResponder (service discovery) */
63 #define AID_GPS           1021  /* GPS daemon */
64 #define AID_UNUSED1       1022  /* deprecated, DO NOT USE */
65 #define AID_MEDIA_RW      1023  /* internal media storage write access */
66 #define AID_MTP           1024  /* MTP USB driver access */
67 #define AID_UNUSED2       1025  /* deprecated, DO NOT USE */
68 #define AID_DRMRPC        1026  /* group for drm rpc */
69 #define AID_NFC           1027  /* nfc subsystem */
70 #define AID_SDCARD_R      1028  /* external storage read access */
71 #define AID_CLAT          1029  /* clat part of nat464 */
72 #define AID_LOOP_RADIO    1030  /* loop radio devices */
73 #define AID_MEDIA_DRM     1031  /* MediaDrm plugins */
74 #define AID_PACKAGE_INFO  1032  /* access to installed package details */
75 #define AID_SDCARD_PICS   1033  /* external storage photos access */
76 #define AID_SDCARD_AV     1034  /* external storage audio/video access */
77 #define AID_SDCARD_ALL    1035  /* access all users external storage */
78 #define AID_LOGD          1036  /* log daemon */
79 #define AID_SHARED_RELRO  1037  /* creator of shared GNU RELRO files */
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 range 2900-2999 is reserved for OEM, and must never be
86  * used here */
87 #define AID_OEM_RESERVED_START 2900
88 #define AID_OEM_RESERVED_END   2999
89 
90 /* The 3000 series are intended for use as supplemental group id's only.
91  * They indicate special Android capabilities that the kernel is aware of. */
92 #define AID_NET_BT_ADMIN  3001  /* bluetooth: create any socket */
93 #define AID_NET_BT        3002  /* bluetooth: create sco, rfcomm or l2cap sockets */
94 #define AID_INET          3003  /* can create AF_INET and AF_INET6 sockets */
95 #define AID_NET_RAW       3004  /* can create raw INET sockets */
96 #define AID_NET_ADMIN     3005  /* can configure interfaces and routing tables. */
97 #define AID_NET_BW_STATS  3006  /* read bandwidth statistics */
98 #define AID_NET_BW_ACCT   3007  /* change bandwidth statistics accounting */
99 #define AID_NET_BT_STACK  3008  /* bluetooth: access config files */
100 
101 #define AID_EVERYBODY     9997  /* shared between all apps in the same profile */
102 #define AID_MISC          9998  /* access to misc storage */
103 #define AID_NOBODY        9999
104 
105 #define AID_APP          10000  /* first app user */
106 
107 #define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */
108 #define AID_ISOLATED_END   99999 /* end of uids for fully isolated sandboxed processes */
109 
110 #define AID_USER        100000  /* offset for uid ranges for each user */
111 
112 #define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */
113 #define AID_SHARED_GID_END   59999 /* start of gids for apps in each user to share */
114 
115 #if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
116 /*
117  * Used in:
118  *  bionic/libc/bionic/stubs.cpp
119  *  external/libselinux/src/android.c
120  *  system/core/logd/LogStatistics.cpp
121  *  system/core/init/ueventd.cpp
122  *  system/core/init/util.cpp
123  */
124 struct android_id_info {
125     const char *name;
126     unsigned aid;
127 };
128 
129 static const struct android_id_info android_ids[] = {
130     { "root",          AID_ROOT, },
131 
132     { "system",        AID_SYSTEM, },
133 
134     { "radio",         AID_RADIO, },
135     { "bluetooth",     AID_BLUETOOTH, },
136     { "graphics",      AID_GRAPHICS, },
137     { "input",         AID_INPUT, },
138     { "audio",         AID_AUDIO, },
139     { "camera",        AID_CAMERA, },
140     { "log",           AID_LOG, },
141     { "compass",       AID_COMPASS, },
142     { "mount",         AID_MOUNT, },
143     { "wifi",          AID_WIFI, },
144     { "adb",           AID_ADB, },
145     { "install",       AID_INSTALL, },
146     { "media",         AID_MEDIA, },
147     { "dhcp",          AID_DHCP, },
148     { "sdcard_rw",     AID_SDCARD_RW, },
149     { "vpn",           AID_VPN, },
150     { "keystore",      AID_KEYSTORE, },
151     { "usb",           AID_USB, },
152     { "drm",           AID_DRM, },
153     { "mdnsr",         AID_MDNSR, },
154     { "gps",           AID_GPS, },
155     // AID_UNUSED1
156     { "media_rw",      AID_MEDIA_RW, },
157     { "mtp",           AID_MTP, },
158     // AID_UNUSED2
159     { "drmrpc",        AID_DRMRPC, },
160     { "nfc",           AID_NFC, },
161     { "sdcard_r",      AID_SDCARD_R, },
162     { "clat",          AID_CLAT, },
163     { "loop_radio",    AID_LOOP_RADIO, },
164     { "mediadrm",      AID_MEDIA_DRM, },
165     { "package_info",  AID_PACKAGE_INFO, },
166     { "sdcard_pics",   AID_SDCARD_PICS, },
167     { "sdcard_av",     AID_SDCARD_AV, },
168     { "sdcard_all",    AID_SDCARD_ALL, },
169     { "logd",          AID_LOGD, },
170     { "shared_relro",  AID_SHARED_RELRO, },
171 
172     { "shell",         AID_SHELL, },
173     { "cache",         AID_CACHE, },
174     { "diag",          AID_DIAG, },
175 
176     { "net_bt_admin",  AID_NET_BT_ADMIN, },
177     { "net_bt",        AID_NET_BT, },
178     { "inet",          AID_INET, },
179     { "net_raw",       AID_NET_RAW, },
180     { "net_admin",     AID_NET_ADMIN, },
181     { "net_bw_stats",  AID_NET_BW_STATS, },
182     { "net_bw_acct",   AID_NET_BW_ACCT, },
183     { "net_bt_stack",  AID_NET_BT_STACK, },
184 
185     { "everybody",     AID_EVERYBODY, },
186     { "misc",          AID_MISC, },
187     { "nobody",        AID_NOBODY, },
188 };
189 
190 #define android_id_count \
191     (sizeof(android_ids) / sizeof(android_ids[0]))
192 
193 struct fs_path_config {
194     unsigned mode;
195     unsigned uid;
196     unsigned gid;
197     uint64_t capabilities;
198     const char *prefix;
199 };
200 
201 /* Rules for directories and files has moved to system/code/libcutils/fs_config.c */
202 
203 __BEGIN_DECLS
204 
205 /*
206  * Used in:
207  *  build/tools/fs_config/fs_config.c
208  *  build/tools/fs_get_stats/fs_get_stats.c
209  *  system/extras/ext4_utils/make_ext4fs_main.c
210  *  external/squashfs-tools/squashfs-tools/android.c
211  *  system/core/cpio/mkbootfs.c
212  *  system/core/adb/file_sync_service.cpp
213  *  system/extras/ext4_utils/canned_fs_config.c
214  */
215 void fs_config(const char *path, int dir, const char *target_out_path,
216                unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities);
217 
218 ssize_t fs_config_generate(char *buffer, size_t length, const struct fs_path_config *pc);
219 
220 __END_DECLS
221 
222 #endif
223 #endif
224