Revert "arc-setup: Validate media_profiles.xml is not a symlink"
This reverts commit 19c8e2d9069efa802ac482710c95afdcbcdc35a5.
Reason for revert: break arc-r pfq
Original change's description:
> arc-setup: Validate media_profiles.xml is not a symlink
>
> Validate /run/arc/oem/etc/media_profiles.xml is not a symlink before
> writing to it.
>
> BUG=chromium:1133047
> TEST=emerge arc-setup
> TEST=cros_workon_make --board=${BOARD} chromeos-base/arc-setup --test
>
> Change-Id: I1f58326031663cb60a8bf693712788805d8104e3
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2441654
> Commit-Queue: Long Cheng <lgcheng@google.com>
> Tested-by: Long Cheng <lgcheng@google.com>
> Reviewed-by: Ereth McKnight-MacNeil <ereth@chromium.org>
> Reviewed-by: Greg Kerr <kerrnel@chromium.org>
Bug: chromium:1133047
Change-Id: Ib33e002f298a018286545b9cdf44c111108ce25e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2481151
Reviewed-by: Long Cheng <lgcheng@google.com>
Reviewed-by: Ereth McKnight-MacNeil <ereth@chromium.org>
Tested-by: Long Cheng <lgcheng@google.com>
Commit-Queue: Long Cheng <lgcheng@google.com>
diff --git a/arc/setup/arc_setup.cc b/arc/setup/arc_setup.cc
index 3081522..1330811 100644
--- a/arc/setup/arc_setup.cc
+++ b/arc/setup/arc_setup.cc
@@ -844,7 +844,7 @@
base::FilePath(oem_mount_directory)
.Append("etc")
.Append(arc_paths_->media_profile_file);
- EXIT_IF(!SafeCopyFile(media_profile_xml, new_media_profile_xml));
+ EXIT_IF(!base::CopyFile(media_profile_xml, new_media_profile_xml));
EXIT_IF(
!Chown(kHostArcCameraUid, kHostArcCameraGid, new_media_profile_xml));
}
@@ -863,7 +863,7 @@
const base::FilePath platform_xml_file =
base::FilePath(oem_mount_directory)
.Append(arc_paths_->platform_xml_file_relative);
- EXIT_IF(!SafeCopyFile(hardware_features_xml, platform_xml_file));
+ EXIT_IF(!base::CopyFile(hardware_features_xml, platform_xml_file));
// TODO(chromium:1083652) Remove dynamic shell scripts once all overlays
// are migrated to static XML config.
diff --git a/arc/setup/arc_setup_util.cc b/arc/setup/arc_setup_util.cc
index bb9646a..4d10771 100644
--- a/arc/setup/arc_setup_util.cc
+++ b/arc/setup/arc_setup_util.cc
@@ -22,7 +22,6 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
-#include <sys/sendfile.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statfs.h>
@@ -1007,40 +1006,4 @@
return true;
}
-bool SafeCopyFile(const base::FilePath& src_path,
- const base::FilePath& dest_path) {
- struct stat st;
- ssize_t len, ret;
-
- brillo::SafeFD root = brillo::SafeFD::Root().first;
- brillo::SafeFD::SafeFDResult result(
- root.OpenExistingFile(src_path, O_RDONLY | O_CLOEXEC));
- if (brillo::SafeFD::IsError(result.second)) {
- LOG(ERROR) << "Failed to open src path " << src_path;
- return false;
- }
- brillo::SafeFD src_fd(std::move(result.first));
-
- brillo::SafeFD dest_fd(root.MakeFile(dest_path, 0644 /*permissions*/).first);
- if (!dest_fd.is_valid()) {
- LOG(ERROR) << "Failed to open dest path " << dest_path;
- return false;
- }
-
- fstat(src_fd.get(), &st);
- len = st.st_size;
-
- do {
- ret = sendfile(dest_fd.get(), src_fd.get(), NULL, len);
- if (ret == -1) {
- PLOG(ERROR) << "Fail to copy file " << src_path << " to " << dest_path
- << errno;
- return false;
- }
- len -= ret;
- } while (len > 0 && ret > 0);
-
- return true;
-}
-
} // namespace arc
diff --git a/arc/setup/arc_setup_util.h b/arc/setup/arc_setup_util.h
index 64ab0e2..0d038dd 100644
--- a/arc/setup/arc_setup_util.h
+++ b/arc/setup/arc_setup_util.h
@@ -271,11 +271,6 @@
// Returns the user and group ids for a user.
bool GetUserId(const std::string& user, uid_t* user_id, gid_t* group_id);
-// Make a copy of file |src_path| to |dest_path|.
-// Use SafeFD to validate there is no symlink in the path.
-bool SafeCopyFile(const base::FilePath& src_path,
- const base::FilePath& dest_path);
-
} // namespace arc
#endif // ARC_SETUP_ARC_SETUP_UTIL_H_
diff --git a/arc/setup/arc_setup_util_test.cc b/arc/setup/arc_setup_util_test.cc
index 060b141..9228879 100644
--- a/arc/setup/arc_setup_util_test.cc
+++ b/arc/setup/arc_setup_util_test.cc
@@ -930,21 +930,4 @@
}
}
-TEST(ArcSetupUtil, SafeCopyFile) {
- base::ScopedTempDir temp_dir;
- ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
- const base::FilePath src_file = temp_dir.GetPath().Append("srcfile");
-
- // Create a new source file and write it.
- ASSERT_TRUE(WriteToFile(src_file, 0755, "testabc"));
-
- const base::FilePath dest_file =
- temp_dir.GetPath().Append("dest").Append("destfile");
- ASSERT_TRUE(SafeCopyFile(src_file, dest_file));
-
- const base::FilePath symlink = temp_dir.GetPath().Append("symlink");
- ASSERT_TRUE(base::CreateSymbolicLink(dest_file, symlink));
- ASSERT_FALSE(SafeCopyFile(src_file, symlink));
-}
-
} // namespace arc