* Martin D Kealey ([EMAIL PROTECTED]) [081202 04:37]:
> On Tue, 25 Nov 2008, Dave Whipp wrote:
>
> sub setstat(String|File $filename, StatBuf $stat) {
> ...
> if $caps.CAP_FOWNER {
> # we're privileged, so it *should* just work.
> POSIX::chown $filename, $stat.uid, $stat.gid;
> POSIX::chmod $filename, Fcntl::ST_PERM($stat.mode);
> POSIX::utime $filename, $stat.mtime, $stat.atime;
> return;
> ...
> if catching_exception(IO_error) {
> throw IO_error(EPERM, $filename, "Can't give file away");
Implementing things this way is as big a mistake as doing this:
(Perl5 syntax)
if(-r $fn)
{ open READ, '<', $fn;
while( <READ> )
For the two reasons:
(1) you have a race condition: the permission may change between
the test and the actual open(). In very rare cases, which
makes those bug hard to trace
(2) the check itself is flawed: whether you can chown() does not
only depend on the OS, but also on the disk: might be a CD-ROM.
The only correct way to implement it, is simply try chown() and
handle the error. Yes, you need quite more code for that.
--
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
[EMAIL PROTECTED] [EMAIL PROTECTED]
http://Mark.Overmeer.net http://solutions.overmeer.net