Cannot cd into directory when permissions are granted via ACLs instead of traditional unix permissions #9046
Description
I have a couple of directories that are owned by other users, but where I have permissions via ACLs
Something like this:
^mkdir -m 0770 foo
setfacl -m u:myuser:rwX -m d:u:myuser:rwX foo
cd /tmp/foo
results in Cannot change directory to /tmp/foo: You are neither the owner, in the group, nor the super user and do not have permission
however exec sh -c 'cd /tmp/foo; exec nu'
works fine and running ls in the resulting shell works just as well
I had a brief look at the code and it seems that on windows have_permission() tries to actually read_dir() the directory that we want to cd into, but only linux it tries to guess whether we have access from the metadata by looking at owner, group and the respective permission bits.
This can lead to false negatives (as in my case), and maybe false positives as well when things like selinux come into play (I haven't had much contact with that, but I vaguely recall something like that is possible)
As the current error messages are more helpful to inexperienced users, I think my preferred approach to improve this would be:
- try read_dir() first, akin to whats done on windows
- If that works, don't perform any other checks and allow cd to proceed (fixes my false negative)
- If it doesn't, do the current look-at-metadata-thing
- Return any error just as it does now (keep helpfull error messages)
- If the metadata looks like it should have worked, pass on the error message from the original read_dir (instead of the current OK return value, to catch eventual false positives)
But I'd also be fine with something like cd --force
or anything else that just lets me get on with it ;)