summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/aptconfiguration.cc16
-rw-r--r--apt-pkg/contrib/gpgv.cc2
-rw-r--r--apt-pkg/contrib/proxy.cc19
-rw-r--r--apt-pkg/contrib/strutl.cc113
-rw-r--r--apt-pkg/deb/debmetaindex.cc42
-rw-r--r--apt-pkg/deb/debsystem.cc2
6 files changed, 122 insertions, 72 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 32778e273..68135c926 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -39,8 +39,8 @@ static void setDefaultConfigurationForCompressors() {
_config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
_config->CndSet("Dir::Bin::xz", "/usr/bin/xz");
_config->CndSet("Dir::Bin::lz4", "/usr/bin/lz4");
- if (FileExists(_config->FindFile("Dir::Bin::xz")) == true) {
- _config->Set("Dir::Bin::lzma", _config->FindFile("Dir::Bin::xz"));
+ if (FileExists(_config->Find("Dir::Bin::xz")) == true) {
+ _config->Set("Dir::Bin::lzma", _config->Find("Dir::Bin::xz"));
_config->Set("APT::Compressor::lzma::Binary", "xz");
if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) {
_config->Set("APT::Compressor::lzma::CompressArg::", "--format=lzma");
@@ -125,7 +125,7 @@ const Configuration::getCompressionTypes(bool const &Cached) {
// add the special "uncompressed" type
if (std::find(types.begin(), types.end(), "uncompressed") == types.end())
{
- std::string const uncompr = _config->FindFile("Dir::Bin::uncompressed", "");
+ std::string const uncompr = _config->Find("Dir::Bin::uncompressed", "");
if (uncompr.empty() == true || FileExists(uncompr) == true)
types.push_back("uncompressed");
}
@@ -366,31 +366,31 @@ const Configuration::getCompressors(bool const Cached) {
setDefaultConfigurationForCompressors();
compressors.push_back(Compressor(".", "", "", NULL, NULL, 0));
- if (_config->Exists("Dir::Bin::lz4") == false || FileExists(_config->FindFile("Dir::Bin::lz4")) == true)
+ if (_config->Exists("Dir::Bin::lz4") == false || FileExists(_config->Find("Dir::Bin::lz4")) == true)
compressors.push_back(Compressor("lz4",".lz4","lz4","-1","-d",50));
#ifdef HAVE_LZ4
else
compressors.push_back(Compressor("lz4",".lz4","false", NULL, NULL, 50));
#endif
- if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->FindFile("Dir::Bin::gzip")) == true)
+ if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->Find("Dir::Bin::gzip")) == true)
compressors.push_back(Compressor("gzip",".gz","gzip","-6n","-d",100));
#ifdef HAVE_ZLIB
else
compressors.push_back(Compressor("gzip",".gz","false", NULL, NULL, 100));
#endif
- if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true)
+ if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->Find("Dir::Bin::xz")) == true)
compressors.push_back(Compressor("xz",".xz","xz","-6","-d",200));
#ifdef HAVE_LZMA
else
compressors.push_back(Compressor("xz",".xz","false", NULL, NULL, 200));
#endif
- if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true)
+ if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->Find("Dir::Bin::bzip2")) == true)
compressors.push_back(Compressor("bzip2",".bz2","bzip2","-6","-d",300));
#ifdef HAVE_BZ2
else
compressors.push_back(Compressor("bzip2",".bz2","false", NULL, NULL, 300));
#endif
- if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true)
+ if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->Find("Dir::Bin::lzma")) == true)
compressors.push_back(Compressor("lzma",".lzma","lzma","-6","-d",400));
#ifdef HAVE_LZMA
else
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc
index 0929ae0e2..1873f41f2 100644
--- a/apt-pkg/contrib/gpgv.cc
+++ b/apt-pkg/contrib/gpgv.cc
@@ -47,7 +47,7 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
int const &statusfd, int fd[2], std::string const &key)
{
#define EINTERNAL 111
- std::string const aptkey = _config->FindFile("Dir::Bin::apt-key", "/usr/bin/apt-key");
+ std::string const aptkey = _config->Find("Dir::Bin::apt-key", "/usr/bin/apt-key");
bool const Debug = _config->FindB("Debug::Acquire::gpgv", false);
diff --git a/apt-pkg/contrib/proxy.cc b/apt-pkg/contrib/proxy.cc
index cbe640634..4529cf230 100644
--- a/apt-pkg/contrib/proxy.cc
+++ b/apt-pkg/contrib/proxy.cc
@@ -51,19 +51,26 @@ bool AutoDetectProxy(URI &URL)
if(Popen(&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
return _error->Error("ProxyAutoDetect command '%s' failed!", AutoDetectProxyCmd.c_str());
char buf[512];
- if (PipeFd.ReadLine(buf, sizeof(buf)) == nullptr)
- return _error->Error("Failed to read in AutoDetectProxy");
+ bool const goodread = PipeFd.ReadLine(buf, sizeof(buf)) != nullptr;
PipeFd.Close();
- ExecWait(Child, "ProxyAutoDetect", true);
+ if (ExecWait(Child, "ProxyAutoDetect") == false)
+ return false;
+ // no output means the detector has no idea which proxy to use
+ // and apt will use the generic proxy settings
+ if (goodread == false)
+ return true;
auto const cleanedbuf = _strstrip(buf);
-
+ // We warn about this as the implementor probably meant to use DIRECT instead
if (cleanedbuf[0] == '\0')
- return _error->Warning("ProxyAutoDetect returned no data");
+ {
+ _error->Warning("ProxyAutoDetect command returned an empty line");
+ return true;
+ }
if (Debug)
std::clog << "auto detect command returned: '" << cleanedbuf << "'" << std::endl;
- if (strstr(cleanedbuf, URL.Access.c_str()) == cleanedbuf)
+ if (strstr(cleanedbuf, URL.Access.c_str()) == cleanedbuf || strcmp(cleanedbuf, "DIRECT") == 0)
_config->Set("Acquire::"+URL.Access+"::proxy::"+URL.Host, cleanedbuf);
return true;
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index fba1e3306..84fc14bb1 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -867,7 +867,7 @@ bool ReadMessages(int Fd, vector<string> &List)
// ---------------------------------------------------------------------
/* This was lifted from the boa webserver which lifted it from 'wn-v1.07'
Made it a bit more robust with a few tolower_ascii though. */
-static int MonthConv(char *Month)
+static int MonthConv(char const * const Month)
{
switch (tolower_ascii(*Month))
{
@@ -930,46 +930,87 @@ static time_t timegm(struct tm *t)
method used to ignore the timezone and assume always UTC. */
bool RFC1123StrToTime(const char* const str,time_t &time)
{
- struct tm t;
- auto const &posix = std::locale("C.UTF-8");
- auto const parse_time = [&](char const * const s, bool const has_timezone) {
- std::istringstream ss(str);
- ss.imbue(posix);
- ss >> std::get_time(&t, s);
- if (has_timezone && ss.fail() == false)
- {
- std::string timezone;
- ss >> timezone;
- if (timezone.empty())
+ unsigned short day = 0;
+ signed int year = 0; // yes, Y23K problem – we gonna worry then…
+ std::string weekday, month, datespec, timespec, zone;
+ std::istringstream ss(str);
+ ss >> weekday;
+ // we only superficially check weekday, mostly to avoid accepting localized
+ // weekdays here and take only its length to decide which datetime format we
+ // encounter here. The date isn't stored.
+ std::transform(weekday.begin(), weekday.end(), weekday.begin(), ::tolower);
+ std::array<char const * const, 7> c_weekdays = {{ "sun", "mon", "tue", "wed", "thu", "fri", "sat" }};
+ if (std::find(c_weekdays.begin(), c_weekdays.end(), weekday.substr(0,3)) == c_weekdays.end())
+ return false;
+
+ switch (weekday.length())
+ {
+ case 4:
+ // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
+ if (weekday[3] != ',')
+ return false;
+ ss >> day >> month >> year >> timespec >> zone;
+ break;
+ case 3:
+ // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
+ ss >> month >> day >> timespec >> year;
+ zone = "UTC";
+ break;
+ case 0:
+ case 1:
+ case 2:
+ return false;
+ default:
+ // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
+ if (weekday[weekday.length() - 1] != ',')
+ return false;
+ ss >> datespec >> timespec >> zone;
+ auto const expldate = VectorizeString(datespec, '-');
+ if (expldate.size() != 3)
+ return false;
+ try {
+ size_t pos;
+ day = std::stoi(expldate[0], &pos);
+ if (pos != expldate[0].length())
return false;
- if (timezone != "GMT" && timezone != "UTC" && timezone != "Z") // RFC 822
- {
- // numeric timezones as a should of RFC 1123 and generally preferred
- try {
- size_t pos;
- auto const zone = std::stoi(timezone, &pos);
- if (zone != 0 || pos != timezone.length())
- return false;
- } catch (...) {
- return false;
- }
- }
+ year = 1900 + std::stoi(expldate[2], &pos);
+ if (pos != expldate[2].length())
+ return false;
+ strprintf(datespec, "%.4d-%.2d-%.2d", year, MonthConv(expldate[1].c_str()) + 1, day);
+ } catch (...) {
+ return false;
}
- t.tm_isdst = 0;
- return ss.fail() == false;
- };
+ break;
+ }
- bool const good =
- // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
- parse_time("%a, %d %b %Y %H:%M:%S", true) ||
- // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
- parse_time("%A, %d-%b-%y %H:%M:%S", true) ||
- // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
- parse_time("%c", false); // "%a %b %d %H:%M:%S %Y"
- if (good == false)
+ if (ss.fail() || ss.bad() || !ss.eof())
return false;
- time = timegm(&t);
+ if (zone != "GMT" && zone != "UTC" && zone != "Z") // RFC 822
+ {
+ // numeric timezones as a should of RFC 1123 and generally preferred
+ try {
+ size_t pos;
+ auto const z = std::stoi(zone, &pos);
+ if (z != 0 || pos != zone.length())
+ return false;
+ } catch (...) {
+ return false;
+ }
+ }
+
+ if (datespec.empty())
+ {
+ if (month.empty())
+ return false;
+ strprintf(datespec, "%.4d-%.2d-%.2d", year, MonthConv(month.c_str()) + 1, day);
+ }
+
+ std::string const datetime = datespec + ' ' + timespec;
+ struct tm Tm;
+ if (strptime(datetime.c_str(), "%Y-%m-%d %H:%M:%S", &Tm) == nullptr)
+ return false;
+ time = timegm(&Tm);
return true;
}
/*}}}*/
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc
index f756cdb1f..c70c39a45 100644
--- a/apt-pkg/deb/debmetaindex.cc
+++ b/apt-pkg/deb/debmetaindex.cc
@@ -80,20 +80,19 @@ std::string debReleaseIndex::MetaIndexFile(const char *Type) const
return _config->FindDir("Dir::State::lists") +
URItoFileName(MetaIndexURI(Type));
}
-
-std::string debReleaseIndex::MetaIndexURI(const char *Type) const
+static std::string constructMetaIndexURI(std::string URI, std::string const &Dist, char const * const Type)
{
- std::string Res;
-
if (Dist == "/")
- Res = URI;
+ ;
else if (Dist[Dist.size()-1] == '/')
- Res = URI + Dist;
+ URI += Dist;
else
- Res = URI + "dists/" + Dist + "/";
-
- Res += Type;
- return Res;
+ URI += "dists/" + Dist + "/";
+ return URI + Type;
+}
+std::string debReleaseIndex::MetaIndexURI(const char *Type) const
+{
+ return constructMetaIndexURI(URI, Dist, Type);
}
/*}}}*/
// ReleaseIndex Con- and Destructors /*{{{*/
@@ -919,27 +918,30 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
std::string const &Dist, std::string const &Section,
bool const &IsSrc, std::map<std::string, std::string> const &Options) const
{
- debReleaseIndex *Deb = NULL;
- for (std::vector<metaIndex *>::const_iterator I = List.begin();
- I != List.end(); ++I)
+ debReleaseIndex * Deb = nullptr;
+ std::string const FileName = URItoFileName(constructMetaIndexURI(URI, Dist, "Release"));
+ for (auto const &I: List)
{
// We only worry about debian entries here
- if (strcmp((*I)->GetType(), "deb") != 0)
+ if (strcmp(I->GetType(), "deb") != 0)
+ continue;
+
+ auto const D = dynamic_cast<debReleaseIndex*>(I);
+ if (unlikely(D == nullptr))
continue;
- /* This check insures that there will be only one Release file
+ /* This check ensures that there will be only one Release file
queued for all the Packages files and Sources files it
corresponds to. */
- if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist)
+ if (URItoFileName(D->MetaIndexURI("Release")) == FileName)
{
- Deb = dynamic_cast<debReleaseIndex*>(*I);
- if (Deb != NULL)
- break;
+ Deb = D;
+ break;
}
}
// No currently created Release file indexes this entry, so we create a new one.
- if (Deb == NULL)
+ if (Deb == nullptr)
{
Deb = new debReleaseIndex(URI, Dist);
List.push_back(Deb);
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index 56ca8f4c6..e2b1df950 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -221,7 +221,7 @@ signed debSystem::Score(Configuration const &Cnf)
signed Score = 0;
if (FileExists(Cnf.FindFile("Dir::State::status","/var/lib/dpkg/status")) == true)
Score += 10;
- if (FileExists(Cnf.FindFile("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
+ if (FileExists(Cnf.Find("Dir::Bin::dpkg","/usr/bin/dpkg")) == true)
Score += 10;
if (FileExists("/etc/debian_version") == true)
Score += 10;