On Wed, Jul 28, 2021 at 10:33:05AM -0600, Theo de Raadt wrote:
> Klemens Nanni <[email protected]> wrote:
>
> > With the current wording, I'd either expect usage error when passing
> > `-o output' or more wording explaining the behaviour when fetching
> > multiple files.
> >
> > Usage error seems wrong since our synopsis explicitly allows it, but
> > writing the contents behind multiple URLs into the same file, while
> > truncating the file for each URL does not make much sense, either.
> >
> >
> > I came across this as I wanted to fetch multiple URLs at once without
> > scripting, looked at ftp(1) and didn't found anything to do that.
> > Tried `-o' with multiple URLs to see how it behaves as that case isn't
> > documented.
> >
> > So should we at least go with this correction?
> >
> > Index: ftp.1
> > ===================================================================
> > RCS file: /cvs/src/usr.bin/ftp/ftp.1,v
> > retrieving revision 1.122
> > diff -u -p -r1.122 ftp.1
> > --- ftp.1 2 Feb 2021 12:58:42 -0000 1.122
> > +++ ftp.1 28 Jul 2021 15:46:19 -0000
> > @@ -212,7 +212,7 @@ will prompt for the remote machine login
> > identity on the local machine) and, if necessary, prompt for a password
> > and an account with which to log in.
> > .It Fl o Ar output
> > -When fetching a single file or URL, save the contents in
> > +When fetching files or URLs, save the contents in
> > .Ar output .
> > To make the contents go to stdout,
> > use
> >
>
> So it concatenates the output to the one file? Fine. But we should
> also block users from more than one -o option.
Why? ftp(1) does not say multiple `-o's are allowed and nothing would
imply that, either.
I'd let later options overwrite earlier ones as is common.
Specificically, ftp's other options behave the same way:
$ ftp -N foo -o /no-write-perm /nope http://localhost/
Trying ::1...
Requesting http://localhost/
foo: Can't open /no-write-perm: Permission denied
$ ftp -N foo -N bar -o /no-write-perm /nope http://localhost/
Trying ::1...
Requesting http://localhost/
bar: Can't open /no-write-perm: Permission denied
>
> Index: main.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/ftp/main.c,v
> retrieving revision 1.138
> diff -u -p -u -r1.138 main.c
> --- main.c 14 Jul 2021 13:33:57 -0000 1.138
> +++ main.c 28 Jul 2021 16:31:31 -0000
> @@ -501,6 +501,8 @@ main(volatile int argc, char *argv[])
> break;
>
> case 'o':
> + if (outfile)
> + usage();
> outfile = optarg;
> if (*outfile == '\0') {
> pipeout = 0;
>