Bug 206192

Summary: ls -R warns about EACCES on directories it's not going to list anyway
Product: Base System Reporter: Robert Clausecker <fuz>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Some People    
Priority: ---    
Version: 10.2-RELEASE   
Hardware: Any   
OS: Any   

Description Robert Clausecker 2016-01-13 11:03:04 UTC
The FreeBSD implementation of ls -R decides to omit directories from recursive listing which are omitted from listing anyway. This may be in violation of POSIX [1] but that's irrelevant for this bug report. When ls -R encounters a directory without reading permission, it outputs the resulting EACCES. This even happens for directories which are never listed by ls -R anyway due to their names beginning with a dot, which causes ls to output spurious warnings. To reproduce, in an empty directory do:

    mkdir .a
    chmod a-r .a
    ls -R .

The following output results:

    $ ls -R . 
    ls: ./.a: Permission denied

If .a was readable, ls -R would not list it either, so the error message seems wrong.

[1]: http://austingroupbugs.net/view.php?id=1023
Comment 1 nibbana 2016-01-14 16:15:45 UTC
On 9.3, notice that something similar affects rm(1):

$ mkdir aaa; cd aaa; mkdir .bbb; chmod 0077 .bbb
$ cd ..; rm -r aaa
override ---rwxrwx  user/wheel for aaa/.bbb? y
rm: aaa/.bbb: Permission denied
rm: aaa: Directory not empty

I don't know all the rules, but this seems wrong also.
The user was a member of group wheel, and all have rwx permissions,
and it would seem that they ought to be able to remove the directory;
alternatively, perhaps the permissions are hierarchial in nature,
and a lower class user can't do what a higher class user can't do.
Just thought it may be a worthy comment.