blob: 659f614b8461c0e17f6d1162832b3dc0f62764cf [file] [log] [blame]
Mark Salyzyn8b2c7de2015-04-01 07:42:01 -07001/*
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
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -070022#include <stdint.h>
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -070023#include <string.h>
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -070024#include <sys/stat.h>
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -070025
Mark Salyzyn8b2c7de2015-04-01 07:42:01 -070026#include <private/android_filesystem_config.h>
27
Mark Salyzyn8b2c7de2015-04-01 07:42:01 -070028/* Rules for directories.
29** These rules are applied based on "first match", so they
30** should start with the most specific path and work their
31** way up to the root.
32*/
33
34static const struct fs_path_config android_dirs[] = {
35 { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
36 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
37 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
38 { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" },
39 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
40 { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
41 { 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
42 { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
43 { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
44 { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" },
45 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
46 { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
47 { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
48 { 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
49 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
50 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
51 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
52 { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
53 { 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
54 { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
55 { 00755, AID_ROOT, AID_ROOT, 0, 0 },
56};
57
58/* Rules for files.
59** These rules are applied based on "first match", so they
60** should start with the most specific path and work their
61** way up to the root. Prefixes ending in * denotes wildcard
62** and will allow partial matches.
63*/
64static const struct fs_path_config android_files[] = {
65 { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
66 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
67 { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
68 { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" },
69 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
70 { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
71 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
72 { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
73 { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
74 { 00644, AID_APP, AID_APP, 0, "data/data/*" },
75
76 /* the following five files are INTENTIONALLY set-uid, but they
77 * are NOT included on user builds. */
78 { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
79 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" },
80 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" },
81 { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
82 { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" },
83
84 /* the following files have enhanced capabilities and ARE included in user builds. */
85 { 00750, AID_ROOT, AID_SHELL, (1ULL << CAP_SETUID) | (1ULL << CAP_SETGID), "system/bin/run-as" },
86 { 00700, AID_SYSTEM, AID_SHELL, (1ULL << CAP_BLOCK_SUSPEND), "system/bin/inputflinger" },
87
88 { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },
89 { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },
90 { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
91 { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
92 { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" },
93 { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
94 { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" },
95 { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
96 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
97 { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
98 { 00750, AID_ROOT, AID_SHELL, 0, "init*" },
99 { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
100 { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
101 { 00644, AID_ROOT, AID_ROOT, 0, 0 },
102};
103
104void fs_config(const char *path, int dir,
105 unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities)
106{
107 const struct fs_path_config *pc;
108 int plen;
109
110 if (path[0] == '/') {
111 path++;
112 }
113
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -0700114 pc = dir ? android_dirs : android_files;
Mark Salyzyn7e826332015-04-15 22:30:30 +0000115 plen = strlen(path);
Mark Salyzyn4e5f71a2015-04-01 09:24:22 -0700116 for(; pc->prefix; pc++){
Mark Salyzyn7e826332015-04-15 22:30:30 +0000117 int len = strlen(pc->prefix);
118 if (dir) {
119 if(plen < len) continue;
120 if(!strncmp(pc->prefix, path, len)) break;
121 continue;
122 }
123 /* If name ends in * then allow partial matches. */
124 if (pc->prefix[len -1] == '*') {
125 if(!strncmp(pc->prefix, path, len - 1)) break;
126 } else if (plen == len){
127 if(!strncmp(pc->prefix, path, len)) break;
Mark Salyzyn8b2c7de2015-04-01 07:42:01 -0700128 }
129 }
130 *uid = pc->uid;
131 *gid = pc->gid;
132 *mode = (*mode & (~07777)) | pc->mode;
133 *capabilities = pc->capabilities;
134}