diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-27 21:04:07 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-27 21:04:07 +0000 |
commit | 4ad6fb7ea3e18361b6021a23a7401af4085d3602 (patch) | |
tree | 0b1ef80e76bd342e334660593c19487fe103de63 /src/libutil | |
parent | 015ac7c7da6dfc93d287b89e443648656a88665d (diff) |
* Fix setuid builds.
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index eac124edb..de2dd12ad 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -13,6 +13,10 @@ #include <sys/wait.h> #include <fcntl.h> +#include <sys/types.h> +#include <pwd.h> +#include <grp.h> + #include "util.hh" @@ -913,7 +917,7 @@ void switchToNixUser() /* Lookup the Nix gid. */ struct group * gr = getgrnam(NIX_GROUP); if (!gr) { - cerr << format("missing group `%1%'\n") % NIX_GROUP; + std::cerr << format("missing group `%1%'\n") % NIX_GROUP; exit(1); } @@ -921,7 +925,7 @@ void switchToNixUser() int maxGids = 512, nrGids; gid_t gids[maxGids]; if ((nrGids = getgroups(maxGids, gids)) == -1) { - cerr << format("unable to query gids\n"); + std::cerr << format("unable to query gids\n"); exit(1); } @@ -955,14 +959,14 @@ void switchToNixUser() because we cannot do it after we have dropped root uid. */ nixGid = gr->gr_gid; if (_setgid(nixGid) != 0 || getgid() != nixGid || getegid() != nixGid) { - cerr << format("unable to set gid to `%1%'\n") % NIX_GROUP; + std::cerr << format("unable to set gid to `%1%'\n") % NIX_GROUP; exit(1); } /* Lookup the Nix uid. */ struct passwd * pw = getpwnam(NIX_USER); if (!pw) { - cerr << format("missing user `%1%'\n") % NIX_USER; + std::cerr << format("missing user `%1%'\n") % NIX_USER; exit(1); } @@ -971,7 +975,7 @@ void switchToNixUser() succeeded.*/ nixUid = pw->pw_uid; if (_setuid(nixUid) != 0 || getuid() != nixUid || geteuid() != nixUid) { - cerr << format("unable to set uid to `%1%'\n") % NIX_USER; + std::cerr << format("unable to set uid to `%1%'\n") % NIX_USER; exit(1); } |