Subject: Patch for passive mode data port range.

From: Masachika ISHIZUKA <[email-masked]>
Date: Sun, 24 May 1998 17:30:11 +0900

Hi.

  I'm using wu-ftpd 2.4.2.beta-16.
  This version of the server would use data ports in range
1024..4999(?) when a passive mode client requested a data
connection to the server.

  This patch is that the server will use data ports in range
49152..65535 in FreeBSD. If you want to use old range, specify
-U option.

================================================================
--- ftpd.c.orig	Mon Dec 22 08:25:06 1997
+++ ftpd.c	Sun May 24 17:07:40 1998
@@ -245,6 +245,7 @@
 #include <prot.h>
 #endif
 
+int restricted_data_ports = 1;
 int anonymous = 1;
 int guest;
 int type;
@@ -452,7 +453,7 @@
         envp++;
     LastArgv = envp[-1] + strlen(envp[-1]);
 
-    while ((c = getopt(argc, argv, ":aAvdlLiot:T:u:")) != -1) {
+    while ((c = getopt(argc, argv, ":aAvdlLioUt:T:u:")) != -1) {
         switch (c) {
 
         case 'a':
@@ -499,6 +500,10 @@
                 timeout = maxtimeout;
             break;
 
+	case 'U':
+	    restricted_data_ports = 0;
+	    break;
+
         case 'u':
             {
                 unsigned int val = 0;
@@ -3375,6 +3380,16 @@
         perror_reply(425, "Can't open passive connection");
         return;
     }
+#ifdef IP_PORTRANGE
+    {
+      int on = restricted_data_ports ? IP_PORTRANGE_HIGH
+	: IP_PORTRANGE_DEFAULT;
+      
+      if (setsockopt(pdata, IPPROTO_IP, IP_PORTRANGE,
+		     (char *)&on, sizeof(on)) < 0)
+	goto pasv_error;
+    }
+#endif
     pasv_addr = ctrl_addr;
     pasv_addr.sin_port = 0;
     delay_signaling(); /* we can't allow any signals while euid==0: kinch */