aboutsummaryrefslogtreecommitdiff
path: root/lib/libfetch
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2018-05-29 13:07:36 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2018-05-29 13:07:36 +0000
commit5f04ebd4d3ed2b5970913c8b02b2b251a897a3c0 (patch)
tree1fb244ecce9750c2a55f6701834aceeb15208f04 /lib/libfetch
parent12e7376216e0cb3792a5f69ef356901abba9e496 (diff)
Notes
Diffstat (limited to 'lib/libfetch')
-rw-r--r--lib/libfetch/common.c38
-rw-r--r--lib/libfetch/fetch.c4
-rw-r--r--lib/libfetch/ftp.c6
3 files changed, 34 insertions, 14 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index 6b62f4397eb6..6ea92f1d4591 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -1361,19 +1361,20 @@ fetch_read_word(FILE *f)
static int
fetch_netrc_open(void)
{
- const char *p;
+ struct passwd *pwd;
char fn[PATH_MAX];
+ const char *p;
+ int fd, serrno;
if ((p = getenv("NETRC")) != NULL) {
+ DEBUGF("NETRC=%s\n", p);
if (snprintf(fn, sizeof(fn), "%s", p) >= (int)sizeof(fn)) {
fetch_info("$NETRC specifies a file name "
"longer than PATH_MAX");
return (-1);
}
} else {
- if ((p = getenv("HOME")) != NULL) {
- struct passwd *pwd;
-
+ if ((p = getenv("HOME")) == NULL) {
if ((pwd = getpwuid(getuid())) == NULL ||
(p = pwd->pw_dir) == NULL)
return (-1);
@@ -1382,7 +1383,12 @@ fetch_netrc_open(void)
return (-1);
}
- return (open(fn, O_RDONLY));
+ if ((fd = open(fn, O_RDONLY)) < 0) {
+ serrno = errno;
+ DEBUGF("%s: %s\n", fn, strerror(serrno));
+ errno = serrno;
+ }
+ return (fd);
}
/*
@@ -1392,24 +1398,32 @@ int
fetch_netrc_auth(struct url *url)
{
const char *word;
+ int serrno;
FILE *f;
- if (url->netrcfd == -2)
+ if (url->netrcfd < 0)
url->netrcfd = fetch_netrc_open();
if (url->netrcfd < 0)
return (-1);
- if ((f = fdopen(url->netrcfd, "r")) == NULL)
+ if ((f = fdopen(url->netrcfd, "r")) == NULL) {
+ serrno = errno;
+ DEBUGF("fdopen(netrcfd): %s", strerror(errno));
+ close(url->netrcfd);
+ url->netrcfd = -1;
+ errno = serrno;
return (-1);
+ }
rewind(f);
+ DEBUGF("searching netrc for %s\n", url->host);
while ((word = fetch_read_word(f)) != NULL) {
if (strcmp(word, "default") == 0) {
- DEBUGF("Using default .netrc settings");
+ DEBUGF("using default netrc settings\n");
break;
}
if (strcmp(word, "machine") == 0 &&
(word = fetch_read_word(f)) != NULL &&
strcasecmp(word, url->host) == 0) {
- DEBUGF("Using .netrc settings for %s", word);
+ DEBUGF("using netrc settings for %s\n", word);
break;
}
}
@@ -1441,9 +1455,13 @@ fetch_netrc_auth(struct url *url)
}
}
fclose(f);
+ url->netrcfd = -1;
return (0);
- ferr:
+ferr:
+ serrno = errno;
fclose(f);
+ url->netrcfd = -1;
+ errno = serrno;
return (-1);
}
diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c
index f1c0c287aeb4..ea8c33864706 100644
--- a/lib/libfetch/fetch.c
+++ b/lib/libfetch/fetch.c
@@ -272,6 +272,7 @@ fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
fetch_syserr();
return (NULL);
}
+ u->netrcfd = -1;
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
fetch_syserr();
@@ -286,7 +287,6 @@ fetchMakeURL(const char *scheme, const char *host, int port, const char *doc,
seturl(pwd);
#undef seturl
u->port = port;
- u->netrcfd = -2;
return (u);
}
@@ -352,7 +352,7 @@ fetchParseURL(const char *URL)
fetch_syserr();
return (NULL);
}
- u->netrcfd = -2;
+ u->netrcfd = -1;
/* scheme name */
if ((p = strstr(URL, ":/"))) {
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index d3f69e65f7b0..72165d63fd19 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -914,7 +914,8 @@ ftp_authenticate(conn_t *conn, struct url *url, struct url *purl)
fetch_netrc_auth(url);
user = url->user;
if (*user == '\0')
- user = getenv("FTP_LOGIN");
+ if ((user = getenv("FTP_LOGIN")) != NULL)
+ DEBUGF("FTP_LOGIN=%s\n", user);
if (user == NULL || *user == '\0')
user = FTP_ANONYMOUS_USER;
if (purl && url->port == fetch_default_port(url->scheme))
@@ -928,7 +929,8 @@ ftp_authenticate(conn_t *conn, struct url *url, struct url *purl)
if (e == FTP_NEED_PASSWORD) {
pwd = url->pwd;
if (*pwd == '\0')
- pwd = getenv("FTP_PASSWORD");
+ if ((pwd = getenv("FTP_PASSWORD")) != NULL)
+ DEBUGF("FTP_PASSWORD=%s\n", pwd);
if (pwd == NULL || *pwd == '\0') {
if ((logname = getlogin()) == NULL)
logname = FTP_ANONYMOUS_USER;