Unable to change ACL-permissions for symbolic links

the chmod-manual page states about the -h option: If the file is a symbolic link, change the mode of the link itself rather than the file that the link points to.

But somehow this doesn't seem to have an effect. it always manipulates the original file instead of the symbolic link although this should be the default behaviour anyway. I tried with several different links and checked with 'ls -le'. It doesn't matter whether I try to add permissions or get rid of all of them with 'chmod -h -N ./linkfile' or 'chmod -N -h ./linkfile'.

Any help would be appreciated although I guess I could live with all the symbolic links in my home directory having the "group:everyone deny delete" restriction on them.. :S

MacBook Pro, Mac OS X (10.5.2)

Posted on Mar 13, 2008 9:49 AM

Reply
16 replies

Mar 13, 2008 5:34 PM in response to xnav

FYI, man chmod on my machine shows:

CHMOD(1) BSD General Commands Manual
NAME chmod -- change file modes or Access Control Lists

<snip>

DESCRIPTION
The chmod utility modifies the file mode bits of the listed files as specified by the mode operand. It
may also be used to modify the Access Control Lists (ACLs) associated with the listed files.

The generic options are as follows:

-f Do not display a diagnostic message if chmod could not modify the mode for file.

-H If the -R option is specified, symbolic links on the command line are followed. (Symbolic
links encountered in the tree traversal are not followed by default.)

-h If the file is a symbolic link, change the mode of the link itself rather than the file that
the link points to.

<snip>

BSD July 08, 2004

Mar 13, 2008 5:53 PM in response to baltwo

OK, any idea why my man page would be incorrect or how I could reload the pages?
NAME
chmod -- change file modes or Access Control Lists

SYNOPSIS
chmod [-fv] [-R [-H | -L | -P]] mode file ...
chmod [-fv] [-R [-H | -L | -P]] [-a | +a | =a] ACE file ...
chmod [-fv] [-R [-H | -L | -P]] [-E] file ...
chmod [-fv] [-R [-H | -L | -P]] [-C] file ...

Mar 13, 2008 6:15 PM in response to apfelfresser

apfelfresser wrote:
the chmod-manual page states about the -h option: If the file is a symbolic link, change the mode of the link itself rather than the file that the link points to.

But somehow this doesn't seem to have an effect. it always manipulates the original file instead of the symbolic link

OK, this is a well-known bug in FreeBSD, at least older versions, which carried over into Darwin.

But, it was at least partially fixed in 10.4, if you issued the command as root. See for example RE: issue with chown -h and symlinks on 10.3.9 and the rest of that topic. I haven't really looked at this since then.

There were some more interesting topics discussing this (before the fix) but they all seem to have been archived now. Basically these system calls were not initially implemented in the BSD kernel: lchflags(2), lchmod(2), lchown(2), lutimes(2). However the all important lchown(2) is present in 10.5 (as it was in 10.4):
macbook:/ root$ nm -x mach_kernel | grep lchown
001e438e 0f 01 0000 0003c4ae _lchown

Mar 14, 2008 8:28 PM in response to Michael Conniff

as Michael showed, in the nm output. lchmod isn't implemented in the Darwin kernel.

Also, there is no manpage for lchown. but it's referenced by the following manpage.

[symlink(7)|http://developer.apple.com/documentation/Darwin/Reference/ManPages/m an7/symlink.7.html#//apple_ref/doc/man/7/symlink]

And a quick look at the kernel

andya Macintosh:/:111> nm -x /mach.sym | grep chmod
001d9f6a 03 00 0000 000240bb _chmod
001d9e09 03 00 0000 000240c2 chmodextended
001da1e6 03 00 0000 00027527 _fchmod
001da084 03 00 0000 0002752f fchmodextended

The only reference to the lchmod that I was able to find in the kernel source was
in the "bsd/sys/stat.h" file:

int lchmod(const char *, mode_t);

But this prototype is all that there is. The function isn't defined. There is also a reference to the function _lchmod in the dynmaic library that chmod(1) is linked to:

/usr/lib/libSystem.B.dylib
000abe87 0f 01 0000 00008925 _lchmod

So it appears that OS X still doesn't support changing the permissions/mode of a symbolic link.

Mar 14, 2008 9:54 PM in response to Nils C. Anderson

..." So it appears that OS X still doesn't support changing the permissions/mode of a symbolic link."...

' chmod -h' is working here (for permissions, but not ACLs) and I'm pretty sure it was working in Tiger - but permissions on symbolic links seem to be irrelevant anyway.
Eg:<pre>
$ echo blah > file
$ ln -s file link
$ ls -ln file link
-rw-r--r-- 1 502 502 4 Mar 15 00:20 file
lrwxr-xr-x 1 502 502 4 Mar 15 00:20 link -> file
$ chmod -h 700 link
$ ls -ln file link
-rw-r--r-- 1 502 502 4 Mar 15 00:20 file
lrwx------ 1 502 502 4 Mar 15 00:20 link -> file</pre>

So ' chmod -h' works in principle, but eg.:<pre>
$ chmod -h 0 link
$ ls -ln file link
-rw-r--r-- 1 502 502 4 Mar 15 00:20 file

ls: link: Permission denied
l--------- 1 502 502 4 Mar 15 00:20 link
$ cat link
blah</pre>

I never did understand that.

But getting back to the original problem, there is something strange going on here. From the command line, I can't manipulate ACLs on symbolic links at all. Whether using ' chmod -h or setting inherit rules on a folder then creating a link, I can't generate a symbolic link with an ACL.

However, "Finder" apparently can. So to remove ACLs from a symbolic link, the only workaround I can see is to remove them from the parent folder if applicable, then use "Get Info" to apply the folder's permissions/ACLs to "enclosed items".

Mar 15, 2008 1:29 AM in response to apfelfresser

thanks a lot for the help and info everybody! at least i know now exactly what the problem is.

Michael Conniff wrote:
But, it was at least partially fixed in 10.4, if you issued the command as root.

does that mean if I get to boot 10.4 Panther from an old CD, I should be able to delete those ACLs? Or is there any BSD-Live CD that can boot on Apple hardware and supports ACLs on symbolic links? if that won't work i'll give up.. :-/

Mar 15, 2008 6:05 AM in response to biovizier

$ ls -ln file link
-rw-r--r-- 1 502 502 4 Mar 15 00:20 file
ls: link: Permission denied
l--------- 1 502 502 4 Mar 15 00:20 link
$ cat link
blah

I never did understand that.


Are you referring to the "Permission denied" message. the permissons on the symlink are preventing you from reading the symlinks contents, which is the name of the file that it's linked too. Notice that it's missing the '-> file' bit.

Message was edited by: Nils C. Anderson

Mar 15, 2008 6:19 AM in response to Nils C. Anderson

Thanks. Actually, what seems strange to me is that despite the link "link" having a mode of "0", it is possible to follow it, and to ' cat' the original file.

I recognize that I do have "read" privileges for the original file "file", but what's the point of having (and by extension, modfying) permissions on a symbolic link if the permissions don't seem to do anything?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Unable to change ACL-permissions for symbolic links

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.