summaryrefslogtreecommitdiff
path: root/www/wwwoffle/patches.v6/patch-bh
blob: 7556d4b41aee830b935b1133a8c5a55379d1dcc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
$NetBSD: patch-bh,v 1.1 1999/11/26 06:09:01 itohy Exp $

--- ftp.c.orig	Sat Sep 11 23:00:02 1999
+++ ftp.c	Thu Nov 25 20:00:36 1999
@@ -473,52 +473,87 @@
 
  /* Create the data connection. */
 
- if(write_string(server_ctrl,"PASV\r\n")==-1)
-   {
-    msg=PrintMessage(Warning,"Failed to write 'PASV' command to remote FTP host [%!s].");
-    return(msg);
-   }
+ if(write_string(server_ctrl,"EPSV\r\n")==-1) {
+     msg=PrintMessage(Warning,"Failed to write 'EPSV' command to remote FTP host [%!s].");
+     return(msg);
+ }
 
  do
-   {
-    str=read_line_or_timeout(server_ctrl,str,SocketTimeout);
-    PrintMessage(ExtraDebug,"FTP: sent 'PASV'; got: %s",str);
-   }
+ {
+     str=read_line_or_timeout(server_ctrl,str,SocketTimeout);
+#if DEBUG_FTP
+     PrintMessage(Debug,"FTP: sent 'EPSV'; got: %s",str);
+#endif
+ }
  while(str && (!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2]) || str[3]!=' '));
 
- if(!str || atoi(str)!=227)
-   {
-    if(str)
-      {
-       char *p=str+strlen(str)-1;
-       while(*p=='\n' || *p=='\r') *p--=0;
-       msg=PrintMessage(Warning,"Got '%s' message after sending 'PASV' command",str);
-      }
-    else
-       msg=PrintMessage(Warning,"No reply from FTP server to 'PASV' command; timed out?");
-    return(msg);
-   }
+ if(!str) {
+     msg=PrintMessage(Warning,"No reply from FTP server to 'EPSV' command; timed out?");
+     return(msg);
+ }
+
+ if(atoi(str) == 229) {
+     host=strchr(str,'(') + 1;
+     if(sscanf(host,"%*c%*c%*c%d%*c",&port_h) != 1) {
+         char *p=str+strlen(str)-1;
+         while(*p=='\n' || *p=='\r') *p--=0;
+         msg=PrintMessage(Warning,"Got '%s' message after sending 'EPSV' command, cannot parse %d.",str, port_h);
+         return(msg);
+     }
+     if (SocketRemoteName(server_ctrl, &host, NULL, NULL)) {
+         msg=PrintMessage(Warning,"Cannot determine server address.");
+         return(msg);
+     }
+ } else if (atoi(str) != 500) {
+     char *p=str+strlen(str)-1;
+
+     while(*p=='\n' || *p=='\r') *p--=0;
+     msg=PrintMessage(Warning,"Got '%s' message after sending 'EPSV' command",str);
+     return(msg);
+ } else { /* Let's try PASV instead then */
+     if(write_string(server_ctrl,"PASV\r\n")==-1) {
+         msg=PrintMessage(Warning,"Failed to write 'PASV' command to remote FTP host [%!s].");
+         return(msg);
+     }  
+ 
+     do
+     {
+         str=read_line_or_timeout(server_ctrl,str,SocketTimeout);
+#if DEBUG_FTP
+         PrintMessage(Debug,"FTP: sent 'PASV'; got: %s",str);
+#endif
+     }
+     while(str && (!isdigit(str[0]) || !isdigit(str[1]) || !isdigit(str[2]) || str[3]!=' '));
+ 
+     if(!str) {
+         msg=PrintMessage(Warning,"No reply from FTP server to 'PASV' command; timed out?");
+         return(msg);
+     }  
+ 
+     if(atoi(str) == 227) {
+ 
+         if((host=strchr(str,',')))
+         {
+             while(isdigit(*--host));
+             host++;
+         }
+   
+         if(!host || sscanf(host,"%*d,%*d,%*d,%*d%n,%d,%d",&l,&port_h,&port_l)!=2)
+         {
+             char *p=str+strlen(str)-1;
+             while(*p=='\n' || *p=='\r') *p--=0;
+             msg=PrintMessage(Warning,"Got '%s' message after sending 'PASV' command, cannot parse.",str);
+             return(msg);
+         }
+         port_h = port_l+256*port_h;
+         host[l]=0;
+         for(;l>0;l--)
+             if(host[l]==',')
+                 host[l]='.';
+     }     
+ }
 
- if((host=strchr(str,',')))
-   {
-    while(isdigit(*--host));
-    host++;
-   }
-
- if(!host || sscanf(host,"%*d,%*d,%*d,%*d%n,%d,%d",&l,&port_h,&port_l)!=2)
-   {
-    char *p=str+strlen(str)-1;
-    while(*p=='\n' || *p=='\r') *p--=0;
-    msg=PrintMessage(Warning,"Got '%s' message after sending 'PASV' command, cannot parse.",str);
-    return(msg);
-   }
-
- host[l]=0;
- for(;l>0;l--)
-    if(host[l]==',')
-       host[l]='.';
-
- server_data=OpenClientSocket(host,port_l+256*port_h,ConnectTimeout);
+ server_data=OpenClientSocket(host, port_h,ConnectTimeout);
  init_buffer(server_data);
 
  if(server_data==-1)