source:
npl/system/netkit-ftp/patches/03-netkit-ftp.usagi-ipv6.patch
@
b4abfab
Last change on this file since b4abfab was c5c522c, checked in by , 8 years ago | |
---|---|
|
|
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 1 28-Nov-2000: 2 IPv6 support. (Hiroyuki YAMAMORI <h-yamamo@db3.so-net.ne.jp>) 3 1 4 8-Jul-2000: 2 5 Fix misused printf-function call (not %n-exploitable though). 3 6 -
configure
diff -uNr netkit-ftp-0.17/configure netkit-ftp/configure
old new 24 24 --binmode=mode Mode for binaries [755] 25 25 --manmode=mode Mode for manual pages [644] 26 26 --with-c-compiler=cc Program for compiling C source [guessed] 27 --enable-ipv6 Enable IPv6 support 27 28 EOF 28 29 exit 0;; 29 30 --verbose) ;; … … 39 40 --manmode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;; 40 41 --with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;; 41 42 --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 42 48 *) echo "Unrecognized option: $1"; exit 1;; 43 49 esac 44 50 shift … … 142 148 143 149 LDFLAGS= 144 150 LIBS= 151 152 rm -f __conftest* 153 154 ################################################## 155 ## Enable IPv6 156 echo -n "Whether to enable IPv6 support... " 157 if [ x"$ENABLE_IPV6" = x"yes" ]; then 158 echo yes 159 CFLAGS="$CFLAGS -DINET6" 160 else 161 echo no 162 fi 163 164 rm -f __conftest* 165 166 ## Search IPv6 Library / Headers 167 if [ 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 186 fi 145 187 146 188 rm -f __conftest* 147 189 -
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// 16 D -
ftp/CVS/Repository
diff -uNr netkit-ftp-0.17/ftp/CVS/Repository netkit-ftp/ftp/CVS/Repository
old new 1 usagi/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 16 16 cmds.o glob.o: glob.h 17 17 18 18 install: ftp 19 install -d $(INSTALLROOT)$(BINDIR) 19 20 install -s -m$(BINMODE) ftp $(INSTALLROOT)$(BINDIR) 20 21 ln -sf ftp $(INSTALLROOT)$(BINDIR)/pftp 22 install -d $(INSTALLROOT)$(MANDIR)/man1 21 23 install -m$(MANMODE) ftp.1 $(INSTALLROOT)$(MANDIR)/man1 22 24 ln -sf ftp.1 $(INSTALLROOT)$(MANDIR)/man1/pftp.1 25 install -d $(INSTALLROOT)$(MANDIR)/man5 23 26 install -m$(MANMODE) netrc.5 $(INSTALLROOT)$(MANDIR)/man5 24 27 25 28 clean: -
ftp/cmds.c
diff -uNr netkit-ftp-0.17/ftp/cmds.c netkit-ftp/ftp/cmds.c
old new 1 /* $USAGI$ */ 2 1 3 /* 2 4 * Copyright (c) 1985, 1989 Regents of the University of California. 3 5 * All rights reserved. … … 35 37 * from: @(#)cmds.c 5.26 (Berkeley) 3/5/91 36 38 */ 37 39 char cmds_rcsid[] = 38 "$Id: cmds.c,v 1.3 3 2000/07/23 01:36:59 dhollandExp $";40 "$Id: cmds.c,v 1.3 2001/01/12 21:36:27 sekiya Exp $"; 39 41 40 42 /* 41 43 * FTP User Program -- Command Routines. … … 190 192 setpeer(int argc, char *argv[]) 191 193 { 192 194 char *host; 193 unsigned shortport;195 char *port; 194 196 195 197 if (connected) { 196 198 printf("Already connected to %s, use close first.\n", … … 205 207 code = -1; 206 208 return; 207 209 } 208 port = ftp_port;210 port = NULL; 209 211 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]; 218 213 } 219 214 host = hookup(argv[1], port); 220 215 if (host) { 221 216 int overbose; 222 217 223 218 connected = 1; 219 try_epsv = 1; 220 try_eprt = 1; 224 221 /* 225 222 * Set up defaults for FTP. 226 223 */ -
ftp/cmdtab.c
diff -uNr netkit-ftp-0.17/ftp/cmdtab.c netkit-ftp/ftp/cmdtab.c
old new 35 35 * from: @(#)cmdtab.c 5.10 (Berkeley) 6/1/90 36 36 */ 37 37 char cmdtab_rcsid[] = 38 "$Id: cmdtab.c,v 1. 8 1999/09/28 15:36:05 dhollandExp $";38 "$Id: cmdtab.c,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $"; 39 39 40 40 #include <string.h> /* for NULL */ 41 41 #include "ftp_var.h" -
ftp/domacro.c
diff -uNr netkit-ftp-0.17/ftp/domacro.c netkit-ftp/ftp/domacro.c
old new 35 35 * from: @(#)domacro.c 1.8 (Berkeley) 9/28/90 36 36 */ 37 37 char domacro_rcsid[] = 38 "$Id: domacro.c,v 1. 4 1996/08/14 23:27:28 dhollandExp $";38 "$Id: domacro.c,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $"; 39 39 40 40 #include <errno.h> 41 41 #include <ctype.h> -
ftp/ftp.1
diff -uNr netkit-ftp-0.17/ftp/ftp.1 netkit-ftp/ftp/ftp.1
old new 30 30 .\" SUCH DAMAGE. 31 31 .\" 32 32 .\" from: @(#)ftp.1 6.18 (Berkeley) 7/30/91 33 .\" $Id: ftp.1,v 1.1 4 2000/07/30 23:56:59 dhollandExp $33 .\" $Id: ftp.1,v 1.1.1.1 2000/11/03 19:18:15 mk Exp $ 34 34 .\" 35 35 .Dd August 15, 1999 36 36 .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 1 32 /* 2 33 * Copyright (c) 1985, 1989 Regents of the University of California. 3 34 * All rights reserved. … … 35 66 * From: @(#)ftp.c 5.38 (Berkeley) 4/22/91 36 67 */ 37 68 char ftp_rcsid[] = 38 "$Id: ftp.c,v 1. 25 1999/12/13 20:33:20 dhollandExp $";69 "$Id: ftp.c,v 1.11 2001/02/11 12:26:59 yoshfuji Exp $"; 39 70 40 71 #include <sys/param.h> 41 72 #include <sys/stat.h> … … 63 94 #include "ftp_var.h" 64 95 #include "cmds.h" 65 96 97 #ifdef _USAGI 98 #include "version.h" 99 #else 66 100 #include "../version.h" 101 #endif 102 103 union 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 67 122 68 123 int data = -1; 69 124 off_t restart_point = 0; 70 125 71 static struct sockaddr_in hisctladdr;72 static struct sockaddr_in data_addr;73 static struct sockaddr_in myctladdr;126 static union sockunion hisctladdr; 127 static union sockunion data_addr; 128 static union sockunion myctladdr; 74 129 static int ptflag = 0; 75 130 static sigjmp_buf recvabort; 76 131 static sigjmp_buf sendabort; … … 96 151 static FILE *dataconn(const char *); 97 152 98 153 char * 99 hookup(c har *host, intport)154 hookup(const char *host, const char *port) 100 155 { 101 register struct hostent *hp = 0; 102 int s, tos; 156 int s, tos, error; 103 157 socklen_t len; 104 158 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 } 106 169 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'; 119 180 } 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)); 132 183 code = -1; 133 184 return (0); 134 185 } 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(""); 155 237 } 238 cause = "ftp: connect"; 239 close(s); 240 s = -1; 156 241 continue; 157 242 } 158 perror("ftp: connect"); 243 /* finally we got one */ 244 break; 245 } 246 if (s < 0) { 247 perror(cause); 159 248 code = -1; 160 goto bad; 249 freeaddrinfo(res0); 250 return NULL; 161 251 } 162 len = sizeof (myctladdr); 252 len = res->ai_addrlen; 253 memcpy(&hisctladdr, res->ai_addr, len); 254 freeaddrinfo(res0); 163 255 if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) { 164 256 perror("ftp: getsockname"); 165 257 code = -1; 166 258 goto bad; 167 259 } 168 260 #ifdef IP_TOS 261 if (hisctladdr.su_family == AF_INET) 262 { 169 263 tos = IPTOS_LOWDELAY; 170 264 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0) 171 265 perror("ftp: setsockopt TOS (ignored)"); 266 } 172 267 #endif 173 268 cin = fdopen(s, "r"); 174 269 cout = fdopen(s, "w"); … … 182 277 goto bad; 183 278 } 184 279 if (verbose) 185 printf("Connected to %s .\n", hostname);280 printf("Connected to %s (%s).\n", hostname, hbuf); 186 281 if (getreply(0) > 2) { /* read startup message from server */ 187 282 if (cin) 188 283 (void) fclose(cin); … … 392 487 } 393 488 if (dig < 4 && isdigit(c)) 394 489 code = code * 10 + (c - '0'); 395 if (!pflag && code == 227)490 if (!pflag && (code == 227 || code == 228)) 396 491 pflag = 1; 492 else if (!pflag && code == 229) 493 pflag = 100; 397 494 if (dig > 4 && pflag == 1 && isdigit(c)) 398 495 pflag = 2; 399 496 if (pflag == 2) { … … 405 502 pflag = 3; 406 503 } 407 504 } 505 if (pflag == 100 && c == '(') 506 pflag = 2; 408 507 if (dig == 4 && c == '-') { 409 508 if (continuation) 410 509 code = 0; … … 1083 1182 static int 1084 1183 initconn(void) 1085 1184 { 1086 registerchar *p, *a;1185 u_char *p, *a; 1087 1186 int result, tmpno = 0; 1088 1187 socklen_t len; 1089 1188 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 1093 1201 if (passivemode) { 1094 data = socket(AF_INET, SOCK_STREAM, 0); 1202 data_addr = hisctladdr; 1203 data = socket(data_addr.su_family, SOCK_STREAM, 0); 1095 1204 if (data < 0) { 1096 1205 perror("ftp: socket"); 1097 1206 return(1); … … 1100 1209 setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, 1101 1210 sizeof (on)) < 0) 1102 1211 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) { 1104 1254 printf("Passive mode refused.\n"); 1105 return(1);1255 goto bad; 1106 1256 } 1107 1257 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 1108 1264 /* 1109 1265 * What we've got at this point is a string of comma separated 1110 1266 * one-byte unsigned integer values, separated by commas. 1111 * The first four are the an IP address. The fifth is the MSB1112 * of the port number, the sixth is the LSB. From that we'll1113 * prepare a sockaddr_in.1114 1267 */ 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 } 1362 psv_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"); 1122 1382 } 1123 1383 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 1129 1384 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) { 1131 1388 perror("ftp: connect"); 1132 1389 return(1); 1133 1390 } 1134 1391 #ifdef IP_TOS 1392 if (data_addr.su_family == AF_INET) 1393 { 1135 1394 tos = IPTOS_THROUGHPUT; 1136 1395 if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&tos, 1137 1396 sizeof(tos)) < 0) 1138 1397 perror("ftp: setsockopt TOS (ignored)"); 1398 } 1139 1399 #endif 1140 1400 return(0); 1141 1401 } 1142 1402 noport: 1143 1403 data_addr = myctladdr; 1144 1404 if (sendport) 1145 data_addr.s in_port = 0; /* let system pick one */1405 data_addr.su_port = 0; /* let system pick one */ 1146 1406 if (data != -1) 1147 1407 (void) close(data); 1148 data = socket( AF_INET, SOCK_STREAM, 0);1408 data = socket(data_addr.su_family, SOCK_STREAM, 0); 1149 1409 if (data < 0) { 1150 1410 perror("ftp: socket"); 1151 1411 if (tmpno) … … 1172 1432 if (listen(data, 1) < 0) 1173 1433 perror("ftp: listen"); 1174 1434 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: 1182 1476 if (result == ERROR && sendport == -1) { 1183 1477 sendport = 0; 1184 1478 tmpno = 1; … … 1189 1483 if (tmpno) 1190 1484 sendport = 1; 1191 1485 #ifdef IP_TOS 1486 if (data_addr.su_family == AF_INET) 1487 { 1192 1488 on = IPTOS_THROUGHPUT; 1193 1489 if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0) 1194 1490 perror("ftp: setsockopt TOS (ignored)"); 1491 } 1195 1492 #endif 1196 1493 return (0); 1197 1494 bad: … … 1204 1501 static FILE * 1205 1502 dataconn(const char *lmode) 1206 1503 { 1207 struct sockaddr_in from;1504 union sockunion from; 1208 1505 int s, tos; 1209 1506 socklen_t fromlen = sizeof(from); 1210 1507 … … 1220 1517 (void) close(data); 1221 1518 data = s; 1222 1519 #ifdef IP_TOS 1520 if (from.su_family == AF_INET) 1521 { 1223 1522 tos = IPTOS_THROUGHPUT; 1224 1523 if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0) 1225 1524 perror("ftp: setsockopt TOS (ignored)"); 1525 } 1226 1526 #endif 1227 1527 return (fdopen(data, lmode)); 1228 1528 } … … 1284 1584 static struct comvars { 1285 1585 int connect; 1286 1586 char name[MAXHOSTNAMELEN]; 1287 struct sockaddr_in mctl;1288 struct sockaddr_in hctl;1587 union sockunion mctl; 1588 union sockunion hctl; 1289 1589 FILE *in; 1290 1590 FILE *out; 1291 1591 int tpe; … … 1323 1623 connected = op->connect; 1324 1624 if (hostname) { 1325 1625 (void) strncpy(ip->name, hostname, sizeof(ip->name) - 1); 1326 ip->name[s trlen(ip->name)] = '\0';1626 ip->name[sizeof(ip->name) - 1] = '\0'; 1327 1627 } 1328 1628 else { 1329 1629 ip->name[0] = 0; … … 1352 1652 ip->ntflg = ntflag; 1353 1653 ntflag = op->ntflg; 1354 1654 (void) strncpy(ip->nti, ntin, 16); 1355 (ip->nti)[ strlen(ip->nti)] = '\0';1655 (ip->nti)[16] = '\0'; /* shouldn't use strlen */ 1356 1656 (void) strcpy(ntin, op->nti); 1357 1657 (void) strncpy(ip->nto, ntout, 16); 1358 (ip->nto)[ strlen(ip->nto)] = '\0';1658 (ip->nto)[16] = '\0'; 1359 1659 (void) strcpy(ntout, op->nto); 1360 1660 ip->mapflg = mapflag; 1361 1661 mapflag = op->mapflg; 1362 1662 (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1); 1363 (ip->mi)[ strlen(ip->mi)] = '\0';1663 (ip->mi)[MAXPATHLEN - 1] = '\0'; 1364 1664 (void) strcpy(mapin, op->mi); 1365 1665 (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1); 1366 (ip->mo)[ strlen(ip->mo)] = '\0';1666 (ip->mo)[MAXPATHLEN - 1] = '\0'; 1367 1667 (void) strcpy(mapout, op->mo); 1368 1668 (void) signal(SIGINT, oldintr); 1369 1669 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 1 3 /* 2 4 * Copyright (c) 1985, 1989 Regents of the University of California. 3 5 * All rights reserved. … … 31 33 * SUCH DAMAGE. 32 34 * 33 35 * from: @(#)ftp_var.h 5.9 (Berkeley) 6/1/90 34 * $Id: ftp_var.h,v 1. 12 1999/10/02 18:39:17 dhollandExp $36 * $Id: ftp_var.h,v 1.3 2001/01/12 21:36:27 sekiya Exp $ 35 37 */ 36 38 37 39 /* … … 112 114 Extern int mflag; /* flag: if != 0, then active multi command */ 113 115 114 116 Extern int options; /* used during socket creation */ 117 Extern int try_epsv; /* try EPSV for this session */ 118 Extern int try_eprt; /* try EPRT for this session */ 115 119 116 120 /* 117 121 * Format of command table. … … 140 144 Extern char macbuf[4096]; 141 145 #define MACBUF_SIZE 4096 142 146 143 char *hookup(c har *host, intport);147 char *hookup(const char *host, const char *port); 144 148 struct cmd *getcmd(const char *); 145 149 char **makeargv(int *pargc, char **parg); 146 150 int dologin(const char *host);
Note: See TracBrowser
for help on using the repository browser.