-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Andreas Kohlbach wrote:
> Hi,
> 
> though the man page of wget mentions .netrc, I assume this is a bug.
> 
> For my understanding if you provide a --user=user and --password=password
> at the command line this should overwrite any setting elsewhere, as in
> the .netrc. It doesn't. And it took me quite some time and bothering
> other guys to realise that it seems wget is ignoring --user and
> --password at the command line if a .netrc exists with the matching
> content.

Here's what I see:

search_netrc has the code:

  if (*acc && *passwd)
    return;

This occurs before acc or passwd are set (but strangely, after the netrc
is parsed, which is silly), and means that if acc and passwd already
point at valid strings (even if empty), then we exit without changing them.

This is why I wasn't sure I'd be able to reproduce the problem (though I
hadn't gotten around to trying it yet). However, a closer inspection of
http.c shows I misread the call in gethttp:

  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);

search_netrc only gets the value of user and passwd, as obtained from
the URL. Therefore, http://foo:[EMAIL PROTECTED]/ will override netrc, but
opt.user and opt.http_user aren't checked until after netrc.

The problem could be solved by simply moving the search_netrc down below
  the other places where user/passwd get set.

As Josh points out, the question remains whether this should be our
behavior; I vote yes, as command-line arguments should always override
rc files, in general. Of course, these values could well have come from
.wgetrc and not the command-line; but even so,
more-specific-to-our-application should override general, so .wgetrc
still wins over .netrc.

While we're changing things, we should move the first snippit I
mentioned above, to before where we bother parsing the .netrc.

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG3Y1d7M8hyUobTrERCAS8AJ4vWhnXBegLSUzbuTH2hjmNJ+lTCgCcCPJw
3XT7t6VXLgIJlGI7Q+PDm9c=
=Mbro
-----END PGP SIGNATURE-----

Reply via email to