1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-13 07:34:50 +00:00

mod_ftp is a FTP Protocol module to serve httpd content over the

FTP protocol (whereever the HTTP protocol could also be used). It
provides both RETR/REST retrieval and STOR/APPE upload, using the
same user/permissions model as httpd (so it shares the same security
considerations as mod_dav plus mod_dav_fs).

WWW: http://httpd.apache.org/mod_ftp/

Feature safe:	yes
This commit is contained in:
Mikhail Teterin 2012-03-13 17:02:32 +00:00
parent 217f13c9a1
commit 31440623dd
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=293252
12 changed files with 405 additions and 0 deletions

View File

@ -471,6 +471,7 @@
SUBDIR += mod_fcgid
SUBDIR += mod_fileiri
SUBDIR += mod_flickr
SUBDIR += mod_ftp
SUBDIR += mod_geoip2
SUBDIR += mod_gnutls
SUBDIR += mod_gzip2

0
www/mod_ftp/.deps Normal file
View File

32
www/mod_ftp/Makefile Normal file
View File

@ -0,0 +1,32 @@
# New ports collection makefile for: mod_ftp
# Date created: June 21, 2011 Oct 5
# Whom: Mikhail Teterin <mi@aldan.algebra.com>
#
# $FreeBSD$
#
PORTNAME= mod_ftp
DISTVERSION= 0.9.6-beta
CATEGORIES= www ftp
MASTER_SITES= ${MASTER_SITE_APACHE}
MASTER_SITE_SUBDIR=httpd/mod_ftp
MAINTAINER= mi@aldan.algebra.com
COMMENT= Serve web-server's content via FTP
MAKE_JOBS_SAFE= yes
USE_BZIP2= yes
WRKSRC= ${WRKDIR}/${PORTNAME}-${PORTVERSION:R}
USE_APACHE= 20+
HAS_CONFIGURE= yes
CONFIGURE_SCRIPT=configure.apxs
CONFIGURE_ENV+= APXS="${APXS}"
post-install:
@${CAT} ${PKGMESSAGE}
${TEST} -e ${PREFIX}/${APACHEETCDIR}/extra/ftpd.conf || \
${CP} -p ${PREFIX}/${APACHEETCDIR}/extra/ftpd.conf.dist \
${PREFIX}/${APACHEETCDIR}/extra/ftpd.conf
.include <bsd.port.mk>

2
www/mod_ftp/distinfo Normal file
View File

@ -0,0 +1,2 @@
SHA256 (mod_ftp-0.9.6-beta.tar.bz2) = 4c1946f786d3bdd56d34b0b9303bd2b4d526c4c8c976d492bc8f41cfbfa90e1d
SIZE (mod_ftp-0.9.6-beta.tar.bz2) = 95732

View File

@ -0,0 +1,40 @@
--- Makefile.apxs 2009-09-28 13:09:53.000000000 -0400
+++ Makefile.apxs 2011-06-21 15:48:39.000000000 -0400
@@ -21,5 +21,5 @@
TARGETS =
-INSTALL_TARGETS = install-conf install-ftpdocs install-manual install-include
+INSTALL_TARGETS = install-conf install-include
DISTCLEAN_TARGETS = config.apxs.log modules/ftp/ftp_config.h
EXTRACLEAN_TARGETS =
@@ -41,6 +41,5 @@
install-conf:
@echo Installing configuration files
- @$(MKINSTALLDIRS) $(exp_sysconfdir) $(exp_sysconfdir)/extra \
- $(exp_sysconfdir)/original $(exp_sysconfdir)/original/extra
+ @$(MKINSTALLDIRS) $(exp_sysconfdir) $(exp_sysconfdir)/extra
@cd $(ftp_srcdir)/docs/conf; \
for j in $(ftp_srcdir)/docs/conf; do \
@@ -55,20 +54,9 @@
-e 's#@rel_logfiledir@#$(rel_logfiledir)#;' \
-e 's#@@FTPPort@@#$(FTPPORT)#;' \
- < $$i > $(exp_sysconfdir)/original/$$i; \
- chmod 0644 $(exp_sysconfdir)/original/$$i; \
- if test ! -f $(exp_sysconfdir)/$$i; then \
- cp $(exp_sysconfdir)/original/$$i \
- $(exp_sysconfdir)/$$i; \
- chmod 0644 $(exp_sysconfdir)/$$i; \
- fi; \
+ < $$i > $(exp_sysconfdir)/$$i.dist; \
+ chmod 0644 $(exp_sysconfdir)/$$i.dist; \
fi; \
done ; \
done
- @awk -f $(ftp_srcdir)/build/addloadexample.awk \
- -v MODULE=ftp -v DSO=.so -v LIBPATH=$(rel_libexecdir) \
- -v EXAMPLECONF=$(rel_sysconfdir)/extra/ftpd.conf \
- $(DESTDIR)$(httpd_conffile) > $(DESTDIR)$(httpd_conffile).new && \
- ( mv $(DESTDIR)$(httpd_conffile) $(DESTDIR)$(httpd_conffile).bak && \
- mv $(DESTDIR)$(httpd_conffile).new $(DESTDIR)$(httpd_conffile) );
svnroot=http://svn.apache.org/repos/asf/httpd

View File

@ -0,0 +1,21 @@
Patch provided by William A. Rowe Jr. (the mod_ftp author) to fix a
rare crash after serving a file:
--- modules/ftp/ftp_commands.c 2009-09-21 15:09:19.000000000 -0400
+++ modules/ftp/ftp_commands.c 2011-11-30 16:21:38.000000000 -0500
@@ -2171,6 +2171,7 @@
}
clean_up:
+ ap_lingering_close(cdata);
ap_destroy_sub_req(rr);
/* Replace the filters and connection */
@@ -2181,7 +2182,6 @@
r->connection = c;
/* Close the data connection, send confirmation, and return */
- ap_lingering_close(cdata);
fc->datasock = NULL;
fc->filter_mask = 0;

View File

@ -0,0 +1,238 @@
Support real ls-like sorting options. See:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51409
--- modules/ftp/ftp_commands.c 2009-09-21 15:09:19.000000000 -0400
+++ modules/ftp/ftp_commands.c 2011-06-22 03:00:31.000000000 -0400
@@ -24,6 +24,8 @@
#include "mod_ftp.h"
#include "ftp_internal.h"
-#include "apr_version.h"
-#include "apr_network_io.h"
+#include <apr_version.h>
+#include <apr_getopt.h>
+#include <apr_network_io.h>
+#include <apr_strings.h>
#include "http_vhost.h"
@@ -665,22 +667,66 @@ static int common_list(request_rec *r, c
apr_status_t rv;
apr_size_t nbytes;
- char *varg = apr_pstrdup(r->pool, arg);
const char *test, *sl;
int res;
int decend = 0;
+ apr_getopt_t *options;
+ char **argv, option;
+ const char *optval;
+ char * const *p;
+ int argc;
+ /* Sort by name ascending by default */
+ int reverse = 0;
+ enum ftp_sort sortby = SORT_BY_NAME; /* Why not SORT_NONE? */
+
+ /* TODO: improve error reporting with detailed status explanation */
+ if ((res = apr_tokenize_to_argv(arg, &argv, r->pool))) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
+ "Attempt to tokenize string `%s' failed", arg);
+ return res;
+ }
+ for (p = argv, argc = 0; *p; p++)
+ argc++;
- while (*varg == '-')
- {
- if (ftp_parse2(r->pool, varg, &word, &varg, FTP_KEEP_WHITESPACE)) {
- varg = word;
- break;
- }
- /* More Cowbell! TODO: expand the accepted dash patterns */
- if (ap_strchr(word, 'l')) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Split `%s' into %d word%s",
+ arg, argc, argc == 1 ? "" : "s");
+
+ /*
+ * apr_getopt ignores argv[0] thinking, it is the program's name,
+ * but we want it to start with it, so we shift argv and argc by one:
+ */
+ if ((res = apr_getopt_init(&options, r->pool, argc + 1, (const char **)argv - 1))) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
+ "apr_getopt_init failed");
+ return res;
+ }
+
+ /* Disable apr_getopt's own error-reporting: */
+ options->errfn = NULL;
+
+ while (apr_getopt(options, "Slrtcu", &option, &optval) != APR_EOF) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking option `%c'", option);
+ switch(option) {
+ case 'l':
dashl = 1;
- }
- /* -- 'end of dash-opts' by convention allows patterns like '-*' */
- if (ap_strchr(word + 1, '-')) {
- break;
+ continue;
+ case 'r':
+ reverse = 1;
+ continue;
+ case 't':
+ sortby = SORT_BY_MTIME;
+ continue;
+ case 'c':
+ sortby = SORT_BY_CTIME;
+ continue;
+ case 'u':
+ sortby = SORT_BY_ATIME;
+ continue;
+ case 'S':
+ sortby = SORT_BY_SIZE;
+ continue;
+ default:
+ /* TODO: communicate this back to the client too */
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "Ignoring unrecognized listing option `%c'", option);
}
}
@@ -696,5 +748,9 @@ static int common_list(request_rec *r, c
}
- arg = varg;
+ arg = argv[options->ind - 1] ? argv[options->ind - 1] : "";
+
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s-listing `%s', "
+ "sorting by %d (%sscending)", is_list ? "Long" : "Short",
+ arg ? arg : "nill!", (int)sortby, reverse ? "de" : "a");
if (is_list && (ap_strchr_c(arg, '*') != NULL))
@@ -768,5 +824,5 @@ static int common_list(request_rec *r, c
/* Construct the sorted array of directory contents */
- if ((direntry = ftp_direntry_get(r, pattern)) == NULL) {
+ if ((direntry = ftp_direntry_get(r, pattern, sortby, reverse)) == NULL) {
fc->response_notes = apr_psprintf(r->pool, FTP_MSG_NOSUCHFILE,
ftp_escape_control_text(arg, r->pool));
--- modules/ftp/ftp_internal.h 2009-09-17 14:06:43.000000000 -0400
+++ modules/ftp/ftp_internal.h 2011-06-22 02:59:53.000000000 -0400
@@ -160,4 +160,13 @@ typedef enum {
} ftp_loginlimit_t;
+enum ftp_sort {
+ SORT_BY_NAME,
+ SORT_BY_MTIME,
+ SORT_BY_ATIME,
+ SORT_BY_CTIME,
+ SORT_BY_SIZE,
+ SORT_NONE
+};
+
/* Directory entry structure. Used for directory listings */
typedef struct ftp_direntry
@@ -170,4 +179,5 @@ typedef struct ftp_direntry
apr_off_t size;
apr_off_t csize;
+ apr_time_t atime, mtime, ctime;
apr_int32_t nlink;
struct ftp_direntry *child; /* For descending */
@@ -254,5 +264,6 @@ int ftp_limitlogin_loggedout(conn_rec *c
int ftp_eprt_decode(apr_int32_t *family, char **addr, apr_port_t *port,
char *arg);
-struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern);
+struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern,
+ enum ftp_sort sortby, int reverse);
void ftp_set_authorization(request_rec *r);
--- modules/ftp/ftp_util.c 2009-09-17 17:36:36.000000000 -0400
+++ modules/ftp/ftp_util.c 2011-06-22 03:05:05.000000000 -0400
@@ -210,4 +210,7 @@ static struct ftp_direntry *ftp_direntry
dirent->size = rr->finfo.size;
dirent->csize = rr->finfo.csize;
+ dirent->ctime = rr->finfo.ctime;
+ dirent->atime = rr->finfo.atime;
+ dirent->mtime = rr->finfo.mtime;
dirent->modestring = apr_pstrdup(r->pool,
ftp_modestring_get(
@@ -267,6 +270,6 @@ static struct ftp_direntry *ftp_direntry
* be greater than d2.
*/
-static int ftp_dsortf(struct ftp_direntry ** d1,
- struct ftp_direntry ** d2)
+static int ftp_dsortf(const struct ftp_direntry ** d1,
+ const struct ftp_direntry ** d2)
{
/* Simple sort based on filename */
@@ -274,4 +277,32 @@ static int ftp_dsortf(struct ftp_direntr
}
+static int ftp_dsortf_desc(const struct ftp_direntry ** d1,
+ const struct ftp_direntry ** d2)
+{
+ /* Simple sort based on filename, descending */
+ return strcmp((*d2)->name, (*d1)->name);
+}
+
+#define FTP_DSORT_NUM(field) \
+static int ftp_dsort_##field(const struct ftp_direntry ** d1, \
+ const struct ftp_direntry ** d2) \
+{ \
+ if ((*d1)->field == (*d2)->field) \
+ return 0; \
+ return (*d1)->field < (*d2)->field ? 1 : -1; \
+} \
+static int ftp_dsort_desc_##field(const struct ftp_direntry ** d1, \
+ const struct ftp_direntry ** d2) \
+{ \
+ if ((*d1)->field == (*d2)->field) \
+ return 0; \
+ return (*d1)->field > (*d2)->field ? 1 : -1; \
+}
+
+FTP_DSORT_NUM(mtime)
+FTP_DSORT_NUM(ctime)
+FTP_DSORT_NUM(atime)
+FTP_DSORT_NUM(size)
+
/* ftp_direntry_get: Return an array of ftp_direntry structures based
* on the uri stored in the request rec. An extra
@@ -283,5 +310,6 @@ static int ftp_dsortf(struct ftp_direntr
* Returns: The sorted array of directory entries on success, NULL otherwise
*/
-struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern)
+struct ftp_direntry *ftp_direntry_get(request_rec *r, const char *pattern,
+ enum ftp_sort sortby, int reverse)
{
struct ftp_direntry *p, *head, *current, **a;
@@ -293,4 +321,14 @@ struct ftp_direntry *ftp_direntry_get(re
const char *path, *search;
+ int (*compar[])(const struct ftp_direntry **,
+ const struct ftp_direntry **) = {
+ /* The order here must match the enum ftp_sort! */
+ ftp_dsortf, ftp_dsortf_desc,
+ ftp_dsort_mtime, ftp_dsort_desc_mtime,
+ ftp_dsort_atime, ftp_dsort_desc_atime,
+ ftp_dsort_ctime, ftp_dsort_desc_ctime,
+ ftp_dsort_size, ftp_dsort_desc_size
+ };
+
/*
* The actual search pattern, used to determine if we should recurse into
@@ -374,5 +412,5 @@ struct ftp_direntry *ftp_direntry_get(re
const char *newpattern = apr_pstrcat(r->pool, fname,
"/*", NULL);
- p->child = ftp_direntry_get(r, newpattern);
+ p->child = ftp_direntry_get(r, newpattern, sortby, reverse);
}
else {
@@ -396,6 +434,9 @@ struct ftp_direntry *ftp_direntry_get(re
}
num = i;
- qsort((void *) a, num, sizeof(struct ftp_direntry *),
- (int (*) (const void *, const void *)) ftp_dsortf);
+ if (sortby != SORT_NONE) {
+ qsort((void *) a, num, sizeof(struct ftp_direntry *),
+ (int (*)(const void *,
+ const void *))compar[sortby * 2 + reverse]);
+ }
/* Re-construct the list from the sorted list */

View File

@ -0,0 +1,21 @@
--- configure.apxs 2009-09-17 14:09:20.000000000 -0400
+++ configure.apxs 2011-06-21 23:58:53.000000000 -0400
@@ -117,18 +117,2 @@
> modules/ftp/ftp_config.h
fi
-
-echo ""
-echo "Finished, run 'make' to compile mod_ftp"
-echo ""
-echo "Run 'make FTPPORT=8021 install' to install mod_ftp"
-echo "(The default FTPPORT is $FTPPORT if not specified)"
-echo ""
-echo "The manual pages ftp/index.html and mod/mod_ftp.html"
-echo "will be installed to help get you started."
-echo
-echo "The conf/extra/ftpd.conf will be installed as an example"
-echo "for you to work from. In your configuration file,"
-echo " `$APXS -q exp_sysconfdir`/`$APXS -q progname`.conf"
-echo "uncomment the line '#Include conf/extra/ftpd.conf'"
-echo "to activate this example mod_ftp configuration."
-

View File

@ -0,0 +1,31 @@
See:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51412
--- modules/ftp/ftp_commands.c 2009-09-21 15:09:19.000000000 -0400
+++ modules/ftp/ftp_commands.c 2011-06-21 14:58:42.000000000 -0400
@@ -1676,4 +1676,5 @@
{
ftp_connection *fc = ftp_get_module_config(r->connection->conn_config);
+ long pbsz;
char *endp;
@@ -1687,15 +1688,16 @@
}
- fc->pbsz = strtol(arg, &endp, 10);
+ pbsz = strtol(arg, &endp, 10);
/*
* Return 501 if we were unable to parse the argument or if there was a
* possibility of an overflow
*/
- if (((*arg == '\0') || (*endp != '\0')) || fc->pbsz < 0
- || fc->pbsz == LONG_MAX) {
+ if (((*arg == '\0') || (*endp != '\0')) || pbsz <= 0 || pbsz >= INT_MAX) {
fc->response_notes = "Could not parse PBSZ argument";
return FTP_REPLY_SYNTAX_ERROR;
}
+ fc->pbsz = pbsz;
+
fc->response_notes = apr_psprintf(r->pool, "PBSZ Command OK. "
"Protection buffer size set to %d",

7
www/mod_ftp/pkg-descr Normal file
View File

@ -0,0 +1,7 @@
mod_ftp is a FTP Protocol module to serve httpd content over the
FTP protocol (whereever the HTTP protocol could also be used). It
provides both RETR/REST retrieval and STOR/APPE upload, using the
same user/permissions model as httpd (so it shares the same security
considerations as mod_dav plus mod_dav_fs).
WWW: http://httpd.apache.org/mod_ftp/

7
www/mod_ftp/pkg-message Normal file
View File

@ -0,0 +1,7 @@
This port does not install mod_ftp's documentation.
Please, visit
http://httpd.apache.org/mod_ftp/mod/mod_ftp.html
for up-to-date information.

5
www/mod_ftp/pkg-plist Normal file
View File

@ -0,0 +1,5 @@
@unexec if cmp -s %D/%%APACHEETCDIR%%/extra/ftpd.conf.dist %D/%%APACHEETCDIR%%/extra/ftpd.conf ; then rm -f %D/%%APACHEETCDIR%%/extra/ftpd.conf ; fi
%%APACHEETCDIR%%/extra/ftpd.conf.dist
@exec if [ ! -e %D/%%APACHEETCDIR%%/extra/ftpd.conf ] ; then cp -p %D/%%APACHEETCDIR%%/extra/ftpd.conf.dist %D/%%APACHEETCDIR%%/extra/ftpd.conf ; fi
%%APACHEMODDIR%%/%%AP_MODULE%%
%%APACHEINCLUDEDIR%%/mod_ftp.h