Subject: Re: CVS commit: basesrc/usr.bin/ftp
To: Luke Mewburn <lukem@wasabisystems.com>
From: Alan Barrett <apb@cequrux.com>
List: source-changes
Date: 07/05/2002 12:07:38
On Fri, 05 Jul 2002, Luke Mewburn wrote:
> I am aware of UNIX's semantics.  But the submitter of pr 15419 has a
> situation where the behaviour of ftp(1) parsing
> ftp://somehost/private/foo/blah.tgz as
> 	connect to somehost
> 	cd private
> 	cd foo
> 	get blah.tgz
> doesn't work due to permission issues.  (If ftp did "cd private/foo" instead
> of "cd private ; cd foo", it does work).

I still think that it would be useful for the ftp man page to have an
example showing exactly how the user can use %2F escapes to control what
happens.  I append a patch that does so.

I also agree with Greg:  While the problem is a "permission issue", it's
not necessarily "read permission" that's required.  The appended patch
changes this too.

--apb (Alan Barrett)

--- ftp.1	2002/07/04 06:39:28	1.84
+++ ftp.1	2002/07/05 09:59:11
@@ -1447,7 +1447,15 @@
 .Pp
 The following formats are valid syntax for an auto-fetch element:
 .Bl -tag -width "FOO "
-.It [user@]host:[path][/]
+.\" was: .It [user@]host:[path][/]
+.It Xo
+. Sm off
+. Op Ar user Cm \&@
+. Ar host Cm \&:
+. Op Ar path
+. Op Cm /
+. Sm on
+.Xc
 .Dq Classic
 .Tn FTP
 format.
@@ -1471,7 +1479,20 @@
 in the current directory.
 Otherwise, the full remote name is used as the local name,
 relative to the local root directory.
-.It ftp://[user[:password]@]host[:port]/path[/][;type=X]
+.\" was: .It ftp://[user[:password]@]host[:port]/path[/][;type=X]
+.It Xo
+. Sm off
+. Cm ftp://
+. Oo Ar user
+.  Op Cm \&: Ar password
+.  Cm \&@
+. Oc \&
+. Ar host Oo Cm \&: Ar port Oc
+. Cm / Ar path
+. Op Cm /
+. Op Cm ;type= Ar X
+. Sm on
+.Xc
 An
 .Tn FTP
 URL, retrieved using the
@@ -1493,20 +1514,94 @@
 .Ar password
 if supplied, otherwise prompt the user for one.
 .Pp
+If a suffix of
+.Sq ;type=A
+or
+.Sq ;type=I
+is supplied, then the transfer type will take place as
+ascii or binary (respectively).
+The default transfer type is binary.
+.Pp
 In order to be compliant with
 .Cm RFC 1738 ,
 .Nm
-has the following behaviour for
+interprets the
+.Ar path
+part of an
 .Dq ftp://
-auto-fetches:
+auto-fetch URL as follows:
 .Bl -bullet
 .It
-The leading
+The
+.Sq Cm /
+immediately after the
+.Ar host Ns Oo Cm \&: Ns Ar port Oc
+is interpreted as a separator before the
+.Ar path ,
+and not as part of the
+.Ar path
+itself.
+.It
+Any leading
+.Sq Cm /
+in the
+.Ar path
+is ignored.
+.It
+The
+.Ar path
+is interpreted as a
+.So Cm / Sc Ns -separated
+list of name components.
+For all but the last such component,
+.Nm
+performs the equivalent of a
+.Ic cd
+command,
+except that empty name components
+(which result from double slashes
+.Sq Cm //
+within the
+.Ar path )
+are ignored.
+For the last path component,
+.Nm
+performs the equivalent of a
+.Ic get
+command.
+.It
+Any
+.Sq Cm \&% Ns Ar XX
+codes within the path components are decoded, with
+.Ar XX
+representing a character code in hexadecimal.
+This decoding takes place after the
+.Ar path
+has been split into components,
+but before each component is used in the equivalent of a
+.Ic cd
+or
+.Ic get
+command.
+The most commonly used codes are
+.Sq %2F
+(which represents
+.Sq / )
+and
+.Sq %7E
+(which represents
+.Sq ~ ) .
+.El
+.Pp
+The above interpretation has the following consequences:
+.Bl -bullet
+.It
+Because any leading
 .Sq /
 is stripped from
 .Ar path ,
-resulting in a transfer relative from the default login directory of
-the user.
+the path is interpreted relative to the
+default login directory of the user.
 If the
 .Pa /
 directory is required, use a leading path of
@@ -1525,20 +1620,58 @@
 use
 .Dq ftp://myname:mypass@localhost/%2fetc/motd
 .It
-You must have read access to each of the intermediate directories,
-as each sub-directory is
-.Ic cd Ns -ed
-to in order.
+The exact
+.Ic cd
+and
+.Ic get
+commands can be controlled by careful choice of
+where to use
+.Sq /
+and where to use
+.Sq %2F
+(or
+.Sq %2f ) .
+For example, the following URLs correspond to the
+equivalents of the following commands:
+.Bl -tag -width "ftp://host/%2Fdir1%2Fdir2%2Ffile"
+.It ftp://host/dir1/dir2/file
+.Dq "cd dir1" ,
+.Dq "cd dir2" ,
+.Dq "get file" .
+.It ftp://host/%2Fdir1/dir2/file
+.Dq "cd /dir1" ,
+.Dq "cd dir2" ,
+.Dq "get file" .
+.It ftp://host/dir1%2Fdir2/file
+.Dq "cd dir1/dir2" ,
+.Dq "get file" .
+.It ftp://host/%2Fdir1%2Fdir2/file
+.Dq "cd /dir1/dir2" ,
+.Dq "get file" .
+.It ftp://host/dir1%2Fdir2%2Ffile
+.Dq "get dir1/dir2/file" .
+.It ftp://host/%2Fdir1%2Fdir2%2Ffile
+.Dq "get /dir1/dir2/file" .
 .El
-.Pp
-If a suffix of
-.Sq ;type=A
-or
-.Sq ;type=I
-is supplied, then the transfer type will take place as
-ascii or binary (respectively).
-The default transfer type is binary.
-.It http://[user[:password]@]host[:port]/path
+.It
+You must have appropriate access permission for each of the
+intermediate directories that is used in the equivalent of a
+.Ic cd
+command.
+.El
+
+.\" was: .It http://[user[:password]@]host[:port]/path
+.It Xo
+. Sm off
+. Cm http://
+. Oo Ar user
+.  Op Cm \&: Ar password
+.  Cm \&@
+. Oc \&
+. Ar host Oo Cm \&: Ar port Oc
+. Cm / Ar path
+. Sm on
+.Xc
 An
 .Tn HTTP
 URL, retrieved using the
@@ -1558,7 +1691,13 @@
 (and optionally
 .Sq password )
 is in the URL, use them for the first attempt to authenticate.
-.It file:///path
+.\" was: .It file:///path
+.It Xo
+. Sm off
+. Cm file://
+. Cm / Ar path
+. Sm on
+.Xc
 A local URL, copied from
 .Ar /path .
 .El

 (end)