1 diff -uNr netkit-ftp-0.17/CVS/Entries netkit-ftp/CVS/Entries
2 diff -uNr netkit-ftp-0.17/ChangeLog netkit-ftp/ChangeLog
3 --- netkit-ftp-0.17/ChangeLog Sun Jul 23 04:38:08 2000
4 +++ netkit-ftp/ChangeLog Tue Nov 28 03:50:10 2000
7 + IPv6 support. (Hiroyuki YAMAMORI <h-yamamo@db3.so-net.ne.jp>)
10 Fix misused printf-function call (not %n-exploitable though).
12 diff -uNr netkit-ftp-0.17/configure netkit-ftp/configure
13 --- netkit-ftp-0.17/configure Sat Jul 29 21:00:28 2000
14 +++ netkit-ftp/configure Sat Jan 27 06:14:54 2001
16 --binmode=mode Mode for binaries [755]
17 --manmode=mode Mode for manual pages [644]
18 --with-c-compiler=cc Program for compiling C source [guessed]
19 + --enable-ipv6 Enable IPv6 support
24 --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
25 --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
26 --without-readline|--disable-readline) WITHOUT_READLINE=1;;
28 + --disable-ipv6) ENABLE_IPV6=no;;
29 + --enable-ipv6=*) ENABLE_IPV6=`echo $1 | sed 's/^[^=]*=//'`;;
30 + --enable-ipv6) ENABLE_IPV6=yes;;
32 *) echo "Unrecognized option: $1"; exit 1;;
42 +##################################################
44 +echo -n "Whether to enable IPv6 support... "
45 +if [ x"$ENABLE_IPV6" = x"yes" ]; then
47 + CFLAGS="$CFLAGS -DINET6"
54 +## Search IPv6 Library / Headers
55 +if [ x"$ENABLE_IPV6" = x"yes" ]; then
56 + echo -n "Search for IPv6 library... "
57 + inet6libdirs="/usr/local/v6/lib /usr/local/lib /usr /usr/inet6/lib"
60 + for inet6libdir in $inet6libdirs; do
61 + for inet6lib in $inet6libs; do
62 + if [ -d $inet6libdir ] && [ -f $inet6libdir/lib$inet6lib.a ]; then
68 + if [ x"$inet6found" = x"yes" ]; then
69 + echo "$inet6libdir/lib$inet6lib.a"
70 + LIBS="$LIBS -L$inet6libdir -l$inet6lib"
78 diff -uNr netkit-ftp-0.17/ftp/CVS/Entries netkit-ftp/ftp/CVS/Entries
79 --- netkit-ftp-0.17/ftp/CVS/Entries Thu Jan 1 02:00:00 1970
80 +++ netkit-ftp/ftp/CVS/Entries Mon Feb 19 06:50:49 2001
82 +/.cvsignore/1.1.1.1/Fri Nov 3 19:18:15 2000//
83 +/Makefile/1.4/Sat Jan 27 05:57:08 2001//
84 +/cmds.c/1.3/Fri Jan 12 21:36:27 2001//
85 +/cmds.h/1.1.1.1/Fri Nov 3 19:18:15 2000//
86 +/cmdtab.c/1.1.1.1/Fri Nov 3 19:18:15 2000//
87 +/domacro.c/1.1.1.1/Fri Nov 3 19:18:15 2000//
88 +/ftp.1/1.1.1.1/Fri Nov 3 19:18:15 2000//
89 +/ftp.c/1.11/Sun Feb 11 12:26:59 2001//
90 +/ftp_var.h/1.3/Fri Jan 12 21:36:27 2001//
91 +/glob.c/1.1.1.1/Fri Nov 3 19:18:15 2000//
92 +/glob.h/1.1.1.1/Fri Nov 3 19:18:15 2000//
93 +/main.c/1.1.1.1/Fri Nov 3 19:18:15 2000//
94 +/netrc.5/1.1.1.1/Fri Nov 3 19:18:15 2000//
95 +/pathnames.h/1.1.1.1/Fri Nov 3 19:18:15 2000//
96 +/ruserpass.c/1.1.1.1/Fri Nov 3 19:18:15 2000//
98 diff -uNr netkit-ftp-0.17/ftp/CVS/Repository netkit-ftp/ftp/CVS/Repository
99 --- netkit-ftp-0.17/ftp/CVS/Repository Thu Jan 1 02:00:00 1970
100 +++ netkit-ftp/ftp/CVS/Repository Mon Feb 19 06:50:49 2001
102 +usagi/src/netkit-ftp/ftp
103 diff -uNr netkit-ftp-0.17/ftp/CVS/Root netkit-ftp/ftp/CVS/Root
104 --- netkit-ftp-0.17/ftp/CVS/Root Thu Jan 1 02:00:00 1970
105 +++ netkit-ftp/ftp/CVS/Root Mon Feb 19 06:50:49 2001
107 +:pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi
108 diff -uNr netkit-ftp-0.17/ftp/Makefile netkit-ftp/ftp/Makefile
109 --- netkit-ftp-0.17/ftp/Makefile Sun Aug 1 09:00:12 1999
110 +++ netkit-ftp/ftp/Makefile Sat Jan 27 07:57:08 2001
112 cmds.o glob.o: glob.h
115 + install -d $(INSTALLROOT)$(BINDIR)
116 install -s -m$(BINMODE) ftp $(INSTALLROOT)$(BINDIR)
117 ln -sf ftp $(INSTALLROOT)$(BINDIR)/pftp
118 + install -d $(INSTALLROOT)$(MANDIR)/man1
119 install -m$(MANMODE) ftp.1 $(INSTALLROOT)$(MANDIR)/man1
120 ln -sf ftp.1 $(INSTALLROOT)$(MANDIR)/man1/pftp.1
121 + install -d $(INSTALLROOT)$(MANDIR)/man5
122 install -m$(MANMODE) netrc.5 $(INSTALLROOT)$(MANDIR)/man5
125 diff -uNr netkit-ftp-0.17/ftp/cmds.c netkit-ftp/ftp/cmds.c
126 --- netkit-ftp-0.17/ftp/cmds.c Sun Jul 23 04:36:59 2000
127 +++ netkit-ftp/ftp/cmds.c Fri Jan 12 23:36:27 2001
132 * Copyright (c) 1985, 1989 Regents of the University of California.
133 * All rights reserved.
135 * from: @(#)cmds.c 5.26 (Berkeley) 3/5/91
142 * FTP User Program -- Command Routines.
144 setpeer(int argc, char *argv[])
147 - unsigned short port;
151 printf("Already connected to %s, use close first.\n",
152 @@ -205,22 +207,17 @@
159 - port = atoi(argv[2]);
161 - printf("%s: bad port number-- %s\n", argv[1], argv[2]);
162 - printf ("usage: %s host-name [port]\n", argv[0]);
166 - port = htons(port);
169 host = hookup(argv[1], port);
177 * Set up defaults for FTP.
179 diff -uNr netkit-ftp-0.17/ftp/cmdtab.c netkit-ftp/ftp/cmdtab.c
180 --- netkit-ftp-0.17/ftp/cmdtab.c Tue Sep 28 18:36:05 1999
181 +++ netkit-ftp/ftp/cmdtab.c Fri Nov 3 21:18:15 2000
183 * from: @(#)cmdtab.c 5.10 (Berkeley) 6/1/90
185 char cmdtab_rcsid[] =
189 #include <string.h> /* for NULL */
191 diff -uNr netkit-ftp-0.17/ftp/domacro.c netkit-ftp/ftp/domacro.c
192 --- netkit-ftp-0.17/ftp/domacro.c Thu Aug 15 02:27:28 1996
193 +++ netkit-ftp/ftp/domacro.c Fri Nov 3 21:18:15 2000
195 * from: @(#)domacro.c 1.8 (Berkeley) 9/28/90
197 char domacro_rcsid[] =
203 diff -uNr netkit-ftp-0.17/ftp/ftp.1 netkit-ftp/ftp/ftp.1
204 --- netkit-ftp-0.17/ftp/ftp.1 Mon Jul 31 02:56:59 2000
205 +++ netkit-ftp/ftp/ftp.1 Fri Nov 3 21:18:15 2000
209 .\" from: @(#)ftp.1 6.18 (Berkeley) 7/30/91
215 diff -uNr netkit-ftp-0.17/ftp/ftp.c netkit-ftp/ftp/ftp.c
216 --- netkit-ftp-0.17/ftp/ftp.c Mon Dec 13 22:33:20 1999
217 +++ netkit-ftp/ftp/ftp.c Sun Feb 11 14:26:59 2001
222 + * Copyright (C) 1997 and 1998 WIDE Project.
223 + * All rights reserved.
225 + * Redistribution and use in source and binary forms, with or without
226 + * modification, are permitted provided that the following conditions
228 + * 1. Redistributions of source code must retain the above copyright
229 + * notice, this list of conditions and the following disclaimer.
230 + * 2. Redistributions in binary form must reproduce the above copyright
231 + * notice, this list of conditions and the following disclaimer in the
232 + * documentation and/or other materials provided with the distribution.
233 + * 3. Neither the name of the project nor the names of its contributors
234 + * may be used to endorse or promote products derived from this software
235 + * without specific prior written permission.
237 + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
238 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
239 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
240 + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
241 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
242 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
243 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
245 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
246 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251 * Copyright (c) 1985, 1989 Regents of the University of California.
252 * All rights reserved.
254 * From: @(#)ftp.c 5.38 (Berkeley) 4/22/91
260 #include <sys/param.h>
261 #include <sys/stat.h>
267 +#include "version.h"
269 #include "../version.h"
277 + struct sockaddr su_sa;
278 + struct sockaddr_in su_sin;
280 + struct sockaddr_in6 su_sin6;
283 +#define su_family su_sa.sa_family
284 +#define su_port su_si.si_port
287 +#define ex_af2prot(a) (a == AF_INET ? 1 : (a == AF_INET6 ? 2 : 0))
289 +#define ex_af2prot(a) (a == AF_INET ? 1 : 0)
293 off_t restart_point = 0;
295 -static struct sockaddr_in hisctladdr;
296 -static struct sockaddr_in data_addr;
297 -static struct sockaddr_in myctladdr;
298 +static union sockunion hisctladdr;
299 +static union sockunion data_addr;
300 +static union sockunion myctladdr;
301 static int ptflag = 0;
302 static sigjmp_buf recvabort;
303 static sigjmp_buf sendabort;
304 @@ -96,79 +151,119 @@
305 static FILE *dataconn(const char *);
308 -hookup(char *host, int port)
309 +hookup(const char *host, const char *port)
311 - register struct hostent *hp = 0;
315 static char hostnamebuf[256];
317 + struct addrinfo hints, *res, *res0;
318 + char hbuf[MAXHOSTNAMELEN], pbuf[NI_MAXSERV];
319 + char *cause = "ftp: unknown";
322 + strncpy(pbuf, port, sizeof(pbuf) - 1);
323 + pbuf[sizeof(pbuf) - 1] = '\0';
325 + sprintf(pbuf, "%d", ntohs(ftp_port));
327 memset(&hisctladdr, 0, sizeof(hisctladdr));
328 - if (inet_aton(host, &hisctladdr.sin_addr)) {
329 - hisctladdr.sin_family = AF_INET;
330 - strncpy(hostnamebuf, host, sizeof(hostnamebuf));
331 - hostnamebuf[sizeof(hostnamebuf)-1]=0;
334 - hp = gethostbyname(host);
336 - fprintf(stderr, "ftp: %s: ", host);
337 - herror((char *)NULL);
339 - return((char *) 0);
340 + memset(&hints, 0, sizeof(hints));
341 + hints.ai_flags = AI_CANONNAME;
342 + hints.ai_socktype = SOCK_STREAM;
343 + error = getaddrinfo(host, pbuf, &hints, &res0);
351 - hisctladdr.sin_family = hp->h_addrtype;
352 - if (hp->h_length > (int)sizeof(hisctladdr.sin_addr)) {
353 - hp->h_length = sizeof(hisctladdr.sin_addr);
355 - memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length);
356 - (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
357 - hostnamebuf[sizeof(hostnamebuf)-1] = 0;
359 - hostname = hostnamebuf;
360 - s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
362 - perror("ftp: socket");
363 + fprintf(stderr, "ftp: %s%s%s: %s\n", host, hbuf, pbuf,
364 + gai_strerror(error));
368 - hisctladdr.sin_port = port;
369 - while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) {
370 - if (hp && hp->h_addr_list[1]) {
371 - int oerrno = errno;
373 - fprintf(stderr, "ftp: connect to address %s: ",
374 - inet_ntoa(hisctladdr.sin_addr));
376 - perror((char *) 0);
378 - memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
380 - fprintf(stdout, "Trying %s...\n",
381 - inet_ntoa(hisctladdr.sin_addr));
383 - s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
385 - perror("ftp: socket");
389 + if (res0->ai_canonname) {
390 + struct addrinfo h, *a;
391 + memset(&h, 0, sizeof(h));
392 + h.ai_family = PF_UNSPEC;
393 + h.ai_socktype = SOCK_STREAM;
394 + h.ai_flags = AI_NUMERICHOST;
395 + if (!getaddrinfo(res0->ai_canonname, NULL, &h, &a)) {
396 + strncpy(hostnamebuf, res0->ai_canonname, sizeof(hostnamebuf));
399 + strncpy(hostnamebuf, host, sizeof(hostnamebuf));
402 + strncpy(hostnamebuf, host, sizeof(hostnamebuf));
403 + hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
404 + hostname = hostnamebuf;
407 + for (res = res0; res; res = res->ai_next) {
408 + if (!ex_af2prot(res->ai_family)) {
409 + cause = "ftp: mismatch address family";
410 + errno = EPROTONOSUPPORT;
413 + if ((size_t)res->ai_addrlen > sizeof(hisctladdr)) {
414 + cause = "ftp: mismatch struct sockaddr size";
418 + if (getnameinfo(res->ai_addr, res->ai_addrlen,
419 + hbuf, sizeof(hbuf), NULL, 0,
421 + strcpy(hbuf, "???");
422 + if (res0->ai_next) /* if we have multiple possibilities */
423 + fprintf(stdout, "Trying %s...\n", hbuf);
424 + s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
426 + cause = "ftp: socket";
429 + while ((error = connect(s, res->ai_addr, res->ai_addrlen)) < 0
430 + && errno == EINTR) {
434 + /* this "if" clause is to prevent print warning twice */
435 + if (res->ai_next) {
437 + "ftp: connect to address %s", hbuf);
440 + cause = "ftp: connect";
445 - perror("ftp: connect");
446 + /* finally we got one */
453 + freeaddrinfo(res0);
456 - len = sizeof (myctladdr);
457 + len = res->ai_addrlen;
458 + memcpy(&hisctladdr, res->ai_addr, len);
459 + freeaddrinfo(res0);
460 if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
461 perror("ftp: getsockname");
466 + if (hisctladdr.su_family == AF_INET)
468 tos = IPTOS_LOWDELAY;
469 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
470 perror("ftp: setsockopt TOS (ignored)");
473 cin = fdopen(s, "r");
474 cout = fdopen(s, "w");
479 - printf("Connected to %s.\n", hostname);
480 + printf("Connected to %s (%s).\n", hostname, hbuf);
481 if (getreply(0) > 2) { /* read startup message from server */
486 if (dig < 4 && isdigit(c))
487 code = code * 10 + (c - '0');
488 - if (!pflag && code == 227)
489 + if (!pflag && (code == 227 || code == 228))
491 + else if (!pflag && code == 229)
493 if (dig > 4 && pflag == 1 && isdigit(c))
500 + if (pflag == 100 && c == '(')
502 if (dig == 4 && c == '-') {
505 @@ -1083,15 +1182,25 @@
509 - register char *p, *a;
511 int result, tmpno = 0;
515 - u_long a1,a2,a3,a4,p1,p2;
517 + int tos, error = 0;
518 + u_int ad[16], po[2], af, alen, plen;
519 + char *pasvcmd = NULL;
520 + char hbuf[MAXHOSTNAMELEN], pbuf[NI_MAXSERV];
523 + if (myctladdr.su_family == AF_INET6
524 + && (IN6_IS_ADDR_LINKLOCAL(&myctladdr.su_sin6.sin6_addr)
525 + || IN6_IS_ADDR_SITELOCAL(&myctladdr.su_sin6.sin6_addr))) {
526 + fprintf(stderr, "use of scoped address can be troublesome\n");
530 - data = socket(AF_INET, SOCK_STREAM, 0);
531 + data_addr = hisctladdr;
532 + data = socket(data_addr.su_family, SOCK_STREAM, 0);
534 perror("ftp: socket");
536 @@ -1100,52 +1209,201 @@
537 setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
539 perror("ftp: setsockopt (ignored)");
540 - if (command("PASV") != COMPLETE) {
541 + switch (data_addr.su_family) {
545 + result = command(pasvcmd = "EPSV 1");
546 + if (code / 10 == 22 && code != 229) {
548 + "wrong server: return code must be 229\n");
549 + result = COMPLETE + 1;
553 + result = COMPLETE + 1;
555 + if (result != COMPLETE) {
557 + result = command(pasvcmd = "PASV");
563 + result = command(pasvcmd = "EPSV 2");
564 + if (code / 10 == 22 && code != 229) {
566 + "wrong server: return code must be 229\n");
567 + result = COMPLETE + 1;
570 + result = COMPLETE + 1;
572 + if (result != COMPLETE) {
574 + result = command(pasvcmd = "LPSV");
579 + result = COMPLETE + 1;
582 + if (result != COMPLETE) {
583 printf("Passive mode refused.\n");
588 +#define pack2(var) \
589 + (((var[0] & 0xff) << 8) | ((var[1] & 0xff) << 0))
590 +#define pack4(var) \
591 + ((((var)[0] & 0xff) << 24) | (((var)[1] & 0xff) << 16) | \
592 + (((var)[2] & 0xff) << 8) | (((var)[3] & 0xff) << 0))
595 * What we've got at this point is a string of comma separated
596 * one-byte unsigned integer values, separated by commas.
597 - * The first four are the an IP address. The fifth is the MSB
598 - * of the port number, the sixth is the LSB. From that we'll
599 - * prepare a sockaddr_in.
602 - if (sscanf(pasv,"%ld,%ld,%ld,%ld,%ld,%ld",
603 - &a1,&a2,&a3,&a4,&p1,&p2)
606 - printf("Passive mode address scan failure. Shouldn't happen!\n");
609 + if (strcmp(pasvcmd, "PASV") == 0) {
610 + if (data_addr.su_family != AF_INET) {
614 + if (code / 10 == 22 && code != 227) {
618 + if (sscanf(pasv, "%u,%u,%u,%u,%u,%u",
619 + &ad[0], &ad[1], &ad[2], &ad[3],
620 + &po[0], &po[1]) != 6) {
624 + data_addr.su_sin.sin_addr.s_addr = htonl(pack4(ad));
625 + data_addr.su_port = htons(pack2(po));
627 + if (strcmp(pasvcmd, "LPSV") == 0) {
628 + if (code / 10 == 22 && code != 228) {
632 + switch (data_addr.su_family) {
634 + if (sscanf(pasv, "%u,%u,%u,%u,%u,%u,%u,%u,%u",
636 + &ad[0], &ad[1], &ad[2], &ad[3],
637 + &plen, &po[0], &po[1]) != 9) {
641 + if (af != 4 || alen != 4 || plen != 2) {
645 + data_addr.su_sin.sin_addr.s_addr =
647 + data_addr.su_port = htons(pack2(po));
652 + "%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u",
654 + &ad[0], &ad[1], &ad[2], &ad[3],
655 + &ad[4], &ad[5], &ad[6], &ad[7],
656 + &ad[8], &ad[9], &ad[10], &ad[11],
657 + &ad[12], &ad[13], &ad[14], &ad[15],
658 + &plen, &po[0], &po[1]) != 21) {
662 + if (af != 6 || alen != 16 || plen != 2) {
666 + data_addr.su_sin6.sin6_addr.s6_addr32[0] =
668 + data_addr.su_sin6.sin6_addr.s6_addr32[1] =
669 + htonl(pack4(ad+4));
670 + data_addr.su_sin6.sin6_addr.s6_addr32[2] =
671 + htonl(pack4(ad+8));
672 + data_addr.su_sin6.sin6_addr.s6_addr32[3] =
673 + htonl(pack4(ad+12));
674 + data_addr.su_port = htons(pack2(po));
680 + } else if (strncmp(pasvcmd, "EPSV", 4) == 0) {
684 + if (code / 10 == 22 && code != 229) {
688 + if (sscanf(pasv, "%c%c%c%u%c", &delim[0], &delim[1],
689 + &delim[2], &epsvpo, &delim[3]) != 5) {
693 + if (delim[0] != delim[1] || delim[0] != delim[2]
694 + || delim[0] != delim[3]) {
698 + data_addr.su_port = htons(epsvpo);
708 + "Passive mode address scan failure. Shouldn't happen!\n");
712 + "Passive mode AF mismatch. Shouldn't happen!\n");
718 + "wrong server: return code must be %d\n", error);
721 + fprintf(stderr, "Bug\n");
724 - data_addr.sin_family = AF_INET;
725 - data_addr.sin_addr.s_addr = htonl((a1 << 24) | (a2 << 16) |
727 - data_addr.sin_port = htons((p1 << 8) | p2);
729 if (connect(data, (struct sockaddr *) &data_addr,
730 sizeof(data_addr))<0) {
731 perror("ftp: connect");
735 + if (data_addr.su_family == AF_INET)
737 tos = IPTOS_THROUGHPUT;
738 if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&tos,
740 perror("ftp: setsockopt TOS (ignored)");
746 data_addr = myctladdr;
748 - data_addr.sin_port = 0; /* let system pick one */
749 + data_addr.su_port = 0; /* let system pick one */
752 - data = socket(AF_INET, SOCK_STREAM, 0);
753 + data = socket(data_addr.su_family, SOCK_STREAM, 0);
755 perror("ftp: socket");
757 @@ -1172,13 +1430,47 @@
758 if (listen(data, 1) < 0)
759 perror("ftp: listen");
761 - a = (char *)&data_addr.sin_addr;
762 - p = (char *)&data_addr.sin_port;
763 -#define UC(b) (((int)b)&0xff)
765 - command("PORT %d,%d,%d,%d,%d,%d",
766 - UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
767 - UC(p[0]), UC(p[1]));
768 + af = ex_af2prot(data_addr.su_family);
769 + if (try_eprt && af > 1) { /* only IPv6 */
770 + if (getnameinfo((struct sockaddr *)&data_addr, len,
771 + hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
772 + NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
773 + result = command("EPRT |%d|%s|%s|",
775 + if (result != COMPLETE) {
782 + result = COMPLETE + 1;
784 + if (result == COMPLETE)
787 + p = (u_char *)&data_addr.su_port;
788 + switch (data_addr.su_family) {
790 + a = (u_char *)&data_addr.su_sin.sin_addr;
791 + result = command("PORT %u,%u,%u,%u,%u,%u",
792 + a[0], a[1], a[2], a[3], p[0], p[1]);
796 + a = (u_char *)&data_addr.su_sin6.sin6_addr;
798 + "LPRT 6,16,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,2,%d,%d",
799 + a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
800 + a[8], a[9],a[10],a[11],a[12],a[13],a[14],a[15],
805 + result = COMPLETE + 1; /* xxx */
809 if (result == ERROR && sendport == -1) {
812 @@ -1189,9 +1481,12 @@
816 + if (data_addr.su_family == AF_INET)
818 on = IPTOS_THROUGHPUT;
819 if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
820 perror("ftp: setsockopt TOS (ignored)");
825 @@ -1204,7 +1499,7 @@
827 dataconn(const char *lmode)
829 - struct sockaddr_in from;
830 + union sockunion from;
832 socklen_t fromlen = sizeof(from);
834 @@ -1220,9 +1515,12 @@
838 + if (from.su_family == AF_INET)
840 tos = IPTOS_THROUGHPUT;
841 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
842 perror("ftp: setsockopt TOS (ignored)");
845 return (fdopen(data, lmode));
847 @@ -1284,8 +1582,8 @@
848 static struct comvars {
850 char name[MAXHOSTNAMELEN];
851 - struct sockaddr_in mctl;
852 - struct sockaddr_in hctl;
853 + union sockunion mctl;
854 + union sockunion hctl;
858 @@ -1323,7 +1621,7 @@
859 connected = op->connect;
861 (void) strncpy(ip->name, hostname, sizeof(ip->name) - 1);
862 - ip->name[strlen(ip->name)] = '\0';
863 + ip->name[sizeof(ip->name) - 1] = '\0';
867 @@ -1352,18 +1650,18 @@
870 (void) strncpy(ip->nti, ntin, 16);
871 - (ip->nti)[strlen(ip->nti)] = '\0';
872 + (ip->nti)[16] = '\0'; /* shouldn't use strlen */
873 (void) strcpy(ntin, op->nti);
874 (void) strncpy(ip->nto, ntout, 16);
875 - (ip->nto)[strlen(ip->nto)] = '\0';
876 + (ip->nto)[16] = '\0';
877 (void) strcpy(ntout, op->nto);
878 ip->mapflg = mapflag;
879 mapflag = op->mapflg;
880 (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1);
881 - (ip->mi)[strlen(ip->mi)] = '\0';
882 + (ip->mi)[MAXPATHLEN - 1] = '\0';
883 (void) strcpy(mapin, op->mi);
884 (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1);
885 - (ip->mo)[strlen(ip->mo)] = '\0';
886 + (ip->mo)[MAXPATHLEN - 1] = '\0';
887 (void) strcpy(mapout, op->mo);
888 (void) signal(SIGINT, oldintr);
890 diff -uNr netkit-ftp-0.17/ftp/ftp_var.h netkit-ftp/ftp/ftp_var.h
891 --- netkit-ftp-0.17/ftp/ftp_var.h Sat Oct 2 21:39:17 1999
892 +++ netkit-ftp/ftp/ftp_var.h Fri Jan 12 23:36:27 2001
897 * Copyright (c) 1985, 1989 Regents of the University of California.
898 * All rights reserved.
902 * from: @(#)ftp_var.h 5.9 (Berkeley) 6/1/90
909 Extern int mflag; /* flag: if != 0, then active multi command */
911 Extern int options; /* used during socket creation */
912 +Extern int try_epsv; /* try EPSV for this session */
913 +Extern int try_eprt; /* try EPRT for this session */
916 * Format of command table.
918 Extern char macbuf[4096];
919 #define MACBUF_SIZE 4096
921 -char *hookup(char *host, int port);
922 +char *hookup(const char *host, const char *port);
923 struct cmd *getcmd(const char *);
924 char **makeargv(int *pargc, char **parg);
925 int dologin(const char *host);