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

* Use setreuid if setresuid is not available.

This commit is contained in:
Eelco Dolstra 2006-12-03 14:32:22 +00:00
parent a9f9241054
commit 84d6459bd5
2 changed files with 17 additions and 7 deletions

View file

@ -244,13 +244,19 @@ static void setuidInit()
could also modify the Nix executables (say, replace them by a
Trojan horse), so the problem is already there. */
#if HAVE_SETRESUID
setresuid(nixUid, nixUid, nixUid);
setresgid(nixGid, nixGid, nixGid);
#else
#if 0 && HAVE_SETRESUID
if (setresuid(nixUid, nixUid, nixUid)) abort();
if (setresgid(nixGid, nixGid, nixGid)) abort();
#elif HAVE_SETREUID
/* Note: doesn't set saved uid/gid! */
setuid(nixUid);
setgid(nixGid);
fprintf(stderr, "warning: cannot set saved uid\n");
if (setreuid(nixUid, nixUid)) abort();
if (setregid(nixGid, nixGid)) abort();
#else
/* Note: doesn't set real and saved uid/gid! */
fprintf(stderr, "warning: cannot set real and saved uids\n");
if (setuid(nixUid)) abort();
if (setgid(nixGid)) abort();
#endif
}