summaryrefslogtreecommitdiff
path: root/methods/aptmethod.h
diff options
context:
space:
mode:
Diffstat (limited to 'methods/aptmethod.h')
-rw-r--r--methods/aptmethod.h19
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);