From 47f87072ad42338a9b6397a250abf2775d051d8e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Sep 2004 21:12:53 +0000 Subject: * A very dirty hack to make setuid installations a bit nicer to use. Previously there was the problem that all files read by nix-env etc. should be reachable and readable by the Nix user. So for instance building a Nix expression in your home directory meant that the home directory should have at least g+x or o+x permission so that the Nix user could reach the Nix expression. Now we just switch back to the original user just prior to reading sources and the like. The places where this happens are somewhat arbitrary, however. Any scope that has a live SwitchToOriginalUser object in it is executed as the original user. * Back out r1385. setreuid() sets the saved uid to the new real/effective uid, which prevents us from switching back to the original uid. setresuid() doesn't have this problem (although the manpage has a bug: specifying -1 for the saved uid doesn't leave it unchanged; an explicit value must be specified). --- src/libstore/store.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 110ec2b48..5b471a1d9 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -157,7 +157,10 @@ void copyPath(const Path & src, const Path & dst) CopySink sink; sink.fd = pipe.writeSide; - dumpPath(src, sink); + { + SwitchToOriginalUser sw; + dumpPath(src, sink); + } /* Wait for the child to finish. */ int status = pid.wait(true); @@ -421,7 +424,11 @@ Path addToStore(const Path & _srcPath) Path srcPath(absPath(_srcPath)); debug(format("adding `%1%' to the store") % srcPath); - Hash h = hashPath(srcPath); + Hash h; + { + SwitchToOriginalUser sw; + h = hashPath(srcPath); + } string baseName = baseNameOf(srcPath); Path dstPath = canonPath(nixStore + "/" + (string) h + "-" + baseName); -- cgit v1.2.3