Operating System - HP-UX
1823274 Members
3561 Online
109648 Solutions
New Discussion юеВ

How do you change permissions on a logical link?

 
SOLVED
Go to solution
John Goetz
Advisor

How do you change permissions on a logical link?

Example:

#pwd
/var/spool/lp
# ln -s /var/adm/lp/log log

Would like /var/spool/lp/log to has a sticky bit.

10 REPLIES 10
Steven E. Protter
Exalted Contributor

Re: How do you change permissions on a logical link?

chmod will do the job same as any other file. You probably have to hit the actual file, not the soft link.

I've noticed in the past thad chmod -R doesnt change soft links.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Steven E. Protter
Exalted Contributor

Re: How do you change permissions on a logical link?

chmod will do the job same as any other file. You probably have to hit the actual file, not the soft link.

I've noticed in the past thad chmod -R doesnt change soft links.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Simon Hargrave
Honored Contributor

Re: How do you change permissions on a logical link?

John, you cannot do this. The permissions of a symbolic link are ignored by the system, and only the real permissions of the "target" are taken into account.

See "man 4 symlink" for more details.

Simon
Patrick Wallek
Honored Contributor

Re: How do you change permissions on a logical link?

The link permissions do NOT matter. As long as the sticky bit is set on /var/adm/lp/log itself you should be OK.
Fabio Ettore
Honored Contributor
Solution

Re: How do you change permissions on a logical link?

Hi,

as SEP said you should change the main file in order to have other permissions on link.

Anyway I see that both files are on the same filesystem (/var).
Then you can create an hard link, no soft link:

#pwd
/var/spool/lp
# ln /var/adm/lp/log log

Then you can change permissions on link too.
In order to set sticky bit:

#pwd
/var/spool/lp
# chmod 1555 log
# ll log
-r-xr-xr-t 2 root sys 15096 Mar 2 10:35 log

Does it help you?

Best regards,
Fabio
WISH? IMPROVEMENT!
A. Clay Stephenson
Acclaimed Contributor

Re: How do you change permissions on a logical link?

If you really want to do this, there is a way. Several months ago this question came up and being curious I did a little digging and decided that there had to be a system call to do this. It turns out that there is an undocumented system call, lchmod(), which acts on symbolic links just as its documented counterpart, chmod(), acts on regular files. There is no command so you will need to compile it yourself. I intentionally did it in K&R C so that even the bundled C compiler will handle it.

Compile/link it like this:

cc lchmod.c -o lchmod

Execute it like this:

lchmod 1755 symlink1 [symlink2 ...]

NOTE: This puppy only understands octal modes. It is left as a student exercise to make it understamd symbolic (e.g. rwx) modes.

If it ain't broke, I can fix that.
Simon Hargrave
Honored Contributor

Re: How do you change permissions on a logical link?

I believe that is for "novelty purposes only" though, since regardless of the permissions set, the OS will still ignore them.

I just compiled and tested you program, lchmod 000'd a symlink, and I could still view it.
RAC_1
Honored Contributor

Re: How do you change permissions on a logical link?

As others have told if you try changing the perms on link, it will change the perms on the actual file.

You can also use lchmod call as told by AC.
Or you can just remove the link, set up the umask as you want and re-create the link.

Anil
There is no substitute to HARDWORK
A. Clay Stephenson
Acclaimed Contributor

Re: How do you change permissions on a logical link?

While it is true that the OS ignores the mode of the symbolic link (even if set to 000) there are a few cases where the permissions of the softlink itself matter. In HP-UX, the softlink's sticky bit (Octal 1000) is often used as a flag for the Software Distribution System. In all cases, access to the referenced file is controlled by the mode of the referenced file itself and not the mode/owner/group of the symbolic 0link.

If it ain't broke, I can fix that.
Tim D Fulford
Honored Contributor

Re: How do you change permissions on a logical link?

I would not worry

I use the following to follow the link to get the "real" permissions, even of linked files..

ls -lL

Regards

Tim
-