Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/atf/dist/tools If we are running the test as an...



details:   https://anonhg.NetBSD.org/src/rev/cd2d1f64a446
branches:  trunk
changeset: 960772:cd2d1f64a446
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Mar 28 16:35:37 2021 +0000

description:
If we are running the test as an unprivileged user, hand ownership of the
test directory to that user.

diffstat:

 external/bsd/atf/dist/tools/fs.cpp           |  11 +++++++++++
 external/bsd/atf/dist/tools/fs.hpp           |   1 +
 external/bsd/atf/dist/tools/test-program.cpp |   4 +++-
 3 files changed, 15 insertions(+), 1 deletions(-)

diffs (47 lines):

diff -r e82c76c4c691 -r cd2d1f64a446 external/bsd/atf/dist/tools/fs.cpp
--- a/external/bsd/atf/dist/tools/fs.cpp        Sun Mar 28 16:28:15 2021 +0000
+++ b/external/bsd/atf/dist/tools/fs.cpp        Sun Mar 28 16:35:37 2021 +0000
@@ -683,6 +683,17 @@
     }
 }
 
+void
+impl::change_ownership(const path& p, const std::pair < int, int >& user)
+{
+    if (::chown(p.c_str(), user.first, user.second) == -1) {
+        std::stringstream ss;
+        ss << IMPL_NAME "::chown(" << p.str() << ", " << user.first << ", "
+           << user.second << ")";
+        throw tools::system_error(ss.str(), "chown(2) failed", errno);
+    }
+}
+
 impl::path
 impl::change_directory(const path& dir)
 {
diff -r e82c76c4c691 -r cd2d1f64a446 external/bsd/atf/dist/tools/fs.hpp
--- a/external/bsd/atf/dist/tools/fs.hpp        Sun Mar 28 16:28:15 2021 +0000
+++ b/external/bsd/atf/dist/tools/fs.hpp        Sun Mar 28 16:35:37 2021 +0000
@@ -368,6 +368,7 @@
 void rmdir(const path&);
 
 tools::fs::path change_directory(const tools::fs::path&);
+void change_ownership(const tools::fs::path&, const std::pair< int, int >&);
 void cleanup(const tools::fs::path&);
 tools::fs::path get_current_dir(void);
 
diff -r e82c76c4c691 -r cd2d1f64a446 external/bsd/atf/dist/tools/test-program.cpp
--- a/external/bsd/atf/dist/tools/test-program.cpp      Sun Mar 28 16:28:15 2021 +0000
+++ b/external/bsd/atf/dist/tools/test-program.cpp      Sun Mar 28 16:35:37 2021 +0000
@@ -304,8 +304,10 @@
 
     const std::pair< int, int > user = tools::get_required_user(
         params->metadata, params->config);
-    if (user.first != -1 && user.second != -1)
+    if (user.first != -1 && user.second != -1) {
+        tools::fs::change_ownership(params->workdir, user);
         tools::user::drop_privileges(user);
+    }
 
     // The input 'tp' parameter may be relative and become invalid once
     // we change the current working directory.



Home | Main Index | Thread Index | Old Index