summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-07-09 16:38:49 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2020-12-18 19:31:19 +0100
commite6c55283d235aa9404395d30f2db891f36995c49 (patch)
tree2ab7b38e4f6e6b0d61a4431d30866d42abe2d38a /apt-pkg/acquire.cc
parent97be873d782c5e9aaa8b4f4f4e6e18805d0fa51c (diff)
Keep URIs encoded in the acquire system
We do not deal a lot with URIs which need encoding, but then we do it is a pain that we store it decoded in the acquire system as it means we have to decode and reencode URIs eventually which is potentially giving us slightly different URIs. We see that in our own testing framework while setting up redirects as the config options are effectively double-encoded and decoded to pass them around successfully as otherwise %2f and / in an URI are treated the same. This commit adds the infrastructure for methods to opt into getting URIs send in encoded form (and returning them to us in encoded form, too) so that we eventually do not have to touch the URIs which is how it should be. This means though that we have to deal with methods who do not support this yet (aka: all at the moment) for which we decode and encode while communicating with them.
Diffstat (limited to 'apt-pkg/acquire.cc')
-rw-r--r--apt-pkg/acquire.cc46
1 files changed, 40 insertions, 6 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 1cffc0463..8693de930 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -51,6 +51,12 @@
using namespace std;
+std::string pkgAcquire::URIEncode(std::string const &part) /*{{{*/
+{
+ // The "+" is encoded as a workaround for an S3 bug (LP#1003633 and LP#1086997)
+ return QuoteString(part, _config->Find("Acquire::URIEncode", "+~ ").c_str());
+}
+ /*}}}*/
// Acquire::pkgAcquire - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* We grab some runtime state from the configuration space */
@@ -662,10 +668,11 @@ static void CheckDropPrivsMustBeDisabled(pkgAcquire const &Fetcher)
if (_config->Exists(conf) == true)
continue;
- if (IsAccessibleBySandboxUser(source.Path, false) == false)
+ auto const filepath = DeQuoteString(source.Path);
+ if (not IsAccessibleBySandboxUser(filepath, false))
{
_error->NoticeE("pkgAcquire::Run", _("Download is performed unsandboxed as root as file '%s' couldn't be accessed by user '%s'."),
- source.Path.c_str(), SandboxUser.c_str());
+ filepath.c_str(), SandboxUser.c_str());
_config->CndSet("Binary::file::APT::Sandbox::User", "root");
_config->CndSet("Binary::copy::APT::Sandbox::User", "root");
}
@@ -880,6 +887,7 @@ class pkgAcquire::MethodConfig::Private
{
public:
bool AuxRequests = false;
+ bool SendURIEncoded = false;
};
pkgAcquire::MethodConfig::MethodConfig() : d(new Private()), Next(0), SingleInstance(false),
Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false),
@@ -897,6 +905,17 @@ void pkgAcquire::MethodConfig::SetAuxRequests(bool const value) /*{{{*/
d->AuxRequests = value;
}
/*}}}*/
+bool pkgAcquire::MethodConfig::GetSendURIEncoded() const /*{{{*/
+{
+ return d->SendURIEncoded;
+}
+ /*}}}*/
+void pkgAcquire::MethodConfig::SetSendURIEncoded(bool const value) /*{{{*/
+{
+ d->SendURIEncoded = value;
+}
+ /*}}}*/
+
// Queue::Queue - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -1073,10 +1092,25 @@ bool pkgAcquire::Queue::Shutdown(bool Final)
/* */
pkgAcquire::Queue::QItem *pkgAcquire::Queue::FindItem(string URI,pkgAcquire::Worker *Owner)
{
- for (QItem *I = Items; I != 0; I = I->Next)
- if (I->URI == URI && I->Worker == Owner)
- return I;
- return 0;
+ if (Owner->Config->GetSendURIEncoded())
+ {
+ for (QItem *I = Items; I != nullptr; I = I->Next)
+ if (I->URI == URI && I->Worker == Owner)
+ return I;
+ }
+ else
+ {
+ for (QItem *I = Items; I != nullptr; I = I->Next)
+ {
+ if (I->Worker != Owner)
+ continue;
+ ::URI tmpuri{I->URI};
+ tmpuri.Path = DeQuoteString(tmpuri.Path);
+ if (URI == std::string(tmpuri))
+ return I;
+ }
+ }
+ return nullptr;
}
/*}}}*/
// Queue::ItemDone - Item has been completed /*{{{*/