X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/95278287f4e1eeaf5d96749d6fc9bfc53fb400d0..607bab3fe856d228f22e1cd96dbb7204e2f3375d:/apt-pkg/deb/debmetaindex.cc diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 6ed722e68..97f881269 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -39,6 +39,7 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ std::vector Architectures; std::vector Languages; bool UsePDiffs; + std::string UseByHash; }; std::vector DebEntries; @@ -48,6 +49,9 @@ class APT_HIDDEN debReleaseIndexPrivate /*{{{*/ time_t ValidUntilMin; time_t ValidUntilMax; + std::vector Architectures; + std::vector NoSupportForAll; + debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {} }; /*}}}*/ @@ -134,6 +138,21 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, DefCompressionTypes = os.str(); } } + std::string DefKeepCompressedAs; + { + std::vector comps = APT::Configuration::getCompressors(); + if (comps.empty() == false) + { + std::sort(comps.begin(), comps.end(), + [](APT::Configuration::Compressor const &a, APT::Configuration::Compressor const &b) { return a.Cost < b.Cost; }); + std::ostringstream os; + for (auto const &c : comps) + if (c.Cost != 0) + os << c.Extension.substr(1) << ' '; + DefKeepCompressedAs = os.str(); + } + DefKeepCompressedAs += "uncompressed"; + } std::string const NativeArch = _config->Find("APT::Architecture"); bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false); for (std::vector::const_iterator E = entries.begin(); E != entries.end(); ++E) @@ -149,12 +168,37 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, bool const KeepCompressed = APT_T_CONFIG_BOOL("KeepCompressed", GzipIndex); bool const DefaultEnabled = APT_T_CONFIG_BOOL("DefaultEnabled", true); bool const UsePDiffs = APT_T_CONFIG_BOOL("PDiffs", E->UsePDiffs); + std::string const UseByHash = APT_T_CONFIG_STR("By-Hash", E->UseByHash); std::string const CompressionTypes = APT_T_CONFIG_STR("CompressionTypes", DefCompressionTypes); + std::string KeepCompressedAs = APT_T_CONFIG_STR("KeepCompressedAs", ""); #undef APT_T_CONFIG_BOOL #undef APT_T_CONFIG_STR if (tplMetaKey.empty()) continue; + if (KeepCompressedAs.empty()) + KeepCompressedAs = DefKeepCompressedAs; + else + { + std::vector const defKeep = VectorizeString(DefKeepCompressedAs, ' '); + std::vector const valKeep = VectorizeString(KeepCompressedAs, ' '); + std::vector keep; + for (auto const &val : valKeep) + { + if (val.empty()) + continue; + if (std::find(defKeep.begin(), defKeep.end(), val) == defKeep.end()) + continue; + keep.push_back(val); + } + if (std::find(keep.begin(), keep.end(), "uncompressed") == keep.end()) + keep.push_back("uncompressed"); + std::ostringstream os; + std::copy(keep.begin(), keep.end()-1, std::ostream_iterator(os, " ")); + os << *keep.rbegin(); + KeepCompressedAs = os.str(); + } + for (std::vector::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L) { if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos) @@ -245,16 +289,26 @@ static void GetIndexTargetsFor(char const * const Type, std::string const &URI, Options.insert(std::make_pair("TARGET_OF", Type)); Options.insert(std::make_pair("CREATED_BY", *T)); Options.insert(std::make_pair("PDIFFS", UsePDiffs ? "yes" : "no")); + Options.insert(std::make_pair("BY_HASH", UseByHash)); Options.insert(std::make_pair("DEFAULTENABLED", DefaultEnabled ? "yes" : "no")); Options.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes)); + Options.insert(std::make_pair("KEEPCOMPRESSEDAS", KeepCompressedAs)); Options.insert(std::make_pair("SOURCESENTRY", E->sourcesEntry)); + bool IsOpt = IsOptional; + if (IsOpt == false) + { + auto const arch = Options.find("ARCHITECTURE"); + if (arch != Options.end() && arch->second == "all") + IsOpt = true; + } + IndexTarget Target( MetaKey, ShortDesc, LongDesc, Options.find("BASE_URI")->second + MetaKey, - IsOptional, + IsOpt, KeepCompressed, Options ); @@ -286,12 +340,12 @@ void debReleaseIndex::AddComponent(std::string const &sourcesEntry, /*{{{*/ std::vector const &Targets, std::vector const &Architectures, std::vector Languages, - bool const usePDiffs) + bool const usePDiffs, std::string const &useByHash) { if (Languages.empty() == true) Languages.push_back("none"); debReleaseIndexPrivate::debSectionEntry const entry = { - sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs + sourcesEntry, Name, Targets, Architectures, Languages, usePDiffs, useByHash }; if (isSrc) d->DebSrcEntries.push_back(entry); @@ -328,11 +382,23 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro Suite = Section.FindS("Suite"); Codename = Section.FindS("Codename"); + { + std::string const archs = Section.FindS("Architectures"); + if (archs.empty() == false) + d->Architectures = VectorizeString(archs, ' '); + } + { + std::string const targets = Section.FindS("No-Support-for-Architecture-all"); + if (targets.empty() == false) + d->NoSupportForAll = VectorizeString(targets, ' '); + } bool FoundHashSum = false; - for (int i=0;HashString::SupportedHashes()[i] != NULL; i++) + bool FoundStrongHashSum = false; + auto const SupportedHashes = HashString::SupportedHashes(); + for (int i=0; SupportedHashes[i] != NULL; i++) { - if (!Section.Find(HashString::SupportedHashes()[i], Start, End)) + if (!Section.Find(SupportedHashes[i], Start, End)) continue; std::string Name; @@ -343,17 +409,20 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro if (!parseSumData(Start, End, Name, Hash, Size)) return false; + HashString const hs(SupportedHashes[i], Hash); if (Entries.find(Name) == Entries.end()) { metaIndex::checkSum *Sum = new metaIndex::checkSum; Sum->MetaKeyFilename = Name; Sum->Size = Size; Sum->Hashes.FileSize(Size); - APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);) + APT_IGNORE_DEPRECATED(Sum->Hash = hs;) Entries[Name] = Sum; } - Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash)); + Entries[Name]->Hashes.push_back(hs); FoundHashSum = true; + if (FoundStrongHashSum == false && hs.usable() == true) + FoundStrongHashSum = true; } } @@ -363,13 +432,18 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); return false; } + if(FoundStrongHashSum == false) + { + if (ErrorText != NULL) + strprintf(*ErrorText, _("No Hash entry in Release file %s, which is considered strong enough for security purposes"), Filename.c_str()); + return false; + } std::string const StrDate = Section.FindS("Date"); if (RFC1123StrToTime(StrDate.c_str(), Date) == false) { - if (ErrorText != NULL) - strprintf(*ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); - return false; + _error->Warning( _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + Date = 0; } bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true); @@ -409,15 +483,18 @@ bool debReleaseIndex::Load(std::string const &Filename, std::string * const Erro MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge); } - if (MinAge != 0 && ValidUntil != 0) { - time_t const min_date = Date + MinAge; - if (ValidUntil < min_date) - ValidUntil = min_date; - } - if (MaxAge != 0) { - time_t const max_date = Date + MaxAge; - if (ValidUntil == 0 || ValidUntil > max_date) - ValidUntil = max_date; + if (MinAge != 0 || ValidUntil != 0 || MaxAge != 0) + { + if (MinAge != 0 && ValidUntil != 0) { + time_t const min_date = Date + MinAge; + if (ValidUntil < min_date) + ValidUntil = min_date; + } + if (MaxAge != 0 && Date != 0) { + time_t const max_date = Date + MaxAge; + if (ValidUntil == 0 || ValidUntil > max_date) + ValidUntil = max_date; + } } } @@ -518,7 +595,7 @@ bool debReleaseIndex::SetTrusted(TriState const pTrusted) Trusted = pTrusted; else if (Trusted != pTrusted) // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite - return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); + return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Trusted", URI.c_str(), Dist.c_str()); return true; } bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil) @@ -526,7 +603,7 @@ bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil) if (d->CheckValidUntil == TRI_UNSET) d->CheckValidUntil = pCheckValidUntil; else if (d->CheckValidUntil != pCheckValidUntil) - return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str()); + return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str()); return true; } bool debReleaseIndex::SetValidUntilMin(time_t const Valid) @@ -534,7 +611,7 @@ bool debReleaseIndex::SetValidUntilMin(time_t const Valid) if (d->ValidUntilMin == 0) d->ValidUntilMin = Valid; else if (d->ValidUntilMin != Valid) - return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str()); + return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str()); return true; } bool debReleaseIndex::SetValidUntilMax(time_t const Valid) @@ -542,7 +619,7 @@ bool debReleaseIndex::SetValidUntilMax(time_t const Valid) if (d->ValidUntilMax == 0) d->ValidUntilMax = Valid; else if (d->ValidUntilMax != Valid) - return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str()); + return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str()); return true; } bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy) @@ -560,12 +637,12 @@ bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy) finger.erase(std::remove(finger.begin(), finger.end(), ' '), finger.end()); std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper); if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos) - return _error->Error(_("Invalid value set for option %s concerning source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint"); + return _error->Error(_("Invalid value set for option %s regarding source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint"); } SignedBy = pSignedBy; } else if (SignedBy != pSignedBy) - return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI.c_str(), Dist.c_str()); + return _error->Error(_("Conflicting values set for option %s regarding source %s %s"), "Signed-By", URI.c_str(), Dist.c_str()); return true; } /*}}}*/ @@ -588,6 +665,20 @@ bool debReleaseIndex::IsTrusted() const return FileExists(MetaIndexFile("InRelease")); } /*}}}*/ +bool debReleaseIndex::IsArchitectureSupported(std::string const &arch) const/*{{{*/ +{ + if (d->Architectures.empty()) + return true; + return std::find(d->Architectures.begin(), d->Architectures.end(), arch) != d->Architectures.end(); +} + /*}}}*/ +bool debReleaseIndex::IsArchitectureAllSupportedFor(IndexTarget const &target) const/*{{{*/ +{ + if (d->NoSupportForAll.empty()) + return true; + return std::find(d->NoSupportForAll.begin(), d->NoSupportForAll.end(), target.Option(IndexTarget::CREATED_BY)) == d->NoSupportForAll.end(); +} + /*}}}*/ std::vector *debReleaseIndex::GetIndexFiles() /*{{{*/ { if (Indexes != NULL) @@ -726,6 +817,10 @@ static std::vector parsePlusMinusOptions(std::string const &Name, / else Values = defaultValues; + // all is a very special architecture users shouldn't be concerned with explicitly + if (Name == "arch" && std::find(Values.begin(), Values.end(), "all") == Values.end()) + Values.push_back("all"); + if ((val = Options.find(Name + "+")) != Options.end()) { std::vector const plus = VectorizeString(val->second, ','); @@ -822,6 +917,17 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ UsePDiffs = StringToBool(opt->second); } + std::string UseByHash = _config->Find("APT::Acquire::By-Hash", "yes"); + UseByHash = _config->Find("Acquire::By-Hash", UseByHash); + { + std::string const host = ::URI(URI).Host; + UseByHash = _config->Find("APT::Acquire::" + host + "::By-Hash", UseByHash); + UseByHash = _config->Find("Acquire::" + host + "::By-Hash", UseByHash); + std::map::const_iterator const opt = Options.find("by-hash"); + if (opt != Options.end()) + UseByHash = opt->second; + } + auto const entry = Options.find("sourceslist-entry"); Deb->AddComponent( entry->second, @@ -830,7 +936,8 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ mytargets, parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()), parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true)), - UsePDiffs + UsePDiffs, + UseByHash ); if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||