diff options
-rw-r--r-- | usr.bin/ftp/fetch.c | 119 | ||||
-rw-r--r-- | usr.bin/ftp/util.c | 110 |
2 files changed, 104 insertions, 125 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 7ca878b1062..35115141fa3 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.52 2005/04/05 22:37:00 henning Exp $ */ +/* $OpenBSD: fetch.c,v 1.53 2005/04/11 15:16:50 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -38,7 +38,7 @@ */ #if !defined(lint) && !defined(SMALL) -static char rcsid[] = "$OpenBSD: fetch.c,v 1.52 2005/04/05 22:37:00 henning Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.53 2005/04/11 15:16:50 deraadt Exp $"; #endif /* not lint and not SMALL */ /* @@ -86,7 +86,7 @@ char *urldecode(const char *); #define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) static const char *at_encoding_warning = - "Extra `@' characters in usernames and passwords should be encoded as %%40"; + "Extra `@' characters in usernames and passwords should be encoded as %%40"; jmp_buf httpabort; @@ -98,31 +98,17 @@ jmp_buf httpabort; static int url_get(const char *origline, const char *proxyenv, const char *outfile) { + char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *ep, *portnum, *path; + char *hosttail, *cause = "unknown", *line, *host, *port, *buf = NULL; + int error, i, isftpurl = 0, isfileurl = 0, isredirect = 0, rval = -1; struct addrinfo hints, *res0, *res; - int error; - int i, isftpurl, isfileurl, isredirect; - volatile int s, out; - size_t len; - char *cp, *ep, *portnum, *path; - char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST]; const char * volatile savefile; - char *line, *host, *port, *buf; - char * volatile proxy; - char *hosttail; + char * volatile proxy = NULL; + volatile int s = -1, out; volatile sig_t oldintr; + FILE *fin = NULL; off_t hashbytes; - char *cause = "unknown"; - FILE *fin; - int rval; - - s = -1; - proxy = NULL; - fin = NULL; - buf = NULL; - isftpurl = 0; - isfileurl = 0; - isredirect = 0; - rval = -1; + size_t len; line = strdup(origline); if (line == NULL) @@ -873,54 +859,53 @@ bad_ftp_url: char * urldecode(const char *str) { - char *ret; - char c; - int i, reallen; - - if (str == NULL) - return NULL; - if ((ret = malloc(strlen(str)+1)) == NULL) - err(1, "Can't allocate memory for URL decoding"); - for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { - c = str[i]; - if (c == '+') { - *ret = ' '; - continue; - } - /* Can't use strtol here because next char after %xx may be - * a digit. */ - if (c == '%' && isxdigit(str[i+1]) && isxdigit(str[i+2])) { - *ret = hextochar(&str[i+1]); - i+=2; - continue; - } - *ret = c; - } - *ret = '\0'; - - return ret-reallen; + char *ret, c; + int i, reallen; + + if (str == NULL) + return NULL; + if ((ret = malloc(strlen(str)+1)) == NULL) + err(1, "Can't allocate memory for URL decoding"); + for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { + c = str[i]; + if (c == '+') { + *ret = ' '; + continue; + } + /* Can't use strtol here because next char after %xx may be + * a digit. */ + if (c == '%' && isxdigit(str[i+1]) && isxdigit(str[i+2])) { + *ret = hextochar(&str[i+1]); + i+=2; + continue; + } + *ret = c; + } + *ret = '\0'; + + return ret-reallen; } char hextochar(const char *str) { - char c, ret; - - c = str[0]; - ret = c; - if (isalpha(c)) - ret -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - ret -= '0'; - ret *= 16; - - c = str[1]; - ret += c; - if (isalpha(c)) - ret -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - ret -= '0'; - return ret; + char c, ret; + + c = str[0]; + ret = c; + if (isalpha(c)) + ret -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + ret -= '0'; + ret *= 16; + + c = str[1]; + ret += c; + if (isalpha(c)) + ret -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + ret -= '0'; + return ret; } int diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 6aa70bbc69e..131bfca5acc 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.39 2004/09/16 04:39:16 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.40 2005/04/11 15:16:50 deraadt Exp $ */ /* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */ /*- @@ -71,7 +71,7 @@ */ #if !defined(lint) && !defined(SMALL) -static char rcsid[] = "$OpenBSD: util.c,v 1.39 2004/09/16 04:39:16 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.40 2005/04/11 15:16:50 deraadt Exp $"; #endif /* not lint and not SMALL */ /* @@ -108,8 +108,7 @@ static void updateprogressmeter(int); void setpeer(int argc, char *argv[]) { - char *host; - char *port; + char *host, *port; if (connected) { fprintf(ttyout, "Already connected to %s, use close first.\n", @@ -248,14 +247,11 @@ setpeer(int argc, char *argv[]) int ftp_login(const char *host, char *user, char *pass) { - char tmp[80]; - char *acct; + char tmp[80], *acct = NULL, hostname[MAXHOSTNAMELEN]; char anonpass[MAXLOGNAME + 1 + MAXHOSTNAMELEN]; /* "user@hostname" */ - char hostname[MAXHOSTNAMELEN]; - struct passwd *pw; int n, aflag = 0, retry = 0; + struct passwd *pw; - acct = NULL; if (user == NULL) { if (ruserpass(host, &user, &pass, &acct) < 0) { code = -1; @@ -391,32 +387,30 @@ another(int *pargc, char ***pargv, const char *prompt) char * remglob(char *argv[], int doswitch, char **errbuf) { - char temp[MAXPATHLEN]; - static char buf[MAXPATHLEN]; - static FILE *ftemp = NULL; - static char **args; - int oldverbose, oldhash, fd; - char *cp, *mode; - - if (!mflag) { - if (!doglob) - args = NULL; - else { - if (ftemp) { - (void)fclose(ftemp); - ftemp = NULL; - } - } - return (NULL); - } - if (!doglob) { - if (args == NULL) - args = argv; - if ((cp = *++args) == NULL) - args = NULL; - return (cp); - } - if (ftemp == NULL) { + char temp[MAXPATHLEN], *cp, *mode; + static char buf[MAXPATHLEN], **args; + static FILE *ftemp = NULL; + int oldverbose, oldhash, fd; + + if (!mflag) { + if (!doglob) + args = NULL; + else { + if (ftemp) { + (void)fclose(ftemp); + ftemp = NULL; + } + } + return (NULL); + } + if (!doglob) { + if (args == NULL) + args = argv; + if ((cp = *++args) == NULL) + args = NULL; + return (cp); + } + if (ftemp == NULL) { int len; if ((cp = getenv("TMPDIR")) == NULL || *cp == '\0') @@ -432,47 +426,47 @@ remglob(char *argv[], int doswitch, char **errbuf) if (temp[len-1] != '/') temp[len++] = '/'; (void)strlcpy(&temp[len], TMPFILE, sizeof temp - len); - if ((fd = mkstemp(temp)) < 0) { - warn("unable to create temporary file %s", temp); - return (NULL); - } - close(fd); + if ((fd = mkstemp(temp)) < 0) { + warn("unable to create temporary file %s", temp); + return (NULL); + } + close(fd); oldverbose = verbose; verbose = (errbuf != NULL) ? -1 : 0; oldhash = hash; hash = 0; - if (doswitch) - pswitch(!proxy); - for (mode = "w"; *++argv != NULL; mode = "a") - recvrequest("NLST", temp, *argv, mode, 0, 0); + if (doswitch) + pswitch(!proxy); + for (mode = "w"; *++argv != NULL; mode = "a") + recvrequest("NLST", temp, *argv, mode, 0, 0); if ((code / 100) != COMPLETE) { if (errbuf != NULL) *errbuf = reply_string; } if (doswitch) pswitch(!proxy); - verbose = oldverbose; + verbose = oldverbose; hash = oldhash; - ftemp = fopen(temp, "r"); - (void)unlink(temp); - if (ftemp == NULL) { + ftemp = fopen(temp, "r"); + (void)unlink(temp); + if (ftemp == NULL) { if (errbuf == NULL) fputs("can't find list of remote files, oops.\n", ttyout); else *errbuf = "can't find list of remote files, oops."; - return (NULL); - } - } - if (fgets(buf, sizeof(buf), ftemp) == NULL) { - (void)fclose(ftemp); + return (NULL); + } + } + if (fgets(buf, sizeof(buf), ftemp) == NULL) { + (void)fclose(ftemp); ftemp = NULL; - return (NULL); - } - if ((cp = strchr(buf, '\n')) != NULL) - *cp = '\0'; - return (buf); + return (NULL); + } + if ((cp = strchr(buf, '\n')) != NULL) + *cp = '\0'; + return (buf); } int |