ls mystery

Frank Shute frank at
Mon Feb 16 09:36:04 GMT 2004

On Mon, Feb 16, 2004 at 08:54:44AM +0000, Michael Abbott wrote:
> > # ls -al /usr/ports/distfiles | grep xc
> > drw-r--r--   2 root   wheel       512 Oct 31 03:03 xc
>      ^
>      No "execute" access on this directory.
> > $ ls -al /usr/ports/distfiles/xc
> >
> > <zilch>
> In this context "x" means ability to search directory, so this is normal.
> Of course, root being root gets to ignore this flag.
> > Why can't I read the dir as a user (group wheel) with permissions of
> > 644 but I can with permissions of 755? What the hell have the
> > executable bits got to do with reading a dir? I'm confused... :(
> To be precise, on a directory the "r" bit allows you to access a file *if*
> you know its name, while the "x" bit allows you to list the files in the
> directory.  Not quite sure what it's used for in practical security
> application, but that's the standard protection model.
> > I think I saw some ls stuff going in when I cvs-upped the other night
> > to 4.9 RELEASE. Anybody aware of a problem or am I getting something
> > wrong?
> There's definitely nothing wrong here, this is standard behaviour.

Now tell me that this isn't wrong... :)

$ ls -al /usr/ports/distfiles/xc


$ /bin/ls -al /usr/ports/distfiles/xc


$ ls /usr/ports/distfiles/xc


$ /bin/ls /usr/ports/distfiles/xc



Bugs? A veritable swarm of them. BTW, I checked with strace that the
ls without the full path was invoking /bin/ls.....I thought I'd been
cracked. That's on 4.8 STABLE & 4.9RC and with both /bin/sh and pdksh
so it's not shell related.

If as you say that you can't get a listing on a dir without the
executable bit set (and I've just shown you I can), then why doesn't
ls give you "permission denied"? Is it time for a pr? The behaviour is
so inconsistent that it's not funny. If it's inconsistent for a reason
(I can't think of one) then it should be documented in the manpage(s).

BTW, I checked cvs and it looks like they've just been fiddling around
the edges. 



 Tel: 01423 323019
PGP keyID: 0xC0B341A3

More information about the Ukfreebsd mailing list