de8c2f
--- proftpd-1.3.2a/modules/mod_facts.c.mlsd	2009-04-28 22:17:45.000000000 +0100
de8c2f
+++ proftpd-1.3.2a/modules/mod_facts.c	2009-09-07 14:17:39.000000000 +0100
de8c2f
@@ -22,7 +22,7 @@
de8c2f
  * resulting executable, without including the source code for OpenSSL in the
de8c2f
  * source distribution.
de8c2f
  *
de8c2f
- * $Id: mod_facts.c,v 1.13.2.1 2009/04/28 21:17:45 castaglia Exp $
de8c2f
+ * $Id: mod_facts.c,v 1.22 2009/04/09 15:59:38 castaglia Exp $
de8c2f
  */
de8c2f
 
de8c2f
 #include "conf.h"
de8c2f
@@ -227,7 +227,17 @@
de8c2f
     ptr = buf + buflen;
de8c2f
   }
de8c2f
 
de8c2f
-  snprintf(ptr, bufsz - buflen, " %s\n", info->path);
de8c2f
+  /* MLST entries are not sent via pr_data_xfer(), and thus we do not need
de8c2f
+   * to include an LF at the end; it is appended by pr_response_send_raw().
de8c2f
+   * But MLSD entries DO need the trailing LF, so that it can be converted
de8c2f
+   * into a CRLF sequence by pr_data_xfer().
de8c2f
+   */
de8c2f
+  if (strcmp(session.curr_cmd, C_MLSD) == 0) {
de8c2f
+    snprintf(ptr, bufsz - buflen, " %s\n", info->path);
de8c2f
+
de8c2f
+  } else {
de8c2f
+    snprintf(ptr, bufsz - buflen, " %s", info->path);
de8c2f
+  }
de8c2f
 
de8c2f
   buf[bufsz-1] = '\0';
de8c2f
   buflen = strlen(buf);
de8c2f
@@ -244,11 +254,17 @@
de8c2f
  * channel, wherease MLSD's output is sent via a data transfer, much like
de8c2f
  * LIST or NLST.
de8c2f
  */
de8c2f
-static char mlinfo_buf[PR_TUNABLE_BUFFER_SIZE];
de8c2f
+static char *mlinfo_buf = NULL;
de8c2f
+static size_t mlinfo_bufsz = 0;
de8c2f
 static size_t mlinfo_buflen = 0;
de8c2f
 
de8c2f
 static void facts_mlinfobuf_init(void) {
de8c2f
-  memset(mlinfo_buf, '\0', sizeof(mlinfo_buf));
de8c2f
+  if (mlinfo_buf == NULL) {
de8c2f
+    mlinfo_bufsz = pr_config_get_xfer_bufsz();
de8c2f
+    mlinfo_buf = palloc(session.pool, mlinfo_bufsz);
de8c2f
+  }
de8c2f
+
de8c2f
+  memset(mlinfo_buf, '\0', mlinfo_bufsz);
de8c2f
   mlinfo_buflen = 0;
de8c2f
 }
de8c2f
 
de8c2f
@@ -261,11 +277,11 @@
de8c2f
   /* If this buffer will exceed the capacity of mlinfo_buf, then flush
de8c2f
    * mlinfo_buf.
de8c2f
    */
de8c2f
-  if (buflen >= (sizeof(mlinfo_buf) - mlinfo_buflen)) {
de8c2f
+  if (buflen >= (mlinfo_bufsz - mlinfo_buflen)) {
de8c2f
     (void) facts_mlinfobuf_flush();
de8c2f
   }
de8c2f
 
de8c2f
-  sstrcat(mlinfo_buf, buf, sizeof(mlinfo_buf));
de8c2f
+  sstrcat(mlinfo_buf, buf, mlinfo_bufsz);
de8c2f
   mlinfo_buflen += buflen;
de8c2f
 }
de8c2f
 
de8c2f
@@ -358,6 +374,8 @@
de8c2f
   char buf[PR_TUNABLE_BUFFER_SIZE];
de8c2f
 
de8c2f
   (void) facts_mlinfo_fmt(info, buf, sizeof(buf));
de8c2f
+
de8c2f
+  /* The trailing CRLF will be added by pr_response_send_raw(). */
de8c2f
   pr_response_send_raw("%s", buf);
de8c2f
 }
de8c2f
 
de8c2f
@@ -595,7 +613,6 @@
de8c2f
  */
de8c2f
 
de8c2f
 MODRET facts_mff(cmd_rec *cmd) {
de8c2f
-  register unsigned int i;
de8c2f
   const char *path, *decoded_path;
de8c2f
   char *facts, *ptr;
de8c2f
 
de8c2f
@@ -606,18 +623,16 @@
de8c2f
 
de8c2f
   facts = cmd->argv[1];
de8c2f
 
de8c2f
-  /* The path can contain spaces; it is thus the concatenation of all of the
de8c2f
-   * arguments after the timestamp.
de8c2f
+  /* The path can contain spaces.  Thus we need to use cmd->arg, not cmd->argv,
de8c2f
+   * to find the path.  But cmd->arg contains the facts as well.  Thus we
de8c2f
+   * find the FIRST space in cmd->arg; the path is everything past that space.
de8c2f
    */
de8c2f
-  path = pstrdup(cmd->tmp_pool, cmd->argv[2]);
de8c2f
-  for (i = 3; i < cmd->argc; i++) {
de8c2f
-    path = pstrcat(cmd->tmp_pool, path, " ", cmd->argv[i], NULL);
de8c2f
-  }
de8c2f
+  ptr = strchr(cmd->arg, ' ');
de8c2f
+  path = pstrdup(cmd->tmp_pool, ptr + 1);
de8c2f
 
de8c2f
   decoded_path = pr_fs_decode_path(cmd->tmp_pool, path);
de8c2f
 
de8c2f
-  if (!dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, (char *) decoded_path,
de8c2f
-      NULL)) {
de8c2f
+  if (!dir_check(cmd->tmp_pool, cmd, cmd->group, (char *) decoded_path, NULL)) {
de8c2f
     pr_log_debug(DEBUG4, MOD_FACTS_VERSION ": %s command denied by <Limit>",
de8c2f
       cmd->argv[0]);
de8c2f
     pr_response_add_err(R_550, _("Unable to handle command"));
de8c2f
@@ -739,7 +754,6 @@
de8c2f
 }
de8c2f
 
de8c2f
 MODRET facts_mfmt(cmd_rec *cmd) {
de8c2f
-  register unsigned int i;
de8c2f
   const char *path, *decoded_path;
de8c2f
   char *timestamp, *ptr;
de8c2f
   int res;
de8c2f
@@ -751,18 +765,16 @@
de8c2f
 
de8c2f
   timestamp = cmd->argv[1];
de8c2f
 
de8c2f
-  /* The path can contain spaces; it is thus the concatenation of all of the
de8c2f
-   * arguments after the timestamp.
de8c2f
+  /* The path can contain spaces.  Thus we need to use cmd->arg, not cmd->argv,
de8c2f
+   * to find the path.  But cmd->arg contains the facts as well.  Thus we
de8c2f
+   * find the FIRST space in cmd->arg; the path is everything past that space.
de8c2f
    */
de8c2f
-  path = pstrdup(cmd->tmp_pool, cmd->argv[2]);
de8c2f
-  for (i = 3; i < cmd->argc; i++) {
de8c2f
-    path = pstrcat(cmd->tmp_pool, path, " ", cmd->argv[i], NULL);
de8c2f
-  }
de8c2f
+  ptr = strchr(cmd->arg, ' ');
de8c2f
+  path = pstrdup(cmd->tmp_pool, ptr + 1);
de8c2f
 
de8c2f
   decoded_path = pr_fs_decode_path(cmd->tmp_pool, path);
de8c2f
 
de8c2f
-  if (!dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, (char *) decoded_path,
de8c2f
-      NULL)) {
de8c2f
+  if (!dir_check(cmd->tmp_pool, cmd, cmd->group, (char *) decoded_path, NULL)) {
de8c2f
     pr_log_debug(DEBUG4, MOD_FACTS_VERSION ": %s command denied by <Limit>",
de8c2f
       cmd->argv[0]);
de8c2f
     pr_response_add_err(R_550, _("Unable to handle command"));
de8c2f
@@ -820,33 +832,28 @@
de8c2f
   DIR *dirh;
de8c2f
   struct dirent *dent;
de8c2f
 
de8c2f
-  if (cmd->argc > 2) {
de8c2f
-    pr_response_add_err(R_501, _("Invalid number of arguments"));
de8c2f
-    return PR_ERROR(cmd);
de8c2f
-  }
de8c2f
-
de8c2f
   if (cmd->argc != 1) {
de8c2f
-    path = cmd->argv[1];
de8c2f
+    path = pstrdup(cmd->tmp_pool, cmd->arg);
de8c2f
     decoded_path = pr_fs_decode_path(cmd->tmp_pool, path);
de8c2f
 
de8c2f
   } else {
de8c2f
     decoded_path = path = pr_fs_getcwd();
de8c2f
   }
de8c2f
 
de8c2f
-  if (!dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, (char *) decoded_path,
de8c2f
-      NULL)) {
de8c2f
+  if (!dir_check(cmd->tmp_pool, cmd, cmd->group, (char *) decoded_path, NULL)) {
de8c2f
     pr_log_debug(DEBUG4, MOD_FACTS_VERSION ": %s command denied by <Limit>",
de8c2f
       cmd->argv[0]);
de8c2f
     pr_response_add_err(R_550, _("Unable to handle command"));
de8c2f
     return PR_ERROR(cmd);
de8c2f
   }
de8c2f
 
de8c2f
-  /* RFC3659 explicitly does NOT support glob characters. */
de8c2f
+  /* RFC3659 explicitly does NOT support glob characters.  So warn about
de8c2f
+   * this, but let the command continue as is.  We don't actually call
de8c2f
+   * glob(3) here, so no expansion will occur.
de8c2f
+   */
de8c2f
   if (strpbrk(decoded_path, "{[*?") != NULL) {
de8c2f
-    pr_log_debug(DEBUG2, MOD_FACTS_VERSION ": unable to handle MLSD command: "
de8c2f
-      "target '%s' contains glob characters", decoded_path);
de8c2f
-    pr_response_add_err(R_550, _("Unable to handle command"));
de8c2f
-    return PR_ERROR(cmd);
de8c2f
+    pr_log_debug(DEBUG9, MOD_FACTS_VERSION ": glob characters in MLSD ('%s') "
de8c2f
+      "ignored", decoded_path);
de8c2f
   }
de8c2f
 
de8c2f
   /* Make sure that the given path is actually a directory. */
de8c2f
@@ -870,11 +877,11 @@
de8c2f
     int xerrno = errno;
de8c2f
 
de8c2f
     pr_trace_msg("fileperms", 1, "MLSD, user '%s' (UID %lu, GID %lu): "
de8c2f
-      "error reading directory '%s': %s", session.user,
de8c2f
+      "error opening directory '%s': %s", session.user,
de8c2f
       (unsigned long) session.uid, (unsigned long) session.gid,
de8c2f
       decoded_path, strerror(xerrno));
de8c2f
 
de8c2f
-    pr_response_add_err(R_550, _("'%s' cannot be listed"), path);
de8c2f
+    pr_response_add_err(R_550, "%s: %s", path, strerror(xerrno));
de8c2f
     return PR_ERROR(cmd);
de8c2f
   }
de8c2f
 
de8c2f
@@ -899,16 +906,14 @@
de8c2f
     /* Check that the file can be listed. */
de8c2f
     abs_path = dir_realpath(cmd->tmp_pool, rel_path);
de8c2f
     if (abs_path) {
de8c2f
-      res = dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, abs_path,
de8c2f
-        &hidden);
de8c2f
+      res = dir_check(cmd->tmp_pool, cmd, cmd->group, abs_path, &hidden);
de8c2f
       
de8c2f
     } else {
de8c2f
       abs_path = dir_canonical_path(cmd->tmp_pool, rel_path);
de8c2f
       if (abs_path == NULL)
de8c2f
         abs_path = rel_path;
de8c2f
 
de8c2f
-      res = dir_check_canon(cmd->tmp_pool, cmd->argv[0], cmd->group, abs_path,
de8c2f
-        &hidden);
de8c2f
+      res = dir_check_canon(cmd->tmp_pool, cmd, cmd->group, abs_path, &hidden);
de8c2f
     }
de8c2f
 
de8c2f
     if (!res || hidden) {
de8c2f
@@ -955,20 +960,15 @@
de8c2f
   const char *path, *decoded_path;
de8c2f
   struct mlinfo info;
de8c2f
 
de8c2f
-  if (cmd->argc > 2) {
de8c2f
-    pr_response_add_err(R_501, _("Invalid number of arguments"));
de8c2f
-    return PR_ERROR(cmd);
de8c2f
-  }
de8c2f
-
de8c2f
   if (cmd->argc != 1) {
de8c2f
-    path = cmd->argv[1];
de8c2f
+    path = pstrdup(cmd->tmp_pool, cmd->arg);
de8c2f
     decoded_path = pr_fs_decode_path(cmd->tmp_pool, path);
de8c2f
 
de8c2f
   } else {
de8c2f
     decoded_path = path = pr_fs_getcwd();
de8c2f
   }
de8c2f
 
de8c2f
-  if (!dir_check(cmd->tmp_pool, cmd->argv[0], cmd->group, (char *) decoded_path,
de8c2f
+  if (!dir_check(cmd->tmp_pool, cmd, cmd->group, (char *) decoded_path,
de8c2f
       &hidden)) {
de8c2f
     pr_log_debug(DEBUG4, MOD_FACTS_VERSION ": %s command denied by <Limit>",
de8c2f
       cmd->argv[0]);
de8c2f
@@ -1155,6 +1155,7 @@
de8c2f
 
de8c2f
   pr_feat_add("MFF modify;UNIX.group;UNIX.mode;");
de8c2f
   pr_feat_add("MFMT");
de8c2f
+  pr_feat_add("TVFS");
de8c2f
 
de8c2f
   facts_mlst_feat_add(session.pool);
de8c2f