note 36884 deleted from function.fileperms by aidan
| From: | aidan@php.net | Date: | Sat, 10 Jul 2004 13:27:05 +0000 |
| Subject: | note 36884 deleted from function.fileperms by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72992@lists.php.net to get a copy of this message | ||
Note Submitter: zilinex@linuxmail.com
----
here is the correct translation for the fileperms like the ls shows is with the option -l :
function TranslatePerm( $in_Perms ) {
$sP;
if(($in_Perms & 0xC000) == 0xC000) // Socket
$sP = 's';
elseif(($in_Perms & 0xA000) == 0xA000) // Symbolic Link
$sP = 'l';
elseif(($in_Perms & 0x8000) == 0x8000) // Regular
$sP = '−';
elseif(($in_Perms & 0x6000) == 0x6000) // Block special
$sP = 'b';
elseif(($in_Perms & 0x4000) == 0x4000) // Directory
$sP = 'd';
elseif(($in_Perms & 0x2000) == 0x2000) // Character special
$sP = 'c';
elseif(($in_Perms & 0x1000) == 0x1000) // FIFO pipe
$sP = 'p';
else // UNKNOWN
$sP = 'u';
// owner
$sP .= (($in_Perms & 0x0100) ? 'r' : '−') .
(($in_Perms & 0x0080) ? 'w' : '−') .
(($in_Perms & 0x0040) ? (($in_Perms & 0x0800) ? 's' : 'x' ) :
(($in_Perms & 0x0800) ? 'S' :
'−'));
// group
$sP .= (($in_Perms & 0x0020) ? 'r' : '−') .
(($in_Perms & 0x0010) ? 'w' : '−') .
(($in_Perms & 0x0008) ? (($in_Perms & 0x0400) ? 's' : 'x' ) :
(($in_Perms & 0x0400) ? 'S' :
'−'));
// world
$sP .= (($in_Perms & 0x0004) ? 'r' : '−') .
(($in_Perms & 0x0002) ? 'w' : '−') .
(($in_Perms & 0x0001) ? (($in_Perms & 0x0200) ? 't' : 'x' )
:
(($in_Perms & 0x0200) ? 'T' :
'−'));
return $sP;
}
$file = lstat("/bin/bash");
echo TranslatePerm($file['mode']);
//(for HTML)
which lead to :
-rwxr-xr-x
the function mfunGetPerms does not return correct permissions.
for example :
$perm=fileperms("/dev/ttyS0" /*a symbolic link*/");
echo exec("ll /dev/ttyS0");
echo mfunGetPerms($perm);
echo TranslatePerm($perm);
lr-xr-xr-x 1 root root 5 Oct 19 11:10 /dev/ttyS0 -> tts/0l //exec
cr-xr-xr-x //mfunGetPerms
lr-xr-xr-x //TranslatePerm