diff options
author | David Kalnischkies <david@kalnischkies.de> | 2017-07-07 16:24:21 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2017-07-26 19:09:04 +0200 |
commit | ea408c560ed85bb4ef7cf8f72f8463653501332c (patch) | |
tree | 30dcfc690db0353e786cc9873b6e11803a157611 /methods/aptmethod.h | |
parent | 51751106976b1c6afa8f7991790db87b239fcc84 (diff) |
reimplement and document auth.conf
We have support for an netrc-like auth.conf file since 0.7.25 (closing
518473), but it was never documented in apt that it even exists and
netrc seems to have fallen out of usage as a manpage for it no longer
exists making the feature even more arcane.
On top of that the code was a bit of a mess (as it is written in c-style)
and as a result the matching of machine tokens to URIs also a bit
strange by checking for less specific matches (= without path) first.
We now do a single pass over the stanzas.
In practice early adopters of the undocumented implementation will not
really notice the differences and the 'new' behaviour is simpler to
document and more usual for an apt user.
Closes: #811181
Diffstat (limited to 'methods/aptmethod.h')
-rw-r--r-- | methods/aptmethod.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/methods/aptmethod.h b/methods/aptmethod.h index 04858e29d..a9af63fb7 100644 --- a/methods/aptmethod.h +++ b/methods/aptmethod.h @@ -5,6 +5,7 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> +#include <apt-pkg/netrc.h> #include <algorithm> #include <locale> @@ -42,6 +43,24 @@ public: return true; } + bool MaybeAddAuthTo(URI &uri) + { + if (uri.User.empty() == false || uri.Password.empty() == false) + return true; + auto const netrc = _config->FindFile("Dir::Etc::netrc"); + if (netrc.empty() == true) + return true; + // ignore errors with opening the auth file as it doesn't need to exist + _error->PushToStack(); + FileFd authconf(netrc, FileFd::ReadOnly); + _error->RevertToStack(); + if (authconf.IsOpen() == false) + return true; + if (authconf.Seek(0) == false) + return false; + return MaybeAddAuth(authconf, uri); + } + bool CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const APT_NONNULL(2) { Hashes Hash(Itm->ExpectedHashes); |