diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-04 19:08:34 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-04 19:08:34 +0100 |
| commit | 05b84d4e92b79fa47259907a78d8375bb5490135 (patch) | |
| tree | b49cb8b43943d02370bbf260a239acbfecbd761b | |
| parent | daa643205f76da5cb3e899aba2a047fc2c6f1994 (diff) | |
| download | busybox-w32-05b84d4e92b79fa47259907a78d8375bb5490135.tar.gz busybox-w32-05b84d4e92b79fa47259907a78d8375bb5490135.tar.bz2 busybox-w32-05b84d4e92b79fa47259907a78d8375bb5490135.zip | |
ftpgetput: add EPSV support (PASV-like thing for IPv6)
Based on a patch by Kev Kitchens.
function old new delta
xconnect_ftpdata 149 223 +74
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/ftpgetput.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 3f98e07f3..697955e82 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
| @@ -156,7 +156,7 @@ static int xconnect_ftpdata(void) | |||
| 156 | unsigned port_num; | 156 | unsigned port_num; |
| 157 | 157 | ||
| 158 | /* | 158 | /* |
| 159 | TODO: PASV command will not work for IPv6. RFC2428 describes | 159 | PASV command will not work for IPv6. RFC2428 describes |
| 160 | IPv6-capable "extended PASV" - EPSV. | 160 | IPv6-capable "extended PASV" - EPSV. |
| 161 | 161 | ||
| 162 | "EPSV [protocol]" asks server to bind to and listen on a data port | 162 | "EPSV [protocol]" asks server to bind to and listen on a data port |
| @@ -171,15 +171,16 @@ but we don't need that. | |||
| 171 | NB: PASV may still work for some servers even over IPv6. | 171 | NB: PASV may still work for some servers even over IPv6. |
| 172 | For example, vsftp happily answers | 172 | For example, vsftp happily answers |
| 173 | "227 Entering Passive Mode (0,0,0,0,n,n)" and proceeds as usual. | 173 | "227 Entering Passive Mode (0,0,0,0,n,n)" and proceeds as usual. |
| 174 | |||
| 175 | TODO2: need to stop ignoring IP address in PASV response. | ||
| 176 | */ | 174 | */ |
| 177 | //if (ftpcmd("EPSV", NULL) != 229) { | 175 | if (!ENABLE_FEATURE_IPV6 |
| 176 | || ftpcmd("EPSV", NULL) != 229 | ||
| 177 | ) { | ||
| 178 | /* maybe also go straight to PAST if lsa->u.sa.sa_family == AF_INET? */ | ||
| 178 | if (ftpcmd("PASV", NULL) != 227) { | 179 | if (ftpcmd("PASV", NULL) != 227) { |
| 179 | ftp_die("PASV"); | 180 | ftp_die("PASV"); |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 182 | /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage] | 183 | /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]" |
| 183 | * Server's IP is N1.N2.N3.N4 (we ignore it) | 184 | * Server's IP is N1.N2.N3.N4 (we ignore it) |
| 184 | * Server's port for data connection is P1*256+P2 */ | 185 | * Server's port for data connection is P1*256+P2 */ |
| 185 | buf_ptr = strrchr(buf, ')'); | 186 | buf_ptr = strrchr(buf, ')'); |
| @@ -192,7 +193,16 @@ TODO2: need to stop ignoring IP address in PASV response. | |||
| 192 | buf_ptr = strrchr(buf, ','); | 193 | buf_ptr = strrchr(buf, ','); |
| 193 | *buf_ptr = '\0'; | 194 | *buf_ptr = '\0'; |
| 194 | port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; | 195 | port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; |
| 195 | //} | 196 | } else { |
| 197 | /* Response is "NNN garbage(|||P1|)" | ||
| 198 | * Server's port for data connection is P1 */ | ||
| 199 | buf_ptr = strrchr(buf, '|'); | ||
| 200 | if (buf_ptr) *buf_ptr = '\0'; | ||
| 201 | |||
| 202 | buf_ptr = strrchr(buf, '|'); | ||
| 203 | *buf_ptr = '\0'; | ||
| 204 | port_num = xatoul_range(buf_ptr + 1, 0, 65535); | ||
| 205 | } | ||
| 196 | 206 | ||
| 197 | set_nport(&lsa->u.sa, htons(port_num)); | 207 | set_nport(&lsa->u.sa, htons(port_num)); |
| 198 | return xconnect_stream(lsa); | 208 | return xconnect_stream(lsa); |
