Tcl Source Code

View Ticket
Login
Ticket UUID: 1617990
Title: Incorrect result of access() for NFS mounted files
Type: Bug Version: None
Submitter: decosterjos Created on: 2006-12-18 12:48:34
Subsystem: 37. File System Assigned To: vincentdarley
Priority: 5 Medium Severity:
Status: Open Last Modified: 2006-12-19 23:07:43
Resolution: Wont Fix Closed By: dkf
    Closed on: 2006-12-18 14:24:40
Description:
Hi,

When running test cmdAH-16.3 on an NFS mounted file system, the 'file readable' command returned the incorrect result. Running some test with the access system call as used in the TclpObjAccess function showed the problem. This was the test program:

#include <iostream>

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
    std::cout << "access: " 
              << access("gorp.file", R_OK) 
              << std::endl;

    struct stat st;
    int rt = stat("gorp.file", &st);

    std::cout << "stat mode: " << std::oct 
              << st.st_mode
      << std::dec << std::endl;
    std::cout << "& S_IRUSR = " 
              << (st.st_mode & S_IRUSR) << std::endl;
    
    return 0;
}

The result of running this program on the NFS mounted file system was:

access: 0                  ===> expected -1
stat mode: 100333
& S_IRUSR = 0

The result of running this program on the local file system was:

access: -1
stat mode: 100333
& S_IRUSR = 0

access reports the NFS file incorrectly as being readable while stat always return the correct result.

Kind regards,

Jos.
User Comments: decosterjos added on 2006-12-19 23:07:43:
Logged In: YES 
user_id=370749
Originator: YES

Another option would be to skip the test on network file systems (as done in fCmd.test):

testConstraint notNetworkFilesystem 0

test cmdAH-16.3 {Tcl_FileObjCmd: readable} {
    -constraints {unix notRoot testchmod notNetworkFilesystem}
    -setup   {testchmod 0333 $gorpfile}
    -body    {file reada $gorpfile}
    -result  0
}

A file not readable for yourself is not often useful, i guess this problem come from an NFS/acess() implementation never tested for a file not readable for yourself.

dgp added on 2006-12-18 22:51:46:
Logged In: YES 
user_id=80530
Originator: NO


This sounds similar to troubles
we had with Linux NFS and test
fCmd-18.10.  For that, we created
the notNetworkFilesystem constraint.
Feel free to expand use of that.

decosterjos added on 2006-12-18 22:30:06:

File Added - 207717: TclpObjAccess.c

Logged In: YES 
user_id=370749
Originator: YES

Possible combination of access and stat.
File Added: TclpObjAccess.c

dkf added on 2006-12-18 21:24:40:
Logged In: YES 
user_id=79902
Originator: NO

Checking stat() results is not always helpful either. For example, it is possible for access() to verify that you're allowed to read a file based on any Access Control List entries attached to the file, but stat() doesn't look at those. This is a known problem when using some filesystems (e.g. AFS). That NFS is broken the other way is just unfortunate, and probably unfixable too.

Attachments: