summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
Diffstat (limited to 'methods')
-rw-r--r--methods/aptmethod.h15
-rw-r--r--methods/basehttp.cc12
2 files changed, 27 insertions, 0 deletions
diff --git a/methods/aptmethod.h b/methods/aptmethod.h
index f564499f0..9499367c8 100644
--- a/methods/aptmethod.h
+++ b/methods/aptmethod.h
@@ -539,6 +539,9 @@ class aptAuthConfMethod : public aptMethod
{
std::vector<std::unique_ptr<FileFd>> authconfs;
+ protected:
+ std::vector<std::string> inaccessibleAuthConfs;
+
public:
bool Configuration(std::string Message) override
{
@@ -555,6 +558,12 @@ class aptAuthConfMethod : public aptMethod
{
authconfs.emplace_back(new FileFd());
authconfs.back()->Open(netrc, FileFd::ReadOnly);
+ if (authconfs.back()->IsOpen() == false)
+ {
+ struct stat st;
+ if (stat(netrc.c_str(), &st) == 0)
+ inaccessibleAuthConfs.push_back(netrc);
+ }
}
auto const netrcparts = _config->FindDir("Dir::Etc::netrcparts");
@@ -564,6 +573,12 @@ class aptAuthConfMethod : public aptMethod
{
authconfs.emplace_back(new FileFd());
authconfs.back()->Open(netrcpart, FileFd::ReadOnly);
+ if (authconfs.back()->IsOpen() == false)
+ {
+ struct stat st;
+ if (stat(netrcpart.c_str(), &st) == 0)
+ inaccessibleAuthConfs.push_back(netrcpart);
+ }
}
}
_error->RevertToStack();
diff --git a/methods/basehttp.cc b/methods/basehttp.cc
index db0ed228f..8dd596f8f 100644
--- a/methods/basehttp.cc
+++ b/methods/basehttp.cc
@@ -506,6 +506,18 @@ BaseHttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req)
std::string err;
strprintf(err, "HttpError%u", Req.Result);
SetFailReason(err);
+ if (Req.Result == 401 && inaccessibleAuthConfs.empty() == false)
+ {
+ std::string conflist;
+ std::string msg;
+ for (auto const &path : inaccessibleAuthConfs)
+ conflist += (conflist.empty() ? "" : ", ") + path;
+ strprintf(msg, _("Authentication credentials may be configured in %s, "
+ "but the file(s) are not readable by the current user. "
+ "Try running this command as root."),
+ conflist.c_str());
+ Warning(std::move(msg));
+ }
_error->Error("%u %s", Req.Result, Req.Code);
}
if (Req.haveContent == HaveContent::TRI_TRUE)