Operating System - HP-UX
1829716 Members
3070 Online
109992 Solutions
New Discussion

Permission on Symbolic links

 
Arunvijai_4
Honored Contributor

Permission on Symbolic links

Hi All,

Can you anyone clarify why we get lrwxrwxrwx when a symbolic is created ? Is it depends on umask value ?

Thanks,
Arun
"A ship in the harbor is safe, but that is not what ships are built for"
21 REPLIES 21
RAC_1
Honored Contributor

Re: Permission on Symbolic links

Yes. You are right. umask decides that.
Also perms on links do not matter, as long as they have atleast read and file to which it points have right perms.
There is no substitute to HARDWORK
Steven E. Protter
Exalted Contributor

Re: Permission on Symbolic links

Also, the user that creats symbolic links owns them. They have to be planned,have a proper umask set by the user (profile) prior to being created.

In your situation, any and all users will be able to access the area being linked to. They may (hopefully) not be able to do anything if unauthorized by permissions after that.

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
Arunvijai_4
Honored Contributor

Re: Permission on Symbolic links

RAC,

Thank you, can you please expand a bit on how umask decides the permission. I just wanted to know a solid reason for getting lrwxrwxrwx.

Thanks,
Arun
"A ship in the harbor is safe, but that is not what ships are built for"
RAC_1
Honored Contributor

Re: Permission on Symbolic links

With umask you can not get execute perms.
Say I set umask of 000, then resulting files will be as follows.
-rw-rw-rw- 1 root sys 0 Sep 13 10:21 /tmp/test

What is does is as follows.

subtract umask from 666 - for files
subtract umask from 777 - for dirs

so with umask of 00, files will have 777 perms.

In your case, looks that some changed perms to 777. (perms on link can be changed with perms to 777.
There is no substitute to HARDWORK
morganelan
Trusted Contributor

Re: Permission on Symbolic links

umask only masks the default file and directory permissions

default file permission: -rw-rw-rw
default dir permission: -rwxrwxrwx

if you apply umkas of 022

access permissions of the new file created would be = 666 - 022 = 644 (rw-r--r--)

for dir = 777 - 022 = 755 (rwxr-xr-x)

If you need to set an executable bit from a shell created file, you must issue an explicit chmod after first creating the file.
Kamal Mirdad
Muthukumar_5
Honored Contributor

Re: Permission on Symbolic links

You can view umask value in display mode as,
# umask -S
u=rwx,g=rwx,o=rwx
# umask
00
#
# ln -s test.c link
# ls -l
total 16
lrwxrwxrwx 1 root sys 6 Sep 13 00:17 link -> test.c
-rw-rw-rw- 1 root sys 3 Sep 13 00:16 test.c
# umask 002
# umask -S
u=rwx,g=rwx,o=rx
# rm link
# ln -s test.c link
# ls -l
total 16
lrwxrwxr-x 1 root sys 6 Sep 13 00:18 link -> test.c
-rw-rw-rw- 1 root sys 3 Sep 13 00:16 test.c

When you change umask value, file permission is changed.

hth.
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: Permission on Symbolic links

Based on your answers, i understand umask is nothing to do while creating symbolic links.
{
umask=022
file=666
symlink to a file = 666-022 = 644
}

The above logic is wrong in symlink. Correct me if i am wrong.

--Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Bharat Katkar
Honored Contributor

Re: Permission on Symbolic links

Hi Arun,
To make it more clear....

Files are created with default permission as "666" and directories as "777".

Now umask default value is "022" so files and directories gets created with "644" and "755" respectively.

This happens as "777-022=755" and "666-022=644".

umask is substratcted from the default permissions of the files/directories.

So umask can control the default values of permission for files/directories being created.

You can change umask to have any permissions.

Hope that helps.
Regards,

You need to know a lot to actually know how little you know
Ivajlo Yanakiev
Respected Contributor

Re: Permission on Symbolic links

yes you are right.
links is special file :)
it take permission from original file.

if original files is
700
your link will take
700
but you will see 777 if you use ls -la.

Arunvijai_4
Honored Contributor

Re: Permission on Symbolic links

Why it is taking 777 ? That is my original question. Can anyone be more precise ?

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Bharat Katkar
Honored Contributor

Re: Permission on Symbolic links

Symbolic link depends on the umask value irrespective of file permissions.
If it is getting created as 777 then your umask value while creating sym link is 000.

Hard link is irresptive of umask and depends on file permission.

Regards,
You need to know a lot to actually know how little you know
VEL_1
Valued Contributor

Re: Permission on Symbolic links

Hi,

Permissions on a symbolic link doesn't really mean anything. You can not change the permissions of the symbolic link ( It will be like lrwxrwxrwx). If you attempt to chmod a symlink, you'll actually change the permissions on the file being pointed to.


Thanks.
VEL_1
Valued Contributor

Re: Permission on Symbolic links


If u worked on HP-UX means, Refer the following link:

http://www.unix.com/showpost.php?p=73792&postcount=5
Robert-Jan Goossens
Honored Contributor

Re: Permission on Symbolic links

For what its worths, you change the permissions of a link.

# ls -la
lrwxr-xr-x 1 root sys 10 Sep 13 10:26 gorj -> /home/gorj
# lchmod 777 gorj
# ll
lrwxrwxrwx 1 root sys 10 Sep 13 10:26 gorj -> /home/gorj

attached lchmod.

Regards,
Robert-Jan
morganelan
Trusted Contributor

Re: Permission on Symbolic links

By default, chmod follows symbolic links and changes the mode on the file pointed to by the symbolic link. Symbolic links do not have modes so using chmod on a symbolic link always succeeds and has no effect.

The -H, -L and -P options are ignored unless the -R option is specified. In addition, these options override each other and the command's actions are determined by the last one specified.

Options

-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.
-L If the -R option is specified, both symbolic links on the command line and symbolic links encountered in the tree traversal are followed.
-P If the -R option is specified, no symbolic links are followed.
-R If file designates a directory, chmod changes the mode of each file in the entire subtree connected at that point.
-h Do not follow symbolic links.
Kamal Mirdad
Muthukumar_5
Honored Contributor

Re: Permission on Symbolic links

Symbolic links are differentiated as,

1) hard link (forcible links)
2) soft link

When ever, a new file or directory is creating in forcible manner then it will get same file permission, ownership from source file / directory

# ls -l
total 16
-rw-rw-rw- 1 root sys 3 Sep 13 04:09 source
#
# ln -f source link
# ls -l
total 32
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 link
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 source

Symbolic links are following umask setting for directory generally (666). A symbolic file or directory will not contain any file contents. It is link to source. It is using with default directory umask setting.

You can get this from the following,

# umask 22
# mkdir hi
# ls -l
total 32
drwxr-xr-x 2 root sys 96 Sep 13 04:12 hi
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 link
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 source
# ln -s source link2
# ls -l
total 32
drwxr-xr-x 2 root sys 96 Sep 13 04:12 hi
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 link
lrwxr-xr-x 1 root sys 6 Sep 13 04:13 link2 -> source
-rw-rw-rw- 2 root sys 3 Sep 13 04:09 source
#

hi directory and new symbolic file link2 is using same permission setting.

hth.
Easy to suggest when don't know about the problem!
Ivajlo Yanakiev
Respected Contributor

Re: Permission on Symbolic links

there are two links
1. Hard links
it is one file with two names.
if you change permission on any name you will change permission on all name /this is in reality the same file/

you create this link

ln source link

2. Soft link
you create new file that point to source file.

you can not change permission on source using link. they are different files.

you create soft link using
ln -s source link

and your link will take permission from source but you will see 777 that is decision
by default.
Orhan Biyiklioglu
Respected Contributor

Re: Permission on Symbolic links

Taking 777 is a special way to specify the "don't care condition" on many unix systems.

Since the permission bits are a posix requirement for any file they must be specified in any case, therefore most systems adopt 777 for this purpose.

However, on HP-UX umask affects the permissions of the created symbolic link, but they still does not affect access rights to the original file.
Stephen Keane
Honored Contributor

Re: Permission on Symbolic links

If you set umask to all zeroes you'll get a link aith lrwxrwxrwx

e.g.

# touch file
# umask 000
# ln -s file link1
# umask 002
# ln -s file link2
# umask 022
# ln -s file link3
# umask 222
# ln -s file link4
# ll link*

should give

lrwxrwxrwx 1 root sys 4 Sep 13 16:22 link1 -> file
lrwxrwxr-x 1 root sys 4 Sep 13 16:22 link2 -> file
lrwxr-xr-x 1 root sys 4 Sep 13 16:22 link3 -> file
lr-xr-xr-x 1 root sys 4 Sep 13 16:22 link4 -> file


A. Clay Stephenson
Acclaimed Contributor

Re: Permission on Symbolic links

If you look at the symlink() system call, you will note that there is no mode argument like there is for the creat() system call which is used to create all other files. Symbolic links are always created with 777 mode (modified by the current umask value). Even in C (much less the shell), you only have the ability to alter the mode of the symlink via umask. Man 2 symlink, 2 creat for details.

If you are really concerned about the mode of symlinks (and the mode is ignored; only the mode of the object pointed to matters), there is a way to change them using the undocumented lchmod() system call. Compile the attached code like this:

cc -o lchmod lchmod.c

Use it like this:
lchmod 1666 symlink1 symlink2 ...

It only understand octal modes (what you refer to as permissions) but could be modified to understand symbolic modes. That is left as a student exercise (I don't feel inclined to use those stupid symbolic values). This code is intentionally done in K&R C so that even the Bundled C compiler will process it but could be converted to ANSI syntax in well under 1 minute.

If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: Permission on Symbolic links

Some of yopu may havbe missed this (very useful) URL above:

http://www.unix.com/showpost.php?p=73792&postcount=5

It gives an excellent overview of symlinks, both historical and from several flavors of Unix. It puts the HP-UX behavior into perspective.


Bill Hassell, sysadmin