}
/*}}}*/
-static bool AllowInsecureRepositories(metaIndex const * const MetaIndexParser, pkgAcqMetaClearSig * const TransactionManager, pkgAcquire::Item * const I) /*{{{*/
+static bool MessageInsecureRepository(bool const isError, std::string const &msg)/*{{{*/
{
- if(MetaIndexParser->GetTrusted() == metaIndex::TRI_YES || _config->FindB("Acquire::AllowInsecureRepositories") == true)
+ if (isError)
+ {
+ _error->Error("%s", msg.c_str());
+ _error->Notice("%s", _("Updating such a repository securily is impossible and therefore disabled by default."));
+ }
+ else
+ {
+ _error->Warning("%s", msg.c_str());
+ _error->Notice("%s", _("Data from such a repository can not be authenticated and is therefore potentially dangerous to use."));
+ }
+ _error->Notice("%s", _("See apt-secure(8) manpage for repository creation and user configuration details."));
+ return false;
+}
+static bool MessageInsecureRepository(bool const isError, char const * const msg, std::string const &repo)
+{
+ std::string m;
+ strprintf(m, msg, repo.c_str());
+ return MessageInsecureRepository(isError, m);
+}
+ /*}}}*/
+static bool AllowInsecureRepositories(char const * const msg, std::string const &repo,/*{{{*/
+ metaIndex const * const MetaIndexParser, pkgAcqMetaClearSig * const TransactionManager, pkgAcquire::Item * const I)
+{
+ if(MetaIndexParser->GetTrusted() == metaIndex::TRI_YES)
return true;
- _error->Error(_("Use --allow-insecure-repositories to force the update"));
+ if (_config->FindB("Acquire::AllowInsecureRepositories") == true)
+ {
+ MessageInsecureRepository(false, msg, repo);
+ return true;
+ }
+
+ MessageInsecureRepository(true, msg, repo);
TransactionManager->AbortTransaction();
I->Status = pkgAcquire::Item::StatError;
return false;
// at this point the real Items are loaded in the fetcher
ExpectedAdditionalItems = 0;
+ bool metaBaseSupportsByHash = false;
+ if (TransactionManager != NULL && TransactionManager->MetaIndexParser != NULL)
+ metaBaseSupportsByHash = TransactionManager->MetaIndexParser->GetSupportsAcquireByHash();
+
for (std::vector <IndexTarget>::iterator Target = IndexTargets.begin();
Target != IndexTargets.end();
++Target)
if (types.empty() == false)
{
std::ostringstream os;
+ // add the special compressiontype byhash first if supported
+ std::string const useByHashConf = Target->Option(IndexTarget::BY_HASH);
+ bool useByHash = false;
+ if(useByHashConf == "force")
+ useByHash = true;
+ else
+ useByHash = StringToBool(useByHashConf) == true && metaBaseSupportsByHash;
+ if (useByHash == true)
+ os << "by-hash ";
std::copy(types.begin(), types.end()-1, std::ostream_iterator<std::string>(os, " "));
os << *types.rbegin();
Target->Options["COMPRESSIONTYPES"] = os.str();
if (filename.empty() == false)
{
new NoActionItem(Owner, *Target, filename);
+ std::string const idxfilename = GetFinalFileNameFromURI(Target->URI + ".diff/Index");
+ if (FileExists(idxfilename))
+ new NoActionItem(Owner, *Target, idxfilename);
continue;
}
return Header;
}
/*}}}*/
-bool pkgAcqMetaClearSig::VerifyDone(std::string const &Message,
+bool pkgAcqMetaClearSig::VerifyDone(std::string const &Message, /*{{{*/
pkgAcquire::MethodConfig const * const Cnf)
{
Item::VerifyDone(Message, Cnf);
return true;
}
+ /*}}}*/
// pkgAcqMetaClearSig::Done - We got a file /*{{{*/
void pkgAcqMetaClearSig::Done(std::string const &Message,
HashStringList const &Hashes,
if (AuthPass == false)
{
- if (Status == StatAuthError)
+ if (Status == StatAuthError || Status == StatTransientNetworkError)
{
- // if we expected a ClearTextSignature (InRelease) and got a file,
- // but it wasn't valid we end up here (see VerifyDone).
+ // if we expected a ClearTextSignature (InRelease) but got a network
+ // error or got a file, but it wasn't valid, we end up here (see VerifyDone).
// As these is usually called by web-portals we do not try Release/Release.gpg
// as this is gonna fail anyway and instead abort our try (LP#346386)
TransactionManager->AbortTransaction();
if(CheckStopAuthentication(this, Message))
return;
- _error->Warning(_("The data from '%s' is not signed. Packages "
- "from that repository can not be authenticated."),
- ClearsignedTarget.Description.c_str());
-
// No Release file was present, or verification failed, so fall
// back to queueing Packages files without verification
// only allow going further if the users explicitely wants it
- if(AllowInsecureRepositories(TransactionManager->MetaIndexParser, TransactionManager, this) == true)
+ if(AllowInsecureRepositories(_("The repository '%s' is not signed."), ClearsignedTarget.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
{
Status = StatDone;
pkgAcquire::Item::Failed(Message, Cnf);
Status = StatDone;
- _error->Warning(_("The repository '%s' does not have a Release file. "
- "This is deprecated, please contact the owner of the "
- "repository."), Target.Description.c_str());
-
// No Release file was present so fall
// back to queueing Packages files without verification
// only allow going further if the users explicitely wants it
- if(AllowInsecureRepositories(TransactionManager->MetaIndexParser, TransactionManager, this) == true)
+ if(AllowInsecureRepositories(_("The repository '%s' does not have a Release file."), Target.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
{
// ensure old Release files are removed
TransactionManager->TransactionStageRemoval(this, GetFinalFilename());
"given to override it."));
Status = StatDone;
} else {
- _error->Error("%s", downgrade_msg.c_str());
+ MessageInsecureRepository(true, downgrade_msg);
if (TransactionManager->IMSHit == false)
Rename(MetaIndex->DestFile, MetaIndex->DestFile + ".FAILED");
Item::Failed("Message: " + downgrade_msg, Cnf);
return;
}
}
- else
- _error->Warning(_("The data from '%s' is not signed. Packages "
- "from that repository can not be authenticated."),
- MetaIndex->Target.Description.c_str());
// ensures that a Release.gpg file in the lists/ is removed by the transaction
TransactionManager->TransactionStageRemoval(this, DestFile);
// only allow going further if the users explicitely wants it
- if(AllowInsecureRepositories(TransactionManager->MetaIndexParser, TransactionManager, this) == true)
+ if (AllowInsecureRepositories(_("The repository '%s' is not signed."), MetaIndex->Target.Description, TransactionManager->MetaIndexParser, TransactionManager, this) == true)
{
if (RealFileExists(FinalReleasegpg) || RealFileExists(FinalInRelease))
{
FileFd Fd(IndexDiffFile,FileFd::ReadOnly);
pkgTagFile TF(&Fd);
- if (_error->PendingError() == true)
+ if (Fd.IsOpen() == false || Fd.Failed())
return false;
pkgTagSection Tags;
}
/*}}}*/
// AcqIndex::Init - defered Constructor /*{{{*/
-void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
- string const &ShortDesc)
+static void NextCompressionExtension(std::string &CurrentCompressionExtension, std::string &CompressionExtensions, bool const preview)
{
- Stage = STAGE_DOWNLOAD;
-
- DestFile = GetPartialFileNameFromURI(URI);
-
size_t const nextExt = CompressionExtensions.find(' ');
if (nextExt == std::string::npos)
{
CurrentCompressionExtension = CompressionExtensions;
- CompressionExtensions.clear();
+ if (preview == false)
+ CompressionExtensions.clear();
}
else
{
CurrentCompressionExtension = CompressionExtensions.substr(0, nextExt);
- CompressionExtensions = CompressionExtensions.substr(nextExt+1);
+ if (preview == false)
+ CompressionExtensions = CompressionExtensions.substr(nextExt+1);
}
+}
+void pkgAcqIndex::Init(string const &URI, string const &URIDesc,
+ string const &ShortDesc)
+{
+ Stage = STAGE_DOWNLOAD;
+
+ DestFile = GetPartialFileNameFromURI(URI);
+ NextCompressionExtension(CurrentCompressionExtension, CompressionExtensions, false);
if (CurrentCompressionExtension == "uncompressed")
{
Desc.URI = URI;
}
+ else if (CurrentCompressionExtension == "by-hash")
+ {
+ NextCompressionExtension(CurrentCompressionExtension, CompressionExtensions, true);
+ if(unlikely(TransactionManager->MetaIndexParser == NULL || CurrentCompressionExtension.empty()))
+ return;
+ if (CurrentCompressionExtension != "uncompressed")
+ {
+ Desc.URI = URI + '.' + CurrentCompressionExtension;
+ DestFile = DestFile + '.' + CurrentCompressionExtension;
+ }
+
+ HashStringList const Hashes = GetExpectedHashes();
+ HashString const * const TargetHash = Hashes.find(NULL);
+ if (unlikely(TargetHash == nullptr))
+ return;
+ std::string const ByHash = "/by-hash/" + TargetHash->HashType() + "/" + TargetHash->HashValue();
+ size_t const trailing_slash = Desc.URI.find_last_of("/");
+ if (unlikely(trailing_slash == std::string::npos))
+ return;
+ Desc.URI = Desc.URI.replace(
+ trailing_slash,
+ Desc.URI.substr(trailing_slash+1).size()+1,
+ ByHash);
+ }
else if (unlikely(CurrentCompressionExtension.empty()))
return;
else
DestFile = DestFile + '.' + CurrentCompressionExtension;
}
- if(TransactionManager->MetaIndexParser != NULL)
- InitByHashIfNeeded();
Desc.Description = URIDesc;
Desc.Owner = this;
QueueURI(Desc);
}
/*}}}*/
-// AcqIndex::AdjustForByHash - modify URI for by-hash support /*{{{*/
-void pkgAcqIndex::InitByHashIfNeeded()
-{
- // TODO:
- // - (maybe?) add support for by-hash into the sources.list as flag
- // - make apt-ftparchive generate the hashes (and expire?)
- std::string HostKnob = "APT::Acquire::" + ::URI(Desc.URI).Host + "::By-Hash";
- if(_config->FindB("APT::Acquire::By-Hash", false) == true ||
- _config->FindB(HostKnob, false) == true ||
- TransactionManager->MetaIndexParser->GetSupportsAcquireByHash())
- {
- HashStringList const Hashes = GetExpectedHashes();
- if(Hashes.usable())
- {
- // FIXME: should we really use the best hash here? or a fixed one?
- HashString const * const TargetHash = Hashes.find("");
- std::string const ByHash = "/by-hash/" + TargetHash->HashType() + "/" + TargetHash->HashValue();
- size_t const trailing_slash = Desc.URI.find_last_of("/");
- Desc.URI = Desc.URI.replace(
- trailing_slash,
- Desc.URI.substr(trailing_slash+1).size()+1,
- ByHash);
- } else {
- _error->Warning(
- "Fetching ByHash requested but can not find record for %s",
- GetMetaKey().c_str());
- }
- }
-}
- /*}}}*/
// AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/
// ---------------------------------------------------------------------
/* The only header we use is the last-modified header. */
// Methods like e.g. "file:" will give us a (compressed) FileName that is
// not the "DestFile" we set, in this case we uncompress from the local file
if (FileName != DestFile && RealFileExists(DestFile) == false)
+ {
Local = true;
+ if (Target.KeepCompressed == true)
+ {
+ // but if we don't keep the uncompress we copy the compressed file first
+ Stage = STAGE_DOWNLOAD;
+ Desc.URI = "copy:" + FileName;
+ QueueURI(Desc);
+ SetActiveSubprocess("copy");
+ return;
+ }
+ }
else
EraseFileName = FileName;
return;
}
- // If we want compressed indexes, just copy in place for hash verification
- if (Target.KeepCompressed == true)
- {
- DestFile = GetPartialFileNameFromURI(Target.URI + '.' + CurrentCompressionExtension);
- EraseFileName = "";
- Stage = STAGE_DECOMPRESS_AND_VERIFY;
- Desc.URI = "copy:" + FileName;
- QueueURI(Desc);
- SetActiveSubprocess("copy");
- return;
- }
-
// get the binary name for your used compression type
string decompProg;
if(CurrentCompressionExtension == "uncompressed")
return;
}
+ if (Target.KeepCompressed == true)
+ {
+ DestFile = "/dev/null";
+ EraseFileName.clear();
+ }
+ else
+ DestFile += ".decomp";
+
// queue uri for the next stage
Stage = STAGE_DECOMPRESS_AND_VERIFY;
- DestFile += ".decomp";
Desc.URI = decompProg + ":" + FileName;
QueueURI(Desc);
SetActiveSubprocess(decompProg);
HashStringList const &,
pkgAcquire::MethodConfig const * const)
{
+ if (Target.KeepCompressed == true && DestFile == "/dev/null")
+ DestFile = GetPartialFileNameFromURI(Target.URI + '.' + CurrentCompressionExtension);
+
// Done, queue for rename on transaction finished
TransactionManager->TransactionStageCopy(this, DestFile, GetFinalFilename());
return;
_error->PushToStack();
_error->Errno("pkgAcqFile::Done", "Symlinking file %s failed", DestFile.c_str());
std::stringstream msg;
- _error->DumpErrors(msg);
+ _error->DumpErrors(msg, GlobalError::DEBUG, false);
_error->RevertToStack();
ErrorText = msg.str();
Status = StatError;