External
|
|
|
|
<?php
function whereis ($filename){
$path = GetEnv('path') or GetEnv('PATH') or GetEnv('Path');
$paths = explode(';', $path);
//Throw in a few more places to look
$paths[] = '/usr/bin/';
$paths[] = '/usr/sbin/';
$paths[] = '/usr/local/bin/';
$paths[] = '/usr/local/sbin/';
$paths[] = './';
$paths[] = './cgi/';
$whereis = '';
reset($paths);
while (!$whereis && (list(,$p) = each($paths))){
if ($p){
$end = $p[strlen($p)-1];
if ($end != '/' && $end != '\'){
$p .= '/';
}
$f = $p . $filename;
if (file_exists($f)){
$perms = fileperms($f);
$owner = fileowner($f);
$myuid = getmyuid();
//Enhancement: If somebody could figure out how to chase down
//Group IDs without invoking exec() et al...
if (($perms & 1) || (($perms & 64) && ($owner == $myuid))){
$whereis = $f;
}
}
}
}
return $whereis;
}
/*
echo "Whereis: ", whereis('whereis'), "<BR>n";
echo "Whoami: ", whereis('whoami'), "<BR>n";
echo "asdf: ", whereis('asdf'), "<BR>n";
*/
?>
|
|
|
Usage Example
|
echo "Whereis: ", whereis('whereis'), "<BR>n";
echo "Whoami: ", whereis('whoami'), "<BR>n";
echo "asdf: ", whereis('asdf'), "<BR>n";
|
|
|
Rate This Script
|
|
|
|