aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/process_TEST.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-19 20:08:23 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:16 +0100
commitb17e35dcdbd14c3a73511b19c0e82cd52d212499 (patch)
tree364f3cf12893e0661af2a0de126d26b9ee99bd9d /paludis/util/process_TEST.cc
parent322fc9a9acd2cfed2c3b7c70ee022e34fc1fd1f7 (diff)
downloadpaludis-b17e35dcdbd14c3a73511b19c0e82cd52d212499.tar.gz
paludis-b17e35dcdbd14c3a73511b19c0e82cd52d212499.tar.xz
Process::setuid_setgid
Diffstat (limited to 'paludis/util/process_TEST.cc')
-rw-r--r--paludis/util/process_TEST.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/paludis/util/process_TEST.cc b/paludis/util/process_TEST.cc
index 1c344b04a..a7361f3c0 100644
--- a/paludis/util/process_TEST.cc
+++ b/paludis/util/process_TEST.cc
@@ -22,11 +22,12 @@
#include <test/test_framework.hh>
#include <test/test_runner.hh>
#include <sstream>
+#include <sys/types.h>
+#include <pwd.h>
using namespace paludis;
using namespace test;
-
namespace test_cases
{
struct TrueTest : TestCase
@@ -208,5 +209,28 @@ namespace test_cases
TEST_CHECK_EQUAL(test_t_process.run().wait(), 0);
}
} test_ptys;
+
+ struct SetuidTest : TestCase
+ {
+ SetuidTest() : TestCase("setuid") { }
+
+ void run()
+ {
+ if (0 != getuid())
+ return;
+
+ std::stringstream stdout_stream;
+ Process whoami_process(ProcessCommand({"sh", "-c", "whoami ; groups"}));
+ whoami_process.capture_stdout(stdout_stream);
+
+ struct passwd * nobody(getpwnam("nobody"));
+ if (nobody)
+ {
+ whoami_process.setuid_setgid(nobody->pw_uid, nobody->pw_gid);
+ TEST_CHECK_EQUAL(whoami_process.run().wait(), 0);
+ TEST_CHECK_EQUAL(stdout_stream.str(), "nobody\nnobody\n");
+ }
+ }
+ } test_setuid;
}