* Remove SwitchToOriginalUser, we're not going to need it anymore.

This commit is contained in:
Eelco Dolstra 2006-12-02 14:34:14 +00:00
parent 626f8ee42f
commit 9c9cdb06d0
8 changed files with 4 additions and 63 deletions

View file

@ -358,8 +358,6 @@ static Expr parse(EvalState & state,
Expr parseExprFromFile(EvalState & state, Path path) Expr parseExprFromFile(EvalState & state, Path path)
{ {
SwitchToOriginalUser sw;
assert(path[0] == '/'); assert(path[0] == '/');
#if 0 #if 0

View file

@ -92,10 +92,7 @@ Path addPermRoot(const Path & _storePath, const Path & _gcRoot,
Path realRoot = canonPath((format("%1%/%2%/auto/%3%") Path realRoot = canonPath((format("%1%/%2%/auto/%3%")
% nixStateDir % gcRootsDir % hash).str()); % nixStateDir % gcRootsDir % hash).str());
{
SwitchToOriginalUser sw;
createSymlink(gcRoot, storePath, true); createSymlink(gcRoot, storePath, true);
}
createSymlink(realRoot, gcRoot, false); createSymlink(realRoot, gcRoot, false);
} }

View file

@ -207,10 +207,7 @@ void copyPath(const Path & src, const Path & dst)
files. */ files. */
CopySink sink; CopySink sink;
{
SwitchToOriginalUser sw;
dumpPath(src, sink); dumpPath(src, sink);
}
CopySource source(sink.s); CopySource source(sink.s);
restorePath(dst, source); restorePath(dst, source);

View file

@ -96,25 +96,15 @@ Path makeFixedOutputPath(bool recursive,
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
bool fixed, bool recursive, string hashAlgo) bool fixed, bool recursive, string hashAlgo)
{ {
Hash h(htSHA256); Hash h = hashPath(htSHA256, srcPath);
{
SwitchToOriginalUser sw;
h = hashPath(htSHA256, srcPath);
}
string baseName = baseNameOf(srcPath); string baseName = baseNameOf(srcPath);
Path dstPath; Path dstPath;
if (fixed) { if (fixed) {
HashType ht(parseHashType(hashAlgo)); HashType ht(parseHashType(hashAlgo));
Hash h2(ht); Hash h2 = recursive ? hashPath(ht, srcPath) : hashFile(ht, srcPath);
{
SwitchToOriginalUser sw;
h2 = recursive ? hashPath(ht, srcPath) : hashFile(ht, srcPath);
}
dstPath = makeFixedOutputPath(recursive, hashAlgo, h2, baseName); dstPath = makeFixedOutputPath(recursive, hashAlgo, h2, baseName);
} }

View file

@ -909,37 +909,6 @@ static gid_t savedGid, nixGid;
#endif #endif
SwitchToOriginalUser::SwitchToOriginalUser()
{
#if HAVE_SETRESUID
/* Temporarily switch the effective uid/gid back to the saved
uid/gid (which is the uid/gid of the user that executed the Nix
program; it's *not* the real uid/gid, since we changed that to
the Nix user in switchToNixUser()). */
if (haveSwitched) {
if (setuid(savedUid) == -1)
throw SysError(format("temporarily restoring uid to `%1%'") % savedUid);
if (setgid(savedGid) == -1)
throw SysError(format("temporarily restoring gid to `%1%'") % savedGid);
}
#endif
}
SwitchToOriginalUser::~SwitchToOriginalUser()
{
#if HAVE_SETRESUID
/* Switch the effective uid/gid back to the Nix user. */
if (haveSwitched) {
if (setuid(nixUid) == -1)
throw SysError(format("restoring uid to `%1%'") % nixUid);
if (setgid(nixGid) == -1)
throw SysError(format("restoring gid to `%1%'") % nixGid);
}
#endif
}
void switchToNixUser() void switchToNixUser()
{ {
#if 0 #if 0

View file

@ -250,12 +250,6 @@ bool string2Int(const string & s, int & n);
/* Setuid support. */ /* Setuid support. */
struct SwitchToOriginalUser
{
SwitchToOriginalUser();
~SwitchToOriginalUser();
};
void switchToNixUser(); void switchToNixUser();

View file

@ -943,7 +943,6 @@ static void opSwitchProfile(Globals & globals,
Path profile = opArgs.front(); Path profile = opArgs.front();
Path profileLink = getHomeDir() + "/.nix-profile"; Path profileLink = getHomeDir() + "/.nix-profile";
SwitchToOriginalUser sw;
switchLink(profileLink, profile); switchLink(profileLink, profile);
} }
@ -1092,7 +1091,6 @@ static void opDefaultExpr(Globals & globals,
Path defNixExpr = absPath(opArgs.front()); Path defNixExpr = absPath(opArgs.front());
Path defNixExprLink = getDefNixExprPath(); Path defNixExprLink = getDefNixExprPath();
SwitchToOriginalUser sw;
switchLink(defNixExprLink, defNixExpr); switchLink(defNixExprLink, defNixExpr);
} }
@ -1196,7 +1194,6 @@ void run(Strings args)
if (!op) throw UsageError("no operation specified"); if (!op) throw UsageError("no operation specified");
if (globals.profile == "") { if (globals.profile == "") {
SwitchToOriginalUser sw;
Path profileLink = getHomeDir() + "/.nix-profile"; Path profileLink = getHomeDir() + "/.nix-profile";
globals.profile = pathExists(profileLink) globals.profile = pathExists(profileLink)
? absPath(readLink(profileLink), dirOf(profileLink)) ? absPath(readLink(profileLink), dirOf(profileLink))

View file

@ -34,7 +34,6 @@ static bool indirectRoot = false;
static Path fixPath(Path path) static Path fixPath(Path path)
{ {
SwitchToOriginalUser sw;
path = absPath(path); path = absPath(path);
while (!isInStore(path)) { while (!isInStore(path)) {
if (!isLink(path)) break; if (!isLink(path)) break;