Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Feb 2003 15:32:46 GMT
From:      Jeremy Prior <jez@chagford.netcraft.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/48784: No way to disable directory listings in ftpd
Message-ID:  <200302281532.h1SFWj8A005539@chagford.netcraft.com>

next in thread | raw e-mail | index | archive | help

>Number:         48784
>Category:       bin
>Synopsis:       No way to disable directory listings in ftpd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 28 07:40:07 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jeremy Prior
>Release:        FreeBSD 4.7-STABLE i386
>Organization:
Netcraft Ltd
>Environment:
System: FreeBSD chagford.netcraft.com 4.7-STABLE FreeBSD 4.7-STABLE #1: Fri Jan 17 21:34:17 GMT 2003 root@chagford.netcraft.com:/usr/obj/usr/src/sys/CHAGFORD i386


	
>Description:
	We need to run a customer-facing ftpd that doesn't allow
	directory listings.  The base system's one can be made to
	prevent this if the right bits are lopped-out. :-)

>How-To-Repeat:
	Connect to ftpd and type `dir'

>Fix:

	Patch follows:

--- ftpd.diff begins here ---
Index: Makefile
===================================================================
RCS file: /usr/cvs/src/libexec/ftpd/Makefile,v
retrieving revision 1.33.2.6
diff -u -r1.33.2.6 Makefile
--- Makefile	11 Feb 2003 14:28:28 -0000	1.33.2.6
+++ Makefile	28 Feb 2003 13:51:32 -0000
@@ -12,10 +12,14 @@
 LDADD=	-lskey -lmd -lcrypt -lutil
 DPADD=	${LIBSKEY} ${LIBMD} ${LIBCRYPT} ${LIBUTIL}
 
+.if defined(NO_LISTINGS)
+CFLAGS+=-DNO_LISTINGS
+.else
 LSDIR=	../../bin/ls
 .PATH:	${.CURDIR}/${LSDIR}
 SRCS+=	ls.c cmp.c print.c util.c
 CFLAGS+=-Dmain=ls_main -I${.CURDIR}/${LSDIR}
+.endif
 
 DPADD+=	${LIBM}
 LDADD+=	-lm
Index: ftpcmd.y
===================================================================
RCS file: /usr/cvs/src/libexec/ftpd/ftpcmd.y,v
retrieving revision 1.16.2.19
diff -u -r1.16.2.19 ftpcmd.y
--- ftpcmd.y	11 Feb 2003 14:28:28 -0000	1.16.2.19
+++ ftpcmd.y	28 Feb 2003 14:01:34 -0000
@@ -475,25 +475,33 @@
 		}
 	| NLST check_login CRLF
 		{
+#ifndef NO_LISTINGS
 			if ($2)
 				send_file_list(".");
+#endif
 		}
 	| NLST check_login SP pathstring CRLF
 		{
+#ifndef NO_LISTINGS
 			if ($2)
 				send_file_list($4);
 			free($4);
+#endif
 		}
 	| LIST check_login CRLF
 		{
+#ifndef NO_LISTINGS
 			if ($2)
 				retrieve(_PATH_LS " -lgA", "");
+#endif
 		}
 	| LIST check_login SP pathstring CRLF
 		{
+#ifndef NO_LISTINGS
 			if ($2)
 				retrieve(_PATH_LS " -lgA %s", $4);
 			free($4);
+#endif
 		}
 	| STAT check_login SP pathname CRLF
 		{
@@ -1127,8 +1135,10 @@
 	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
 	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name ]" },
 	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
+#ifndef NO_LISTINGS
 	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
 	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
+#endif
 	{ "SITE", SITE, SITECMD, 1,	"site-cmd [ <sp> arguments ]" },
 	{ "SYST", SYST, ARGS, 1,	"(get type of operating system)" },
 	{ "STAT", STAT, OSTR, 1,	"[ <sp> path-name ]" },
Index: ftpd.c
===================================================================
RCS file: /usr/cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.62.2.48
diff -u -r1.62.2.48 ftpd.c
--- ftpd.c	14 Feb 2003 12:42:42 -0000	1.62.2.48
+++ ftpd.c	28 Feb 2003 13:51:34 -0000
@@ -2970,6 +2970,7 @@
 send_file_list(whichf)
 	char *whichf;
 {
+#ifndef NO_LISTINGS
 	struct stat st;
 	DIR *dirp = NULL;
 	struct dirent *dir;
@@ -3100,6 +3101,7 @@
 		freeglob = 0;
 		globfree(&gl);
 	}
+#endif
 }
 
 void
Index: popen.c
===================================================================
RCS file: /usr/cvs/src/libexec/ftpd/popen.c,v
retrieving revision 1.18.2.3
diff -u -r1.18.2.3 popen.c
--- popen.c	9 Aug 2001 00:53:18 -0000	1.18.2.3
+++ popen.c	11 Aug 2001 08:09:21 -0000
@@ -143,6 +143,7 @@
 			}
 			(void)close(pdes[1]);
 		}
+#ifndef NO_LISTINGS
 		if (strcmp(gargv[0], _PATH_LS) == 0) {
 			/* Reset getopt for ls_main() */
 			optreset = optind = optopt = 1;
@@ -157,6 +158,7 @@
 			}
 			exit(ls_main(gargc, gargv));
 		}
+#endif
 		execv(gargv[0], gargv);
 		_exit(1);
 	}
--- ftpd.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200302281532.h1SFWj8A005539>