[PATCH] src/libexec/ftpd: fix nlist with -option does not work

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] src/libexec/ftpd: fix nlist with -option does not work

SASANO Takayoshi
Hello,

At least OpenBSD-6.5 and 6.6's ftpd does not work NLIST command with any
-option like this.

----
ftp> nlist
150 Opening ASCII mode data connection for 'file list'.
uaa
_sysupgrade
226 Transfer complete.
ftp> nlist -LF
550 -LF: No such file or directory.
ftp>
----

Here is the remedy, ok?

Index: extern.h
===================================================================
RCS file: /cvs/src/libexec/ftpd/extern.h,v
retrieving revision 1.20
diff -u -p -r1.20 extern.h
--- extern.h 8 May 2019 23:56:48 -0000 1.20
+++ extern.h 18 Nov 2019 05:48:53 -0000
@@ -89,7 +89,7 @@ void renamecmd(char *, char *);
 char   *renamefrom(char *);
 void reply(int, const char *, ...);
 void reply_r(int, const char *, ...);
-enum ret_cmd { RET_FILE, RET_LIST };
+enum ret_cmd { RET_FILE, RET_LIST, RET_NLIST };
 void retrieve(enum ret_cmd, char *);
 void send_file_list(char *);
 void setproctitle(const char *, ...);
Index: ftpd.c
===================================================================
RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.228
diff -u -p -r1.228 ftpd.c
--- ftpd.c 3 Jul 2019 03:24:04 -0000 1.228
+++ ftpd.c 18 Nov 2019 05:48:53 -0000
@@ -1124,7 +1124,10 @@ retrieve(enum ret_cmd cmd, char *name)
  fin = fopen(name, "r");
  st.st_size = 0;
  } else {
- fin = ftpd_ls("-lgA", name, &pid);
+ if (cmd == RET_NLIST)
+ fin = ftpd_ls(name, ".", &pid);
+ else
+ fin = ftpd_ls("-lgA", name, &pid);
  st.st_size = -1;
  st.st_blksize = BUFSIZ;
  }
@@ -1166,7 +1169,8 @@ retrieve(enum ret_cmd cmd, char *name)
  goto done;
  }
  }
- dout = dataconn(name, st.st_size, "w");
+ dout = dataconn((cmd == RET_NLIST) ? "file list" : name,
+ st.st_size, "w");
  if (dout == NULL)
  goto done;
  time(&start);
@@ -2626,7 +2630,7 @@ send_file_list(char *whichf)
  */
  if (dirname[0] == '-' && *dirlist == NULL &&
     transflag == 0) {
- retrieve(RET_FILE, dirname);
+ retrieve(RET_NLIST, dirname);
  goto out;
  }
  perror_reply(550, whichf);

--
SASANO Takayoshi (JG1UAA) <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

(re) [PATCH] src/libexec/ftpd: fix nlist with -option does not work

SASANO Takayoshi
ping

On Mon, 18 Nov 2019 14:56:46 +0900,
SASANO Takayoshi wrote:

>
> Hello,
>
> At least OpenBSD-6.5 and 6.6's ftpd does not work NLIST command with any
> -option like this.
>
> ----
> ftp> nlist
> 150 Opening ASCII mode data connection for 'file list'.
> uaa
> _sysupgrade
> 226 Transfer complete.
> ftp> nlist -LF
> 550 -LF: No such file or directory.
> ftp>
> ----
>
> Here is the remedy, ok?
>
> Index: extern.h
> ===================================================================
> RCS file: /cvs/src/libexec/ftpd/extern.h,v
> retrieving revision 1.20
> diff -u -p -r1.20 extern.h
> --- extern.h 8 May 2019 23:56:48 -0000 1.20
> +++ extern.h 18 Nov 2019 05:48:53 -0000
> @@ -89,7 +89,7 @@ void renamecmd(char *, char *);
>  char   *renamefrom(char *);
>  void reply(int, const char *, ...);
>  void reply_r(int, const char *, ...);
> -enum ret_cmd { RET_FILE, RET_LIST };
> +enum ret_cmd { RET_FILE, RET_LIST, RET_NLIST };
>  void retrieve(enum ret_cmd, char *);
>  void send_file_list(char *);
>  void setproctitle(const char *, ...);
> Index: ftpd.c
> ===================================================================
> RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
> retrieving revision 1.228
> diff -u -p -r1.228 ftpd.c
> --- ftpd.c 3 Jul 2019 03:24:04 -0000 1.228
> +++ ftpd.c 18 Nov 2019 05:48:53 -0000
> @@ -1124,7 +1124,10 @@ retrieve(enum ret_cmd cmd, char *name)
>   fin = fopen(name, "r");
>   st.st_size = 0;
>   } else {
> - fin = ftpd_ls("-lgA", name, &pid);
> + if (cmd == RET_NLIST)
> + fin = ftpd_ls(name, ".", &pid);
> + else
> + fin = ftpd_ls("-lgA", name, &pid);
>   st.st_size = -1;
>   st.st_blksize = BUFSIZ;
>   }
> @@ -1166,7 +1169,8 @@ retrieve(enum ret_cmd cmd, char *name)
>   goto done;
>   }
>   }
> - dout = dataconn(name, st.st_size, "w");
> + dout = dataconn((cmd == RET_NLIST) ? "file list" : name,
> + st.st_size, "w");
>   if (dout == NULL)
>   goto done;
>   time(&start);
> @@ -2626,7 +2630,7 @@ send_file_list(char *whichf)
>   */
>   if (dirname[0] == '-' && *dirlist == NULL &&
>      transflag == 0) {
> - retrieve(RET_FILE, dirname);
> + retrieve(RET_NLIST, dirname);
>   goto out;
>   }
>   perror_reply(550, whichf);
>
> --
> SASANO Takayoshi (JG1UAA) <[hidden email]>
>

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] src/libexec/ftpd: fix nlist with -option does not work

Jan Klemkow
In reply to this post by SASANO Takayoshi
On Mon, Nov 18, 2019 at 02:56:46PM +0900, SASANO Takayoshi wrote:

> At least OpenBSD-6.5 and 6.6's ftpd does not work NLIST command with
> any -option like this.
>
> ----
> ftp> nlist
> 150 Opening ASCII mode data connection for 'file list'.
> uaa
> _sysupgrade
> 226 Transfer complete.
> ftp> nlist -LF
> 550 -LF: No such file or directory.
> ftp>
> ----
>
> Here is the remedy, ok?

I don't like the idea to let the client call custom options of ls(1).
It seems to be secure, but no one knows what options will implemented in
ls(1) in the future.  Also the FTP RFC does not mention custom options,
as far as I can see.

It's just possible to do that, because traditional ftp daemons (like
ours) call ls(1).  I'm more interested in avoiding option insertion by
put a "--" before the clients parameters.

bye,
Jan