Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

-r broken on root_squash NFS?

by zigdon (Deacon)
on Jun 06, 2008 at 21:17 UTC ( #690766=perlquestion: print w/replies, xml ) Need Help??

zigdon has asked for the wisdom of the Perl Monks concerning the following question:

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@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@dbdb$ perl -le 'print "lies" if -r shift' somefile.png dan@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@dbdb$ sudo perl -le 'print "lies" if -r shift' somefile.png lies dan@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? The perldoc page for -r says:
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.
But surely NFS doesn't count as a local filesystem? What am I missing?

-- zigdon

Replies are listed 'Best First'.
Re: -r broken on root_squash NFS?
by pc88mxer (Vicar) on Jun 06, 2008 at 21:22 UTC
    The root_squash option means that root will be mapped to the user nobody. That's why the file is not readable by root.

    Sorry, misunderstood the question. See a better answer below.

      Right... But why does '-r' still says it's readable?

      -- zigdon

        You're right. I bet perl is determining readability by calling access(2). From the man page:
          access() may not work correctly on NFS file systems  with  UID  mapping
          enabled,  because UID mapping is done on the server and hidden from the
          client, which checks permissions.
        
        and root_squash is a server option.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://690766]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-06-26 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (110 votes). Check out past polls.

    Notices?