summaryrefslogtreecommitdiff
path: root/net/tnftp/files/src
diff options
context:
space:
mode:
Diffstat (limited to 'net/tnftp/files/src')
-rw-r--r--net/tnftp/files/src/Makefile.in3
-rw-r--r--net/tnftp/files/src/cmds.c248
-rw-r--r--net/tnftp/files/src/cmdtab.c16
-rw-r--r--net/tnftp/files/src/complete.c10
-rw-r--r--net/tnftp/files/src/domacro.c14
-rw-r--r--net/tnftp/files/src/extern.h11
-rw-r--r--net/tnftp/files/src/fetch.c25
-rw-r--r--net/tnftp/files/src/ftp.150
-rw-r--r--net/tnftp/files/src/ftp.c187
-rw-r--r--net/tnftp/files/src/ftp.cat127
-rw-r--r--net/tnftp/files/src/ftp_var.h13
-rw-r--r--net/tnftp/files/src/main.c40
-rw-r--r--net/tnftp/files/src/progressbar.c17
-rw-r--r--net/tnftp/files/src/progressbar.h4
-rw-r--r--net/tnftp/files/src/ruserpass.c14
-rw-r--r--net/tnftp/files/src/util.c151
-rw-r--r--net/tnftp/files/src/version.h5
17 files changed, 531 insertions, 304 deletions
diff --git a/net/tnftp/files/src/Makefile.in b/net/tnftp/files/src/Makefile.in
index 627310e4ca7..6d6d75df0b5 100644
--- a/net/tnftp/files/src/Makefile.in
+++ b/net/tnftp/files/src/Makefile.in
@@ -1,5 +1,4 @@
-#
-# $Id: Makefile.in,v 1.1.1.1 2003/03/01 00:02:21 lukem Exp $
+# NetBSD: Makefile.in,v 1.3 2005/05/11 03:01:40 lukem Exp
#
srcdir = @srcdir@
diff --git a/net/tnftp/files/src/cmds.c b/net/tnftp/files/src/cmds.c
index 4ba717a65f4..96f931b8fde 100644
--- a/net/tnftp/files/src/cmds.c
+++ b/net/tnftp/files/src/cmds.c
@@ -1,4 +1,5 @@
-/* $NetBSD: cmds.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: cmds.c,v 1.6 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
@@ -72,7 +73,7 @@
/*
* Copyright (C) 1997 and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -84,7 +85,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -104,7 +105,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmds.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: cmds.c,v 1.6 2005/05/11 02:41:28 lukem Exp");
#endif
#endif /* not lint */
#endif
@@ -137,6 +138,11 @@ const char *mname;
static int confirm(const char *, const char *);
+static const char *doprocess(char *, size_t, const char *, int, int, int);
+static const char *domap(char *, size_t, const char *);
+static const char *docase(char *, size_t, const char *);
+static const char *dotrans(char *, size_t, const char *);
+
static int
confirm(const char *cmd, const char *file)
{
@@ -378,9 +384,11 @@ setstruct(int argc, char *argv[])
void
put(int argc, char *argv[])
{
+ char buf[MAXPATHLEN];
char *cmd;
int loc = 0;
- char *locfile, *remfile;
+ char *locfile;
+ const char *remfile;
if (argc == 2) {
argc++;
@@ -404,15 +412,26 @@ put(int argc, char *argv[])
if (loc) /* If argv[2] is a copy of the old argv[1], update it */
remfile = locfile;
cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
- if (loc && ntflag)
- remfile = dotrans(remfile);
- if (loc && mapflag)
- remfile = domap(remfile);
+ remfile = doprocess(buf, sizeof(buf), remfile,
+ 0, loc && ntflag, loc && mapflag);
sendrequest(cmd, locfile, remfile,
locfile != argv[1] || remfile != argv[2]);
free(locfile);
}
+static const char *
+doprocess(char *dst, size_t dlen, const char *src,
+ int casef, int transf, int mapf)
+{
+ if (casef)
+ src = docase(dst, dlen, src);
+ if (transf)
+ src = dotrans(dst, dlen, src);
+ if (mapf)
+ src = domap(dst, dlen, src);
+ return src;
+}
+
/*
* Send multiple files.
*/
@@ -422,7 +441,7 @@ mput(int argc, char *argv[])
int i;
sigfunc oldintr;
int ointer;
- char *tp;
+ const char *tp;
if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
fprintf(ttyout, "usage: %s local-files\n", argv[0]);
@@ -443,13 +462,9 @@ mput(int argc, char *argv[])
continue;
}
if (mflag && confirm(argv[0], cp)) {
- tp = cp;
- if (mcase)
- tp = docase(tp);
- if (ntflag)
- tp = dotrans(tp);
- if (mapflag)
- tp = domap(tp);
+ char buf[MAXPATHLEN];
+ tp = doprocess(buf, sizeof(buf), cp,
+ mcase, ntflag, mapflag);
sendrequest((sunique) ? "STOU" : "STOR",
cp, tp, cp != tp || !interactive);
if (!mflag && fromatty) {
@@ -471,8 +486,9 @@ mput(int argc, char *argv[])
if (!doglob) {
if (mflag && confirm(argv[0], argv[i])) {
- tp = (ntflag) ? dotrans(argv[i]) : argv[i];
- tp = (mapflag) ? domap(tp) : tp;
+ char buf[MAXPATHLEN];
+ tp = doprocess(buf, sizeof(buf), argv[i],
+ 0, ntflag, mapflag);
sendrequest((sunique) ? "STOU" : "STOR",
argv[i], tp, tp != argv[i] || !interactive);
if (!mflag && fromatty) {
@@ -497,8 +513,10 @@ mput(int argc, char *argv[])
for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
cpp++) {
if (mflag && confirm(argv[0], *cpp)) {
- tp = (ntflag) ? dotrans(*cpp) : *cpp;
- tp = (mapflag) ? domap(tp) : tp;
+ char buf[MAXPATHLEN];
+ tp = *cpp;
+ tp = doprocess(buf, sizeof(buf), *cpp,
+ 0, ntflag, mapflag);
sendrequest((sunique) ? "STOU" : "STOR",
*cpp, tp, *cpp != tp || !interactive);
if (!mflag && fromatty) {
@@ -540,8 +558,10 @@ get(int argc, char *argv[])
int
getit(int argc, char *argv[], int restartit, const char *mode)
{
- int loc, rval;
- char *remfile, *locfile, *olocfile;
+ int loc, rval;
+ char *remfile, *olocfile;
+ const char *locfile;
+ char buf[MAXPATHLEN];
loc = rval = 0;
if (argc == 2) {
@@ -563,13 +583,8 @@ getit(int argc, char *argv[], int restartit, const char *mode)
code = -1;
return (0);
}
- locfile = olocfile;
- if (loc && mcase)
- locfile = docase(locfile);
- if (loc && ntflag)
- locfile = dotrans(locfile);
- if (loc && mapflag)
- locfile = domap(locfile);
+ locfile = doprocess(buf, sizeof(buf), olocfile,
+ loc && mcase, loc && ntflag, loc && mapflag);
if (restartit) {
struct stat stbuf;
int ret;
@@ -649,7 +664,8 @@ mget(int argc, char *argv[])
{
sigfunc oldintr;
int ointer;
- char *cp, *tp;
+ char *cp;
+ const char *tp;
int restartit;
if (argc == 0 ||
@@ -674,6 +690,7 @@ mget(int argc, char *argv[])
if (sigsetjmp(jabort, 1))
mabort();
while ((cp = remglob(argv, proxy, NULL)) != NULL) {
+ char buf[MAXPATHLEN];
if (*cp == '\0' || !connected) {
mflag = 0;
continue;
@@ -687,13 +704,7 @@ mget(int argc, char *argv[])
}
if (!confirm(argv[0], cp))
continue;
- tp = cp;
- if (mcase)
- tp = docase(tp);
- if (ntflag)
- tp = dotrans(tp);
- if (mapflag)
- tp = domap(tp);
+ tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
if (restartit) {
struct stat stbuf;
@@ -1376,7 +1387,7 @@ mls(int argc, char *argv[])
ointer = interactive;
interactive = 1;
if (confirm("Continue with", argv[0])) {
- mflag ++;
+ mflag++;
}
interactive = ointer;
}
@@ -1666,7 +1677,7 @@ do_chmod(int argc, char *argv[])
(void)command("SITE CHMOD %s %s", argv[1], argv[2]);
}
-#define COMMAND_1ARG(argc, argv, cmd) \
+#define COMMAND_1ARG(argc, argv, cmd) \
if (argc == 1) \
command(cmd); \
else \
@@ -1868,26 +1879,25 @@ setcase(int argc, char *argv[])
* convert the given name to lower case if it's all upper case, into
* a static buffer which is returned to the caller
*/
-char *
-docase(char *name)
+static const char *
+docase(char *dst, size_t dlen, const char *src)
{
- static char new[MAXPATHLEN];
- int i, dochange;
+ size_t i;
+ int dochange = 1;
- dochange = 1;
- for (i = 0; name[i] != '\0' && i < sizeof(new) - 1; i++) {
- new[i] = name[i];
- if (islower((unsigned char)new[i]))
+ for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
+ dst[i] = src[i];
+ if (islower((unsigned char)dst[i]))
dochange = 0;
}
- new[i] = '\0';
+ dst[i] = '\0';
if (dochange) {
- for (i = 0; new[i] != '\0'; i++)
- if (isupper((unsigned char)new[i]))
- new[i] = tolower((unsigned char)new[i]);
+ for (i = 0; dst[i] != '\0'; i++)
+ if (isupper((unsigned char)dst[i]))
+ dst[i] = tolower((unsigned char)dst[i]);
}
- return (new);
+ return dst;
}
void
@@ -1922,22 +1932,24 @@ setntrans(int argc, char *argv[])
(void)strlcpy(ntout, argv[2], sizeof(ntout));
}
-char *
-dotrans(char *name)
+static const char *
+dotrans(char *dst, size_t dlen, const char *src)
{
- static char new[MAXPATHLEN];
- char *cp1, *cp2 = new;
- int i, ostop, found;
+ const char *cp1;
+ char *cp2 = dst;
+ size_t i, ostop;
for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
continue;
- for (cp1 = name; *cp1; cp1++) {
- found = 0;
+ for (cp1 = src; *cp1; cp1++) {
+ int found = 0;
for (i = 0; *(ntin + i) && i < 16; i++) {
if (*cp1 == *(ntin + i)) {
found++;
if (i < ostop) {
*cp2++ = *(ntout + i);
+ if (cp2 - dst >= dlen - 1)
+ goto out;
}
break;
}
@@ -1946,8 +1958,9 @@ dotrans(char *name)
*cp2++ = *cp1;
}
}
+out:
*cp2 = '\0';
- return (new);
+ return dst;
}
void
@@ -1983,12 +1996,12 @@ setnmap(int argc, char *argv[])
(void)strlcpy(mapout, cp, MAXPATHLEN);
}
-char *
-domap(char *name)
+static const char *
+domap(char *dst, size_t dlen, const char *src)
{
- static char new[MAXPATHLEN];
- char *cp1 = name, *cp2 = mapin;
- char *tp[9], *te[9];
+ const char *cp1 = src;
+ char *cp2 = mapin;
+ const char *tp[9], *te[9];
int i, toks[9], toknum = 0, match = 1;
for (i=0; i < 9; ++i) {
@@ -2031,130 +2044,127 @@ domap(char *name)
{
toks[toknum] = 0;
}
- cp1 = new;
- *cp1 = '\0';
- cp2 = mapout;
- while (*cp2) {
+ cp2 = dst;
+ *cp2 = '\0';
+ cp1 = mapout;
+ while (*cp1) {
match = 0;
- switch (*cp2) {
+ switch (*cp1) {
case '\\':
- if (*(cp2 + 1)) {
- *cp1++ = *++cp2;
+ if (*(cp1 + 1)) {
+ *cp2++ = *++cp1;
}
break;
case '[':
LOOP:
- if (*++cp2 == '$' &&
- isdigit((unsigned char)*(cp2+1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
+ if (*++cp1 == '$' &&
+ isdigit((unsigned char)*(cp1+1))) {
+ if (*++cp1 == '0') {
+ const char *cp3 = src;
while (*cp3) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
match = 1;
}
- else if (toks[toknum = *cp2 - '1']) {
- char *cp3 = tp[toknum];
+ else if (toks[toknum = *cp1 - '1']) {
+ const char *cp3 = tp[toknum];
while (cp3 != te[toknum]) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
match = 1;
}
}
else {
- while (*cp2 && *cp2 != ',' &&
- *cp2 != ']') {
- if (*cp2 == '\\') {
- cp2++;
+ while (*cp1 && *cp1 != ',' &&
+ *cp1 != ']') {
+ if (*cp1 == '\\') {
+ cp1++;
}
- else if (*cp2 == '$' &&
- isdigit((unsigned char)*(cp2+1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
+ else if (*cp1 == '$' &&
+ isdigit((unsigned char)*(cp1+1))) {
+ if (*++cp1 == '0') {
+ const char *cp3 = src;
while (*cp3) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
}
else if (toks[toknum =
- *cp2 - '1']) {
- char *cp3=tp[toknum];
+ *cp1 - '1']) {
+ const char *cp3=tp[toknum];
while (cp3 !=
te[toknum]) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
}
}
- else if (*cp2) {
- *cp1++ = *cp2++;
+ else if (*cp1) {
+ *cp2++ = *cp1++;
}
}
- if (!*cp2) {
+ if (!*cp1) {
fputs(
"nmap: unbalanced brackets.\n",
ttyout);
- return (name);
+ return (src);
}
match = 1;
- cp2--;
+ cp1--;
}
if (match) {
- while (*++cp2 && *cp2 != ']') {
- if (*cp2 == '\\' && *(cp2 + 1)) {
- cp2++;
+ while (*++cp1 && *cp1 != ']') {
+ if (*cp1 == '\\' && *(cp1 + 1)) {
+ cp1++;
}
}
- if (!*cp2) {
+ if (!*cp1) {
fputs(
"nmap: unbalanced brackets.\n",
ttyout);
- return (name);
+ return (src);
}
break;
}
- switch (*++cp2) {
+ switch (*++cp1) {
case ',':
goto LOOP;
case ']':
break;
default:
- cp2--;
+ cp1--;
goto LOOP;
}
break;
case '$':
- if (isdigit((unsigned char)*(cp2 + 1))) {
- if (*++cp2 == '0') {
- char *cp3 = name;
+ if (isdigit((unsigned char)*(cp1 + 1))) {
+ if (*++cp1 == '0') {
+ const char *cp3 = src;
while (*cp3) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
}
- else if (toks[toknum = *cp2 - '1']) {
- char *cp3 = tp[toknum];
+ else if (toks[toknum = *cp1 - '1']) {
+ const char *cp3 = tp[toknum];
while (cp3 != te[toknum]) {
- *cp1++ = *cp3++;
+ *cp2++ = *cp3++;
}
}
break;
}
/* intentional drop through */
default:
- *cp1++ = *cp2;
+ *cp2++ = *cp1;
break;
}
- cp2++;
- }
- *cp1 = '\0';
- if (!*new) {
- return (name);
+ cp1++;
}
- return (new);
+ *cp2 = '\0';
+ return *dst ? dst : src;
}
void
diff --git a/net/tnftp/files/src/cmdtab.c b/net/tnftp/files/src/cmdtab.c
index b072ee3b36a..9f52b0d012d 100644
--- a/net/tnftp/files/src/cmdtab.c
+++ b/net/tnftp/files/src/cmdtab.c
@@ -1,4 +1,5 @@
-/* $NetBSD: cmdtab.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: cmdtab.c,v 1.5 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: cmdtab.c,v 1.44 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@@ -65,6 +66,17 @@
* SUCH DAMAGE.
*/
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
+#else
+__RCSID("NetBSD: cmdtab.c,v 1.5 2005/05/11 02:41:28 lukem Exp");
+#endif
+#endif /* not lint */
+#endif
+
#include "tnftp.h"
#include "ftp_var.h"
@@ -180,7 +192,7 @@ HSTR empty[] = "";
#define CMPL0
#else /* !NO_EDITCOMPLETE */
#define CMPL(x) #x,
-#define CMPL0 empty,
+#define CMPL0 empty,
#endif /* !NO_EDITCOMPLETE */
struct cmd cmdtab[] = {
diff --git a/net/tnftp/files/src/complete.c b/net/tnftp/files/src/complete.c
index fb8def2ac8f..60578967665 100644
--- a/net/tnftp/files/src/complete.c
+++ b/net/tnftp/files/src/complete.c
@@ -1,4 +1,5 @@
-/* $NetBSD: complete.c,v 1.1.1.1 2003/02/28 10:44:52 lukem Exp $ */
+/* NetBSD: complete.c,v 1.3 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp */
/*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -36,6 +37,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("NetBSD: complete.c,v 1.3 2005/05/11 02:41:28 lukem Exp");
+#endif /* not lint */
+#endif
+
/*
* FTP user program - command and file completion routines
*/
diff --git a/net/tnftp/files/src/domacro.c b/net/tnftp/files/src/domacro.c
index 1fc8f25a33e..27c7657de89 100644
--- a/net/tnftp/files/src/domacro.c
+++ b/net/tnftp/files/src/domacro.c
@@ -1,4 +1,5 @@
-/* $NetBSD: domacro.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: domacro.c,v 1.4 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: domacro.c,v 1.20 2003/08/07 11:13:53 agc Exp */
/*
* Copyright (c) 1985, 1993, 1994
@@ -29,6 +30,17 @@
* SUCH DAMAGE.
*/
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
+#else
+__RCSID("NetBSD: domacro.c,v 1.4 2005/05/11 02:41:28 lukem Exp");
+#endif
+#endif /* not lint */
+#endif
+
#include "tnftp.h"
#include "ftp_var.h"
diff --git a/net/tnftp/files/src/extern.h b/net/tnftp/files/src/extern.h
index 7f47a0b38d9..2998cd68fbe 100644
--- a/net/tnftp/files/src/extern.h
+++ b/net/tnftp/files/src/extern.h
@@ -1,4 +1,5 @@
-/* $NetBSD: extern.h,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: extern.h,v 1.5 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: extern.h,v 1.66 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
@@ -70,7 +71,7 @@
/*
* Copyright (C) 1997 and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -82,7 +83,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -129,11 +130,8 @@ void delete(int, char **);
void disconnect(int, char **);
void do_chmod(int, char **);
void do_umask(int, char **);
-char *docase(char *);
void domacro(int, char **);
-char *domap(char *);
void doproxy(int, char **);
-char *dotrans(char *);
void feat(int, char **);
void fget(int, char **);
int fileindir(const char *, const char *);
@@ -253,6 +251,7 @@ void usage(void);
void user(int, char **);
int xconnect(int, const struct sockaddr *, int);
int xlisten(int, int);
+int xpoll(struct pollfd *, int, int);
void *xmalloc(size_t);
StringList *xsl_init(void);
void xsl_add(StringList *, char *);
diff --git a/net/tnftp/files/src/fetch.c b/net/tnftp/files/src/fetch.c
index bf81acffd66..b835808ca76 100644
--- a/net/tnftp/files/src/fetch.c
+++ b/net/tnftp/files/src/fetch.c
@@ -1,4 +1,5 @@
-/* $NetBSD: fetch.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: fetch.c,v 1.7 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: fetch.c,v 1.157 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -42,7 +43,7 @@
#if 0
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: fetch.c,v 1.7 2005/05/11 02:41:28 lukem Exp");
#endif /* not lint */
#endif
@@ -714,7 +715,6 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
/* success */
break;
}
- freeaddrinfo(res0);
if (s < 0) {
warn("Can't connect to %s", host);
@@ -956,7 +956,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
|| match_token(&cp, "WWW-Authenticate:")) {
if (! (token = match_token(&cp, "Basic"))) {
if (debug)
- fprintf(ttyout,
+ fprintf(ttyout,
"skipping unknown auth scheme `%s'\n",
token);
continue;
@@ -1257,6 +1257,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
close(s);
if (closefunc != NULL && fout != NULL)
(*closefunc)(fout);
+ if (res0)
+ freeaddrinfo(res0);
FREEPTR(savefile);
FREEPTR(user);
FREEPTR(pass);
@@ -1397,7 +1399,7 @@ fetch_ftp(const char *url)
} else
dir = NULL;
if (urltype == FTP_URL_T && file != NULL) {
- url_decode(file);
+ url_decode(file);
/* but still don't url_decode(dir) */
}
if (debug)
@@ -1578,7 +1580,10 @@ fetch_ftp(const char *url)
ointeractive = interactive;
interactive = 0;
- xargv[0] = "mget";
+ if (restartautofetch)
+ xargv[0] = "mreget";
+ else
+ xargv[0] = "mget";
mget(xargc, xargv);
interactive = ointeractive;
} else {
@@ -1775,7 +1780,7 @@ auto_put(int argc, char **argv, const char *uploadserver)
pathsep++;
uargv[2] = xstrdup(pathsep);
pathsep[0] = '/';
- } else
+ } else
uargv[2] = xstrdup(pathsep + 1);
pathsep[1] = '\0';
uargc++;
@@ -1784,8 +1789,8 @@ auto_put(int argc, char **argv, const char *uploadserver)
if (debug)
fprintf(ttyout, "auto_put: URL `%s' argv[2] `%s'\n",
path, uargv[2] ? uargv[2] : "<null>");
-
- /* connect and cwd */
+
+ /* connect and cwd */
rval = auto_fetch(1, &path);
free(path);
if(rval >= 0)
@@ -1799,7 +1804,7 @@ auto_put(int argc, char **argv, const char *uploadserver)
}
for(; argv[0] != NULL; argv++) {
- uargv[1] = argv[0];
+ uargv[1] = argv[0];
mput(uargc, uargv);
}
rval = 0;
diff --git a/net/tnftp/files/src/ftp.1 b/net/tnftp/files/src/ftp.1
index bfb1cc97ee4..eda2f1d7015 100644
--- a/net/tnftp/files/src/ftp.1
+++ b/net/tnftp/files/src/ftp.1
@@ -1,6 +1,7 @@
-.\" $NetBSD: ftp.1,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $
+.\" NetBSD: ftp.1,v 1.7 2005/05/11 02:41:28 lukem Exp
+.\" from NetBSD: ftp.1,v 1.109 2005/02/20 20:54:01 wiz Exp
.\"
-.\" Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
@@ -64,7 +65,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd October 7, 2004
+.Dd January 15, 2005
.Dt FTP 1
.Os
.Sh NAME
@@ -951,7 +952,9 @@ traffic.
.Tn FTP
servers are required to support the
.Dv PASV
-command by RFC 1123, some do not.)
+command by
+.Li RFC 1123 ,
+some do not.)
.It Ic pdir Op Ar remote-path
Perform
.Ic dir
@@ -1563,7 +1566,7 @@ ascii or binary (respectively).
The default transfer type is binary.
.Pp
In order to be compliant with
-.Cm RFC 1738 ,
+.Li RFC 1738 ,
.Nm
interprets the
.Ar path
@@ -1614,7 +1617,10 @@ This is unlikely to be useful.
.It
Any
.Sq Li \&% Ns Ar XX
-codes within the path components are decoded, with
+codes
+(per
+.Li RFC 1738 )
+within the path components are decoded, with
.Ar XX
representing a character code in hexadecimal.
This decoding takes place after the
@@ -2222,9 +2228,9 @@ URL requests
.Tn FTP
protocol).
.Pp
-.Em NOTE :
-this is not used for interactive sessions, only for command-line
-fetches.
+See
+.Ev http_proxy
+for further notes about proxy use.
.It Ev http_proxy
URL of
.Tn HTTP
@@ -2235,6 +2241,18 @@ If proxy authentication is required and there is a username and
password in this URL, they will automatically be used in the first
attempt to authenticate to the proxy.
.Pp
+If
+.Dq unsafe
+URL characters are required in the username or password
+(for example
+.Sq @
+or
+.Sq / ) ,
+encode them with
+.Li RFC 1738
+.Sq Li \&% Ns Ar XX
+encoding.
+.Pp
Note that the use of a username and password in
.Ev ftp_proxy
and
@@ -2275,13 +2293,13 @@ for an example of how to make this automatic.
.Sh STANDARDS
.Nm
attempts to be compliant with
-.Cm RFC 959 ,
-.Cm RFC 1123 ,
-.Cm RFC 1738 ,
-.Cm RFC 2068 ,
-.Cm RFC 2389 ,
-.Cm RFC 2428 ,
-.Cm RFC 2732 ,
+.Li RFC 959 ,
+.Li RFC 1123 ,
+.Li RFC 1738 ,
+.Li RFC 2068 ,
+.Li RFC 2389 ,
+.Li RFC 2428 ,
+.Li RFC 2732 ,
and
.Cm draft-ietf-ftpext-mlst-11 .
.Sh HISTORY
diff --git a/net/tnftp/files/src/ftp.c b/net/tnftp/files/src/ftp.c
index 4b56f42d6d7..5481da0c31a 100644
--- a/net/tnftp/files/src/ftp.c
+++ b/net/tnftp/files/src/ftp.c
@@ -1,7 +1,8 @@
-/* $NetBSD: ftp.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: ftp.c,v 1.6 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: ftp.c,v 1.130 2005/05/11 02:29:12 lukem Exp */
/*-
- * Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -68,7 +69,7 @@
/*
* Copyright (C) 1997 and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -80,7 +81,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -102,7 +103,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$NetBSD: ftp.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: ftp.c,v 1.6 2005/05/11 02:41:28 lukem Exp");
#endif
#endif /* not lint */
#endif
@@ -151,6 +152,7 @@ hookup(char *host, char *port)
char hbuf[MAXHOSTNAMELEN];
static char hostnamebuf[MAXHOSTNAMELEN];
char *cause = "unknown";
+ int on = 1;
memset((char *)&hisctladdr, 0, sizeof (hisctladdr));
memset((char *)&myctladdr, 0, sizeof (myctladdr));
@@ -173,7 +175,7 @@ hookup(char *host, char *port)
else
(void)strlcpy(hostnamebuf, host, sizeof(hostnamebuf));
hostname = hostnamebuf;
-
+
for (res = res0; res; res = res->ai_next) {
/*
* make sure that ai_addr is NOT an IPv4 mapped address.
@@ -252,10 +254,12 @@ hookup(char *host, char *port)
#ifdef IPTOS_LOWDELAY
if (hisctladdr.su_family == AF_INET) {
int tos = IPTOS_LOWDELAY;
- if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
- sizeof(int)) < 0)
+ if (setsockopt(s, IPPROTO_IP, IP_TOS,
+ (void *)&tos, sizeof(int)) == -1) {
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_LOWDELAY");
+ }
}
#endif
cin = fdopen(s, "r");
@@ -279,13 +283,11 @@ hookup(char *host, char *port)
code = -1;
goto bad;
}
- {
- int on = 1;
- if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))
- < 0 && debug) {
- warn("setsockopt");
- }
+ if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
+ (void *)&on, sizeof(on)) == -1) {
+ if (debug)
+ warn("setsockopt %s (ignored)", "SO_OOBINLINE");
}
return (hostname);
@@ -519,39 +521,10 @@ getreply(int expecteof)
static int
empty(FILE *cin, FILE *din, int sec)
{
- int nr;
- int nfd = 0;
-
-#ifdef USE_SELECT
- struct timeval t;
- fd_set rmask;
-
- FD_ZERO(&rmask);
- if (cin) {
- if (nfd < fileno(cin))
- nfd = fileno(cin);
- FD_SET(fileno(cin), &rmask);
- }
- if (din) {
- if (nfd < fileno(din))
- nfd = fileno(din);
- FD_SET(fileno(din), &rmask);
- }
-
- t.tv_sec = (long) sec;
- t.tv_usec = 0;
- if ((nr = select(nfd, &rmask, NULL, NULL, &t)) <= 0)
- return nr;
-
- nr = 0;
- if (cin)
- nr |= FD_ISSET(fileno(cin), &rmask) ? 1 : 0;
- if (din)
- nr |= FD_ISSET(fileno(din), &rmask) ? 2 : 0;
-
-#else
- struct pollfd pfd[2];
+ int nr, nfd;
+ struct pollfd pfd[2];
+ nfd = 0;
if (cin) {
pfd[nfd].fd = fileno(cin);
pfd[nfd++].events = POLLIN;
@@ -562,7 +535,7 @@ empty(FILE *cin, FILE *din, int sec)
pfd[nfd++].events = POLLIN;
}
- if ((nr = poll(pfd, nfd, sec * 1000)) <= 0)
+ if ((nr = xpoll(pfd, nfd, sec * 1000)) <= 0)
return nr;
nr = 0;
@@ -571,7 +544,6 @@ empty(FILE *cin, FILE *din, int sec)
nr |= (pfd[nfd++].revents & POLLIN) ? 1 : 0;
if (din)
nr |= (pfd[nfd++].revents & POLLIN) ? 2 : 0;
-#endif
return nr;
}
@@ -1304,15 +1276,16 @@ initconn(void)
return (1);
}
if ((options & SO_DEBUG) &&
- setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
- sizeof(on)) < 0)
+ setsockopt(data, SOL_SOCKET, SO_DEBUG,
+ (void *)&on, sizeof(on)) == -1) {
if (debug)
- warn("setsockopt (ignored)");
+ warn("setsockopt %s (ignored)", "SO_DEBUG");
+ }
result = COMPLETE + 1;
switch (data_addr.su_family) {
case AF_INET:
if (epsv4 && !epsv4bad) {
- pasvcmd = "EPSV";
+ pasvcmd = "EPSV";
result = command("EPSV");
if (!connected)
return (1);
@@ -1335,7 +1308,7 @@ initconn(void)
}
}
if (result != COMPLETE) {
- pasvcmd = "PASV";
+ pasvcmd = "PASV";
result = command("PASV");
if (!connected)
return (1);
@@ -1343,7 +1316,7 @@ initconn(void)
break;
#ifdef INET6
case AF_INET6:
- pasvcmd = "EPSV";
+ pasvcmd = "EPSV";
result = command("EPSV");
if (!connected)
return (1);
@@ -1541,10 +1514,12 @@ initconn(void)
#ifdef IPTOS_THROUGHPUT
if (data_addr.su_family == AF_INET) {
on = IPTOS_THROUGHPUT;
- if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on,
- sizeof(int)) < 0)
+ if (setsockopt(data, IPPROTO_IP, IP_TOS,
+ (void *)&on, sizeof(int)) == -1) {
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_THROUGHPUT");
+ }
}
#endif
return (0);
@@ -1564,9 +1539,9 @@ initconn(void)
return (1);
}
if (!sendport)
- if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
- sizeof(on)) < 0) {
- warn("setsockopt (reuse address)");
+ if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR,
+ (void *)&on, sizeof(on)) == -1) {
+ warn("setsockopt %s", "SO_REUSEADDR");
goto bad;
}
if (bind(data, (struct sockaddr *)&data_addr.si_su,
@@ -1574,11 +1549,12 @@ initconn(void)
warn("bind");
goto bad;
}
- if (options & SO_DEBUG &&
- setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
- sizeof(on)) < 0)
+ if ((options & SO_DEBUG) &&
+ setsockopt(data, SOL_SOCKET, SO_DEBUG,
+ (void *)&on, sizeof(on)) == -1) {
if (debug)
- warn("setsockopt (ignored)");
+ warn("setsockopt %s (ignored)", "SO_DEBUG");
+ }
len = sizeof(data_addr.si_su);
memset((char *)&data_addr, 0, sizeof (data_addr));
if (getsockname(data, (struct sockaddr *)&data_addr.si_su, &len) < 0) {
@@ -1663,7 +1639,7 @@ initconn(void)
if (!connected)
return (1);
skip_port:
-
+
if (result == ERROR && sendport == -1) {
sendport = 0;
tmpno = 1;
@@ -1676,15 +1652,17 @@ initconn(void)
#ifdef IPTOS_THROUGHPUT
if (data_addr.su_family == AF_INET) {
on = IPTOS_THROUGHPUT;
- if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on,
- sizeof(int)) < 0)
+ if (setsockopt(data, IPPROTO_IP, IP_TOS,
+ (void *)&on, sizeof(int)) == -1)
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_THROUGHPUT");
}
#endif
return (0);
bad:
- (void)close(data), data = -1;
+ (void)close(data);
+ data = -1;
if (tmpno)
sendport = 1;
return (1);
@@ -1693,31 +1671,78 @@ initconn(void)
FILE *
dataconn(const char *lmode)
{
- struct sockinet from;
- int s, fromlen = myctladdr.su_len;
+ struct sockinet from;
+ int s, fromlen, flags, rv, timeout;
+ struct timeval endtime, now, td;
+ struct pollfd pfd[1];
- if (passivemode)
+ if (passivemode) /* passive data connection */
return (fdopen(data, lmode));
- s = accept(data, (struct sockaddr *) &from.si_su, &fromlen);
- if (s < 0) {
+ /* active mode data connection */
+
+ if ((flags = fcntl(data, F_GETFL, 0)) == -1)
+ goto dataconn_failed; /* get current socket flags */
+ if (fcntl(data, F_SETFL, flags | O_NONBLOCK) == -1)
+ goto dataconn_failed; /* set non-blocking connect */
+
+ /* NOTE: we now must restore socket flags on successful exit */
+
+ /* limit time waiting on listening socket */
+ pfd[0].fd = data;
+ pfd[0].events = POLLIN;
+ (void)gettimeofday(&endtime, NULL); /* determine end time */
+ endtime.tv_sec += (quit_time > 0) ? quit_time: 60;
+ /* without -q, default to 60s */
+ do {
+ (void)gettimeofday(&now, NULL);
+ timersub(&endtime, &now, &td);
+ timeout = td.tv_sec * 1000 + td.tv_usec/1000;
+ if (timeout < 0)
+ timeout = 0;
+ rv = xpoll(pfd, 1, timeout);
+ } while (rv == -1 && errno == EINTR); /* loop until poll ! EINTR */
+ if (rv == -1) {
+ warn("poll waiting before accept");
+ goto dataconn_failed;
+ }
+ if (rv == 0) {
+ warn("poll timeout waiting before accept");
+ goto dataconn_failed;
+ }
+
+ /* (non-blocking) accept the connection */
+ fromlen = myctladdr.su_len;
+ do {
+ s = accept(data, (struct sockaddr *) &from.si_su, &fromlen);
+ } while (s == -1 && errno == EINTR); /* loop until accept ! EINTR */
+ if (s == -1) {
warn("accept");
- (void)close(data), data = -1;
- return (NULL);
+ goto dataconn_failed;
}
+
(void)close(data);
data = s;
+ if (fcntl(data, F_SETFL, flags) == -1) /* restore socket flags */
+ goto dataconn_failed;
+
#ifdef IPTOS_THROUGHPUT
if (from.su_family == AF_INET) {
int tos = IPTOS_THROUGHPUT;
- if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
- sizeof(int)) < 0) {
+ if (setsockopt(s, IPPROTO_IP, IP_TOS,
+ (void *)&tos, sizeof(int)) == -1) {
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_THROUGHPUT");
}
}
#endif
return (fdopen(data, lmode));
+
+ dataconn_failed:
+ (void)close(data);
+ data = -1;
+ return (NULL);
}
void
@@ -2002,7 +2027,7 @@ gunique(const char *local)
}
len = strlcpy(new, local, sizeof(new));
cp = &new[len];
- *cp++ = '.';
+ *cp++ = '.';
while (!d) {
if (++count == 100) {
fputs("runique: can't find unique file name.\n",
diff --git a/net/tnftp/files/src/ftp.cat1 b/net/tnftp/files/src/ftp.cat1
index 702e7a8de00..ae1d6fb32df 100644
--- a/net/tnftp/files/src/ftp.cat1
+++ b/net/tnftp/files/src/ftp.cat1
@@ -770,7 +770,7 @@ AAUUTTOO--FFEETTCCHHIINNGG FFIILLEESS
fer type will take place as ascii or binary (respectively). The
default transfer type is binary.
- In order to be compliant with RRFFCC 11773388, ffttpp interprets the _p_a_t_h
+ In order to be compliant with RFC 1738, ffttpp interprets the _p_a_t_h
part of an ``ftp://'' auto-fetch URL as follows:
++oo The `/' immediately after the _h_o_s_t[:_p_o_r_t] is interpreted as a
@@ -786,12 +786,12 @@ AAUUTTOO--FFEETTCCHHIINNGG FFIILLEESS
the equivalent of a ccdd command without a directory name. This
is unlikely to be useful.
- ++oo Any `%_X_X' codes within the path components are decoded, with _X_X
- representing a character code in hexadecimal. This decoding
- takes place after the _p_a_t_h has been split into components, but
- before each component is used in the equivalent of a ccdd or ggeett
- command. Some often-used codes are `%2F' (which represents
- `/') and `%7E' (which represents `~').
+ ++oo Any `%_X_X' codes (per RFC 1738) within the path components are
+ decoded, with _X_X representing a character code in hexadecimal.
+ This decoding takes place after the _p_a_t_h has been split into
+ components, but before each component is used in the equivalent
+ of a ccdd or ggeett command. Some often-used codes are `%2F' (which
+ represents `/') and `%7E' (which represents `~').
The above interpretation has the following consequences:
@@ -1066,14 +1066,17 @@ EENNVVIIRROONNMMEENNTT
ftp_proxy URL of FTP proxy to use when making FTP URL requests (if
not defined, use the standard FTP protocol).
- _N_O_T_E: this is not used for interactive sessions, only for
- command-line fetches.
+ See http_proxy for further notes about proxy use.
http_proxy URL of HTTP proxy to use when making HTTP URL requests.
If proxy authentication is required and there is a user-
name and password in this URL, they will automatically be
used in the first attempt to authenticate to the proxy.
+ If ``unsafe'' URL characters are required in the username
+ or password (for example `@' or `/'), encode them with RFC
+ 1738 `%_X_X' encoding.
+
Note that the use of a username and password in ftp_proxy
and http_proxy may be incompatible with other programs
that use it (such as lynx(1)).
@@ -1101,8 +1104,8 @@ SSEEEE AALLSSOO
getservbyname(3), editrc(5), services(5), ftpd(8)
SSTTAANNDDAARRDDSS
- ffttpp attempts to be compliant with RRFFCC 995599, RRFFCC 11112233, RRFFCC 11773388, RRFFCC 22006688,
- RRFFCC 22338899, RRFFCC 22442288, RRFFCC 22773322, and ddrraafftt--iieettff--ffttppeexxtt--mmllsstt--1111.
+ ffttpp attempts to be compliant with RFC 959, RFC 1123, RFC 1738, RFC 2068,
+ RFC 2389, RFC 2428, RFC 2732, and ddrraafftt--iieettff--ffttppeexxtt--mmllsstt--1111.
HHIISSTTOORRYY
The ffttpp command appeared in 4.2BSD.
@@ -1135,4 +1138,4 @@ BBUUGGSS
uses a SIIT translator for IPv6-to-IPv4 translation, ffttpp is unable to
support your configuration.
-NetBSD 2.0 October 7, 2004 NetBSD 2.0
+NetBSD 3.0_BETA January 15, 2005 NetBSD 3.0_BETA
diff --git a/net/tnftp/files/src/ftp_var.h b/net/tnftp/files/src/ftp_var.h
index bd1ced52738..3fd33788013 100644
--- a/net/tnftp/files/src/ftp_var.h
+++ b/net/tnftp/files/src/ftp_var.h
@@ -1,4 +1,5 @@
-/* $NetBSD: ftp_var.h,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: ftp_var.h,v 1.5 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: ftp_var.h,v 1.71 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
@@ -70,7 +71,7 @@
/*
* Copyright (C) 1997 and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -82,7 +83,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -120,9 +121,9 @@
struct cmd {
char *c_name; /* name of command */
const char *c_help; /* help string */
- char c_bell; /* give bell when command completes */
- char c_conn; /* must be connected to use command */
- char c_proxy; /* proxy server may execute */
+ char c_bell; /* give bell when command completes */
+ char c_conn; /* must be connected to use command */
+ char c_proxy; /* proxy server may execute */
#ifndef NO_EDITCOMPLETE
const char *c_complete; /* context sensitive completion list */
#endif /* !NO_EDITCOMPLETE */
diff --git a/net/tnftp/files/src/main.c b/net/tnftp/files/src/main.c
index a8cb503a001..a9bb48af604 100644
--- a/net/tnftp/files/src/main.c
+++ b/net/tnftp/files/src/main.c
@@ -1,4 +1,5 @@
-/* $NetBSD: main.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: main.c,v 1.7 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: main.c,v 1.93 2005/05/11 02:29:12 lukem Exp */
/*-
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
@@ -68,7 +69,7 @@
/*
* Copyright (C) 1997 and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -80,7 +81,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -105,7 +106,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: main.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: main.c,v 1.7 2005/05/11 02:41:28 lukem Exp");
#endif
#endif /* not lint */
#endif
@@ -134,6 +135,7 @@ main(int argc, char *argv[])
struct passwd *pw;
char *cp, *ep, *anonuser, *anonpass, *upload_path;
int dumbterm, s, len, isupload;
+ socklen_t slen;
#if 0 /* XXX */
setlocale(LC_ALL, "");
@@ -199,12 +201,12 @@ main(int argc, char *argv[])
if (s == -1)
err(1, "can't create socket");
len = sizeof(rcvbuf_size);
- if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void *) &rcvbuf_size, &len)
- < 0)
+ if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void *) &rcvbuf_size,
+ &slen) == -1)
err(1, "unable to get default rcvbuf size");
len = sizeof(sndbuf_size);
- if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size, &len)
- < 0)
+ if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size,
+ &slen) == -1)
err(1, "unable to get default sndbuf size");
(void)close(s);
/* sanity check returned buffer sizes */
@@ -449,7 +451,7 @@ main(int argc, char *argv[])
}
if (netrc[0] == '\0' && localhome != NULL) {
if (strlcpy(netrc, localhome, sizeof(netrc)) >= sizeof(netrc) ||
- strlcat(netrc, "/.netrc", sizeof(netrc)) >= sizeof(netrc)) {
+ strlcat(netrc, "/.netrc", sizeof(netrc)) >= sizeof(netrc)) {
warnx("%s/.netrc: %s", localhome,
strerror(ENAMETOOLONG));
netrc[0] = '\0';
@@ -647,7 +649,8 @@ cmdscanner(void)
break;
line[num] = '\0';
} else if (num == sizeof(line) - 2) {
- fputs("sorry, input line too long.\n", ttyout);
+ fputs("Sorry, input line is too long.\n",
+ ttyout);
while ((num = getchar()) != '\n' && num != EOF)
/* void */;
break;
@@ -658,20 +661,23 @@ cmdscanner(void)
HistEvent ev;
cursor_pos = NULL;
- if ((buf = el_gets(el, &num)) == NULL || num == 0) {
+ buf = el_gets(el, &num);
+ if (buf == NULL || num == 0) {
if (fromatty)
putc('\n', ttyout);
quit(0, NULL);
}
- if (buf[--num] == '\n') {
- if (num == 0)
- break;
- } else if (num >= sizeof(line)) {
- fputs("sorry, input line too long.\n", ttyout);
+ if (num >= sizeof(line)) {
+ fputs("Sorry, input line is too long.\n",
+ ttyout);
break;
}
memcpy(line, buf, num);
- line[num] = '\0';
+ if (line[--num] == '\n') {
+ line[num] = '\0';
+ if (num == 0)
+ break;
+ }
history(hist, &ev, H_ENTER, buf);
}
#endif /* !NO_EDITCOMPLETE */
diff --git a/net/tnftp/files/src/progressbar.c b/net/tnftp/files/src/progressbar.c
index 538a7b8e447..6c179775c62 100644
--- a/net/tnftp/files/src/progressbar.c
+++ b/net/tnftp/files/src/progressbar.c
@@ -1,4 +1,5 @@
-/* $NetBSD: progressbar.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: progressbar.c,v 1.6 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp */
/*-
* Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -39,7 +40,7 @@
#if 0
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progressbar.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: progressbar.c,v 1.6 2005/05/11 02:41:28 lukem Exp");
#endif /* not lint */
#endif
@@ -72,7 +73,6 @@ foregroundproc(void)
#endif /* !defined(NO_PROGRESS) */
-#ifndef NO_PROGRESS
static void updateprogressmeter(int);
/*
@@ -86,8 +86,6 @@ updateprogressmeter(int dummy)
progressmeter(0);
errno = oerrno;
}
-#endif /* NO_PROGRESS */
-
/*
* List of order of magnitude prefixes.
@@ -120,7 +118,7 @@ progressmeter(int flag)
struct timeval td;
off_t abbrevsize, bytespersec;
double elapsed;
- int ratio, barlength, i, len, remaining;
+ int ratio, barlength, i, remaining;
/*
* Work variables for progress bar.
@@ -130,7 +128,10 @@ progressmeter(int flag)
* `static' portion of it), be sure to update
* these appropriately.
*/
+#endif
+ int len;
char buf[256]; /* workspace for progress bar */
+#ifndef NO_PROGRESS
#define BAROVERHEAD 43 /* non `*' portion of progress bar */
/*
* stars should contain at least
@@ -207,11 +208,11 @@ progressmeter(int flag)
/*
* calculate the length of the `*' bar, ensuring that
- * the number of stars won't exceed the buffer size
+ * the number of stars won't exceed the buffer size
*/
barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD;
if (prefix)
- barlength -= strlen(prefix);
+ barlength -= strlen(prefix);
if (barlength > 0) {
i = barlength * ratio / 100;
len += snprintf(buf + len, BUFLEFT,
diff --git a/net/tnftp/files/src/progressbar.h b/net/tnftp/files/src/progressbar.h
index 9aa14147ec1..a3f80d179e9 100644
--- a/net/tnftp/files/src/progressbar.h
+++ b/net/tnftp/files/src/progressbar.h
@@ -1,4 +1,5 @@
-/* $NetBSD: progressbar.h,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: progressbar.h,v 1.5 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: progressbar.h,v 1.5 2005/02/10 16:00:38 jmc Exp */
/*-
* Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
@@ -82,7 +83,6 @@ void psummary(int);
void ptransfer(int);
#endif /* !STANDALONE_PROGRESS */
-
#ifdef NO_LONG_LONG
# define LLF "%ld"
# define LLFP(x) "%" x "ld"
diff --git a/net/tnftp/files/src/ruserpass.c b/net/tnftp/files/src/ruserpass.c
index 188c9be86d1..616869837fd 100644
--- a/net/tnftp/files/src/ruserpass.c
+++ b/net/tnftp/files/src/ruserpass.c
@@ -1,4 +1,5 @@
-/* $NetBSD: ruserpass.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: ruserpass.c,v 1.4 2005/05/11 02:41:28 lukem Exp */
+/* from NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp */
/*
* Copyright (c) 1985, 1993, 1994
@@ -29,6 +30,17 @@
* SUCH DAMAGE.
*/
+#if 0
+#include <sys/cdefs.h>
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
+#else
+__RCSID("NetBSD: ruserpass.c,v 1.4 2005/05/11 02:41:28 lukem Exp");
+#endif
+#endif /* not lint */
+#endif
+
#include "tnftp.h"
#include "ftp_var.h"
diff --git a/net/tnftp/files/src/util.c b/net/tnftp/files/src/util.c
index fd1c70b386e..372934cb1d7 100644
--- a/net/tnftp/files/src/util.c
+++ b/net/tnftp/files/src/util.c
@@ -1,4 +1,5 @@
-/* $NetBSD: util.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $ */
+/* NetBSD: util.c,v 1.9 2005/05/11 03:57:57 lukem Exp */
+/* from NetBSD: util.c,v 1.121 2005/05/11 02:29:13 lukem Exp */
/*-
* Copyright (c) 1997-2005 The NetBSD Foundation, Inc.
@@ -72,7 +73,7 @@
#if 0
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.1.1.2 2005/01/03 10:08:40 lukem Exp $");
+__RCSID("NetBSD: util.c,v 1.9 2005/05/11 03:57:57 lukem Exp");
#endif /* not lint */
#endif
@@ -730,7 +731,7 @@ remotemodtime(const char *file, int noisy)
timebuf.tm_hour = hour;
timebuf.tm_mday = day;
timebuf.tm_mon = mo - 1;
- timebuf.tm_year = yy - TM_YEAR_BASE;
+ timebuf.tm_year = yy - TM_YEAR_BASE;
timebuf.tm_isdst = -1;
rtime = timegm(&timebuf);
if (rtime == -1) {
@@ -1010,12 +1011,12 @@ void
setupsockbufsize(int sock)
{
- if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size,
- sizeof(rcvbuf_size)) < 0)
+ if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+ (void *)&sndbuf_size, sizeof(rcvbuf_size)) == -1)
warn("unable to set sndbuf size %d", sndbuf_size);
- if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (void *) &rcvbuf_size,
- sizeof(rcvbuf_size)) < 0)
+ if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+ (void *)&rcvbuf_size, sizeof(rcvbuf_size)) == -1)
warn("unable to set rcvbuf size %d", rcvbuf_size);
}
@@ -1225,28 +1226,83 @@ isipv6addr(const char *addr)
/*
* Internal version of connect(2); sets socket buffer sizes first and
- * handles the syscall being interrupted.
+ * supports a connection timeout using a non-blocking connect(2) with
+ * a poll(2).
+ * Socket fcntl flags are temporarily updated to include O_NONBLOCK;
+ * these will not be reverted on connection failure.
* Returns -1 upon failure (with errno set to the problem), or 0 on success.
*/
int
xconnect(int sock, const struct sockaddr *name, int namelen)
{
- int rv;
+ int flags, rv, timeout, error;
+ socklen_t slen;
+ struct timeval endtime, now, td;
+ struct pollfd pfd[1];
setupsockbufsize(sock);
- rv = connect(sock, name, namelen);
- if (rv == -1 && errno == EINTR) {
- fd_set connfd;
- FD_ZERO(&connfd);
- FD_SET(sock, &connfd);
+ if ((flags = fcntl(sock, F_GETFL, 0)) == -1)
+ return -1; /* get current socket flags */
+ if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
+ return -1; /* set non-blocking connect */
+
+ /* NOTE: we now must restore socket flags on successful exit */
+
+ pfd[0].fd = sock;
+ pfd[0].events = POLLIN|POLLOUT;
+
+ if (quit_time > 0) { /* want a non default timeout */
+ (void)gettimeofday(&endtime, NULL);
+ endtime.tv_sec += quit_time; /* determine end time */
+ }
+
+ rv = connect(sock, name, namelen); /* inititate the connection */
+ if (rv == -1) { /* connection error */
+ if (errno != EINPROGRESS) /* error isn't "please wait" */
+ return -1;
+
+ /* connect EINPROGRESS; wait */
do {
- rv = select(sock + 1, NULL, &connfd, NULL, NULL);
+ if (quit_time > 0) { /* determine timeout */
+ (void)gettimeofday(&now, NULL);
+ timersub(&endtime, &now, &td);
+ timeout = td.tv_sec * 1000 + td.tv_usec/1000;
+ if (timeout < 0)
+ timeout = 0;
+ } else {
+ timeout = INFTIM;
+ }
+ pfd[0].revents = 0;
+ rv = xpoll(pfd, 1, timeout);
+ /* loop until poll ! EINTR */
} while (rv == -1 && errno == EINTR);
- if (rv > 0)
- rv = 0;
+
+ if (rv == 0) { /* poll (connect) timed out */
+ errno = ETIMEDOUT;
+ return -1;
+ }
+
+ if (rv == -1) { /* poll error */
+ return -1;
+ } else if (pfd[0].revents & (POLLIN|POLLOUT)) {
+ rv = sizeof(error); /* ok, or pending error */
+ if (getsockopt(sock, SOL_SOCKET, SO_ERROR,
+ &error, &slen) == -1)
+ return -1; /* Solaris pending error */
+ if (error != 0) {
+ errno = error; /* BSD pending error */
+ return -1;
+ }
+ } else {
+ errno = EBADF; /* this shouldn't happen ... */
+ return -1;
+ }
}
- return (rv);
+
+ if (fcntl(sock, F_SETFL, flags) == -1) /* restore socket flags */
+ return -1;
+ return 0;
}
/*
@@ -1261,6 +1317,65 @@ xlisten(int sock, int backlog)
}
/*
+ * Internal version of poll(2), to allow reimplementation by select(2)
+ * on platforms without the former.
+ */
+int
+xpoll(struct pollfd *fds, int nfds, int timeout)
+{
+#if HAVE_POLL
+ return poll(fds, nfds, timeout);
+
+#elif HAVE_SELECT /* implement poll(2) using select(2) */
+ fd_set rset, wset;
+ struct timeval tv, *ptv;
+ int i, max, rv;
+
+ FD_ZERO(&rset); /* build list of read & write events */
+ FD_ZERO(&wset);
+ max = 0;
+ for (i = 0; i < nfds; i++) {
+ if (fds[i].fd > FD_SETSIZE) {
+ warnx("can't select fd %d", fds[i].fd);
+ errno = EINVAL;
+ return -1;
+ } else if (fds[i].fd > max)
+ max = fds[i].fd;
+ if (fds[i].events & POLLIN)
+ FD_SET(fds[i].fd, &rset);
+ if (fds[i].events & POLLOUT)
+ FD_SET(fds[i].fd, &wset);
+ }
+
+ ptv = &tv; /* determine timeout */
+ if (timeout == -1) { /* wait forever */
+ ptv = NULL;
+ } else if (timeout == 0) { /* poll once */
+ ptv->tv_sec = 0;
+ ptv->tv_usec = 0;
+ }
+ else if (timeout != 0) { /* wait timeout milliseconds */
+ ptv->tv_sec = timeout / 1000;
+ ptv->tv_usec = (timeout % 1000) * 1000;
+ }
+ rv = select(max + 1, &rset, &wset, NULL, ptv);
+ if (rv <= 0) /* -1 == error, 0 == timeout */
+ return rv;
+
+ for (i = 0; i < nfds; i++) { /* determine results */
+ if (FD_ISSET(fds[i].fd, &rset))
+ fds[i].revents |= POLLIN;
+ if (FD_ISSET(fds[i].fd, &wset))
+ fds[i].revents |= POLLOUT;
+ }
+ return rv;
+
+#else
+# error no way to implement xpoll
+#endif
+}
+
+/*
* malloc() with inbuilt error checking
*/
void *
diff --git a/net/tnftp/files/src/version.h b/net/tnftp/files/src/version.h
index 273fb39d6e2..bb033553959 100644
--- a/net/tnftp/files/src/version.h
+++ b/net/tnftp/files/src/version.h
@@ -1,4 +1,5 @@
-/* $NetBSD: version.h,v 1.1.1.2 2005/01/03 09:50:10 lukem Exp $ */
+/* NetBSD: version.h,v 1.1.1.6 2005/05/11 02:33:48 lukem Exp */
+/* from NetBSD: version.h,v 1.48 2005/05/11 02:29:13 lukem Exp */
/*-
* Copyright (c) 1999-2005 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -40,5 +41,5 @@
#endif
#ifndef FTP_VERSION
-#define FTP_VERSION "20050103"
+#define FTP_VERSION "20050511"
#endif