diff options
author | Mark Salyzyn | 2015-04-01 09:46:14 -0500 |
---|---|---|
committer | Mark Salyzyn | 2015-04-06 12:04:16 -0500 |
commit | a21c29ee818515d5cde79a01bee86c1e27057096 (patch) | |
tree | b169afae34e9cec6882c2fe6eba9c656245099f5 | |
parent | 8b2c7dee59f0ca89e6a0866537054a0d41dbae97 (diff) | |
download | platform-system-core-a21c29ee818515d5cde79a01bee86c1e27057096.tar.gz platform-system-core-a21c29ee818515d5cde79a01bee86c1e27057096.tar.xz platform-system-core-a21c29ee818515d5cde79a01bee86c1e27057096.zip |
android_filesystem_config: move fs_config to libcutils
Bug: 19908228
Change-Id: Id51c0c50eb2677824d052882f4263193a08e1402
-rw-r--r-- | include/private/android_filesystem_config.h | 136 | ||||
-rw-r--r-- | libcutils/fs_config.c | 11 |
2 files changed, 27 insertions, 120 deletions
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index a3d11a787..167f5a10b 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h | |||
@@ -22,8 +22,6 @@ | |||
22 | #ifndef _ANDROID_FILESYSTEM_CONFIG_H_ | 22 | #ifndef _ANDROID_FILESYSTEM_CONFIG_H_ |
23 | #define _ANDROID_FILESYSTEM_CONFIG_H_ | 23 | #define _ANDROID_FILESYSTEM_CONFIG_H_ |
24 | 24 | ||
25 | #include <string.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <sys/types.h> | 25 | #include <sys/types.h> |
28 | #include <stdint.h> | 26 | #include <stdint.h> |
29 | 27 | ||
@@ -114,6 +112,14 @@ | |||
114 | #define AID_SHARED_GID_END 59999 /* start of gids for apps in each user to share */ | 112 | #define AID_SHARED_GID_END 59999 /* start of gids for apps in each user to share */ |
115 | 113 | ||
116 | #if !defined(EXCLUDE_FS_CONFIG_STRUCTURES) | 114 | #if !defined(EXCLUDE_FS_CONFIG_STRUCTURES) |
115 | /* | ||
116 | * Used in: | ||
117 | * bionic/libc/bionic/stubs.cpp | ||
118 | * external/libselinux/src/android.c | ||
119 | * system/core/logd/LogStatistics.cpp | ||
120 | * system/core/init/ueventd.cpp | ||
121 | * system/core/init/util.cpp | ||
122 | */ | ||
117 | struct android_id_info { | 123 | struct android_id_info { |
118 | const char *name; | 124 | const char *name; |
119 | unsigned aid; | 125 | unsigned aid; |
@@ -191,116 +197,28 @@ struct fs_path_config { | |||
191 | const char *prefix; | 197 | const char *prefix; |
192 | }; | 198 | }; |
193 | 199 | ||
194 | /* Rules for directories. | 200 | /* Rules for directories and files has moved to system/code/libcutils/fs_config.c */ |
195 | ** These rules are applied based on "first match", so they | ||
196 | ** should start with the most specific path and work their | ||
197 | ** way up to the root. | ||
198 | */ | ||
199 | |||
200 | static const struct fs_path_config android_dirs[] = { | ||
201 | { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, | ||
202 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, | ||
203 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" }, | ||
204 | { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" }, | ||
205 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" }, | ||
206 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" }, | ||
207 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local" }, | ||
208 | { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" }, | ||
209 | { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" }, | ||
210 | { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" }, | ||
211 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" }, | ||
212 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" }, | ||
213 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" }, | ||
214 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin" }, | ||
215 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" }, | ||
216 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, | ||
217 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, | ||
218 | { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" }, | ||
219 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, | ||
220 | { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" }, | ||
221 | { 00755, AID_ROOT, AID_ROOT, 0, 0 }, | ||
222 | }; | ||
223 | |||
224 | /* Rules for files. | ||
225 | ** These rules are applied based on "first match", so they | ||
226 | ** should start with the most specific path and work their | ||
227 | ** way up to the root. Prefixes ending in * denotes wildcard | ||
228 | ** and will allow partial matches. | ||
229 | */ | ||
230 | static const struct fs_path_config android_files[] = { | ||
231 | { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" }, | ||
232 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" }, | ||
233 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" }, | ||
234 | { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" }, | ||
235 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" }, | ||
236 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" }, | ||
237 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, | ||
238 | { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" }, | ||
239 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, | ||
240 | { 00644, AID_APP, AID_APP, 0, "data/data/*" }, | ||
241 | |||
242 | /* the following five files are INTENTIONALLY set-uid, but they | ||
243 | * are NOT included on user builds. */ | ||
244 | { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, | ||
245 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" }, | ||
246 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" }, | ||
247 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, | ||
248 | { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" }, | ||
249 | |||
250 | /* the following files have enhanced capabilities and ARE included in user builds. */ | ||
251 | { 00750, AID_ROOT, AID_SHELL, (1 << CAP_SETUID) | (1 << CAP_SETGID), "system/bin/run-as" }, | ||
252 | |||
253 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" }, | ||
254 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" }, | ||
255 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" }, | ||
256 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" }, | ||
257 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" }, | ||
258 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" }, | ||
259 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" }, | ||
260 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, | ||
261 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" }, | ||
262 | { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, | ||
263 | { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, | ||
264 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" }, | ||
265 | { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, | ||
266 | { 00644, AID_ROOT, AID_ROOT, 0, 0 }, | ||
267 | }; | ||
268 | |||
269 | static inline void fs_config(const char *path, int dir, | ||
270 | unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities) | ||
271 | { | ||
272 | const struct fs_path_config *pc; | ||
273 | int plen; | ||
274 | 201 | ||
275 | if (path[0] == '/') { | 202 | #ifdef __cplusplus |
276 | path++; | 203 | extern "C" { |
277 | } | 204 | #endif |
278 | 205 | ||
279 | pc = dir ? android_dirs : android_files; | 206 | /* |
280 | plen = strlen(path); | 207 | * Used in: |
281 | for(; pc->prefix; pc++){ | 208 | * build/tools/fs_config/fs_config.c |
282 | int len = strlen(pc->prefix); | 209 | * build/tools/fs_get_stats/fs_get_stats.c |
283 | if (dir) { | 210 | * external/genext2fs/genext2fs.c |
284 | if(plen < len) continue; | 211 | * external/squashfs-tools/squashfs-tools/android.c |
285 | if(!strncmp(pc->prefix, path, len)) break; | 212 | * system/core/cpio/mkbootfs.c |
286 | continue; | 213 | * system/core/adb/file_sync_service.cpp |
287 | } | 214 | * system/extras/ext4_utils/canned_fs_config.c |
288 | /* If name ends in * then allow partial matches. */ | 215 | */ |
289 | if (pc->prefix[len -1] == '*') { | 216 | void fs_config(const char *path, int dir, |
290 | if(!strncmp(pc->prefix, path, len - 1)) break; | 217 | unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities); |
291 | } else if (plen == len){ | ||
292 | if(!strncmp(pc->prefix, path, len)) break; | ||
293 | } | ||
294 | } | ||
295 | *uid = pc->uid; | ||
296 | *gid = pc->gid; | ||
297 | *mode = (*mode & (~07777)) | pc->mode; | ||
298 | *capabilities = pc->capabilities; | ||
299 | 218 | ||
300 | #if 0 | 219 | #ifdef __cplusplus |
301 | fprintf(stderr,"< '%s' '%s' %d %d %o >\n", | ||
302 | path, pc->prefix ? pc->prefix : "", *uid, *gid, *mode); | ||
303 | #endif | ||
304 | } | 220 | } |
305 | #endif | 221 | #endif |
222 | |||
223 | #endif | ||
306 | #endif | 224 | #endif |
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c index 3f6a20204..659f614b8 100644 --- a/libcutils/fs_config.c +++ b/libcutils/fs_config.c | |||
@@ -19,23 +19,12 @@ | |||
19 | ** by the device side of adb. | 19 | ** by the device side of adb. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #define EXCLUDE_FS_CONFIG_STRUCTURES | ||
23 | |||
24 | #include <stdint.h> | 22 | #include <stdint.h> |
25 | #include <string.h> | 23 | #include <string.h> |
26 | #include <sys/stat.h> | 24 | #include <sys/stat.h> |
27 | 25 | ||
28 | #include <private/android_filesystem_config.h> | 26 | #include <private/android_filesystem_config.h> |
29 | 27 | ||
30 | /* Temporary while EXCLUDE_FS_CONFIG_STRUCTURES is defined */ | ||
31 | struct fs_path_config { | ||
32 | unsigned mode; | ||
33 | unsigned uid; | ||
34 | unsigned gid; | ||
35 | uint64_t capabilities; | ||
36 | const char *prefix; | ||
37 | }; | ||
38 | |||
39 | /* Rules for directories. | 28 | /* Rules for directories. |
40 | ** These rules are applied based on "first match", so they | 29 | ** These rules are applied based on "first match", so they |
41 | ** should start with the most specific path and work their | 30 | ** should start with the most specific path and work their |