From e1430400bf012ab7e29b00c78796a14ce9f97107 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 29 May 2010 12:04:51 +0200 Subject: * apt-pkg/indexrecords.{cc,h}: - add a constant Exists check for MetaKeys * apt-pkg/acquire-item.cc: - do not try PDiff if it is not listed in the Meta file --- apt-pkg/indexrecords.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'apt-pkg/indexrecords.cc') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1fc27b1a1..9a9600531 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -31,6 +31,11 @@ const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) return Entries[MetaKey]; } +bool indexRecords::Exists(string const &MetaKey) const +{ + return Entries.count(MetaKey) == 1; +} + bool indexRecords::Load(const string Filename) /*{{{*/ { FileFd Fd(Filename, FileFd::ReadOnly); -- cgit v1.2.3 From 1ddb859611d2e0f3d9ea12085001810f689e8c99 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 19:27:49 +0200 Subject: * apt-pkg/indexrecords.cc: - backport forgotten Valid-Until patch from the obsolete experimental branch to prevent replay attacks better, thanks to Thomas Viehmann for the initial patch! (Closes: #499897) --- apt-pkg/indexrecords.cc | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'apt-pkg/indexrecords.cc') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1fc27b1a1..24ed02ba5 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -7,8 +7,11 @@ #include #include #include +#include #include #include +#include + /*}}}*/ string indexRecords::GetDist() const { @@ -26,6 +29,11 @@ string indexRecords::GetExpectedDist() const return this->ExpectedDist; } +time_t indexRecords::GetValidUntil() const +{ + return this->ValidUntil; +} + const indexRecords::checkSum *indexRecords::Lookup(const string MetaKey) { return Entries[MetaKey]; @@ -82,7 +90,33 @@ bool indexRecords::Load(const string Filename) /*{{{*/ return false; } - string Strdate = Section.FindS("Date"); // FIXME: verify this somehow? + string Label = Section.FindS("Label"); + string StrDate = Section.FindS("Date"); + string StrValidUntil = Section.FindS("Valid-Until"); + + // if we have a Valid-Until header, use it + if (!StrValidUntil.empty()) + { + // set ValidUntil based on the information in the Release file + if(!StrToTime(StrValidUntil, ValidUntil)) + { + ErrorText = _(("Invalid 'Valid-Until' entry in Release file " + Filename).c_str()); + return false; + } + } else { + // if we don't have a valid-until string, check if we have a default + if (!Label.empty()) + { + int MaxAge = _config->FindI(string("apt::acquire::max-default-age::"+Label).c_str(),0); + if(MaxAge > 0 && !StrToTime(StrDate, ValidUntil)) + { + ErrorText = _(("Invalid 'Date' entry in Release file " + Filename).c_str()); + return false; + } + ValidUntil += 24*60*60*MaxAge; + } + } + return true; } /*}}}*/ @@ -160,6 +194,6 @@ indexRecords::indexRecords() } indexRecords::indexRecords(const string ExpectedDist) : - ExpectedDist(ExpectedDist) + ExpectedDist(ExpectedDist), ValidUntil(0) { } -- cgit v1.2.3 From 0323317c08c0b08bf0ba1ac37a37a8de333cdb40 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 22:55:42 +0200 Subject: enhance the Valid-Until code a bit by using the correct RFC1123StrToTime method and allow for better translations of the error messages --- apt-pkg/indexrecords.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'apt-pkg/indexrecords.cc') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 24ed02ba5..1312e6818 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -91,30 +91,30 @@ bool indexRecords::Load(const string Filename) /*{{{*/ } string Label = Section.FindS("Label"); - string StrDate = Section.FindS("Date"); + string StrDate = Section.FindS("Date"); string StrValidUntil = Section.FindS("Valid-Until"); // if we have a Valid-Until header, use it - if (!StrValidUntil.empty()) + if (StrValidUntil.empty() == false) { // set ValidUntil based on the information in the Release file - if(!StrToTime(StrValidUntil, ValidUntil)) + if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) { - ErrorText = _(("Invalid 'Valid-Until' entry in Release file " + Filename).c_str()); + strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); return false; } } else { // if we don't have a valid-until string, check if we have a default - if (!Label.empty()) + int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + if (Label.empty() == true) + MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::"+Label).c_str(), MaxAge); + + if(MaxAge > 0 && RFC1123StrToTime(StrDate.c_str(), ValidUntil) == false) { - int MaxAge = _config->FindI(string("apt::acquire::max-default-age::"+Label).c_str(),0); - if(MaxAge > 0 && !StrToTime(StrDate, ValidUntil)) - { - ErrorText = _(("Invalid 'Date' entry in Release file " + Filename).c_str()); - return false; - } - ValidUntil += 24*60*60*MaxAge; + strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; } + ValidUntil += 24*60*60*MaxAge; } return true; -- cgit v1.2.3 From bbde96a611f39f5040b332dae1515207db341743 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 8 Jun 2010 23:38:34 +0200 Subject: use the Valid-Until header from the Release file but if the user provides a setting in the configuration prefer the date which is earlier. --- apt-pkg/indexrecords.cc | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'apt-pkg/indexrecords.cc') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index 1312e6818..cdc2897bf 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -88,34 +88,39 @@ bool indexRecords::Load(const string Filename) /*{{{*/ { strprintf(ErrorText, _("No Hash entry in Release file %s"), Filename.c_str()); return false; - } + } string Label = Section.FindS("Label"); string StrDate = Section.FindS("Date"); string StrValidUntil = Section.FindS("Valid-Until"); - // if we have a Valid-Until header, use it + // if we have a Valid-Until header in the Release file, use it as default if (StrValidUntil.empty() == false) { - // set ValidUntil based on the information in the Release file if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false) { strprintf(ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str()); return false; } - } else { - // if we don't have a valid-until string, check if we have a default - int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); - if (Label.empty() == true) - MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::"+Label).c_str(), MaxAge); + } + // get the user settings for this archive and use what expires earlier + int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + if (Label.empty() == true) + MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::" + Label).c_str(), MaxAge); - if(MaxAge > 0 && RFC1123StrToTime(StrDate.c_str(), ValidUntil) == false) - { - strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); - return false; - } - ValidUntil += 24*60*60*MaxAge; + if(MaxAge == 0) // No user settings, use the one from the Release file + return true; + + time_t date; + if (RFC1123StrToTime(StrDate.c_str(), date) == false) + { + strprintf(ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str()); + return false; } + date += 24*60*60*MaxAge; + + if (ValidUntil == 0 || ValidUntil > date) + ValidUntil = date; return true; } -- cgit v1.2.3 From b02fffa64833e1f8e2617669d89de0a6d0882747 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 9 Jun 2010 10:46:35 +0200 Subject: rename the options, document them and reorder the changelog a bit --- apt-pkg/indexrecords.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/indexrecords.cc') diff --git a/apt-pkg/indexrecords.cc b/apt-pkg/indexrecords.cc index cdc2897bf..3bde7437d 100644 --- a/apt-pkg/indexrecords.cc +++ b/apt-pkg/indexrecords.cc @@ -104,9 +104,9 @@ bool indexRecords::Load(const string Filename) /*{{{*/ } } // get the user settings for this archive and use what expires earlier - int MaxAge = _config->FindI("APT::Acquire::Max-Default-Age", 0); + int MaxAge = _config->FindI("Acquire::Max-ValidTime", 0); if (Label.empty() == true) - MaxAge = _config->FindI(string("APT::Acquire::Max-Default-Age::" + Label).c_str(), MaxAge); + MaxAge = _config->FindI(string("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge); if(MaxAge == 0) // No user settings, use the one from the Release file return true; -- cgit v1.2.3