source: npl/system/netkit-ftp/patches/03-netkit-ftp.usagi-ipv6.patch @ 0105685

gcc484ntopperl-5.22
Last change on this file since 0105685 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 25.8 KB
  • ChangeLog

    diff -uNr netkit-ftp-0.17/CVS/Entries netkit-ftp/CVS/Entries
    diff -uNr netkit-ftp-0.17/ChangeLog netkit-ftp/ChangeLog
    old new  
     128-Nov-2000:
     2        IPv6 support. (Hiroyuki YAMAMORI <h-yamamo@db3.so-net.ne.jp>)
     3
    148-Jul-2000:
    25        Fix misused printf-function call (not %n-exploitable though).
    36
  • configure

    diff -uNr netkit-ftp-0.17/configure netkit-ftp/configure
    old new  
    2424    --binmode=mode        Mode for binaries [755]
    2525    --manmode=mode        Mode for manual pages [644]
    2626    --with-c-compiler=cc  Program for compiling C source [guessed]
     27    --enable-ipv6         Enable IPv6 support
    2728EOF
    2829        exit 0;;
    2930        --verbose) ;;
     
    3940        --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
    4041        --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
    4142        --without-readline|--disable-readline) WITHOUT_READLINE=1;;
     43
     44        --disable-ipv6) ENABLE_IPV6=no;;
     45        --enable-ipv6=*) ENABLE_IPV6=`echo $1 | sed 's/^[^=]*=//'`;;
     46        --enable-ipv6) ENABLE_IPV6=yes;;
     47
    4248        *) echo "Unrecognized option: $1"; exit 1;;
    4349esac
    4450shift
     
    142148
    143149LDFLAGS=
    144150LIBS=
     151
     152rm -f __conftest*
     153
     154##################################################
     155## Enable IPv6
     156echo -n "Whether to enable IPv6 support... "
     157if [ x"$ENABLE_IPV6" = x"yes" ]; then
     158    echo yes
     159    CFLAGS="$CFLAGS -DINET6"
     160else
     161    echo no
     162fi
     163
     164rm -f __conftest*
     165
     166## Search IPv6 Library / Headers
     167if [ x"$ENABLE_IPV6" = x"yes" ]; then
     168    echo -n "Search for IPv6 library... "
     169    inet6libdirs="/usr/local/v6/lib /usr/local/lib /usr /usr/inet6/lib"
     170    inet6libs="inet6"
     171    inet6found=no
     172    for inet6libdir in $inet6libdirs; do
     173        for inet6lib in $inet6libs; do
     174            if [ -d $inet6libdir ] && [ -f $inet6libdir/lib$inet6lib.a ]; then
     175                inet6found=yes
     176                break 2
     177            fi
     178        done
     179    done
     180    if [ x"$inet6found" = x"yes" ]; then
     181        echo "$inet6libdir/lib$inet6lib.a"
     182        LIBS="$LIBS -L$inet6libdir -l$inet6lib"
     183    else
     184        echo "not found"
     185    fi
     186fi
    145187
    146188rm -f __conftest*
    147189
  • ftp/CVS/Entries

    diff -uNr netkit-ftp-0.17/ftp/CVS/Entries netkit-ftp/ftp/CVS/Entries
    old new  
     1/.cvsignore/1.1.1.1/Fri Nov  3 19:18:15 2000//
     2/Makefile/1.4/Sat Jan 27 05:57:08 2001//
     3/cmds.c/1.3/Fri Jan 12 21:36:27 2001//
     4/cmds.h/1.1.1.1/Fri Nov  3 19:18:15 2000//
     5/cmdtab.c/1.1.1.1/Fri Nov  3 19:18:15 2000//
     6/domacro.c/1.1.1.1/Fri Nov  3 19:18:15 2000//
     7/ftp.1/1.1.1.1/Fri Nov  3 19:18:15 2000//
     8/ftp.c/1.11/Sun Feb 11 12:26:59 2001//
     9/ftp_var.h/1.3/Fri Jan 12 21:36:27 2001//
     10/glob.c/1.1.1.1/Fri Nov  3 19:18:15 2000//
     11/glob.h/1.1.1.1/Fri Nov  3 19:18:15 2000//
     12/main.c/1.1.1.1/Fri Nov  3 19:18:15 2000//
     13/netrc.5/1.1.1.1/Fri Nov  3 19:18:15 2000//
     14/pathnames.h/1.1.1.1/Fri Nov  3 19:18:15 2000//
     15/ruserpass.c/1.1.1.1/Fri Nov  3 19:18:15 2000//
     16D
  • ftp/CVS/Repository

    diff -uNr netkit-ftp-0.17/ftp/CVS/Repository netkit-ftp/ftp/CVS/Repository
    old new  
     1usagi/src/netkit-ftp/ftp
  • ftp/CVS/Root

    diff -uNr netkit-ftp-0.17/ftp/CVS/Root netkit-ftp/ftp/CVS/Root
    old new  
     1:pserver:anoncvs@anoncvs.linux-ipv6.org:/cvsroot/usagi
  • ftp/Makefile

    diff -uNr netkit-ftp-0.17/ftp/Makefile netkit-ftp/ftp/Makefile
    old new  
    1616cmds.o glob.o: glob.h
    1717
    1818install: ftp
     19        install -d $(INSTALLROOT)$(BINDIR)
    1920        install -s -m$(BINMODE) ftp $(INSTALLROOT)$(BINDIR)
    2021        ln -sf ftp $(INSTALLROOT)$(BINDIR)/pftp
     22        install -d $(INSTALLROOT)$(MANDIR)/man1
    2123        install -m$(MANMODE) ftp.1 $(INSTALLROOT)$(MANDIR)/man1
    2224        ln -sf ftp.1 $(INSTALLROOT)$(MANDIR)/man1/pftp.1
     25        install -d $(INSTALLROOT)$(MANDIR)/man5
    2326        install -m$(MANMODE) netrc.5 $(INSTALLROOT)$(MANDIR)/man5
    2427
    2528clean:
  • ftp/cmds.c

    diff -uNr netkit-ftp-0.17/ftp/cmds.c netkit-ftp/ftp/cmds.c
    old new  
     1/* $USAGI$ */
     2
    13/*
    24 * Copyright (c) 1985, 1989 Regents of the University of California.
    35 * All rights reserved.
     
    3537 * from: @(#)cmds.c     5.26 (Berkeley) 3/5/91
    3638 */
    3739char cmds_rcsid[] =
    38    "$Id: cmds.c,v 1.33 2000/07/23 01:36:59 dholland Exp $";
     40   "$Id: cmds.c,v 1.3 2001/01/12 21:36:27 sekiya Exp $";
    3941
    4042/*
    4143 * FTP User Program -- Command Routines.
     
    190192setpeer(int argc, char *argv[])
    191193{
    192194        char *host;
    193         unsigned short port;
     195        char *port;
    194196
    195197        if (connected) {
    196198                printf("Already connected to %s, use close first.\n",
     
    205207                code = -1;
    206208                return;
    207209        }
    208         port = ftp_port;
     210        port = NULL;
    209211        if (argc > 2) {
    210                 port = atoi(argv[2]);
    211                 if (port < 1) {
    212                         printf("%s: bad port number-- %s\n", argv[1], argv[2]);
    213                         printf ("usage: %s host-name [port]\n", argv[0]);
    214                         code = -1;
    215                         return;
    216                 }
    217                 port = htons(port);
     212                port = argv[2];
    218213        }
    219214        host = hookup(argv[1], port);
    220215        if (host) {
    221216                int overbose;
    222217
    223218                connected = 1;
     219                try_epsv = 1;
     220                try_eprt = 1;
    224221                /*
    225222                 * Set up defaults for FTP.
    226223                 */
  • ftp/cmdtab.c

    diff -uNr netkit-ftp-0.17/ftp/cmdtab.c netkit-ftp/ftp/cmdtab.c
    old new  
    3535 * from: @(#)cmdtab.c   5.10 (Berkeley) 6/1/90
    3636 */
    3737char cmdtab_rcsid[] =
    38   "$Id: cmdtab.c,v 1.8 1999/09/28 15:36:05 dholland Exp $";
     38  "$Id: cmdtab.c,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $";
    3939
    4040#include <string.h>   /* for NULL */
    4141#include "ftp_var.h"
  • ftp/domacro.c

    diff -uNr netkit-ftp-0.17/ftp/domacro.c netkit-ftp/ftp/domacro.c
    old new  
    3535 * from: @(#)domacro.c  1.8 (Berkeley) 9/28/90
    3636 */
    3737char domacro_rcsid[] =
    38   "$Id: domacro.c,v 1.4 1996/08/14 23:27:28 dholland Exp $";
     38  "$Id: domacro.c,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $";
    3939
    4040#include <errno.h>
    4141#include <ctype.h>
  • ftp/ftp.1

    diff -uNr netkit-ftp-0.17/ftp/ftp.1 netkit-ftp/ftp/ftp.1
    old new  
    3030.\" SUCH DAMAGE.
    3131.\"
    3232.\"     from: @(#)ftp.1 6.18 (Berkeley) 7/30/91
    33 .\"     $Id: ftp.1,v 1.14 2000/07/30 23:56:59 dholland Exp $
     33.\"     $Id: ftp.1,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $
    3434.\"
    3535.Dd August 15, 1999
    3636.Dt FTP 1
  • ftp/ftp.c

    diff -uNr netkit-ftp-0.17/ftp/ftp.c netkit-ftp/ftp/ftp.c
    old new  
     1/* $USAGI$ */
     2
     3/*
     4 * Copyright (C) 1997 and 1998 WIDE Project.
     5 * All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 * 1. Redistributions of source code must retain the above copyright
     11 *    notice, this list of conditions and the following disclaimer.
     12 * 2. Redistributions in binary form must reproduce the above copyright
     13 *    notice, this list of conditions and the following disclaimer in the
     14 *    documentation and/or other materials provided with the distribution.
     15 * 3. Neither the name of the project nor the names of its contributors
     16 *    may be used to endorse or promote products derived from this software
     17 *    without specific prior written permission.
     18 *
     19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29 * SUCH DAMAGE.
     30 */
     31
    132/*
    233 * Copyright (c) 1985, 1989 Regents of the University of California.
    334 * All rights reserved.
     
    3566 * From: @(#)ftp.c      5.38 (Berkeley) 4/22/91
    3667 */
    3768char ftp_rcsid[] =
    38   "$Id: ftp.c,v 1.25 1999/12/13 20:33:20 dholland Exp $";
     69  "$Id: ftp.c,v 1.11 2001/02/11 12:26:59 yoshfuji Exp $";
    3970
    4071#include <sys/param.h>
    4172#include <sys/stat.h>
     
    6394#include "ftp_var.h"
    6495#include "cmds.h"
    6596
     97#ifdef _USAGI
     98#include "version.h"
     99#else
    66100#include "../version.h"
     101#endif
     102
     103union sockunion {
     104        struct sockinet {
     105                u_short si_family;
     106                u_short si_port;
     107        } su_si;
     108        struct  sockaddr                su_sa;
     109        struct  sockaddr_in             su_sin;
     110#ifdef INET6
     111        struct  sockaddr_in6            su_sin6;
     112#endif
     113};
     114#define su_family       su_sa.sa_family
     115#define su_port         su_si.si_port
     116
     117#ifdef INET6
     118#define ex_af2prot(a) (a == AF_INET ? 1 : (a == AF_INET6 ? 2 : 0))
     119#else
     120#define ex_af2prot(a) (a == AF_INET ? 1 : 0)
     121#endif
    67122
    68123int data = -1;
    69124off_t restart_point = 0;
    70125
    71 static struct sockaddr_in hisctladdr;
    72 static struct sockaddr_in data_addr;
    73 static struct sockaddr_in myctladdr;
     126static union sockunion hisctladdr;
     127static union sockunion data_addr;
     128static union sockunion myctladdr;
    74129static int ptflag = 0;
    75130static sigjmp_buf recvabort;
    76131static sigjmp_buf sendabort;
     
    96151static FILE *dataconn(const char *);
    97152
    98153char *
    99 hookup(char *host, int port)
     154hookup(const char *host, const char *port)
    100155{
    101         register struct hostent *hp = 0;
    102         int s, tos;
     156        int s, tos, error;
    103157        socklen_t len;
    104158        static char hostnamebuf[256];
    105 
     159        struct addrinfo hints, *res, *res0;
     160        char hbuf[MAXHOSTNAMELEN], pbuf[NI_MAXSERV];
     161        char *cause = "ftp: unknown";
     162
     163        if (port) {
     164                strncpy(pbuf, port, sizeof(pbuf) - 1);
     165                pbuf[sizeof(pbuf) - 1] = '\0';
     166        } else {
     167                sprintf(pbuf, "%d", ntohs(ftp_port));
     168        }
    106169        memset(&hisctladdr, 0, sizeof(hisctladdr));
    107         if (inet_aton(host, &hisctladdr.sin_addr)) {
    108                 hisctladdr.sin_family = AF_INET;
    109                 strncpy(hostnamebuf, host, sizeof(hostnamebuf));
    110                 hostnamebuf[sizeof(hostnamebuf)-1]=0;
    111         }
    112         else {
    113                 hp = gethostbyname(host);
    114                 if (hp == NULL) {
    115                         fprintf(stderr, "ftp: %s: ", host);
    116                         herror((char *)NULL);
    117                         code = -1;
    118                         return((char *) 0);
     170        memset(&hints, 0, sizeof(hints));
     171        hints.ai_flags = AI_CANONNAME;
     172        hints.ai_socktype = SOCK_STREAM;
     173        error = getaddrinfo(host, pbuf, &hints, &res0);
     174        if (error) {
     175                if (port) {
     176                        strcpy(hbuf, " ");
     177                } else {
     178                        hbuf[0] = '\0';
     179                        pbuf[0] = '\0';
    119180                }
    120                 hisctladdr.sin_family = hp->h_addrtype;
    121                 if (hp->h_length > (int)sizeof(hisctladdr.sin_addr)) {
    122                         hp->h_length = sizeof(hisctladdr.sin_addr);
    123                 }
    124                 memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length);
    125                 (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
    126                 hostnamebuf[sizeof(hostnamebuf)-1] = 0;
    127         }
    128         hostname = hostnamebuf;
    129         s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
    130         if (s < 0) {
    131                 perror("ftp: socket");
     181                fprintf(stderr, "ftp: %s%s%s: %s\n", host, hbuf, pbuf,
     182                                                gai_strerror(error));
    132183                code = -1;
    133184                return (0);
    134185        }
    135         hisctladdr.sin_port = port;
    136         while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) {
    137                 if (hp && hp->h_addr_list[1]) {
    138                         int oerrno = errno;
    139 
    140                         fprintf(stderr, "ftp: connect to address %s: ",
    141                                 inet_ntoa(hisctladdr.sin_addr));
    142                         errno = oerrno;
    143                         perror((char *) 0);
    144                         hp->h_addr_list++;
    145                         memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
    146                                hp->h_length);
    147                         fprintf(stdout, "Trying %s...\n",
    148                                 inet_ntoa(hisctladdr.sin_addr));
    149                         (void) close(s);
    150                         s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
    151                         if (s < 0) {
    152                                 perror("ftp: socket");
    153                                 code = -1;
    154                                 return (0);
     186
     187        if (res0->ai_canonname) {
     188                struct addrinfo h, *a;
     189                memset(&h, 0, sizeof(h));
     190                h.ai_family = PF_UNSPEC;
     191                h.ai_socktype = SOCK_STREAM;
     192                h.ai_flags = AI_NUMERICHOST;
     193                if (!getaddrinfo(res0->ai_canonname, NULL, &h, &a)) {
     194                        strncpy(hostnamebuf, res0->ai_canonname, sizeof(hostnamebuf));
     195                        freeaddrinfo(a);
     196                } else
     197                        strncpy(hostnamebuf, host, sizeof(hostnamebuf));
     198        }
     199        else
     200                strncpy(hostnamebuf, host, sizeof(hostnamebuf));
     201        hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
     202        hostname = hostnamebuf;
     203       
     204        s = -1;
     205        for (res = res0; res; res = res->ai_next) {
     206                if (!ex_af2prot(res->ai_family)) {
     207                        cause = "ftp: mismatch address family";
     208                        errno = EPROTONOSUPPORT;
     209                        continue;
     210                }
     211                if ((size_t)res->ai_addrlen > sizeof(hisctladdr)) {
     212                        cause = "ftp: mismatch struct sockaddr size";
     213                        errno = EPROTO;
     214                        continue;
     215                }
     216                if (getnameinfo(res->ai_addr, res->ai_addrlen,
     217                                hbuf, sizeof(hbuf), NULL, 0,
     218                                NI_NUMERICHOST))
     219                        strcpy(hbuf, "???");
     220                if (res0->ai_next)      /* if we have multiple possibilities */
     221                        fprintf(stdout, "Trying %s...\n", hbuf);
     222                s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
     223                if (s < 0) {
     224                        cause = "ftp: socket";
     225                        continue;
     226                }
     227                while ((error = connect(s, res->ai_addr, res->ai_addrlen)) < 0
     228                                && errno == EINTR) {
     229                        ;
     230                }
     231                if (error) {
     232                        /* this "if" clause is to prevent print warning twice */
     233                        if (res->ai_next) {
     234                                fprintf(stderr,
     235                                        "ftp: connect to address %s", hbuf);
     236                                perror("");
    155237                        }
     238                        cause = "ftp: connect";
     239                        close(s);
     240                        s = -1;
    156241                        continue;
    157242                }
    158                 perror("ftp: connect");
     243                /* finally we got one */
     244                break;
     245        }
     246        if (s < 0) {
     247                perror(cause);
    159248                code = -1;
    160                 goto bad;
     249                freeaddrinfo(res0);
     250                return NULL;
    161251        }
    162         len = sizeof (myctladdr);
     252        len = res->ai_addrlen;
     253        memcpy(&hisctladdr, res->ai_addr, len);
     254        freeaddrinfo(res0);
    163255        if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
    164256                perror("ftp: getsockname");
    165257                code = -1;
    166258                goto bad;
    167259        }
    168260#ifdef IP_TOS
     261        if (hisctladdr.su_family == AF_INET)
     262        {
    169263        tos = IPTOS_LOWDELAY;
    170264        if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
    171265                perror("ftp: setsockopt TOS (ignored)");
     266        }
    172267#endif
    173268        cin = fdopen(s, "r");
    174269        cout = fdopen(s, "w");
     
    182277                goto bad;
    183278        }
    184279        if (verbose)
    185                 printf("Connected to %s.\n", hostname);
     280                printf("Connected to %s (%s).\n", hostname, hbuf);
    186281        if (getreply(0) > 2) {  /* read startup message from server */
    187282                if (cin)
    188283                        (void) fclose(cin);
     
    392487                        }
    393488                        if (dig < 4 && isdigit(c))
    394489                                code = code * 10 + (c - '0');
    395                         if (!pflag && code == 227)
     490                        if (!pflag && (code == 227 || code == 228))
    396491                                pflag = 1;
     492                        else if (!pflag && code == 229)
     493                                pflag = 100;
    397494                        if (dig > 4 && pflag == 1 && isdigit(c))
    398495                                pflag = 2;
    399496                        if (pflag == 2) {
     
    405502                                        pflag = 3;
    406503                                }
    407504                        }
     505                        if (pflag == 100 && c == '(')
     506                                pflag = 2;
    408507                        if (dig == 4 && c == '-') {
    409508                                if (continuation)
    410509                                        code = 0;
     
    10831182static int
    10841183initconn(void)
    10851184{
    1086         register char *p, *a;
     1185        u_char *p, *a;
    10871186        int result, tmpno = 0;
    10881187        socklen_t len;
    10891188        int on = 1;
    1090         int tos;
    1091         u_long a1,a2,a3,a4,p1,p2;
    1092 
     1189        int tos, error = 0;
     1190        u_int ad[16], po[2], af, alen, plen;
     1191        char *pasvcmd = NULL;
     1192        char hbuf[MAXHOSTNAMELEN], pbuf[NI_MAXSERV];
     1193
     1194#ifdef INET6
     1195        if (myctladdr.su_family == AF_INET6
     1196         && (IN6_IS_ADDR_LINKLOCAL(&myctladdr.su_sin6.sin6_addr)
     1197          || IN6_IS_ADDR_SITELOCAL(&myctladdr.su_sin6.sin6_addr))) {
     1198                fprintf(stderr, "use of scoped address can be troublesome\n");
     1199        }
     1200#endif
    10931201        if (passivemode) {
    1094                 data = socket(AF_INET, SOCK_STREAM, 0);
     1202                data_addr = hisctladdr;
     1203                data = socket(data_addr.su_family, SOCK_STREAM, 0);
    10951204                if (data < 0) {
    10961205                        perror("ftp: socket");
    10971206                        return(1);
     
    11001209                    setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on,
    11011210                               sizeof (on)) < 0)
    11021211                        perror("ftp: setsockopt (ignored)");
    1103                 if (command("PASV") != COMPLETE) {
     1212                switch (data_addr.su_family) {
     1213                case AF_INET:
     1214#if 0
     1215                        if (try_epsv) {
     1216                                result = command(pasvcmd = "EPSV 1");
     1217                                if (code / 10 == 22 && code != 229) {
     1218                                        fprintf(stderr,
     1219                                  "wrong server: return code must be 229\n");
     1220                                        result = COMPLETE + 1;
     1221                                }
     1222                        } else {
     1223#endif
     1224                        result = COMPLETE + 1;
     1225
     1226                        if (result != COMPLETE) {
     1227                                try_epsv = 0;
     1228                                result = command(pasvcmd = "PASV");
     1229                        }
     1230                        break;
     1231#ifdef INET6
     1232                case AF_INET6:
     1233                        if (try_epsv) {
     1234                                result = command(pasvcmd = "EPSV 2");
     1235                                if (code / 10 == 22 && code != 229) {
     1236                                        fprintf(stderr,
     1237                                  "wrong server: return code must be 229\n");
     1238                                        result = COMPLETE + 1;
     1239                                }
     1240                        } else {
     1241                                result = COMPLETE + 1;
     1242                        }
     1243                        if (result != COMPLETE) {
     1244                                try_epsv = 0;
     1245                                result = command(pasvcmd = "LPSV");
     1246                        }
     1247                        break;
     1248#endif
     1249                default:
     1250                        result = COMPLETE + 1;
     1251                        break;
     1252                }
     1253                if (result != COMPLETE) {
    11041254                        printf("Passive mode refused.\n");
    1105                         return(1);
     1255                        goto bad;
    11061256                }
    11071257
     1258#define pack2(var) \
     1259        (((var[0] & 0xff) << 8) | ((var[1] & 0xff) << 0))
     1260#define pack4(var) \
     1261        ((((var)[0] & 0xff) << 24) | (((var)[1] & 0xff) << 16) | \
     1262         (((var)[2] & 0xff) << 8) | (((var)[3] & 0xff) << 0))
     1263
    11081264                /*
    11091265                 * What we've got at this point is a string of comma separated
    11101266                 * one-byte unsigned integer values, separated by commas.
    1111                  * The first four are the an IP address. The fifth is the MSB
    1112                  * of the port number, the sixth is the LSB. From that we'll
    1113                  * prepare a sockaddr_in.
    11141267                 */
    1115 
    1116                 if (sscanf(pasv,"%ld,%ld,%ld,%ld,%ld,%ld",
    1117                            &a1,&a2,&a3,&a4,&p1,&p2)
    1118                     != 6)
    1119                 {
    1120                         printf("Passive mode address scan failure. Shouldn't happen!\n");
    1121                         return(1);
     1268                error = 0;
     1269                if (strcmp(pasvcmd, "PASV") == 0) {
     1270                        if (data_addr.su_family != AF_INET) {
     1271                                error = 2;
     1272                                goto psv_done;
     1273                        }
     1274                        if (code / 10 == 22 && code != 227) {
     1275                                error = 227;
     1276                                goto psv_done;
     1277                        }
     1278                        if (sscanf(pasv, "%u,%u,%u,%u,%u,%u",
     1279                                        &ad[0], &ad[1], &ad[2], &ad[3],
     1280                                        &po[0], &po[1]) != 6) {
     1281                                error = 1;
     1282                                goto psv_done;
     1283                        }
     1284                        data_addr.su_sin.sin_addr.s_addr = htonl(pack4(ad));
     1285                        data_addr.su_port = htons(pack2(po));
     1286                } else
     1287                    if (strcmp(pasvcmd, "LPSV") == 0) {
     1288                        if (code / 10 == 22 && code != 228) {
     1289                                error = 228;
     1290                                goto psv_done;
     1291                        }
     1292                        switch (data_addr.su_family) {
     1293                        case AF_INET:
     1294                                if (sscanf(pasv, "%u,%u,%u,%u,%u,%u,%u,%u,%u",
     1295                                                &af, &alen,
     1296                                                &ad[0], &ad[1], &ad[2], &ad[3],
     1297                                                &plen, &po[0], &po[1]) != 9) {
     1298                                        error = 1;
     1299                                        goto psv_done;
     1300                                }
     1301                                if (af != 4 || alen != 4 || plen != 2) {
     1302                                        error = 2;
     1303                                        goto psv_done;
     1304                                }
     1305                                data_addr.su_sin.sin_addr.s_addr =
     1306                                                        htonl(pack4(ad));
     1307                                data_addr.su_port = htons(pack2(po));
     1308                                break;
     1309#ifdef INET6
     1310                        case AF_INET6:
     1311                                if (sscanf(pasv,
     1312        "%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u",
     1313                                  &af, &alen,
     1314                                  &ad[0], &ad[1], &ad[2], &ad[3],
     1315                                  &ad[4], &ad[5], &ad[6], &ad[7],
     1316                                  &ad[8], &ad[9], &ad[10], &ad[11],
     1317                                  &ad[12], &ad[13], &ad[14], &ad[15],
     1318                                  &plen, &po[0], &po[1]) != 21) {
     1319                                        error = 1;
     1320                                        goto psv_done;
     1321                                }
     1322                                if (af != 6 || alen != 16 || plen != 2) {
     1323                                        error = 2;
     1324                                        goto psv_done;
     1325                                }
     1326                                data_addr.su_sin6.sin6_addr.s6_addr32[0] =
     1327                                                        htonl(pack4(ad));
     1328                                data_addr.su_sin6.sin6_addr.s6_addr32[1] =
     1329                                                        htonl(pack4(ad+4));
     1330                                data_addr.su_sin6.sin6_addr.s6_addr32[2] =
     1331                                                        htonl(pack4(ad+8));
     1332                                data_addr.su_sin6.sin6_addr.s6_addr32[3] =
     1333                                                        htonl(pack4(ad+12));
     1334                                data_addr.su_port = htons(pack2(po));
     1335                                break;
     1336#endif
     1337                        default:
     1338                                error = 1;
     1339                        }
     1340                } else if (strncmp(pasvcmd, "EPSV", 4) == 0) {
     1341                        char delim[4];
     1342                        u_int epsvpo;
     1343
     1344                        if (code / 10 == 22 && code != 229) {
     1345                                error = 229;
     1346                                goto psv_done;
     1347                        }
     1348                        if (sscanf(pasv, "%c%c%c%u%c", &delim[0], &delim[1],
     1349                                        &delim[2], &epsvpo, &delim[3]) != 5) {
     1350                                error = 1;
     1351                                goto psv_done;
     1352                        }
     1353                        if (delim[0] != delim[1] || delim[0] != delim[2]
     1354                         || delim[0] != delim[3]) {
     1355                                error = 1;
     1356                                goto psv_done;
     1357                        }
     1358                        data_addr.su_port = htons(epsvpo);
     1359                } else {
     1360                        error = 1;
     1361                }
     1362psv_done:
     1363                switch (error) {
     1364                case 0:
     1365                        break;
     1366                case 1:
     1367                        fprintf(stderr,
     1368                  "Passive mode address scan failure. Shouldn't happen!\n");
     1369                        goto bad;
     1370                case 2:
     1371                        fprintf(stderr,
     1372                          "Passive mode AF mismatch. Shouldn't happen!\n");
     1373                        goto bad;
     1374                case 227:
     1375                case 228:
     1376                case 229:
     1377                        fprintf(stderr,
     1378                          "wrong server: return code must be %d\n", error);
     1379                        goto bad;
     1380                default:
     1381                        fprintf(stderr, "Bug\n");
    11221382                }
    11231383
    1124                 data_addr.sin_family = AF_INET;
    1125                 data_addr.sin_addr.s_addr = htonl((a1 << 24) | (a2 << 16) |
    1126                                                   (a3 << 8) | a4);
    1127                 data_addr.sin_port = htons((p1 << 8) | p2);
    1128 
    11291384                if (connect(data, (struct sockaddr *) &data_addr,
    1130                     sizeof(data_addr))<0) {
     1385                            (data_addr.su_family == AF_INET ?
     1386                             sizeof(data_addr.su_sin) :
     1387                             sizeof(data_addr.su_sin6)))<0) {
    11311388                        perror("ftp: connect");
    11321389                        return(1);
    11331390                }
    11341391#ifdef IP_TOS
     1392                if (data_addr.su_family == AF_INET)
     1393                {
    11351394                tos = IPTOS_THROUGHPUT;
    11361395                if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&tos,
    11371396                    sizeof(tos)) < 0)
    11381397                        perror("ftp: setsockopt TOS (ignored)");
     1398                }
    11391399#endif
    11401400                return(0);
    11411401        }
    11421402noport:
    11431403        data_addr = myctladdr;
    11441404        if (sendport)
    1145                 data_addr.sin_port = 0; /* let system pick one */
     1405                data_addr.su_port = 0;  /* let system pick one */
    11461406        if (data != -1)
    11471407                (void) close(data);
    1148         data = socket(AF_INET, SOCK_STREAM, 0);
     1408        data = socket(data_addr.su_family, SOCK_STREAM, 0);
    11491409        if (data < 0) {
    11501410                perror("ftp: socket");
    11511411                if (tmpno)
     
    11721432        if (listen(data, 1) < 0)
    11731433                perror("ftp: listen");
    11741434        if (sendport) {
    1175                 a = (char *)&data_addr.sin_addr;
    1176                 p = (char *)&data_addr.sin_port;
    1177 #define UC(b)   (((int)b)&0xff)
    1178                 result =
    1179                     command("PORT %d,%d,%d,%d,%d,%d",
    1180                       UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),
    1181                       UC(p[0]), UC(p[1]));
     1435                af = ex_af2prot(data_addr.su_family);
     1436                if (try_eprt && af > 1) {      /* only IPv6 */
     1437                        if (getnameinfo((struct sockaddr *)&data_addr, len,
     1438                                        hbuf, sizeof(hbuf), pbuf, sizeof(pbuf),
     1439                                        NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
     1440                                result = command("EPRT |%d|%s|%s|",
     1441                                                        af, hbuf, pbuf);
     1442                                if (result != COMPLETE) {
     1443                                        try_eprt = 0;
     1444                                }
     1445                        } else {
     1446                                result = ERROR;
     1447                        }
     1448                } else {
     1449                        result = COMPLETE + 1;
     1450                }
     1451                if (result == COMPLETE)
     1452                        goto prt_done;
     1453
     1454                p = (u_char *)&data_addr.su_port;
     1455                switch (data_addr.su_family) {
     1456                case AF_INET:
     1457                        a = (u_char *)&data_addr.su_sin.sin_addr;
     1458                        result = command("PORT %u,%u,%u,%u,%u,%u",
     1459                                a[0], a[1], a[2], a[3], p[0], p[1]);
     1460                        break;
     1461#ifdef INET6
     1462                case AF_INET6:
     1463                        a = (u_char *)&data_addr.su_sin6.sin6_addr;
     1464                        result = command(
     1465        "LPRT 6,16,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,2,%d,%d",
     1466                                a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
     1467                                a[8], a[9],a[10],a[11],a[12],a[13],a[14],a[15],
     1468                                p[0], p[1]);
     1469                        break;
     1470#endif
     1471                default:
     1472                        result = COMPLETE + 1; /* xxx */
     1473                }
     1474
     1475        prt_done:
    11821476                if (result == ERROR && sendport == -1) {
    11831477                        sendport = 0;
    11841478                        tmpno = 1;
     
    11891483        if (tmpno)
    11901484                sendport = 1;
    11911485#ifdef IP_TOS
     1486        if (data_addr.su_family == AF_INET)
     1487        {
    11921488        on = IPTOS_THROUGHPUT;
    11931489        if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
    11941490                perror("ftp: setsockopt TOS (ignored)");
     1491        }
    11951492#endif
    11961493        return (0);
    11971494bad:
     
    12041501static FILE *
    12051502dataconn(const char *lmode)
    12061503{
    1207         struct sockaddr_in from;
     1504        union sockunion from;
    12081505        int s, tos;
    12091506        socklen_t fromlen = sizeof(from);
    12101507
     
    12201517        (void) close(data);
    12211518        data = s;
    12221519#ifdef IP_TOS
     1520        if (from.su_family == AF_INET)
     1521        {
    12231522        tos = IPTOS_THROUGHPUT;
    12241523        if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
    12251524                perror("ftp: setsockopt TOS (ignored)");
     1525        }
    12261526#endif
    12271527        return (fdopen(data, lmode));
    12281528}
     
    12841584        static struct comvars {
    12851585                int connect;
    12861586                char name[MAXHOSTNAMELEN];
    1287                 struct sockaddr_in mctl;
    1288                 struct sockaddr_in hctl;
     1587                union sockunion mctl;
     1588                union sockunion hctl;
    12891589                FILE *in;
    12901590                FILE *out;
    12911591                int tpe;
     
    13231623        connected = op->connect;
    13241624        if (hostname) {
    13251625                (void) strncpy(ip->name, hostname, sizeof(ip->name) - 1);
    1326                 ip->name[strlen(ip->name)] = '\0';
     1626                ip->name[sizeof(ip->name) - 1] = '\0';
    13271627        }
    13281628        else {
    13291629                ip->name[0] = 0;
     
    13521652        ip->ntflg = ntflag;
    13531653        ntflag = op->ntflg;
    13541654        (void) strncpy(ip->nti, ntin, 16);
    1355         (ip->nti)[strlen(ip->nti)] = '\0';
     1655        (ip->nti)[16] = '\0';           /* shouldn't use strlen */
    13561656        (void) strcpy(ntin, op->nti);
    13571657        (void) strncpy(ip->nto, ntout, 16);
    1358         (ip->nto)[strlen(ip->nto)] = '\0';
     1658        (ip->nto)[16] = '\0';
    13591659        (void) strcpy(ntout, op->nto);
    13601660        ip->mapflg = mapflag;
    13611661        mapflag = op->mapflg;
    13621662        (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1);
    1363         (ip->mi)[strlen(ip->mi)] = '\0';
     1663        (ip->mi)[MAXPATHLEN - 1] = '\0';
    13641664        (void) strcpy(mapin, op->mi);
    13651665        (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1);
    1366         (ip->mo)[strlen(ip->mo)] = '\0';
     1666        (ip->mo)[MAXPATHLEN - 1] = '\0';
    13671667        (void) strcpy(mapout, op->mo);
    13681668        (void) signal(SIGINT, oldintr);
    13691669        if (abrtflag) {
  • ftp/ftp_var.h

    diff -uNr netkit-ftp-0.17/ftp/ftp_var.h netkit-ftp/ftp/ftp_var.h
    old new  
     1/* $USAGI$ */
     2
    13/*
    24 * Copyright (c) 1985, 1989 Regents of the University of California.
    35 * All rights reserved.
     
    3133 * SUCH DAMAGE.
    3234 *
    3335 *      from: @(#)ftp_var.h     5.9 (Berkeley) 6/1/90
    34  *      $Id: ftp_var.h,v 1.12 1999/10/02 18:39:17 dholland Exp $
     36 *      $Id: ftp_var.h,v 1.3 2001/01/12 21:36:27 sekiya Exp $
    3537 */
    3638
    3739/*
     
    112114Extern int      mflag;          /* flag: if != 0, then active multi command */
    113115
    114116Extern int      options;        /* used during socket creation */
     117Extern int      try_epsv;       /* try EPSV for this session */
     118Extern int      try_eprt;       /* try EPRT for this session */
    115119
    116120/*
    117121 * Format of command table.
     
    140144Extern char macbuf[4096];
    141145#define MACBUF_SIZE 4096
    142146
    143 char *hookup(char *host, int port);
     147char *hookup(const char *host, const char *port);
    144148struct cmd *getcmd(const char *);
    145149char **makeargv(int *pargc, char **parg);
    146150int dologin(const char *host);
Note: See TracBrowser for help on using the repository browser.