diff options
-rw-r--r-- | usr.bin/ftp/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/ftp/fetch.c | 20 | ||||
-rw-r--r-- | usr.bin/ftp/ftp.1 | 9 | ||||
-rw-r--r-- | usr.bin/ftp/main.c | 20 |
4 files changed, 42 insertions, 10 deletions
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 2c944cf5639..64b95240b4c 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.46 2016/12/28 17:48:04 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.47 2017/01/03 17:00:04 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */ /* @@ -137,6 +137,7 @@ extern int proxy; extern char reply_string[]; extern off_t restart_point; extern int keep_alive_timeout; +extern int connect_timeout; extern int pipeout; extern char *action; diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 1c2c2f3f111..260b4284060 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.154 2016/12/28 17:48:04 deraadt Exp $ */ +/* $OpenBSD: fetch.c,v 1.155 2017/01/03 17:00:04 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -167,6 +167,14 @@ url_encode(const char *path) return (epath); } +/* ARGSUSED */ +static void +tooslow(int signo) +{ + dprintf(STDERR_FILENO, "%s: connect taking too long\n", __progname); + _exit(2); +} + /* * Retrieve URL, via the proxy in $proxyvar if necessary. * Modifies the string argument given. @@ -560,6 +568,11 @@ noslash: } #endif /* !SMALL */ + if (connect_timeout) { + (void)signal(SIGALRM, tooslow); + alarmtimer(connect_timeout); + } + for (error = connect(s, res->ai_addr, res->ai_addrlen); error != 0 && errno == EINTR; error = connect_wait(s)) continue; @@ -627,6 +640,11 @@ noslash: fin = fdopen(s, "r+"); #endif /* !NOSSL */ + if (connect_timeout) { + signal(SIGALRM, SIG_DFL); + alarmtimer(0); + } + /* * Construct and send the request. Proxy requests don't want leading /. */ diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1 index 98bf40a35ff..daf7433a67c 100644 --- a/usr.bin/ftp/ftp.1 +++ b/usr.bin/ftp/ftp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ftp.1,v 1.104 2016/12/22 17:26:18 jmc Exp $ +.\" $OpenBSD: ftp.1,v 1.105 2017/01/03 17:00:04 deraadt Exp $ .\" $NetBSD: ftp.1,v 1.22 1997/08/18 10:20:22 lukem Exp $ .\" .\" Copyright (c) 1985, 1989, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)ftp.1 8.3 (Berkeley) 10/9/94 .\" -.Dd $Mdocdate: December 22 2016 $ +.Dd $Mdocdate: January 3 2017 $ .Dt FTP 1 .Os .Sh NAME @@ -62,6 +62,7 @@ .Op Fl S Ar ssl_options .Op Fl s Ar srcaddr .Op Fl U Ar useragent +.Op Fl w Ar seconds .Sm off .Pf http Oo s Oc :// .Op Ar user : password No @ @@ -286,6 +287,10 @@ Forces .Nm to show all responses from the remote server, as well as report on data transfer statistics. +.It Fl w Ar seconds +For URL format connections to HTTP/HTTPS servers, abort a +slow connection after +.Ar seconds . .El .Pp The host with which diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index c16f43c9ea1..e7a3c17db97 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.115 2016/12/28 17:48:04 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.116 2017/01/03 17:00:04 deraadt Exp $ */ /* $NetBSD: main.c,v 1.24 1997/08/18 10:20:26 lukem Exp $ */ /* @@ -80,6 +80,8 @@ #include "cmds.h" #include "ftp_var.h" +int connect_timeout; + #ifndef NOSSL char * const ssl_verify_opts[] = { #define SSL_CAFILE 0 @@ -274,7 +276,7 @@ main(volatile int argc, char *argv[]) httpuseragent = NULL; while ((ch = getopt(argc, argv, - "46AaCc:dD:Eegik:Mmno:pP:r:S:s:tU:vV")) != -1) { + "46AaCc:dD:Eegik:Mmno:pP:r:S:s:tU:vVw:")) != -1) { switch (ch) { case '4': family = PF_INET; @@ -417,6 +419,11 @@ main(volatile int argc, char *argv[]) verbose = 0; break; + case 'w': + connect_timeout = strtonum(optarg, 0, 200, &errstr); + if (errstr) + errx(1, "-w: %s", errstr); + break; default: usage(); } @@ -919,17 +926,18 @@ usage(void) " ftp://[user:password@]host[:port]/file[/] ...\n" " ftp [-C] [-c cookie] [-o output] [-S ssl_options] " "[-s srcaddr]\n" - " [-U useragent] " + " [-U useragent] [-w seconds] " "http[s]://[user:password@]host[:port]/file ...\n" " ftp [-C] [-o output] [-s srcaddr] file:file ...\n" " ftp [-C] [-o output] [-s srcaddr] host:/file[/] ...\n" #else /* !SMALL */ - "ftp [-o output] ftp://[user:password@]host[:port]/file[/] ...\n" + "ftp [-o output] " + "ftp://[user:password@]host[:port]/file[/] ...\n" #ifndef NOSSL - " ftp [-o output] [-S ssl_options] " + " ftp [-o output] [-S ssl_options] [-w seconds] " "http[s]://[user:password@]host[:port]/file ...\n" #else - " ftp [-o output] http://host[:port]/file ...\n" + " ftp [-o output] [-w seconds] http://host[:port]/file ...\n" #endif /* NOSSL */ " ftp [-o output] file:file ...\n" " ftp [-o output] host:/file[/] ...\n" |