9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] ftpfs ahould not expose "." and ".." directories
@ 2008-04-28  8:48 eekee57
  2008-04-28 10:19 ` Pietro Gagliardi
  0 siblings, 1 reply; 8+ messages in thread
From: eekee57 @ 2008-04-28  8:48 UTC (permalink / raw)
  To: 9fans

Hi all. I had a problem trying to use dircp with ftpfs the other day,
and made a little patch to ftpfs to fix it.

The Problem: Many operating systems expose the psuedo-directories "."
and ".." in their directory structure, and understandably many FTP
servers running on those operating systems pass the pseudo-directories
on to their clients. Plan 9 does does not expose those psuedo-
directories, so Plan 9's tar program does not treat them specially.
ftpfs does not hide the pseudo-directories, so Plan 9 tar (and thus
the dircp script too) will fail on encountering them, getting into a
loop until the sequence of directory/../directory/../directory/../
etc. just gets too long. Note that tar may fail to pack all files in
the tree before failing.

My Fix: I have added a little code to ftpfs to hide the "." and ".."
directories when the server operating system is detected as UNIX,
Windows-NT, or Plan 9. I included the Plan 9 case because these 3
operating systems are lumped together in the code, and the heuristics
to tell them apart by detail may be fooled by some server which
happens to list files in a similar manner.

My code consists of 5 near-identical if statements in the function
that parses each line returned from an ftp LIST or NLST command:

664a665,666
> 			if(!strncmp(".", field[7], 2) || !strncmp("..", field[7], 3))
> 				return nil;
675a678,679
> 			if(!strncmp(".", field[8], 2) || !strncmp("..", field[8], 3))
> 				return nil;
686a691,692
> 			if(!strncmp(".", field[9], 2) || !strncmp("..", field[9], 3))
> 				return nil;
697a704,705
> 			if(!strncmp(".", field[3], 2) || !strncmp("..", field[3], 3))
> 				return nil;
712a721,722
> 			if(!strncmp(".", field[0], 2) || !strncmp("..", field[0], 3))
> 				return nil;

return nil results in ftpfs ignoring that line of the listing
entirely. strncmp() may not be the best function as it is supposed to
compare lexicographically. I'm not sure whether a "lexicographic"
comparison is appropriate, but I think Plan 9 strncmp is currently a
simple byte-by-byte comparison.

Patched /sys/src/cmd/ip/ftpfs/proto.c file:
http://eekee.org.uk/plan9/ftpfs..patch/proto.c

Also FYC are an ed script and a context diff:
http://eekee.org.uk/plan9/ftpfs..patch/diff.ed
http://eekee.org.uk/plan9/ftpfs..patch/diff.context


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-04-29 10:16 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-28  8:48 [9fans] ftpfs ahould not expose "." and ".." directories eekee57
2008-04-28 10:19 ` Pietro Gagliardi
2008-04-28 10:38   ` Juan Céspedes
2008-04-28 10:50     ` Charles Forsyth
2008-04-28 13:54       ` Charles Forsyth
2008-04-28 14:12         ` erik quanstrom
2008-04-29  8:32         ` eekee57
2008-04-29 10:16           ` roger peppe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).