[sf-perl] Bug in perl (or does -r not do what I think?)

Dan Boger dan at peeron.com
Fri Jun 6 13:49:23 PDT 2008


I believe this is *only* on an NFS filesystem with root_squash.  I guess it
counts as a local-filesystem according to the manpage:

               Also note that, for the superuser on the local filesystems,
the "-r", "-R", "-w", and
               "-W" tests always return 1, and "-x" and "-X" return 1 if any
execute bit is set in the
               mode.  Scripts run by the superuser may thus need to do a
stat() to determine the
               actual mode of the file, or temporarily set their effective
uid to something else.

Dan

On Fri, Jun 6, 2008 at 1:14 PM, frosty <biztos at mac.com> wrote:

> My first suspicion was that something funny is going on with either the NFS
> or the "file" command, most likely the former.
>
> I just checked and on a local filesystem it's consistent, at least in my
> world (Perl 5.8.6 on RHEL 4.5 i386).
>
>    user at localhost ~ $ ls -l somefile
>    -r--------  1 postgres postgres 4 May 27 17:46 somefile
>    user at localhost ~ $ sudo perl -le 'print "lies" if -r shift' somefile
>    lies
>    user at localhost ~ $ sudo file somefile
>    somefile: ASCII text
>    user at localhost ~ $ file somefile
>    somefile: regular file, no read permission
>    user at localhost ~ $ cat somefile
>    cat: somefile: Permission denied
>    user at localhost ~ $ sudo cat somefile
>    yep
>    user at localhost ~ $
>
> -- f.
>
> On Friday, June 06, 2008, at 01:04PM, "Dan Boger" <dan at peeron.com> wrote:
> >I'm a little bit confused here, maybe one of you guys can spot what I'm
> >missing.
> >
> >I have some files on an NFS filesystem, that is set to root_squash.  The
> >file is owned by my network id (dboger), while I'm logged in locally as
> dan:
> >
> >dan at dbdb$ ls -l somefile.png
> >-r-------- 1 dboger 3813 2008-06-05 16:46 somefile.png
> >
> >I'm trying to figure out if a file is readable, so I do something like:
> >
> >dan at dbdb$ perl -le 'print "lies" if -r shift' somefile.png
> >dan at dbdb$
> >
> >That is correct - the file is owned by a different UID, and is set to
> 0400.
> >
> >Now, I try the same thing as root:
> >
> >dan at dbdb$ sudo perl -le 'print "lies" if -r shift' somefile.png
> >lies
> >dan at dbdb$ sudo file somefile.png
> >couldn't open file
> >somefile.png: regular file, no read permission
> >
> >Is perl just assuming that if I'm root I can always read the file, even
> >though the permissions say that's wrong?
> >
> >What am I missing?
> >
> >Dan
> >
> >--
> >Dan Boger
> >
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>



-- 
Dan Boger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080606/6e83321a/attachment.html 


More information about the SanFrancisco-pm mailing list