about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-12-07T16·40+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-12-07T16·40+0000
commita82d80ddeb6f68ff136124dfb591a404bb195ea3 (patch)
treeb40ce775db3ae90451637f3e61ae4a5fb5ec3ccf /src/libutil/util.cc
parentf76fdb6d42a1b539fcf0b77d8efc5262283a19ea (diff)
* Move setuidCleanup() to libutil.
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index b152dc8f4b0b..fb6411408d08 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -17,6 +17,9 @@
 #include "util.hh"
 
 
+extern char * * environ;
+
+
 namespace nix {
 
 
@@ -818,6 +821,19 @@ void quickExit(int status)
 }
 
 
+void setuidCleanup()
+{
+    /* Don't trust the environment. */
+    environ = 0;
+
+    /* Make sure that file descriptors 0, 1, 2 are open. */
+    for (int fd = 0; fd <= 2; ++fd) {
+        struct stat st;
+        if (fstat(fd, &st) == -1) abort();
+    }
+}
+
+
 //////////////////////////////////////////////////////////////////////