9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: eekee57 <eekee57@fastmail.fm>
To: 9fans@9fans.net
Subject: [9fans] ftpfs ahould not expose "." and ".." directories
Date: Mon, 28 Apr 2008 08:48:13 +0000	[thread overview]
Message-ID: <84378423-1ad3-42a8-8948-2e3291a79dd0@j22g2000hsf.googlegroups.com> (raw)

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


             reply	other threads:[~2008-04-28  8:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-28  8:48 eekee57 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84378423-1ad3-42a8-8948-2e3291a79dd0@j22g2000hsf.googlegroups.com \
    --to=eekee57@fastmail.fm \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).