1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 04:00:59 +01:00

Fixed recalculated drv path issue.

This commit is contained in:
Wouter den Breejen 2007-09-18 17:01:17 +00:00
parent 51cff21c92
commit f435abcdb6
3 changed files with 14 additions and 15 deletions

View file

@ -629,8 +629,8 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
* NOTE: we do not include the username into the hash calculation of the statepath yet, multiple different users can use the same dervation * NOTE: we do not include the username into the hash calculation of the statepath yet, multiple different users can use the same dervation
* but need different state paths. Thats why we keep a 'dummy' value e.g. global hash for everyone, and later at build time recalculate the real state path * but need different state paths. Thats why we keep a 'dummy' value e.g. global hash for everyone, and later at build time recalculate the real state path
*/ */
stateOutPath = makeStatePath(printHash(componentHash), drvName, stateIdentifier); //State path stateOutPath = makeStatePath(printHash(componentHash), drvName, stateIdentifier, queryCurrentUsername()); //State path
drv.env["statePath"] = stateOutPath; drv.env["statePath"] = stateOutPath;
string enableStateS = bool2string("true"); string enableStateS = bool2string("true");
string createDirsBeforeInstallS = bool2string(createDirsBeforeInstall); string createDirsBeforeInstallS = bool2string(createDirsBeforeInstall);

View file

@ -117,13 +117,11 @@ Path makeStorePath(const string & type, const Hash & hash, const string & suffix
+ "-" + suffix; + "-" + suffix;
} }
Path makeStatePath(const string & componentHash, const string & suffix, const string & stateIdentifier) Path makeStatePath(const string & componentHash, const string & suffix, const string & stateIdentifier, const string & username)
{ {
string suffix_stateIdentifier = stateIdentifier; string suffix_stateIdentifier = stateIdentifier;
suffix_stateIdentifier = "-" + suffix_stateIdentifier; suffix_stateIdentifier = "-" + suffix_stateIdentifier;
string username = queryCallingUsername(); //Should NOT be fake-able
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
string s = ":sha256:" + componentHash + ":" string s = ":sha256:" + componentHash + ":"
+ nixStoreState + ":" + suffix + ":" + stateIdentifier + ":" + username; + nixStoreState + ":" + suffix + ":" + stateIdentifier + ":" + username;
@ -143,20 +141,21 @@ void checkStatePath(const Derivation & drv)
string componentHash = drv.stateOutputs.find("state")->second.componentHash; string componentHash = drv.stateOutputs.find("state")->second.componentHash;
string suffix = drv.env.find("name")->second; string suffix = drv.env.find("name")->second;
string stateIdentifier = drv.stateOutputs.find("state")->second.stateIdentifier; string stateIdentifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string drvUser = drv.stateOutputs.find("state")->second.username;
string callingUser = queryCallingUsername();
//Check name (TODO how about sharing of drvs between users?) (user is filled in on the fly)
if(drvUser != callingUser)
throw Error(format("The calling user does not match the user specified in the drv '%1%'") % drvPath);
//TODO Name check Path calculatedPath = makeStatePath(componentHash, suffix, stateIdentifier, callingUser);
//if( user != callinguser
Path calculatedPath = makeStatePath(componentHash, suffix, stateIdentifier); //TODO INCLUDE USER !!!!!!!!!!!!
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! calculatedPath IS NOT CORRECT ANYMORE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
printMsg(lvlError, format("Checking statePath validity: %1% %2%") % drvPath % calculatedPath); printMsg(lvlError, format("Checking statePath validity: %1% %2%") % drvPath % calculatedPath);
//Check Calculated path
if(drvPath != calculatedPath) if(drvPath != calculatedPath)
Error(format("The statepath from the Derivation does not match the recalculated statepath, are u trying to spoof the statepath?")); throw Error(format("The statepath from the Derivation does not match the recalculated statepath, are u trying to spoof the statepath?"));
} }
Path makeFixedOutputPath(bool recursive, Path makeFixedOutputPath(bool recursive,

View file

@ -279,7 +279,7 @@ Path makeFixedOutputPath(bool recursive,
string hashAlgo, Hash hash, string name); string hashAlgo, Hash hash, string name);
/* TODO ... */ /* TODO ... */
Path makeStatePath(const string & componentHash, const string & suffix, const string & stateIdentifier); Path makeStatePath(const string & componentHash, const string & suffix, const string & stateIdentifier, const string & user);
/* TODO ... */ /* TODO ... */
void checkStatePath(const Derivation & drv); void checkStatePath(const Derivation & drv);