You are not logged in.

#1 2013-02-13 21:48:29

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

C, chown, chmod, symlinks and dereferencing

In C, if you want to stat a symlink you can use the non-dereferencing version of stat, namely lstat.
Is there a non-dereferencing version of the chown system call (i.e. lchown?).
The desired behavior is that of "chmod -h..." from the command-line. If no one has an answer then I will dig through the source of chmod to determine how it works.

What about chmod? Is it even possible to change the permission mode of a symlink? There does not seem to be any non-dereferencing options for the command-line utility.

Thanks.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2013-02-13 21:59:28

kaszak696
Member
Registered: 2009-05-26
Posts: 543

Re: C, chown, chmod, symlinks and dereferencing

man 2 chown shows that there indeed is a lchown system call. Manual for chmod doesn't mention lchmod, it seems to be declared in stat.h, but it's inside __USE_BSD define, not sure how that works. Some info about this: http://lists.gnu.org/archive/html//bug- … 00268.html

Last edited by kaszak696 (2013-02-13 22:04:19)


'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard

Offline

#3 2013-02-13 22:05:26

AaronBP
Member
Registered: 2012-08-06
Posts: 149
Website

Re: C, chown, chmod, symlinks and dereferencing

Is there a non-dereferencing version of the chown system call (i.e. lchown?).

Yep, looks that way. There's a man page for it.

lchmod looks like a BSD only thing, though.

EDIT:
Ah, guy above me found it first.

Last edited by AaronBP (2013-02-13 22:07:05)

Offline

#4 2013-02-13 22:57:17

progandy
Member
Registered: 2012-05-17
Posts: 5,180

Re: C, chown, chmod, symlinks and dereferencing

kaszak696 wrote:

man 2 chown shows that there indeed is a lchown system call. Manual for chmod doesn't mention lchmod, it seems to be declared in stat.h, but it's inside __USE_BSD define, not sure how that works. Some info about this: http://lists.gnu.org/archive/html//bug- … 00268.html

lchmod ist defined in unistd.h and is available on BSD as well as Linux (part of X/Open XA UNIX extensions)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2013-02-13 23:12:17

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: C, chown, chmod, symlinks and dereferencing

Thanks. I usually refer to the GNU C library documentation and there is no mention of lchown there.

Eric Blake, in the linked post, wrote:

Right now, gnulib has an lchmod replacement which always calls chmod; this will do the wrong thing if it is ever called on a symlink, but is right for everything else.

(emphasis mine)

Wow. yikes


edit: formatting

Last edited by Xyne (2013-02-13 23:12:41)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#6 2013-02-15 14:56:01

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: C, chown, chmod, symlinks and dereferencing

Lol. Seems like it would be better to omit lchmod entirely than to provide a version that does the wrong thing in the only possible situation where one might need it.

Offline

Board footer

Powered by FluxBB