From 48cbc5413fb2a0e490c2282b9df65da96ad7a9f2 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 17 May 2023 17:18:33 +0200 Subject: Seed snapshot servers for well-known hosts This will attempt to fallback to a per-server setting if we could not determine a value from the release file. --- apt-pkg/deb/debmetaindex.cc | 40 +++++++++++---- apt-pkg/init.cc | 7 +++ doc/examples/configure-index | 1 + test/integration/test-snapshot | 111 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 149 insertions(+), 10 deletions(-) diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 4133540ab..ddc246349 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1295,20 +1295,42 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ Options.emplace("SHADOWED", "true"); + ::URI ArchiveURI(URI); + // Trim trailing and leading / from the path because we don't want them when calculating snapshot url + if (not ArchiveURI.Path.empty() && ArchiveURI.Path[ArchiveURI.Path.length() - 1] == '/') + ArchiveURI.Path.erase(ArchiveURI.Path.length() - 1); + if (not ArchiveURI.Path.empty() && ArchiveURI.Path[0] == '/') + ArchiveURI.Path.erase(0, 1); + std::string Server; + auto const Deb = GetDebReleaseIndexBy(List, URI, Dist, Options); std::string filename; - if (not ReleaseFileName(Deb, filename)) - return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); - auto OldDeb = dynamic_cast(Deb->UnloadedClone()); - if (not OldDeb->Load(filename, nullptr)) - return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); - auto Server = SnapshotServer(OldDeb); - delete OldDeb; + // The Release file and config based on that should be the ultimate source of truth. + if (ReleaseFileName(Deb, filename)) + { + auto OldDeb = dynamic_cast(Deb->UnloadedClone()); + if (not OldDeb->Load(filename, nullptr)) + return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); + Server = SnapshotServer(OldDeb); + delete OldDeb; + } if (Server.empty()) + { + // We did not find a server based on the release file. + // Lookup a fallback based on the host. For a.b.c, this will try a.b.c, .b.c, and .c to allow generalization for cc.archive.ubuntu.com + for (std::string Host = ArchiveURI.Host; not Host.empty() && Server.empty(); Host = Host.find(".", 1) != Host.npos ? Host.substr(Host.find(".", 1)) : "") + Server = _config->Find("Acquire::Snapshots::URI::Host::" + Host); + if (Server == "no") + Server = ""; + } + if (Server.empty()) + { + if (filename.empty()) + return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); return _error->Error("Snapshots not supported for %s %s", URI.c_str(), Dist.c_str()); - - auto SnapshotURI = SubstVar(Server, "@SNAPSHOTID@", Snapshot); + } + auto SnapshotURI = SubstVar(SubstVar(Server, "@SNAPSHOTID@", Snapshot), "@PATH@", ArchiveURI.Path); if (not CreateItemInternalOne(List, SnapshotURI, Dist, Section, IsSrc, SnapshotOptions)) return false; diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index f70dbf308..3990a1f39 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -212,6 +212,13 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.CndSet("Acquire::Snapshots::URI::Origin::Debian", "https://snapshot.debian.org/archive/debian/@SNAPSHOTID@/"); Cnf.CndSet("Acquire::Snapshots::URI::Override::Label::Debian-Security", "https://snapshot.debian.org/archive/debian-security/@SNAPSHOTID@/"); Cnf.CndSet("Acquire::Snapshots::URI::Origin::Ubuntu", "https://snapshot.ubuntu.com/ubuntu/@SNAPSHOTID@/"); + // Preseeds by host + Cnf.CndSet("Acquire::Snapshots::URI::Host::archive.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::deb.debian.org", "https://snapshot.debian.org/archive/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::.archive.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::security.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::ppa.launchpadcontent.net", "https://snapshot.ppa.launchpadcontent.net/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::ppa.launchpad.net", "https://snapshot.ppa.launchpadcontent.net/@PATH@/@SNAPSHOTID@/"); Cnf.CndSet("DPkg::Path", "/usr/sbin:/usr/bin:/sbin:/bin"); diff --git a/doc/examples/configure-index b/doc/examples/configure-index index e6d7c31ea..d220a814f 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -403,6 +403,7 @@ Acquire }; Snapshots::URI { + Host::* ""; // Origin::Debian "https://snapshot.debian.org/snapshot/@SNAPSHOTID@/"; Origin::* ""; Label::* ""; diff --git a/test/integration/test-snapshot b/test/integration/test-snapshot index 609e3ade0..e32b91daf 100755 --- a/test/integration/test-snapshot +++ b/test/integration/test-snapshot @@ -138,6 +138,20 @@ testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' local 'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_binary-all_Packages 0 'http://localhost:${APTHTTPPORT}/snapshot/BANANA/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_snapshot_BANANA_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris -o Acquire::Snapshots::URI::Label::Debian="http://localhost:${APTHTTPPORT}/snapshot/@SNAPSHOTID@/" -SBANANA +msgmsg "Origin: Unknown" +releasechanger 'Origin' 'Unknown' +# XXX: @PATH@ is empty here so we have //, there isn't much we can do here, people don't have to use @PATH@ of course. +testsuccessequal "'https://example.org/snapshots//BANANA/dists/stable/InRelease' example.org_snapshots__BANANA_dists_stable_InRelease 0 +'https://example.org/snapshots//BANANA/dists/stable/main/source/Sources.xz' example.org_snapshots__BANANA_dists_stable_main_source_Sources 0 +'https://example.org/snapshots//BANANA/dists/stable/main/binary-amd64/Packages.xz' example.org_snapshots__BANANA_dists_stable_main_binary-amd64_Packages 0 +'https://example.org/snapshots//BANANA/dists/stable/main/binary-all/Packages.xz' example.org_snapshots__BANANA_dists_stable_main_binary-all_Packages 0 +'https://example.org/snapshots//BANANA/dists/stable/main/i18n/Translation-en.xz' example.org_snapshots__BANANA_dists_stable_main_i18n_Translation-en 0 +'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' localhost:${APTHTTPPORT}_dists_stable_InRelease 0 +'http://localhost:${APTHTTPPORT}/dists/stable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_stable_main_source_Sources 0 +'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-amd64_Packages 0 +'http://localhost:${APTHTTPPORT}/dists/stable/main/binary-all/Packages.xz' localhost:${APTHTTPPORT}_dists_stable_main_binary-all_Packages 0 +'http://localhost:${APTHTTPPORT}/dists/stable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_stable_main_i18n_Translation-en 0 " aptget update --print-uris $option BANANA -o Acquire::Snapshots::URI::Host::localhost="https://example.org/snapshots/@PATH@/@SNAPSHOTID@/" + msgmsg "Snapshots: set in the InRelease file" sed -i '/^Origin: / a\ Snapshots: https://example.org/snapshots/@SNAPSHOTID@/' $(find rootdir/var/lib/apt/lists -name '*Release') @@ -177,6 +191,102 @@ testsuccessequal "'http://localhost:${APTHTTPPORT}/dists/stable/InRelease' local rm rootdir/etc/apt/apt.conf.d/changelog.conf +msgmsg "Testing host-based seed: Ubuntu" + +echo "deb [snapshot=BANANA] http://security.ubuntu.com/ubuntu/ mantic-security main" > rootdir/etc/apt/security.list +testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_InRelease 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-amd64_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_binary-all_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic-security/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic-security_main_i18n_Translation-en 0 +'http://security.ubuntu.com/ubuntu/dists/mantic-security/InRelease' security.ubuntu.com_ubuntu_dists_mantic-security_InRelease 0 +'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-amd64/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-amd64_Packages 0 +'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/binary-all/Packages.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_binary-all_Packages 0 +'http://security.ubuntu.com/ubuntu/dists/mantic-security/main/i18n/Translation-en.xz' security.ubuntu.com_ubuntu_dists_mantic-security_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=security.list -o Dir::Etc::SourceParts=/dev/null +echo "deb [snapshot=BANANA] http://archive.ubuntu.com/ubuntu/ mantic main" > rootdir/etc/apt/archive.list +testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/InRelease' archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null +echo "deb [snapshot=BANANA] http://cc.archive.ubuntu.com/ubuntu/ mantic main" > rootdir/etc/apt/cc.archive.list +testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/InRelease' cc.archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=cc.archive.list -o Dir::Etc::SourceParts=/dev/null + +# with a custom override for .archive.ubuntu.com +testsuccessequal "'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 +'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://cc.snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' cc.snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/InRelease' cc.archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 +'http://cc.archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' cc.archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=cc.archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::.archive.ubuntu.com"="https://cc.snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/" + +testsuccessequal "'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/InRelease' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_InRelease 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://snapshot.ubuntu.com/ubuntu/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ubuntu.com_ubuntu_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/InRelease' archive.ubuntu.com_ubuntu_dists_mantic_InRelease 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-amd64/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-amd64_Packages 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/binary-all/Packages.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_binary-all_Packages 0 +'http://archive.ubuntu.com/ubuntu/dists/mantic/main/i18n/Translation-en.xz' archive.ubuntu.com_ubuntu_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::.archive.ubuntu.com"="https://cc.snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/" + +testfailure "E: Snapshots not supported for http://archive.ubuntu.com/ubuntu/ mantic +E: The list of sources could not be read." aptget update --print-uris -o Dir::Etc::SourceList=archive.list -o Dir::Etc::SourceParts=/dev/null -o "Acquire::Snapshots::URI::Host::archive.ubuntu.com"="no" + +msgmsg "Testing host based-seeds: PPA" + +echo "deb [snapshot=BANANA] http://ppa.launchpad.net/owner/archive/distribution/ mantic main" > rootdir/etc/apt/ppa.list +testsuccessequal "'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/InRelease' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_InRelease 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/InRelease' ppa.launchpad.net_owner_archive_distribution_dists_mantic_InRelease 0 +'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/binary-amd64/Packages.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_binary-amd64_Packages 0 +'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/binary-all/Packages.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_binary-all_Packages 0 +'http://ppa.launchpad.net/owner/archive/distribution/dists/mantic/main/i18n/Translation-en.xz' ppa.launchpad.net_owner_archive_distribution_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=ppa.list -o Dir::Etc::SourceParts=/dev/null + +echo "deb [snapshot=BANANA] http://ppa.launchpadcontent.net/owner/archive/distribution/ mantic main" > rootdir/etc/apt/ppa.list +testsuccessequal "'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/InRelease' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_InRelease 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-amd64/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-amd64_Packages 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/binary-all/Packages.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_binary-all_Packages 0 +'https://snapshot.ppa.launchpadcontent.net/owner/archive/distribution/BANANA/dists/mantic/main/i18n/Translation-en.xz' snapshot.ppa.launchpadcontent.net_owner_archive_distribution_BANANA_dists_mantic_main_i18n_Translation-en 0 +'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/InRelease' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_InRelease 0 +'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/binary-amd64/Packages.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_binary-amd64_Packages 0 +'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/binary-all/Packages.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_binary-all_Packages 0 +'http://ppa.launchpadcontent.net/owner/archive/distribution/dists/mantic/main/i18n/Translation-en.xz' ppa.launchpadcontent.net_owner_archive_distribution_dists_mantic_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=ppa.list -o Dir::Etc::SourceParts=/dev/null + +msgmsg "Testing host based-seeds: Debian" + +echo "deb [snapshot=BANANA] http://deb.debian.org/debian/ unstable main" > rootdir/etc/apt/debian.list +testsuccessequal "'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/InRelease' snapshot.debian.org_archive_debian_BANANA_dists_unstable_InRelease 0 +'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_binary-amd64_Packages 0 +'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_binary-all_Packages 0 +'https://snapshot.debian.org/archive/debian/BANANA/dists/unstable/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian_BANANA_dists_unstable_main_i18n_Translation-en 0 +'http://deb.debian.org/debian/dists/unstable/InRelease' deb.debian.org_debian_dists_unstable_InRelease 0 +'http://deb.debian.org/debian/dists/unstable/main/binary-amd64/Packages.xz' deb.debian.org_debian_dists_unstable_main_binary-amd64_Packages 0 +'http://deb.debian.org/debian/dists/unstable/main/binary-all/Packages.xz' deb.debian.org_debian_dists_unstable_main_binary-all_Packages 0 +'http://deb.debian.org/debian/dists/unstable/main/i18n/Translation-en.xz' deb.debian.org_debian_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=debian.list -o Dir::Etc::SourceParts=/dev/null + +echo "deb [snapshot=BANANA] http://deb.debian.org/debian-security/ stable-security main" > rootdir/etc/apt/debian-security.list +testsuccessequal "'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/InRelease' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_InRelease 0 +'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/binary-amd64/Packages.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_binary-amd64_Packages 0 +'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/binary-all/Packages.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_binary-all_Packages 0 +'https://snapshot.debian.org/archive/debian-security/BANANA/dists/stable-security/main/i18n/Translation-en.xz' snapshot.debian.org_archive_debian-security_BANANA_dists_stable-security_main_i18n_Translation-en 0 +'http://deb.debian.org/debian-security/dists/stable-security/InRelease' deb.debian.org_debian-security_dists_stable-security_InRelease 0 +'http://deb.debian.org/debian-security/dists/stable-security/main/binary-amd64/Packages.xz' deb.debian.org_debian-security_dists_stable-security_main_binary-amd64_Packages 0 +'http://deb.debian.org/debian-security/dists/stable-security/main/binary-all/Packages.xz' deb.debian.org_debian-security_dists_stable-security_main_binary-all_Packages 0 +'http://deb.debian.org/debian-security/dists/stable-security/main/i18n/Translation-en.xz' deb.debian.org_debian-security_dists_stable-security_main_i18n_Translation-en 0 " aptget update --print-uris -o Dir::Etc::SourceList=debian-security.list -o Dir::Etc::SourceParts=/dev/null + exit 0 msgmsg "Failure cases" @@ -188,4 +298,3 @@ testequal "E: Failed to fetch http://localhost:${APTHTTPPORT}/does/not/exist/mai aptget update -o Acquire::Snapshots::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/does/not/exist/@SNAPSHOTID@" -SBANANA - -- cgit v1.2.3-70-g09d2 From 4e35e5079f589700b4b5f1fc00787144bc1c58bf Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 24 May 2023 11:07:26 +0200 Subject: Ensure that Snapshots: no doesn't get overriden by host-name config --- apt-pkg/deb/debmetaindex.cc | 10 +++------- test/integration/test-snapshot | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index ddc246349..4bd7dfa78 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1261,9 +1261,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ #define APT_EMPTY_SERVER \ if (server.empty() == false) \ { \ - if (server != "no") \ - return server; \ - return ""; \ + return server; \ } #define APT_CHECK_SERVER(X, Y) \ if (not Rls->Get##X().empty()) \ @@ -1321,12 +1319,10 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ // Lookup a fallback based on the host. For a.b.c, this will try a.b.c, .b.c, and .c to allow generalization for cc.archive.ubuntu.com for (std::string Host = ArchiveURI.Host; not Host.empty() && Server.empty(); Host = Host.find(".", 1) != Host.npos ? Host.substr(Host.find(".", 1)) : "") Server = _config->Find("Acquire::Snapshots::URI::Host::" + Host); - if (Server == "no") - Server = ""; } - if (Server.empty()) + if (Server.empty() || Server == "no") { - if (filename.empty()) + if (Server != "no" && filename.empty()) return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); return _error->Error("Snapshots not supported for %s %s", URI.c_str(), Dist.c_str()); } diff --git a/test/integration/test-snapshot b/test/integration/test-snapshot index e32b91daf..2bf7d70d4 100755 --- a/test/integration/test-snapshot +++ b/test/integration/test-snapshot @@ -173,6 +173,10 @@ testfailuremsg "E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable E: The list of sources could not be read." aptget update --print-uris -S BANANA +testfailuremsg "E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable +E: Snapshots not supported for http://localhost:${APTHTTPPORT}/ stable +E: The list of sources could not be read." aptget update --print-uris -S BANANA -o Acquire::Snapshots::URI::Host::localhost="https://example.org/snapshots/@PATH@/@SNAPSHOTID@/" + msgmsg "Snapshot URI configured in apt.conf" sed -i '/^Snapshots: / d' $(find rootdir/var/lib/apt/lists -name '*Release') releasechanger 'Label' 'Testcases' -- cgit v1.2.3-70-g09d2 From 4000ee2f9064623e096d975489aec35c99982437 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 24 May 2023 11:22:34 +0200 Subject: Rework the domain iteration in the host fallback Separate the determination of the next level domain into its own function and split out the "we found a result" into its own break for improved readability. --- apt-pkg/deb/debmetaindex.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 4bd7dfa78..ef6bce261 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1283,6 +1283,16 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ #undef APT_EMPTY_SERVER return ""; } + + /// \brief Given a hostname, strip one level down, e.g. a.b.c -> .b.c -> .c, this + /// allows you to match a.b.c against itself, .b.c, and .c, but not b.c + static inline std::string NextLevelDomain(std::string Host) + { + auto nextDot = Host.find(".", 1); + if (nextDot == Host.npos) + return ""; + return Host.substr(nextDot); + } bool CreateItemInternal(std::vector &List, std::string URI, std::string const &Dist, std::string const &Section, bool const &IsSrc, std::map Options) const @@ -1313,12 +1323,17 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ Server = SnapshotServer(OldDeb); delete OldDeb; } + // We did not find a server based on the release file. + // Lookup a fallback based on the host. For a.b.c, this will + // try a.b.c, .b.c, and .c to allow generalization for cc.archive.ubuntu.com if (Server.empty()) { - // We did not find a server based on the release file. - // Lookup a fallback based on the host. For a.b.c, this will try a.b.c, .b.c, and .c to allow generalization for cc.archive.ubuntu.com - for (std::string Host = ArchiveURI.Host; not Host.empty() && Server.empty(); Host = Host.find(".", 1) != Host.npos ? Host.substr(Host.find(".", 1)) : "") + for (std::string Host = ArchiveURI.Host; not Host.empty(); Host = NextLevelDomain(Host)) + { Server = _config->Find("Acquire::Snapshots::URI::Host::" + Host); + if (not Server.empty()) + break; + } } if (Server.empty() || Server == "no") { -- cgit v1.2.3-70-g09d2