Fix http.c and ftp.c passwd logic error

* src/ftp.c (getftp): Fix password/user selection
* src/http.c (initialize_request): Likewise

Before, netrc password won over interactive
--ask-password but now --ask-password wins
after change of program logic

Fixes Issue #48811
This commit is contained in:
vijeth-aradhya 2016-12-25 03:08:14 +05:30 committed by Tim Rühsen
parent 42c2ce71bc
commit 2427ca4ac0
2 changed files with 50 additions and 11 deletions

View File

@ -359,12 +359,32 @@ getftp (struct url *u, struct url *original_url,
*qtyread = restval;
user = u->user;
passwd = u->passwd;
search_netrc (u->host, (const char **)&user, (const char **)&passwd, 1);
user = user ? user : (opt.ftp_user ? opt.ftp_user : opt.user);
/* Find the username with priority */
if (u->user)
user = u->user;
else if (opt.user && (opt.use_askpass || opt.ask_passwd))
user = opt.user;
else if (opt.ftp_user)
user = opt.ftp_user;
else if (opt.user)
user = opt.user;
else
user = NULL;
/* Find the password with priority */
if (u->passwd)
passwd = u->passwd;
else if (opt.passwd && (opt.use_askpass || opt.ask_passwd))
passwd = opt.passwd;
else if (opt.ftp_passwd)
passwd = opt.ftp_passwd;
else if (opt.passwd)
passwd = opt.passwd;
else
passwd = NULL;
/* Check for ~/.netrc if none of the above match */
if (opt.netrc && (!user || !passwd))
search_netrc (u->host, (const char **)&user, (const char **)&passwd, 1);
if (!user) user = "anonymous";
passwd = passwd ? passwd : (opt.ftp_passwd ? opt.ftp_passwd : opt.passwd);
if (!passwd) passwd = "-wget@";
dtsock = -1;

View File

@ -1875,12 +1875,31 @@ initialize_request (const struct url *u, struct http_stat *hs, int *dt, struct u
request_set_header (req, "Accept", "*/*", rel_none);
request_set_header (req, "Accept-Encoding", "identity", rel_none);
/* Find the username and password for authentication. */
*user = u->user;
*passwd = u->passwd;
search_netrc (u->host, (const char **)user, (const char **)passwd, 0);
*user = *user ? *user : (opt.http_user ? opt.http_user : opt.user);
*passwd = *passwd ? *passwd : (opt.http_passwd ? opt.http_passwd : opt.passwd);
/* Find the username with priority */
if (u->user)
*user = u->user;
else if (opt.user && (opt.use_askpass || opt.ask_passwd))
*user = opt.user;
else if (opt.http_user)
*user = opt.http_user;
else if (opt.user)
*user = opt.user;
else
*user = NULL;
/* Find the password with priority */
if (u->passwd)
*passwd = u->passwd;
else if (opt.passwd && (opt.use_askpass || opt.ask_passwd))
*passwd = opt.passwd;
else if (opt.http_passwd)
*passwd = opt.http_passwd;
else if (opt.passwd)
*passwd = opt.passwd;
else
*passwd = NULL;
/* Check for ~/.netrc if none of the above match */
if (opt.netrc && (!(*user) || !(*password)))
search_netrc (u->host, (const char **)user, (const char **)passwd, 0);
/* We only do "site-wide" authentication with "global" user/password
* values unless --auth-no-challange has been requested; URL user/password