2015-04-01 16:42:01 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-11-10 19:22:07 +01:00
|
|
|
#include <private/fs_config.h>
|
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// This file is used to define the properties of the filesystem
|
|
|
|
// images generated by build tools (mkbootfs and mkyaffs2image) and
|
|
|
|
// by the device side of adb.
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2015-04-01 18:24:22 +02:00
|
|
|
#define LOG_TAG "fs_config"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2015-04-01 16:42:01 +02:00
|
|
|
#include <stdint.h>
|
2015-04-01 18:24:22 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-04-01 16:42:01 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2015-04-01 18:24:22 +02:00
|
|
|
#include <sys/types.h>
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-01-10 22:19:54 +01:00
|
|
|
#include <log/log.h>
|
2015-04-01 16:42:01 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
2015-04-16 17:13:32 +02:00
|
|
|
#include <utils/Compat.h>
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2015-04-16 17:40:55 +02:00
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// My kingdom for <endian.h>
|
|
|
|
static inline uint16_t get2LE(const uint8_t* src) {
|
|
|
|
return src[0] | (src[1] << 8);
|
|
|
|
}
|
2015-04-01 18:24:22 +02:00
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
static inline uint64_t get8LE(const uint8_t* src) {
|
2015-04-01 18:24:22 +02:00
|
|
|
uint32_t low, high;
|
|
|
|
|
|
|
|
low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
|
|
|
high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24);
|
2017-03-20 16:15:40 +01:00
|
|
|
return ((uint64_t)high << 32) | (uint64_t)low;
|
2015-04-01 18:24:22 +02:00
|
|
|
}
|
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
#define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1))
|
2015-04-01 20:02:00 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Rules for directories.
|
|
|
|
// These rules are applied based on "first match", so they
|
|
|
|
// should start with the most specific path and work their
|
|
|
|
// way up to the root.
|
2015-04-01 16:42:01 +02:00
|
|
|
|
|
|
|
static const struct fs_path_config android_dirs[] = {
|
2017-05-02 17:56:15 +02:00
|
|
|
// clang-format off
|
2017-03-20 16:15:40 +01:00
|
|
|
{ 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
|
|
|
|
{ 00500, AID_ROOT, AID_ROOT, 0, "config" },
|
|
|
|
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
|
|
|
|
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
|
|
|
|
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral" },
|
|
|
|
{ 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" },
|
|
|
|
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
|
|
|
|
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
|
|
|
|
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
|
|
|
|
{ 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" },
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" },
|
2017-03-20 16:15:40 +01:00
|
|
|
{ 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" },
|
|
|
|
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
|
|
|
|
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64" },
|
|
|
|
{ 00775, AID_ROOT, AID_ROOT, 0, "data/preloads" },
|
|
|
|
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
|
|
|
|
{ 00755, AID_ROOT, AID_SYSTEM, 0, "mnt" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin" },
|
|
|
|
{ 00777, AID_ROOT, AID_ROOT, 0, "sdcard" },
|
|
|
|
{ 00751, AID_ROOT, AID_SDCARD_R, 0, "storage" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin" },
|
|
|
|
{ 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
|
|
|
|
{ 00755, AID_ROOT, AID_ROOT, 0, 0 },
|
2017-05-02 17:56:15 +02:00
|
|
|
// clang-format on
|
2015-04-01 16:42:01 +02:00
|
|
|
};
|
2017-05-02 17:56:15 +02:00
|
|
|
#ifndef __ANDROID_VNDK__
|
|
|
|
auto __for_testing_only__android_dirs = android_dirs;
|
|
|
|
#endif
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Rules for files.
|
|
|
|
// These rules are applied based on "first match", so they
|
|
|
|
// should start with the most specific path and work their
|
|
|
|
// way up to the root. Prefixes ending in * denotes wildcard
|
|
|
|
// and will allow partial matches.
|
2017-03-20 16:15:40 +01:00
|
|
|
static const char sys_conf_dir[] = "/system/etc/fs_config_dirs";
|
|
|
|
static const char sys_conf_file[] = "/system/etc/fs_config_files";
|
2017-05-02 17:56:15 +02:00
|
|
|
// No restrictions are placed on the vendor and oem file-system config files,
|
|
|
|
// although the developer is advised to restrict the scope to the /vendor or
|
|
|
|
// oem/ file-system since the intent is to provide support for customized
|
|
|
|
// portions of a separate vendor.img or oem.img. Has to remain open so that
|
|
|
|
// customization can also land on /system/vendor, /system/oem or /system/odm.
|
|
|
|
// We expect build-time checking or filtering when constructing the associated
|
|
|
|
// fs_config_* files (see build/tools/fs_config/fs_config_generate.c)
|
2017-03-20 16:15:40 +01:00
|
|
|
static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs";
|
|
|
|
static const char ven_conf_file[] = "/vendor/etc/fs_config_files";
|
2017-03-21 16:09:52 +01:00
|
|
|
static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs";
|
|
|
|
static const char oem_conf_file[] = "/oem/etc/fs_config_files";
|
2017-03-22 23:23:24 +01:00
|
|
|
static const char odm_conf_dir[] = "/odm/etc/fs_config_dirs";
|
|
|
|
static const char odm_conf_file[] = "/odm/etc/fs_config_files";
|
2017-03-20 16:15:40 +01:00
|
|
|
static const char* conf[][2] = {
|
2017-03-22 23:23:24 +01:00
|
|
|
{sys_conf_file, sys_conf_dir},
|
|
|
|
{ven_conf_file, ven_conf_dir},
|
|
|
|
{oem_conf_file, oem_conf_dir},
|
|
|
|
{odm_conf_file, odm_conf_dir},
|
2017-03-20 16:15:40 +01:00
|
|
|
};
|
2015-04-01 18:24:22 +02:00
|
|
|
|
2015-04-01 16:42:01 +02:00
|
|
|
static const struct fs_path_config android_files[] = {
|
2017-05-02 17:56:15 +02:00
|
|
|
// clang-format off
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
|
2015-11-24 00:24:13 +01:00
|
|
|
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00644, AID_APP, AID_APP, 0, "data/data/*" },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" },
|
2015-11-15 03:25:31 +01:00
|
|
|
{ 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest/tests.txt" },
|
|
|
|
{ 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest64/tests.txt" },
|
2015-10-28 23:52:37 +01:00
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest/*" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64/*" },
|
2017-06-02 12:59:46 +02:00
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "default.prop" }, // legacy
|
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "system/etc/prop.default" },
|
2017-05-25 13:18:17 +02:00
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "odm/build.prop" },
|
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "odm/default.prop" },
|
2017-03-22 23:23:24 +01:00
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, odm_conf_dir + 1 },
|
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, odm_conf_file + 1 },
|
2017-03-21 16:09:52 +01:00
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_dir + 1 },
|
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_file + 1 },
|
2017-11-28 04:10:10 +01:00
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "product/build.prop" },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump32" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump64" },
|
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/debuggerd" },
|
|
|
|
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },
|
|
|
|
{ 00700, AID_ROOT, AID_ROOT, 0, "system/bin/secilc" },
|
|
|
|
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },
|
2017-05-25 13:18:17 +02:00
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "system/build.prop" },
|
2017-03-20 16:15:40 +01:00
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, sys_conf_dir + 1 },
|
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, sys_conf_file + 1 },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
|
|
|
|
{ 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" },
|
|
|
|
{ 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" },
|
|
|
|
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
|
|
|
|
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
|
|
|
|
{ 00440, AID_ROOT, AID_ROOT, 0, "system/etc/recovery.img" },
|
2017-05-25 13:18:17 +02:00
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "vendor/build.prop" },
|
|
|
|
{ 00600, AID_ROOT, AID_ROOT, 0, "vendor/default.prop" },
|
2017-03-20 16:15:40 +01:00
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 },
|
|
|
|
{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 },
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// the following two files are INTENTIONALLY set-uid, but they
|
|
|
|
// are NOT included on user builds.
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// the following files have enhanced capabilities and ARE included
|
|
|
|
// in user builds.
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND),
|
|
|
|
"system/bin/inputflinger" },
|
2016-10-28 21:41:17 +02:00
|
|
|
{ 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) |
|
|
|
|
CAP_MASK_LONG(CAP_AUDIT_CONTROL) |
|
|
|
|
CAP_MASK_LONG(CAP_SETGID),
|
|
|
|
"system/bin/logd" },
|
2017-08-04 22:35:51 +02:00
|
|
|
{ 00550, AID_SYSTEM, AID_LOG, CAP_MASK_LONG(CAP_SYSLOG),
|
|
|
|
"system/bin/bootstat" },
|
2016-10-28 21:41:17 +02:00
|
|
|
{ 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) |
|
|
|
|
CAP_MASK_LONG(CAP_SETGID),
|
|
|
|
"system/bin/run-as" },
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Support FIFO scheduling mode in SurfaceFlinger.
|
2016-10-28 21:41:17 +02:00
|
|
|
{ 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE),
|
|
|
|
"system/bin/surfaceflinger" },
|
2016-06-17 23:02:16 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Support hostapd administering a network interface.
|
2016-10-28 21:41:17 +02:00
|
|
|
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
|
|
|
|
CAP_MASK_LONG(CAP_NET_RAW),
|
2017-02-14 02:39:45 +01:00
|
|
|
"vendor/bin/hostapd" },
|
2016-07-12 23:30:21 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Support Bluetooth legacy hal accessing /sys/class/rfkill
|
|
|
|
// Support RT scheduling in Bluetooth
|
2017-03-23 18:05:45 +01:00
|
|
|
{ 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) |
|
|
|
|
CAP_MASK_LONG(CAP_SYS_NICE),
|
2017-03-20 16:53:24 +01:00
|
|
|
"vendor/bin/hw/android.hardware.bluetooth@1.0-service" },
|
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// Support wifi_hal_legacy administering a network interface.
|
2017-04-27 03:24:48 +02:00
|
|
|
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
|
|
|
|
CAP_MASK_LONG(CAP_NET_RAW),
|
|
|
|
"vendor/bin/hw/android.hardware.wifi@1.0-service" },
|
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// A non-privileged zygote that spawns isolated processes for web rendering.
|
2016-09-21 23:01:36 +02:00
|
|
|
{ 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) |
|
|
|
|
CAP_MASK_LONG(CAP_SETGID) |
|
2016-10-28 21:41:17 +02:00
|
|
|
CAP_MASK_LONG(CAP_SETPCAP),
|
|
|
|
"system/bin/webview_zygote32" },
|
2016-09-21 23:01:36 +02:00
|
|
|
{ 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) |
|
|
|
|
CAP_MASK_LONG(CAP_SETGID) |
|
2016-10-28 21:41:17 +02:00
|
|
|
CAP_MASK_LONG(CAP_SETPCAP),
|
|
|
|
"system/bin/webview_zygote64" },
|
2016-09-21 23:01:36 +02:00
|
|
|
|
2017-05-02 17:56:15 +02:00
|
|
|
// generic defaults
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
|
|
|
|
{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "init*" },
|
|
|
|
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" },
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
|
|
|
|
{ 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" },
|
|
|
|
{ 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" },
|
2017-03-20 16:53:24 +01:00
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" },
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
|
2016-05-27 06:13:07 +02:00
|
|
|
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" },
|
2015-04-01 16:42:01 +02:00
|
|
|
{ 00644, AID_ROOT, AID_ROOT, 0, 0 },
|
2017-05-02 17:56:15 +02:00
|
|
|
// clang-format on
|
2015-04-01 16:42:01 +02:00
|
|
|
};
|
2017-05-02 17:56:15 +02:00
|
|
|
#ifndef __ANDROID_VNDK__
|
|
|
|
auto __for_testing_only__android_files = android_files;
|
|
|
|
#endif
|
2015-04-01 16:42:01 +02:00
|
|
|
|
2017-04-05 21:15:49 +02:00
|
|
|
static size_t strip(const char* path, size_t len, const char suffix[]) {
|
|
|
|
if (len < strlen(suffix)) return len;
|
|
|
|
if (strncmp(path + len - strlen(suffix), suffix, strlen(suffix))) return len;
|
|
|
|
return len - strlen(suffix);
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
static int fs_config_open(int dir, int which, const char* target_out_path) {
|
2015-04-01 18:24:22 +02:00
|
|
|
int fd = -1;
|
|
|
|
|
2015-07-09 18:50:31 +02:00
|
|
|
if (target_out_path && *target_out_path) {
|
2017-05-02 17:56:15 +02:00
|
|
|
// target_out_path is the path to the directory holding content of
|
|
|
|
// system partition but as we cannot guarantee it ends with '/system'
|
|
|
|
// or with or without a trailing slash, need to strip them carefully.
|
2017-03-20 16:15:40 +01:00
|
|
|
char* name = NULL;
|
2017-04-05 21:15:49 +02:00
|
|
|
size_t len = strlen(target_out_path);
|
|
|
|
len = strip(target_out_path, len, "/");
|
|
|
|
len = strip(target_out_path, len, "/system");
|
|
|
|
if (asprintf(&name, "%.*s%s", (int)len, target_out_path, conf[which][dir]) != -1) {
|
2015-04-16 17:40:55 +02:00
|
|
|
fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_BINARY));
|
2015-04-01 18:24:22 +02:00
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fd < 0) {
|
2017-03-20 16:15:40 +01:00
|
|
|
fd = TEMP_FAILURE_RETRY(open(conf[which][dir], O_RDONLY | O_BINARY));
|
2015-04-01 18:24:22 +02:00
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2017-05-02 23:02:17 +02:00
|
|
|
// if path is "vendor/<stuff>", "oem/<stuff>" or "odm/<stuff>"
|
|
|
|
static bool is_partition(const char* path, size_t len) {
|
|
|
|
static const char* partitions[] = {"vendor/", "oem/", "odm/"};
|
|
|
|
for (size_t i = 0; i < (sizeof(partitions) / sizeof(partitions[0])); ++i) {
|
|
|
|
size_t plen = strlen(partitions[i]);
|
|
|
|
if (len <= plen) continue;
|
|
|
|
if (!strncmp(path, partitions[i], plen)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-23 00:15:56 +02:00
|
|
|
static inline bool prefix_cmp(bool partial, const char* prefix, size_t len, const char* path,
|
|
|
|
size_t plen) {
|
|
|
|
return ((partial && plen >= len) || (plen == len)) && !strncmp(prefix, path, len);
|
|
|
|
}
|
|
|
|
|
2017-05-02 23:02:17 +02:00
|
|
|
// alias prefixes of "<partition>/<stuff>" to "system/<partition>/<stuff>" or
|
|
|
|
// "system/<partition>/<stuff>" to "<partition>/<stuff>"
|
2017-06-23 00:15:56 +02:00
|
|
|
static bool fs_config_cmp(bool partial, const char* prefix, size_t len, const char* path,
|
|
|
|
size_t plen) {
|
|
|
|
// If name ends in * then allow partial matches.
|
|
|
|
if (!partial && prefix[len - 1] == '*') {
|
|
|
|
len--;
|
|
|
|
partial = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prefix_cmp(partial, prefix, len, path, plen)) return true;
|
2017-05-02 23:02:17 +02:00
|
|
|
|
|
|
|
static const char system[] = "system/";
|
|
|
|
if (!strncmp(path, system, strlen(system))) {
|
|
|
|
path += strlen(system);
|
2017-06-23 00:15:56 +02:00
|
|
|
plen -= strlen(system);
|
2017-05-02 23:02:17 +02:00
|
|
|
} else if (len <= strlen(system)) {
|
|
|
|
return false;
|
|
|
|
} else if (strncmp(prefix, system, strlen(system))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
prefix += strlen(system);
|
|
|
|
len -= strlen(system);
|
|
|
|
}
|
2017-06-23 00:15:56 +02:00
|
|
|
return is_partition(prefix, len) && prefix_cmp(partial, prefix, len, path, plen);
|
2015-04-01 18:24:22 +02:00
|
|
|
}
|
2017-06-23 00:15:56 +02:00
|
|
|
#ifndef __ANDROID_VNDK__
|
|
|
|
auto __for_testing_only__fs_config_cmp = fs_config_cmp;
|
|
|
|
#endif
|
2015-04-01 18:24:22 +02:00
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid,
|
|
|
|
unsigned* mode, uint64_t* capabilities) {
|
|
|
|
const struct fs_path_config* pc;
|
2017-03-20 16:15:40 +01:00
|
|
|
size_t which, plen;
|
2015-04-01 16:42:01 +02:00
|
|
|
|
|
|
|
if (path[0] == '/') {
|
|
|
|
path++;
|
|
|
|
}
|
|
|
|
|
2015-04-16 00:30:30 +02:00
|
|
|
plen = strlen(path);
|
2015-04-01 18:24:22 +02:00
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
for (which = 0; which < (sizeof(conf) / sizeof(conf[0])); ++which) {
|
2015-04-16 04:27:39 +02:00
|
|
|
struct fs_path_config_from_file header;
|
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
int fd = fs_config_open(dir, which, target_out_path);
|
|
|
|
if (fd < 0) continue;
|
|
|
|
|
2015-04-16 04:27:39 +02:00
|
|
|
while (TEMP_FAILURE_RETRY(read(fd, &header, sizeof(header))) == sizeof(header)) {
|
2017-03-20 16:15:40 +01:00
|
|
|
char* prefix;
|
|
|
|
uint16_t host_len = get2LE((const uint8_t*)&header.len);
|
2015-04-16 04:27:39 +02:00
|
|
|
ssize_t len, remainder = host_len - sizeof(header);
|
2015-04-01 18:24:22 +02:00
|
|
|
if (remainder <= 0) {
|
2017-03-20 16:15:40 +01:00
|
|
|
ALOGE("%s len is corrupted", conf[which][dir]);
|
2015-04-16 04:27:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-05-02 17:56:15 +02:00
|
|
|
prefix = static_cast<char*>(calloc(1, remainder));
|
2015-04-16 04:27:39 +02:00
|
|
|
if (!prefix) {
|
2017-03-20 16:15:40 +01:00
|
|
|
ALOGE("%s out of memory", conf[which][dir]);
|
2015-04-01 18:24:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-04-16 04:27:39 +02:00
|
|
|
if (TEMP_FAILURE_RETRY(read(fd, prefix, remainder)) != remainder) {
|
|
|
|
free(prefix);
|
2017-03-20 16:15:40 +01:00
|
|
|
ALOGE("%s prefix is truncated", conf[which][dir]);
|
2015-04-16 04:27:39 +02:00
|
|
|
break;
|
2015-04-01 18:24:22 +02:00
|
|
|
}
|
2015-04-16 04:27:39 +02:00
|
|
|
len = strnlen(prefix, remainder);
|
2017-05-02 17:56:15 +02:00
|
|
|
if (len >= remainder) { // missing a terminating null
|
2015-04-16 04:27:39 +02:00
|
|
|
free(prefix);
|
2017-03-20 16:15:40 +01:00
|
|
|
ALOGE("%s is corrupted", conf[which][dir]);
|
2015-04-01 18:24:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-04-16 04:27:39 +02:00
|
|
|
if (fs_config_cmp(dir, prefix, len, path, plen)) {
|
|
|
|
free(prefix);
|
|
|
|
close(fd);
|
2017-03-20 16:15:40 +01:00
|
|
|
*uid = get2LE((const uint8_t*)&(header.uid));
|
|
|
|
*gid = get2LE((const uint8_t*)&(header.gid));
|
|
|
|
*mode = (*mode & (~07777)) | get2LE((const uint8_t*)&(header.mode));
|
|
|
|
*capabilities = get8LE((const uint8_t*)&(header.capabilities));
|
2015-04-16 04:27:39 +02:00
|
|
|
return;
|
2015-04-01 18:24:22 +02:00
|
|
|
}
|
2015-04-16 04:27:39 +02:00
|
|
|
free(prefix);
|
2015-04-16 00:30:30 +02:00
|
|
|
}
|
2015-04-01 18:24:22 +02:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
for (pc = dir ? android_dirs : android_files; pc->prefix; pc++) {
|
2015-04-01 18:24:22 +02:00
|
|
|
if (fs_config_cmp(dir, pc->prefix, strlen(pc->prefix), path, plen)) {
|
|
|
|
break;
|
2015-04-01 16:42:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*uid = pc->uid;
|
|
|
|
*gid = pc->gid;
|
|
|
|
*mode = (*mode & (~07777)) | pc->mode;
|
|
|
|
*capabilities = pc->capabilities;
|
|
|
|
}
|
2015-04-01 20:02:00 +02:00
|
|
|
|
2017-03-20 16:15:40 +01:00
|
|
|
ssize_t fs_config_generate(char* buffer, size_t length, const struct fs_path_config* pc) {
|
|
|
|
struct fs_path_config_from_file* p = (struct fs_path_config_from_file*)buffer;
|
2015-04-01 20:02:00 +02:00
|
|
|
size_t len = ALIGN(sizeof(*p) + strlen(pc->prefix) + 1, sizeof(uint64_t));
|
|
|
|
|
|
|
|
if ((length < len) || (len > UINT16_MAX)) {
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
memset(p, 0, len);
|
|
|
|
uint16_t host_len = len;
|
2017-03-20 16:15:40 +01:00
|
|
|
p->len = get2LE((const uint8_t*)&host_len);
|
|
|
|
p->mode = get2LE((const uint8_t*)&(pc->mode));
|
|
|
|
p->uid = get2LE((const uint8_t*)&(pc->uid));
|
|
|
|
p->gid = get2LE((const uint8_t*)&(pc->gid));
|
|
|
|
p->capabilities = get8LE((const uint8_t*)&(pc->capabilities));
|
2015-04-01 20:02:00 +02:00
|
|
|
strcpy(p->prefix, pc->prefix);
|
|
|
|
return len;
|
|
|
|
}
|