Re: Changes to the filesystem while find is running - comments?
(Because I'm so sick of the broken autoresponders bugtraq is full of,
I've set the From: on this mail to a black-hole address. Please use
the address in the signature if you actually want to reach me.)
>> Before a chdir to "foo", take stock:
>> - record stat("."); DOTFD = open("."); (get a fd to ".")
This is not possible if . is a search-only directory. (While find will
not work very well in such a directory, care should be taken that it
not fall over just because someone happened to chmod the read bits away
from a directory just when find happens to be in it.)
More generally, I've wanted to do this - use file descriptors as
handles onto directories - and often wished for an O_NOACCESS mode to
open() in consequence.
> Of course, open(2) will follow a symlink, if the directory we
> originally stat()ed is replaced by a symlink just before we issue the
> open() call. We of course can guard against that by issuing an
> lstat() on the fd once we have opened it.
ITYPM fstat(), not lstat(), in the last line.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Re: Changes to the filesystem while find is running - comments?
>I can see that that would be useful but it would fail to comply with
>the POSIX standard, which specifies:
>
> The find utility shall be able to descend to arbitrary
> depths in a file hierarchy and shall not fail due to path
> length limitations (unless a path operand specified by the
> application exceeds {PATH_MAX} requirements)
But PATH_MAX is limited and the number of file descriptors is perhaps
not.
(On Solaris, PATH_MAX is 1024 so you require at most 512 file
descriptors to keep the stack of directories: 512 is less than the
default hard limit of 65536 file descriptors per process [S9, S8
and before used 1024, still >> 512)
Casper
Re: Changes to the filesystem while find is running - comments?
On Wed, Nov 24, 2004 at 08:51:38AM +0100, Casper.Dik@Sun.COM wrote:
>
> >I can see that that would be useful but it would fail to comply with
> >the POSIX standard, which specifies:
> >
> > The find utility shall be able to descend to arbitrary
> > depths in a file hierarchy and shall not fail due to path
> > length limitations (unless a path operand specified by the
> > application exceeds {PATH_MAX} requirements)
>
> But PATH_MAX is limited and the number of file descriptors is perhaps
> not.
Systems differ. Some have no limits on the depth of a directory
hierarchy. Certainly I've created directory hierarchies of over
800,000 levels on HP-UX 9 and on Linux. GNU Hurd has no limits at all
(and therefore used not to #define PATH_MAX at all).
> (On Solaris, PATH_MAX is 1024 so you require at most 512 file
> descriptors to keep the stack of directories: 512 is less than the
> default hard limit of 65536 file descriptors per process [S9, S8
> and before used 1024, still >> 512)
A worthwhile point, but since the POSIX standard doesn't mention fd
limits here I suspect that there may be an expectation in some
quarters that find will still be able to work even if the soft limit
is much lower.
That being said, consistently using fchdir() is a robust and sensible
approach. However, I'm trying to correctly solve the problem of
secure downward movement in the directory hierarchy, which as far as I
can see is not fully solved simply by using fchdir().
Regards,
James.