Move "should call fs_config" check back into adbd.
adbd is in a mainline module, while libadbd_fs is not. This means
that we must be able to handle the situation where adbd is new and
libadbd_fs is old. Old versions of libadbd_fs would not have included
the "getuid() == 0" check in adbd_fs_config, so in this situation,
neither side would perform the check. Therefore, the check must be
moved back onto the adbd side.
Bug: 343320259
Change-Id: I4349a6c192dba9941ee6e7bfd29fac2bb2e043ff
diff --git a/daemon/file_sync_service.cpp b/daemon/file_sync_service.cpp
index ab20e58..e9a597e 100644
--- a/daemon/file_sync_service.cpp
+++ b/daemon/file_sync_service.cpp
@@ -68,6 +68,13 @@
using android::base::Realpath;
using android::base::StringPrintf;
+static bool should_use_fs_config() {
+ // Only root has the necessary permissions to be able to apply fs_config.
+ // We can't move this check to adbd_fs_config for backwards compatibility
+ // with old versions of adbd_fs_config, which did not include the check.
+ return getuid() == 0;
+}
+
static bool update_capabilities(const char* path, uint64_t capabilities) {
#if defined(__ANDROID__)
if (capabilities == 0) {
@@ -109,7 +116,9 @@
}
partial_path += path_component;
- adbd_fs_config(partial_path.c_str(), true, nullptr, &uid, &gid, &mode, &capabilities);
+ if (should_use_fs_config()) {
+ adbd_fs_config(partial_path.c_str(), true, nullptr, &uid, &gid, &mode, &capabilities);
+ }
if (adb_mkdir(partial_path.c_str(), mode) == -1) {
if (errno != EEXIST) {
return false;
@@ -518,7 +527,7 @@
uid_t uid = -1;
gid_t gid = -1;
uint64_t capabilities = 0;
- if (!dry_run) {
+ if (!dry_run && should_use_fs_config()) {
adbd_fs_config(path.c_str(), false, nullptr, &uid, &gid, &mode, &capabilities);
}
diff --git a/libs/libadbd_fs/adbd_fs.cpp b/libs/libadbd_fs/adbd_fs.cpp
index e2425ef..92ce2e9 100644
--- a/libs/libadbd_fs/adbd_fs.cpp
+++ b/libs/libadbd_fs/adbd_fs.cpp
@@ -21,10 +21,6 @@
void adbd_fs_config(const char* path, int dir, const char* target_out_path, uid_t* uid, gid_t* gid,
mode_t* mode, uint64_t* capabilities) {
- // Only root has the necessary permissions to be able to apply fs_config.
- if (getuid() != 0) {
- return;
- }
struct fs_config conf;
if (get_fs_config(path, dir, target_out_path, &conf)) {
*uid = conf.uid;