1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Change default anonymous FTP password to "-wget@".

Published in <sxsu239htnl.fsf@florida.arsdigita.de>.
This commit is contained in:
hniksic 2001-04-29 03:53:55 -07:00
parent b44f1701b0
commit dfc1eb5766
8 changed files with 51 additions and 212 deletions

View File

@ -1,3 +1,17 @@
2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com>
* main.c (main): Removed undocumented option `--email-address'.
* netrc.c: Use the latest read_whole_line.
* init.c (defaults): Set opt.ftp_pass to "-wget@".
* mswindows.c (pwd_cuserid): Ditto.
* utils.c (pwd_cuserid): Removed.
* host.c (ftp_getaddress): Removed.
2001-04-28 Hrvoje Niksic <hniksic@arsdigita.com>
(http_loop): Allocate space for filename_plus_orig_suffix with

View File

@ -133,8 +133,6 @@ getftp (struct urlinfo *u, long *len, long restval, ccon *con)
passwd = u->passwd;
search_netrc (u->host, (const char **)&user, (const char **)&passwd, 1);
user = user ? user : opt.ftp_acc;
if (!opt.ftp_pass)
opt.ftp_pass = ftp_getaddress ();
passwd = passwd ? passwd : opt.ftp_pass;
assert (user && passwd);

View File

@ -360,130 +360,6 @@ sufmatch (const char **list, const char *what)
return 0;
}
/* Return email address of the form username@FQDN suitable for
anonymous FTP passwords. This process is error-prone, and the
escape hatch is the MY_HOST preprocessor constant, which can be
used to hard-code either your hostname or FQDN at compile-time.
If the FQDN cannot be determined, a warning is printed, and the
function returns a short `username@' form, accepted by most
anonymous servers.
The returned string is generated by malloc() and should be freed
using free().
If not even the username cannot be divined, it means things are
seriously fucked up, and Wget exits. */
char *
ftp_getaddress (void)
{
static char *address;
/* Do the drill only the first time, as it won't change. */
if (!address)
{
char userid[32]; /* 9 should be enough for Unix, but
I'd rather be on the safe side. */
char *host, *fqdn;
if (!pwd_cuserid (userid))
{
logprintf (LOG_ALWAYS, _("%s: Cannot determine user-id.\n"),
exec_name);
exit (1);
}
#ifdef MY_HOST
STRDUP_ALLOCA (host, MY_HOST);
#else /* not MY_HOST */
#ifdef HAVE_UNAME
{
struct utsname ubuf;
if (uname (&ubuf) < 0)
{
logprintf (LOG_ALWAYS, _("%s: Warning: uname failed: %s\n"),
exec_name, strerror (errno));
fqdn = "";
goto giveup;
}
STRDUP_ALLOCA (host, ubuf.nodename);
}
#else /* not HAVE_UNAME */
#ifdef HAVE_GETHOSTNAME
host = alloca (256);
if (gethostname (host, 256) < 0)
{
logprintf (LOG_ALWAYS, _("%s: Warning: gethostname failed\n"),
exec_name);
fqdn = "";
goto giveup;
}
#else /* not HAVE_GETHOSTNAME */
#error Cannot determine host name.
#endif /* not HAVE_GETHOSTNAME */
#endif /* not HAVE_UNAME */
#endif /* not MY_HOST */
/* If the address we got so far contains a period, don't bother
anymore. */
if (strchr (host, '.'))
fqdn = host;
else
{
/* #### I've seen the following scheme fail on at least one
system! Do we care? */
char *tmpstore;
/* According to Richard Stevens, the correct way to find the
FQDN is to (1) find the host name, (2) find its IP
address using gethostbyname(), and (3) get the FQDN using
gethostbyaddr(). So that's what we'll do. Step one has
been done above. */
/* (2) */
struct hostent *hp = gethostbyname (host);
if (!hp || !hp->h_addr_list)
{
logprintf (LOG_ALWAYS, _("\
%s: Warning: cannot determine local IP address.\n"),
exec_name);
fqdn = "";
goto giveup;
}
/* Copy the argument, so the call to gethostbyaddr doesn't
clobber it -- just in case. */
tmpstore = (char *)alloca (hp->h_length);
memcpy (tmpstore, *hp->h_addr_list, hp->h_length);
/* (3) */
hp = gethostbyaddr (tmpstore, hp->h_length, hp->h_addrtype);
if (!hp || !hp->h_name)
{
logprintf (LOG_ALWAYS, _("\
%s: Warning: cannot reverse-lookup local IP address.\n"),
exec_name);
fqdn = "";
goto giveup;
}
if (!strchr (hp->h_name, '.'))
{
#if 0
/* This gets ticked pretty often. Karl Berry reports
that there can be valid reasons for the local host
name not to be an FQDN, so I've decided to remove the
annoying warning. */
logprintf (LOG_ALWAYS, _("\
%s: Warning: reverse-lookup of local address did not yield FQDN!\n"),
exec_name);
#endif
fqdn = "";
goto giveup;
}
/* Once we're here, hp->h_name contains the correct FQDN. */
STRDUP_ALLOCA (fqdn, hp->h_name);
}
giveup:
address = (char *)xmalloc (strlen (userid) + 1 + strlen (fqdn) + 1);
sprintf (address, "%s@%s", userid, fqdn);
}
return address;
}
/* Print error messages for host errors. */
char *
herrmsg (int error)

View File

@ -227,8 +227,8 @@ defaults (void)
opt.ntry = 20;
opt.reclevel = 5;
opt.add_hostdir = 1;
opt.ftp_acc = xstrdup ("anonymous");
/*opt.ftp_pass = xstrdup (ftp_getaddress ());*/
opt.ftp_acc = xstrdup ("anonymous");
opt.ftp_pass = xstrdup ("-wget@");
opt.netrc = 1;
opt.ftp_glob = 1;
opt.htmlify = 1;

View File

@ -251,7 +251,6 @@ main (int argc, char *const *argv)
{ "debug", no_argument, NULL, 'd' },
{ "delete-after", no_argument, NULL, 136 },
{ "dont-remove-listing", no_argument, NULL, 149 },
{ "email-address", no_argument, NULL, 154 }, /* undocumented (debug) */
{ "follow-ftp", no_argument, NULL, 142 },
{ "force-directories", no_argument, NULL, 'x' },
{ "force-hier", no_argument, NULL, 'x' }, /* obsolete */
@ -400,11 +399,6 @@ hpVqvdkKsxmNWrHSLcFbEY:G:g:T:U:O:l:n:i:o:a:t:D:A:R:P:B:e:Q:X:I:w:C:",
case 150:
setval ("simplehostcheck", "on");
break;
case 154:
/* For debugging purposes. */
printf ("%s\n", ftp_getaddress ());
exit (0);
break;
case 155:
setval ("bindaddress", optarg);
break;

View File

@ -63,32 +63,6 @@ read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
return buf;
}
char *
pwd_cuserid (char *where)
{
char buf[32], *ptr;
int len = sizeof (buf);
if (GetUserName (buf, (LPDWORD) &len) == TRUE)
{
;
}
else if (!!(ptr = getenv ("USERNAME")))
{
strcpy (buf, ptr);
}
else if (!read_registry (HKEY_LOCAL_MACHINE, "Network\\Logon",
"username", buf, &len))
{
return NULL;
}
if (where)
{
strncpy (where, buf, len);
return where;
}
return xstrdup (buf);
}
void
windows_main_junk (int *argc, char **argv, char **exec_name)
{

View File

@ -67,7 +67,7 @@ search_netrc (const char *host, const char **acc, const char **passwd,
/* Find ~/.netrc. */
if (!processed_netrc)
{
char *home = home_dir();
char *home = home_dir ();
netrc_list = NULL;
processed_netrc = 1;
@ -140,51 +140,58 @@ search_netrc (const char *host, const char **acc, const char **passwd,
#ifdef STANDALONE
#include <assert.h>
/* Normally, these functions would be defined by your package. */
# define xmalloc malloc
# define xfree free
# define xstrdup strdup
/* The function reads a whole line. It reads the line realloc-ing the
storage exponentially, doubling the storage after each overflow to
minimize the number of calls to realloc().
It is not an exemplary of correctness, since it kills off the
newline (and no, there is no way to know if there was a newline at
EOF). */
# define xrealloc realloc
# define DYNAMIC_LINE_BUFFER 40
/* Read a line from FP. The function reallocs the storage as needed
to accomodate for any length of the line. Reallocs are done
storage exponentially, doubling the storage after each overflow to
minimize the number of calls to realloc() and fgets(). The newline
character at the end of line is retained.
After end-of-file is encountered without anything being read, NULL
is returned. NULL is also returned on error. To distinguish
between these two cases, use the stdio function ferror(). */
char *
read_whole_line (FILE *fp)
{
char *line;
int i, bufsize, c;
int length = 0;
int bufsize = 81;
char *line = (char *)xmalloc (bufsize);
i = 0;
bufsize = DYNAMIC_LINE_BUFFER;
line = xmalloc(bufsize);
/* Construct the line. */
while ((c = getc(fp)) != EOF && c != '\n')
while (fgets (line + length, bufsize - length, fp))
{
if (i > bufsize - 1)
line = (char *)xrealloc(line, (bufsize <<= 1));
line[i++] = c;
length += strlen (line + length);
assert (length > 0);
if (line[length - 1] == '\n')
break;
/* fgets() guarantees to read the whole line, or to use up the
space we've given it. We can double the buffer
unconditionally. */
bufsize <<= 1;
line = xrealloc (line, bufsize);
}
if (c == EOF && !i)
if (length == 0 || ferror (fp))
{
xfree(line);
xfree (line);
return NULL;
}
/* Check for overflow at zero-termination (no need to double the
buffer in this case. */
if (i == bufsize)
line = (char *)xrealloc(line, i + 1);
line[i] = '\0';
if (length + 1 < bufsize)
/* Relieve the memory from our exponential greediness. We say
`length + 1' because the terminating \0 is not included in
LENGTH. We don't need to zero-terminate the string ourselves,
though, because fgets() does that. */
line = xrealloc (line, length + 1);
return line;
}
#endif /* STANDALONE */
/* Maybe add NEWENTRY to the account information list, LIST. NEWENTRY is

View File

@ -431,31 +431,7 @@ uerrmsg (uerr_t errnum)
/* The Windows versions of the following two functions are defined in
mswindows.c. */
/* A cuserid() immitation using getpwuid(), to avoid hassling with
utmp. Besides, not all systems have cuesrid(). Under Windows, it
is defined in mswindows.c.
If WHERE is non-NULL, the username will be stored there.
Otherwise, it will be returned as a static buffer (as returned by
getpwuid()). In the latter case, the buffer should be copied
before calling getpwuid() or pwd_cuserid() again. */
#ifndef WINDOWS
char *
pwd_cuserid (char *where)
{
struct passwd *pwd;
if (!(pwd = getpwuid (getuid ())) || !pwd->pw_name)
return NULL;
if (where)
{
strcpy (where, pwd->pw_name);
return where;
}
else
return pwd->pw_name;
}
void
fork_to_background (void)
{