1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

* nix-setuid-helper: allow running programs under a different uid.

This commit is contained in:
Eelco Dolstra 2006-12-06 17:29:10 +00:00
parent 9f0efa6611
commit 751f6d2157
3 changed files with 140 additions and 11 deletions

View file

@ -14,7 +14,7 @@
#include <aterm2.h>
extern char * * environ;
#include "setuid-common.hh"
namespace nix {
@ -218,20 +218,11 @@ static void setuidInit()
uid_t nixUid = geteuid();
gid_t nixGid = getegid();
fprintf(stderr, "<<< setuid mode >>>\n");
/* Don't trust the environment. */
environ = 0;
setuidCleanup();
/* Don't trust the current directory. */
if (chdir("/") == -1) abort();
/* 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();
}
/* Set the real (and preferably also the save) uid/gid to the
effective uid/gid. This matters mostly when we're not using
build-users (bad!), since some builders (like Perl) complain