#42711 [Opn->Bgs]: Unable to chown/chgrp of a symlink
| From: | iliaa@php.net | Date: | Wed, 19 Sep 2007 19:51:09 +0000 |
| Subject: | #42711 [Opn->Bgs]: Unable to chown/chgrp of a symlink | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-117714@lists.php.net to get a copy of this message | ||
ID: 42711
Updated by: iliaa@php.net
Reported By: arnaud dot lb at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 5.2.4
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You need to use the lchown() function.
Previous Comments:
------------------------------------------------------------------------
[2007-09-19 14:17:09] arnaud dot lb at gmail dot com
Description:
------------
There is no way to change the owner or group of a symlink.
Using chown and chgrp functions on a symlink affect the file
referenced by the symbolic link, rather than the symbolic link
itself.
There should have a "$dereference" argument to be able to affect the
file referenced by the symlink or the symlink itself.
Reproduce code:
---------------
<?php
// Setup test files
if (file_exists('test-referent')) unlink('test-referent');
if (file_exists('test-symlink')||is_link('test-symlink'))
unlink('test-symlink');
touch('test-referent');
symlink('test-referent', 'test-symlink');
echo shell_exec('chown -h nobody test-symlink test-referent 2>&1');
echo "Original owners: \n";
echo shell_exec("ls -l test-referent test-symlink") . "\n";
// Test changing symlink owner with PHP's chown() function
chown('test-symlink', 'root');
echo "New owners: \n";
echo shell_exec("ls -l test-referent test-symlink");
?>
Expected result:
----------------
chown should affect symlink owner instead of the referenced file
Original owners:
-rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink ->
test-referent
New owners:
-rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 root root 13 2007-09-19 16:04 test-symlink ->
test-referent
Actual result:
--------------
chown has affected the referenced file instead of the symlink itself
Original owners:
-rw-r--r-- 1 nobody root 0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink ->
test-referent
New owners:
-rw-r--r-- 1 root root 0 2007-09-19 16:04 test-referent
lrwxrwxrwx 1 nobody root 13 2007-09-19 16:04 test-symlink ->
test-referent
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42711&edit=1