]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire-item.cc
really do not download Release if InRelease does not verify
[apt.git] / apt-pkg / acquire-item.cc
index b3c41a178bffd5c37be8efdaa6f67f2da5cb1b95..3c66369cf8bcbbbecd5176360ef79645ef9f380e 100644 (file)
@@ -528,7 +528,7 @@ void pkgAcqDiffIndex::Done(string Message,unsigned long long Size,HashStringList
    Item::Done(Message, Size, Hashes, Cnf);
 
    // verify the index target
-   if(Target && Target->MetaKey != "" && MetaIndexParser && Hashes.size() > 0)
+   if(Target && Target->MetaKey != "" && MetaIndexParser && Hashes.usable())
    {
       std::string IndexMetaKey  = Target->MetaKey + ".diff/Index";
       indexRecords::checkSum *Record = MetaIndexParser->Lookup(IndexMetaKey);
@@ -937,7 +937,7 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri
 // AcqBaseIndex::VerifyHashByMetaKey - verify hash for the given metakey /*{{{*/
 bool pkgAcqBaseIndex::VerifyHashByMetaKey(HashStringList const &Hashes)
 {
-   if(MetaKey != "" && Hashes.size() > 0)
+   if(MetaKey != "" && Hashes.usable())
    {
       indexRecords::checkSum *Record = MetaIndexParser->Lookup(MetaKey);
       if(Record && Record->Hashes.usable() && Hashes != Record->Hashes)
@@ -1025,8 +1025,8 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
    DestFile += URItoFileName(URI);
 
-   ComprExt = CompressionExtensions.substr(0, CompressionExtensions.find(' '));
-   if (ComprExt == "uncompressed")
+   CurrentCompressionExtension = CompressionExtensions.substr(0, CompressionExtensions.find(' '));
+   if (CurrentCompressionExtension == "uncompressed")
    {
       Desc.URI = URI;
       if(Target)
@@ -1034,10 +1034,10 @@ void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
    }
    else
    {
-      Desc.URI = URI + '.' + ComprExt;
-      DestFile = DestFile + '.' + ComprExt;
+      Desc.URI = URI + '.' + CurrentCompressionExtension;
+      DestFile = DestFile + '.' + CurrentCompressionExtension;
       if(Target)
-         MetaKey = string(Target->MetaKey) + '.' + ComprExt;
+         MetaKey = string(Target->MetaKey) + '.' + CurrentCompressionExtension;
    }
 
    // load the filesize
@@ -1120,9 +1120,7 @@ void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf)    /*{{{*/
    // on decompression failure, remove bad versions in partial/
    if (Stage == STAGE_DECOMPRESS_AND_VERIFY)
    {
-      string s = _config->FindDir("Dir::State::lists") + "partial/";
-      s += URItoFileName(RealURI)  + '.' + ComprExt;
-      unlink(s.c_str());
+      unlink(EraseFileName.c_str());
    }
 
    Item::Failed(Message,Cnf);
@@ -1139,7 +1137,7 @@ std::string pkgAcqIndex::GetFinalFilename() const
    std::string FinalFile = _config->FindDir("Dir::State::lists");
    FinalFile += URItoFileName(RealURI);
    if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      FinalFile += '.' + ComprExt;
+      FinalFile += '.' + CurrentCompressionExtension;
    return FinalFile;
 }
                                                                        /*}}}*/
@@ -1155,7 +1153,7 @@ void pkgAcqIndex::ReverifyAfterIMS()
 
    // adjust DestFile if its compressed on disk
    if (_config->FindB("Acquire::GzipIndexes",false) == true)
-      DestFile += '.' + ComprExt;
+      DestFile += '.' + CurrentCompressionExtension;
 
    // copy FinalFile into partial/ so that we check the hash again
    string FinalFile = GetFinalFilename();
@@ -1266,6 +1264,8 @@ void pkgAcqIndex::StageDownloadDone(string Message,
    // not the "DestFile" we set, in this case we uncompress from the local file
    if (FileName != DestFile)
       Local = true;
+   else
+      EraseFileName = FileName;
 
    // we need to verify the file against the current Release file again
    // on if-modfied-since hit to avoid a stale attack against us
@@ -1277,6 +1277,7 @@ void pkgAcqIndex::StageDownloadDone(string Message,
          return;
 
       // The files timestamp matches, reverify by copy into partial/
+      EraseFileName = "";
       ReverifyAfterIMS();
       return;
    }
@@ -1285,8 +1286,8 @@ void pkgAcqIndex::StageDownloadDone(string Message,
    if (_config->FindB("Acquire::GzipIndexes",false))
    {
       DestFile = _config->FindDir("Dir::State::lists") + "partial/";
-      DestFile += URItoFileName(RealURI) + '.' + ComprExt;
-
+      DestFile += URItoFileName(RealURI) + '.' + CurrentCompressionExtension;
+      EraseFileName = "";
       Stage = STAGE_DECOMPRESS_AND_VERIFY;
       Desc.URI = "copy:" + FileName;
       QueueURI(Desc);
@@ -1296,13 +1297,13 @@ void pkgAcqIndex::StageDownloadDone(string Message,
 
    // get the binary name for your used compression type
    string decompProg;
-   if(ComprExt == "uncompressed")
+   if(CurrentCompressionExtension == "uncompressed")
       decompProg = "copy";
    else
-      decompProg = _config->Find(string("Acquire::CompressionTypes::").append(ComprExt),"");
+      decompProg = _config->Find(string("Acquire::CompressionTypes::").append(CurrentCompressionExtension),"");
    if(decompProg.empty() == true)
    {
-      _error->Error("Unsupported extension: %s", ComprExt.c_str());
+      _error->Error("Unsupported extension: %s", CurrentCompressionExtension.c_str());
       return;
    }
 
@@ -1344,14 +1345,8 @@ void pkgAcqIndex::StageDecompressDone(string Message,
       return;
    }
    
-   // remove the compressed version of the file (if the file got uncompressed)
-   URI Get = LookupTag(Message, "URI");
-   if (Get.Access != "copy")
-   {
-      // To account for relative paths
-      std::string CompressedFile = Get.Host + Get.Path;
-      unlink(CompressedFile.c_str());
-   }
+   // remove the compressed version of the file
+   unlink(EraseFileName.c_str());
    
    // Done, queue for rename on transaction finished
    TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
@@ -1422,12 +1417,17 @@ void pkgAcqIndexTrans::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
    Item::Failed(Message,Cnf);
 }
                                                                        /*}}}*/
-
+// AcqMetaBase::Add - Add a item to the current Transaction            /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 void pkgAcqMetaBase::Add(Item *I)
 {
    Transaction.push_back(I);
 }
-
+                                                                       /*}}}*/
+// AcqMetaBase::AbortTransaction - Abort the current Transaction       /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 void pkgAcqMetaBase::AbortTransaction()
 {
    if(_config->FindB("Debug::Acquire::Transaction", false) == true)
@@ -1452,6 +1452,9 @@ void pkgAcqMetaBase::AbortTransaction()
    }
 }
                                                                        /*}}}*/
+// AcqMetaBase::TransactionHasError - Check for errors in Transaction          /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 bool pkgAcqMetaBase::TransactionHasError()
 {
    for (pkgAcquire::ItemIterator I = Transaction.begin();
@@ -1462,7 +1465,10 @@ bool pkgAcqMetaBase::TransactionHasError()
 
    return false;
 }
-// Acquire::CommitTransaction - Commit a transaction                   /*{{{*/
+                                                                       /*}}}*/
+// AcqMetaBase::CommitTransaction - Commit a transaction               /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 void pkgAcqMetaBase::CommitTransaction()
 {
    if(_config->FindB("Debug::Acquire::Transaction", false) == true)
@@ -1496,7 +1502,10 @@ void pkgAcqMetaBase::CommitTransaction()
       (*I)->TransactionManager = 0;
    }
 }
-
+                                                                       /*}}}*/
+// AcqMetaBase::CommitTransaction - Commit a transaction               /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 void pkgAcqMetaBase::TransactionStageCopy(Item *I,
                                           const std::string &From,
                                           const std::string &To)
@@ -1504,16 +1513,21 @@ void pkgAcqMetaBase::TransactionStageCopy(Item *I,
    I->PartialFile = From;
    I->DestFile = To;
 }
-
+                                                                       /*}}}*/
+// AcqMetaBase::CommitTransaction - Commit a transaction               /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 void pkgAcqMetaBase::TransactionStageRemoval(Item *I,
                                              const std::string &FinalFile)
 {
    I->PartialFile = "";
    I->DestFile = FinalFile; 
 }
-
-
+                                                                       /*}}}*/
                                                                        /*{{{*/
+// AcqMetaBase::GenerateAuthWarning - Check gpg authentication error   /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 bool pkgAcqMetaBase::GenerateAuthWarning(const std::string &RealURI,
                                          const std::string &Message)
 {
@@ -1547,9 +1561,10 @@ bool pkgAcqMetaBase::GenerateAuthWarning(const std::string &RealURI,
    return false;
 }
                                                                        /*}}}*/
-
-
-pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner,                        /*{{{*/
+// AcqMetaSig::AcqMetaSig - Constructor                                /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner,
                              pkgAcqMetaBase *TransactionManager,
                             string URI,string URIDesc,string ShortDesc,
                              string MetaIndexFile,
@@ -1561,7 +1576,7 @@ pkgAcqMetaSig::pkgAcqMetaSig(pkgAcquire *Owner,                   /*{{{*/
    ShortDesc(ShortDesc)
 {
    DestFile = _config->FindDir("Dir::State::lists") + "partial/";
-   DestFile += URItoFileName(URI);
+   DestFile += URItoFileName(RealURI);
 
    // remove any partial downloaded sig-file in partial/. 
    // it may confuse proxies and is too small to warrant a 
@@ -1600,74 +1615,75 @@ string pkgAcqMetaSig::Custom600Headers() const
 
    return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 }
-
-void pkgAcqMetaSig::Done(string Message,unsigned long long Size, HashStringList const &Hashes,
+                                                                       /*}}}*/
+// pkgAcqMetaSig::Done - The signature was downloaded/verified         /*{{{*/
+// ---------------------------------------------------------------------
+/* The only header we use is the last-modified header. */
+void pkgAcqMetaSig::Done(string Message,unsigned long long Size,
+                         HashStringList const &Hashes,
                         pkgAcquire::MethodConfig *Cfg)
 {
    Item::Done(Message, Size, Hashes, Cfg);
 
-   string FileName = LookupTag(Message,"Filename");
-   if (FileName.empty() == true)
+   if(AuthPass == false)
    {
-      Status = StatError;
-      ErrorText = "Method gave a blank filename";
-      return;
-   }
+      // queue for verify, note that we change DestFile here to point to
+      // the file we want to verify (needed to make gpgv work)
 
-   if (FileName != DestFile)
-   {
-      // We have to copy it into place
-      Local = true;
-      Desc.URI = "copy:" + FileName;
-      QueueURI(Desc);
-      return;
-   }
+      string FileName = LookupTag(Message,"Filename");
+      if (FileName.empty() == true)
+      {
+         Status = StatError;
+         ErrorText = "Method gave a blank filename";
+         return;
+      }
 
-   if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
-      IMSHit = true;
+      if (FileName != DestFile)
+      {
+         // We have to copy it into place
+         Local = true;
+         Desc.URI = "copy:" + FileName;
+         QueueURI(Desc);
+         return;
+      }
 
-   // adjust paths if its a ims-hit
-   if(IMSHit)
-   {
-      string FinalFile = _config->FindDir("Dir::State::lists");
-      FinalFile += URItoFileName(RealURI);
-         
-      TransactionManager->TransactionStageCopy(this, FinalFile, FinalFile);
-   }
+      if(StringToBool(LookupTag(Message,"IMS-Hit"),false) == true)
+      {
+         IMSHit = true;
+         // adjust DestFile on i-m-s hit to the one we already have on disk
+         DestFile = _config->FindDir("Dir::State::lists");
+         DestFile += URItoFileName(RealURI);
+      }
+
+      // this is the file we verify from
+      MetaIndexFileSignature = DestFile;
 
-   // queue for verify
-   if(AuthPass == false)
-   {
       AuthPass = true;
-      Desc.URI = "gpgv:" + DestFile;
+      Desc.URI = "gpgv:" + MetaIndexFileSignature;
       DestFile = MetaIndexFile;
       QueueURI(Desc);
+      ActiveSubprocess = "gpgv";
       return;
    }
-
-   // queue to copy the file in place if it was not a ims hit, on ims
-   // hit the file is already at the right place
-   if(IMSHit == false)
+   else 
    {
-      PartialFile = _config->FindDir("Dir::State::lists") + "partial/";
-      PartialFile += URItoFileName(RealURI);
-      
-      std::string FinalFile = _config->FindDir("Dir::State::lists");
-      FinalFile += URItoFileName(RealURI);
-
-      TransactionManager->TransactionStageCopy(this, PartialFile, FinalFile);
-   }
+      // verify was successful
 
-   // we parse the MetaIndexFile here because at this point we can
-   // trust the data
-   if(AuthPass == true)
-   {
+      // we parse the MetaIndexFile here (and not right after getting 
+      // the pkgAcqMetaIndex) because at this point we can trust the data
+      //
       // load indexes and queue further downloads
       MetaIndexParser->Load(MetaIndexFile);
       QueueIndexes(true);
-   }
 
-   Complete = true;
+      // DestFile points to the the MetaIndeFile at this point, make it
+      // point back to the Release.gpg file
+      std::string FinalFile = _config->FindDir("Dir::State::lists");
+      FinalFile += URItoFileName(RealURI);
+      TransactionManager->TransactionStageCopy(this, MetaIndexFileSignature, FinalFile);
+
+      Complete = true;
+   }
 }
                                                                        /*}}}*/
 void pkgAcqMetaSig::Failed(string Message,pkgAcquire::MethodConfig *Cnf)/*{{{*/
@@ -2159,26 +2175,6 @@ void pkgAcqMetaIndex::Failed(string Message,
          return;
    }
 
-   /* Always move the meta index, even if gpgv failed. This ensures
-    * that PackageFile objects are correctly filled in */
-   if (FileExists(DestFile)) 
-   {
-      string FinalFile = _config->FindDir("Dir::State::lists");
-      FinalFile += URItoFileName(RealURI);
-      /* InRelease files become Release files, otherwise
-       * they would be considered as trusted later on */
-      if (SigFile == DestFile) {
-        RealURI = RealURI.replace(RealURI.rfind("InRelease"), 9,
-                                      "Release");
-        FinalFile = FinalFile.replace(FinalFile.rfind("InRelease"), 9,
-                                      "Release");
-        SigFile = FinalFile;
-      }
-
-      // Done, queue for rename on transaction finished
-      TransactionManager->TransactionStageCopy(this, DestFile, FinalFile);
-   }
-
    _error->Warning(_("The data from '%s' is not signed. Packages "
                      "from that repository can not be authenticated."),
                    URIDesc.c_str());
@@ -2188,11 +2184,35 @@ void pkgAcqMetaIndex::Failed(string Message,
    // only allow going further if the users explicitely wants it
    if(_config->FindB("Acquire::AllowInsecureRepositories") == true)
    {
+      /* Always move the meta index, even if gpgv failed. This ensures
+       * that PackageFile objects are correctly filled in */
+      if (FileExists(DestFile)) 
+      {
+         string FinalFile = _config->FindDir("Dir::State::lists");
+         FinalFile += URItoFileName(RealURI);
+         /* InRelease files become Release files, otherwise
+          * they would be considered as trusted later on */
+         if (SigFile == DestFile) {
+            RealURI = RealURI.replace(RealURI.rfind("InRelease"), 9,
+                                      "Release");
+            FinalFile = FinalFile.replace(FinalFile.rfind("InRelease"), 9,
+                                          "Release");
+            SigFile = FinalFile;
+         }
+
+         // Done, queue for rename on transaction finished
+         TransactionManager->TransactionStageCopy(this, DestFile, FinalFile);
+      }
+
       QueueIndexes(false);
    } else {
       // warn if the repository is unsinged
       _error->Warning("Use --allow-insecure-repositories to force the update");
+      TransactionManager->AbortTransaction();
+      Status = StatError;
+      return;
    } 
+
 }
                                                                        /*}}}*/