version 1.156, 2017/01/07 12:10:11 |
version 1.157, 2017/01/10 17:43:12 |
|
|
#include "ftp_var.h" |
#include "ftp_var.h" |
#include "cmds.h" |
#include "cmds.h" |
|
|
static int url_get(const char *, const char *, const char *); |
static int url_get(const char *, const char *, const char *, int); |
void aborthttp(int); |
void aborthttp(int); |
void abortfile(int); |
void abortfile(int); |
char hextochar(const char *); |
char hextochar(const char *); |
|
|
* Returns -1 on failure, 0 on success |
* Returns -1 on failure, 0 on success |
*/ |
*/ |
static int |
static int |
url_get(const char *origline, const char *proxyenv, const char *outfile) |
url_get(const char *origline, const char *proxyenv, const char *outfile, int lastfile) |
{ |
{ |
char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *portnum, *path, ststr[4]; |
char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *portnum, *path, ststr[4]; |
char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; |
char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; |
|
|
fin = fdopen(s, "r+"); |
fin = fdopen(s, "r+"); |
#endif /* !NOSSL */ |
#endif /* !NOSSL */ |
|
|
|
#ifdef SMALL |
|
if (lastfile) { |
|
if (pipeout) { |
|
if (pledge("stdio rpath inet dns tty", NULL) == -1) |
|
err(1, "pledge"); |
|
} else { |
|
if (pledge("stdio rpath wpath cpath inet dns tty", NULL) == -1) |
|
err(1, "pledge"); |
|
} |
|
} |
|
#endif |
|
|
if (connect_timeout) { |
if (connect_timeout) { |
signal(SIGALRM, SIG_DFL); |
signal(SIGALRM, SIG_DFL); |
alarmtimer(0); |
alarmtimer(0); |
|
|
fclose(fin); |
fclose(fin); |
else if (s != -1) |
else if (s != -1) |
close(s); |
close(s); |
rval = url_get(redirurl, proxyenv, savefile); |
rval = url_get(redirurl, proxyenv, savefile, lastfile); |
free(redirurl); |
free(redirurl); |
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
|
|
warn("Can't open %s", savefile); |
warn("Can't open %s", savefile); |
goto cleanup_url_get; |
goto cleanup_url_get; |
} |
} |
} else |
} else { |
out = fileno(stdout); |
out = fileno(stdout); |
|
#ifdef SMALL |
|
if (lastfile) { |
|
if (pledge("stdio tty", NULL) == -1) |
|
err(1, "pledge"); |
|
} |
|
#endif |
|
} |
|
|
/* Trap signals */ |
/* Trap signals */ |
oldintr = NULL; |
oldintr = NULL; |
|
|
char *cp, *url, *host, *dir, *file, *portnum; |
char *cp, *url, *host, *dir, *file, *portnum; |
char *username, *pass, *pathstart; |
char *username, *pass, *pathstart; |
char *ftpproxy, *httpproxy; |
char *ftpproxy, *httpproxy; |
int rval, xargc; |
int rval, xargc, lastfile; |
volatile int argpos; |
volatile int argpos; |
int dirhasglob, filehasglob, oautologin; |
int dirhasglob, filehasglob, oautologin; |
char rempath[PATH_MAX]; |
char rempath[PATH_MAX]; |
|
|
free(pass); |
free(pass); |
host = dir = file = portnum = username = pass = NULL; |
host = dir = file = portnum = username = pass = NULL; |
|
|
|
lastfile = (argv[argpos+1] == NULL); |
|
|
/* |
/* |
* We muck with the string, so we make a copy. |
* We muck with the string, so we make a copy. |
*/ |
*/ |
|
|
#endif /* !NOSSL */ |
#endif /* !NOSSL */ |
strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { |
strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) { |
redirect_loop = 0; |
redirect_loop = 0; |
if (url_get(url, httpproxy, outfile) == -1) |
if (url_get(url, httpproxy, outfile, lastfile) == -1) |
rval = argpos + 1; |
rval = argpos + 1; |
continue; |
continue; |
} |
} |
|
|
char *passend, *passagain, *userend; |
char *passend, *passagain, *userend; |
|
|
if (ftpproxy) { |
if (ftpproxy) { |
if (url_get(url, ftpproxy, outfile) == -1) |
if (url_get(url, ftpproxy, outfile, lastfile) == -1) |
rval = argpos + 1; |
rval = argpos + 1; |
continue; |
continue; |
} |
} |