diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2019-02-05 16:57:47 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2019-03-01 11:40:32 +0000 |
commit | 25c024910b4c051461a9842d9fe0efc04748c908 (patch) | |
tree | da0c02a6438077a575081f3449b3e91d01a5e7bc /methods/http.cc | |
parent | 54e1ee73059bbad881908028abce574039ec77b9 (diff) |
Add support for /etc/apt/auth.conf.d/*.conf (netrcparts)
This allows us to install matching auth files for sources.list.d
files, for example; very useful.
This converts aptmethod's authfd from one FileFd to a vector of
pointers to FileFd, as FileFd cannot be copied, and move operators
are hard.
(parts cherry-picked from commit feed3ec105cd6be7b5d23da14c6cfca8572ee725)
LP: #1811120
TODO: test/integration/test-authentication-basic is missing, what to do?
Diffstat (limited to 'methods/http.cc')
-rw-r--r-- | methods/http.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/methods/http.cc b/methods/http.cc index d3a5d718f..5f5cd2631 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -758,7 +758,25 @@ void HttpMethod::SendReq(FetchItem *Itm) Req += string("Proxy-Authorization: Basic ") + Base64Encode(Server->Proxy.User + ":" + Server->Proxy.Password) + "\r\n"; + maybe_add_auth (Uri, _config->FindFile("Dir::Etc::netrc")); + if(Uri.User.empty() || Uri.Password.empty()) + { + std::string const netrcparts = _config->FindDir("Dir::Etc::netrcparts"); + if (not netrcparts.empty()) + { + _error->PushToStack(); + std::vector<std::string> files = GetListOfFilesInDir(netrcparts, "conf", true, true); + for (std::vector<std::string>::const_iterator netrc = files.begin(); netrc != files.end(); netrc++) + { + maybe_add_auth (Uri, *netrc); + if (Uri.User.empty() == false || Uri.Password.empty() == false) + break; + } + _error->RevertToStack(); + } + } + if (Uri.User.empty() == false || Uri.Password.empty() == false) { Req += string("Authorization: Basic ") + |