[sf-perl] Bug in perl (or does -r not do what I think?)
not.com at gmail.com
Fri Jun 6 17:13:08 PDT 2008
On Fri, Jun 6, 2008 at 1:04 PM, Dan Boger <dan at peeron.com> wrote:
> I have some files on an NFS filesystem, that is set to root_squash.
To be clear, root_squash means that NFS requests from any client as
root get turned into requests from "nobody":
"root_squash - Requests from root clients are mapped to the nobody
user and group ID "
> 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
> 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?
As Garth noted, perl is asking the OS, and the OS is saying root can
read it- and the OS would let root read it, if it were on a local
filesystem. But the NFS server sees that the client says it's root,
and the NFS server then translates it into a request from "nobody",
and then the NFS server refuses to serve the file...
If you really want to treat NFS clients "root" as local "root", set
the option to no_root_squash
If you want a more reliable readability test, then use something like
open IN,'<',$ARGV or die "Cannot read file '$ARGV': $!, stopped";
More information about the SanFrancisco-pm