summaryrefslogtreecommitdiffstats
path: root/contrib/lukemftp/src
diff options
context:
space:
mode:
authormikeh <mikeh@FreeBSD.org>2005-05-17 03:11:29 +0000
committermikeh <mikeh@FreeBSD.org>2005-05-17 03:11:29 +0000
commit7e8a9605b1b776a2e6c8f20d00d300a4c160d2fc (patch)
treec11ec5608b233e422a77e206a145bda94802aa04 /contrib/lukemftp/src
parent1be5c31f3514eedf5d9af243aff0f5cee4a240c5 (diff)
downloadFreeBSD-src-7e8a9605b1b776a2e6c8f20d00d300a4c160d2fc.zip
FreeBSD-src-7e8a9605b1b776a2e6c8f20d00d300a4c160d2fc.tar.gz
Import latest NetBSD version...changes:
* Whitespace and gcc 4.x fixes. * Fix deallocation bug in fetch.c. * Implement timeouts for accept(2) and connect(2), which accept timeout values with '-q quittime'. (intended to help with active mode through firewalls) * Fix bin/77158 by Ryoji Kanai <rkanai@eeye.com>.
Diffstat (limited to 'contrib/lukemftp/src')
-rw-r--r--contrib/lukemftp/src/cmds.c14
-rw-r--r--contrib/lukemftp/src/cmdtab.c6
-rw-r--r--contrib/lukemftp/src/extern.h9
-rw-r--r--contrib/lukemftp/src/fetch.c22
-rw-r--r--contrib/lukemftp/src/ftp.124
-rw-r--r--contrib/lukemftp/src/ftp.c209
-rw-r--r--contrib/lukemftp/src/ftp_var.h14
-rw-r--r--contrib/lukemftp/src/main.c43
-rw-r--r--contrib/lukemftp/src/progressbar.c8
-rw-r--r--contrib/lukemftp/src/util.c103
-rw-r--r--contrib/lukemftp/src/version.h4
11 files changed, 278 insertions, 178 deletions
diff --git a/contrib/lukemftp/src/cmds.c b/contrib/lukemftp/src/cmds.c
index 087bc56..69dbd18 100644
--- a/contrib/lukemftp/src/cmds.c
+++ b/contrib/lukemftp/src/cmds.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cmds.c,v 1.111 2005/02/11 06:21:22 simonb Exp $ */
+/* $NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $ */
/*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
@@ -72,7 +72,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 +84,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
@@ -103,7 +103,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmds.c,v 1.111 2005/02/11 06:21:22 simonb Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $");
#endif
#endif /* not lint */
@@ -571,10 +571,10 @@ get(int argc, char *argv[])
int
getit(int argc, char *argv[], int restartit, const char *mode)
{
- int loc, rval;
+ int loc, rval;
char *remfile, *olocfile;
const char *locfile;
- char buf[MAXPATHLEN];
+ char buf[MAXPATHLEN];
loc = rval = 0;
if (argc == 2) {
@@ -1690,7 +1690,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 \
diff --git a/contrib/lukemftp/src/cmdtab.c b/contrib/lukemftp/src/cmdtab.c
index 08a3b23..04efade 100644
--- a/contrib/lukemftp/src/cmdtab.c
+++ b/contrib/lukemftp/src/cmdtab.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cmdtab.c,v 1.43 2004/07/15 08:50:10 lukem Exp $ */
+/* $NetBSD: cmdtab.c,v 1.44 2005/04/11 01:49:31 lukem Exp $ */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmdtab.c,v 1.43 2004/07/15 08:50:10 lukem Exp $");
+__RCSID("$NetBSD: cmdtab.c,v 1.44 2005/04/11 01:49:31 lukem Exp $");
#endif
#endif /* not lint */
@@ -188,7 +188,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/contrib/lukemftp/src/extern.h b/contrib/lukemftp/src/extern.h
index 1111c85..f2b802a 100644
--- a/contrib/lukemftp/src/extern.h
+++ b/contrib/lukemftp/src/extern.h
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.64 2005/02/09 23:17:27 christos Exp $ */
+/* $NetBSD: extern.h,v 1.67 2005/05/14 15:26:43 lukem Exp $ */
/*-
* Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
@@ -70,7 +70,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 +82,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
@@ -248,8 +248,9 @@ void updatelocalcwd(void);
void updateremotecwd(void);
void usage(void);
void user(int, char **);
-int xconnect(int, const struct sockaddr *, int);
+int xconnect(int, const struct sockaddr *, socklen_t);
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/contrib/lukemftp/src/fetch.c b/contrib/lukemftp/src/fetch.c
index f2e7763..e2acb01 100644
--- a/contrib/lukemftp/src/fetch.c
+++ b/contrib/lukemftp/src/fetch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.155 2005/01/12 22:37:41 lukem Exp $ */
+/* $NetBSD: fetch.c,v 1.158 2005/05/14 15:26:43 lukem Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.155 2005/01/12 22:37:41 lukem Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.158 2005/05/14 15:26:43 lukem Exp $");
#endif /* not lint */
/*
@@ -219,7 +219,8 @@ auth_url(const char *challenge, char **response, const char *guser,
(void)strlcpy(*response, scheme, rlen);
len = strlcat(*response, " ", rlen);
/* use `clen - 1' to not encode the trailing NUL */
- base64_encode(clear, clen - 1, (unsigned char *)*response + len);
+ base64_encode((unsigned char *)clear, clen - 1,
+ (unsigned char *)*response + len);
memset(clear, 0, clen);
rval = 0;
@@ -733,7 +734,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);
@@ -975,7 +975,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;
@@ -1276,6 +1276,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);
@@ -1416,7 +1418,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)
@@ -1797,7 +1799,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++;
@@ -1806,8 +1808,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)
@@ -1821,7 +1823,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/contrib/lukemftp/src/ftp.1 b/contrib/lukemftp/src/ftp.1
index 23e0b4a..917980f 100644
--- a/contrib/lukemftp/src/ftp.1
+++ b/contrib/lukemftp/src/ftp.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: ftp.1,v 1.108 2005/01/15 21:28:16 lukem Exp $
+.\" $NetBSD: ftp.1,v 1.109 2005/02/20 20:54:01 wiz Exp $
.\"
.\" Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -952,7 +952,7 @@ traffic.
servers are required to support the
.Dv PASV
command by
-.Cm RFC 1123 ,
+.Li RFC 1123 ,
some do not.)
.It Ic pdir Op Ar remote-path
Perform
@@ -1565,7 +1565,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
@@ -1618,7 +1618,7 @@ Any
.Sq Li \&% Ns Ar XX
codes
(per
-.Cm RFC 1738 )
+.Li RFC 1738 )
within the path components are decoded, with
.Ar XX
representing a character code in hexadecimal.
@@ -2248,7 +2248,7 @@ URL characters are required in the username or password
or
.Sq / ) ,
encode them with
-.Cm RFC 1738
+.Li RFC 1738
.Sq Li \&% Ns Ar XX
encoding.
.Pp
@@ -2292,13 +2292,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/contrib/lukemftp/src/ftp.c b/contrib/lukemftp/src/ftp.c
index 72a4262..dae6131 100644
--- a/contrib/lukemftp/src/ftp.c
+++ b/contrib/lukemftp/src/ftp.c
@@ -1,7 +1,7 @@
-/* $NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $ */
+/* $NetBSD: ftp.c,v 1.132 2005/05/14 15:26:43 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 +68,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 +80,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
@@ -99,7 +99,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.132 2005/05/14 15:26:43 lukem Exp $");
#endif
#endif /* not lint */
@@ -118,6 +118,7 @@ __RCSID("$NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $");
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
@@ -125,9 +126,6 @@ __RCSID("$NetBSD: ftp.c,v 1.126 2004/07/20 10:40:22 lukem Exp $");
#include <time.h>
#include <unistd.h>
#include <stdarg.h>
-#ifndef USE_SELECT
-#include <poll.h>
-#endif
#include "ftp_var.h"
@@ -166,11 +164,13 @@ struct sockinet myctladdr, hisctladdr, data_addr;
char *
hookup(char *host, char *port)
{
- int s = -1, len, error, portnum;
+ int s = -1, error, portnum;
struct addrinfo hints, *res, *res0;
char hbuf[MAXHOSTNAMELEN];
static char hostnamebuf[MAXHOSTNAMELEN];
char *cause = "unknown";
+ socklen_t len;
+ int on = 1;
memset((char *)&hisctladdr, 0, sizeof (hisctladdr));
memset((char *)&myctladdr, 0, sizeof (myctladdr));
@@ -193,7 +193,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.
@@ -262,7 +262,7 @@ hookup(char *host, char *port)
res0 = res = NULL;
len = hisctladdr.su_len;
- if (getsockname(s, (struct sockaddr *)&myctladdr.si_su, &len) < 0) {
+ if (getsockname(s, (struct sockaddr *)&myctladdr.si_su, &len) == -1) {
warn("getsockname");
code = -1;
goto bad;
@@ -272,10 +272,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(tos)) == -1) {
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_LOWDELAY");
+ }
}
#endif
cin = fdopen(s, "r");
@@ -299,13 +301,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);
@@ -539,39 +539,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;
@@ -582,7 +553,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;
@@ -591,7 +562,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;
}
@@ -601,7 +571,7 @@ void
abortxfer(int notused)
{
char msgbuf[100];
- int len;
+ size_t len;
sigint_raised = 1;
alarmtimer(0);
@@ -1301,11 +1271,12 @@ int
initconn(void)
{
char *p, *a;
- int result, len, tmpno = 0;
+ int result, tmpno = 0;
int on = 1;
int error;
u_int addr[16], port[2];
u_int af, hal, pal;
+ socklen_t len;
char *pasvcmd = NULL;
#ifdef INET6
@@ -1324,15 +1295,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);
@@ -1355,7 +1327,7 @@ initconn(void)
}
}
if (result != COMPLETE) {
- pasvcmd = "PASV";
+ pasvcmd = "PASV";
result = command("PASV");
if (!connected)
return (1);
@@ -1363,7 +1335,7 @@ initconn(void)
break;
#ifdef INET6
case AF_INET6:
- pasvcmd = "EPSV";
+ pasvcmd = "EPSV";
result = command("EPSV");
if (!connected)
return (1);
@@ -1555,16 +1527,18 @@ initconn(void)
#endif
goto reinit;
}
- warn("connect");
+ warn("connect for data channel");
goto bad;
}
#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(on)) == -1) {
if (debug)
- warn("setsockopt TOS (ignored)");
+ warn("setsockopt %s (ignored)",
+ "IPTOS_THROUGHPUT");
+ }
}
#endif
return (0);
@@ -1584,9 +1558,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,
@@ -1594,14 +1568,15 @@ 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) {
+ if (getsockname(data, (struct sockaddr *)&data_addr.si_su, &len) == -1) {
warn("getsockname");
goto bad;
}
@@ -1683,7 +1658,7 @@ initconn(void)
if (!connected)
return (1);
skip_port:
-
+
if (result == ERROR && sendport == -1) {
sendport = 0;
tmpno = 1;
@@ -1696,15 +1671,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(on)) == -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);
@@ -1713,31 +1690,79 @@ initconn(void)
FILE *
dataconn(const char *lmode)
{
- struct sockinet from;
- int s, fromlen = myctladdr.su_len;
+ struct sockinet from;
+ int s, flags, rv, timeout;
+ struct timeval endtime, now, td;
+ struct pollfd pfd[1];
+ socklen_t fromlen;
- 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(tos)) == -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
@@ -2022,7 +2047,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",
@@ -2059,7 +2084,7 @@ void
abort_squared(int dummy)
{
char msgbuf[100];
- int len;
+ size_t len;
sigint_raised = 1;
alarmtimer(0);
@@ -2118,7 +2143,7 @@ ai_unmapped(struct addrinfo *ai)
#ifdef INET6
struct sockaddr_in6 *sin6;
struct sockaddr_in sin;
- int len;
+ socklen_t len;
if (ai->ai_family != AF_INET6)
return;
diff --git a/contrib/lukemftp/src/ftp_var.h b/contrib/lukemftp/src/ftp_var.h
index 812f000..25f13d4 100644
--- a/contrib/lukemftp/src/ftp_var.h
+++ b/contrib/lukemftp/src/ftp_var.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp_var.h,v 1.69 2005/01/03 09:50:09 lukem Exp $ */
+/* $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 +70,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 +82,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
@@ -112,6 +112,8 @@
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <poll.h>
+
#include <setjmp.h>
#include <stringlist.h>
@@ -128,9 +130,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/contrib/lukemftp/src/main.c b/contrib/lukemftp/src/main.c
index ffed257..5d60cdb 100644
--- a/contrib/lukemftp/src/main.c
+++ b/contrib/lukemftp/src/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.90 2004/07/21 00:09:14 lukem Exp $ */
+/* $NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $ */
/*-
* Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
@@ -68,7 +68,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 +80,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 +104,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.90 2004/07/21 00:09:14 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $");
#endif
#endif /* not lint */
@@ -144,6 +144,7 @@ main(int argc, char *argv[])
struct passwd *pw;
char *cp, *ep, *anonuser, *anonpass, *upload_path;
int dumbterm, s, len, isupload;
+ socklen_t slen;
setlocale(LC_ALL, "");
setprogname(argv[0]);
@@ -206,13 +207,13 @@ main(int argc, char *argv[])
s = socket(AF_INET, SOCK_STREAM, 0);
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)
+ slen = sizeof(rcvbuf_size);
+ 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)
+ slen = sizeof(sndbuf_size);
+ 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 */
@@ -457,7 +458,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';
@@ -655,7 +656,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;
@@ -666,20 +668,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/contrib/lukemftp/src/progressbar.c b/contrib/lukemftp/src/progressbar.c
index 9c8ad10..d0bd35f 100644
--- a/contrib/lukemftp/src/progressbar.c
+++ b/contrib/lukemftp/src/progressbar.c
@@ -1,4 +1,4 @@
-/* $NetBSD: progressbar.c,v 1.6 2005/02/10 16:00:28 jmc Exp $ */
+/* $NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $ */
/*-
* Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progressbar.c,v 1.6 2005/02/10 16:00:28 jmc Exp $");
+__RCSID("$NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $");
#endif /* not lint */
/*
@@ -214,11 +214,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/contrib/lukemftp/src/util.c b/contrib/lukemftp/src/util.c
index 49c9a2a..6f94bb0 100644
--- a/contrib/lukemftp/src/util.c
+++ b/contrib/lukemftp/src/util.c
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.117 2005/01/03 09:50:09 lukem Exp $ */
+/* $NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $ */
/*-
* Copyright (c) 1997-2005 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.117 2005/01/03 09:50:09 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $");
#endif /* not lint */
/*
@@ -749,7 +749,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) {
@@ -1029,12 +1029,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(sndbuf_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);
}
@@ -1244,28 +1244,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)
+xconnect(int sock, const struct sockaddr *name, socklen_t 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)) {
+ slen = 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;
}
/*
@@ -1280,6 +1335,16 @@ 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)
+{
+ return poll(fds, nfds, timeout);
+}
+
+/*
* malloc() with inbuilt error checking
*/
void *
diff --git a/contrib/lukemftp/src/version.h b/contrib/lukemftp/src/version.h
index b864b68..7b69df1 100644
--- a/contrib/lukemftp/src/version.h
+++ b/contrib/lukemftp/src/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.44 2005/01/12 22:37:41 lukem Exp $ */
+/* $NetBSD: version.h,v 1.50 2005/05/14 15:26:43 lukem Exp $ */
/*-
* Copyright (c) 1999-2005 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -40,5 +40,5 @@
#endif
#ifndef FTP_VERSION
-#define FTP_VERSION "20050112"
+#define FTP_VERSION "20050514"
#endif
OpenPOWER on IntegriCloud