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/788cebaf66ee
branches:  trunk
changeset: 954065:788cebaf66ee
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 93d557f03ecd -r 788cebaf66ee 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 93d557f03ecd -r 788cebaf66ee 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 93d557f03ecd -r 788cebaf66ee 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