/usr/share/arc/ldap-monitor/includes/cnvname.inc is in nordugrid-arc-ldap-monitor 5.0.5-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | <?php
// Author: oxana.smirnova@hep.lu.se
// Some name conversion
/**
* @return string
* @param uname string
* @param flag integer
* @desc Takes user DN and attempts to extract a human name
*/
function cnvname ( $uname, $flag="0" )
{
$uname = trim($uname); /* Just for the case, trimming whitespaces */
$needle = "CN=";
$cn = substr(stristr($uname, $needle),3); /* gives "John M. Smith 123/blah" */
$tailpos = strpos($cn, "/");
if ( $tailpos ) $cn = substr($cn,0,$tailpos); /* gives "John M. Smith 123" */
eval("\$cn = \"$cn\";");
$names = explode(" ",$cn); /* gives ("John","M.","Smith","123") */
$nn = count($names); /* gives 4 */
$family = $names[$nn-1]; /* returns "123" */
if ( $nn > 1 && $family != "Doe") { /* catch for the tutorials */
$doestr = substr($family,1,1); /* returns "1" if it is a number, or a letter if it's a name */
if ( preg_match("/[0-9]/",$doestr) ) {
$number = array_pop($names);
$family = end($names);
}
// $family = substr(strrchr($uname, " "), 1);
$name = $cn{0}."."; /* First letter of the name (doesn't work with 8-bit strings) */
if ( $flag == 2 ) $name = $names[0];
eval("\$name = \"$name\";");
$family = $name." ".$family;
} else {
$family = $cn;
}
if ( !$family ) return $uname /* Give up */;
return $family;
}
/**
* @return string
* @param uname string
* @desc Takes user DN and attempts to extract her affiliation
*/
function getorg ( $uname )
{
$uname = trim($uname);
$pieces = explode("/L=", $uname);
if ( count($pieces) == 1 ) $pieces = explode("/DC=", $uname);
if ( count($pieces) == 1 ) $pieces = explode("/OU=", $uname);
if ( count($pieces) == 1 ) $pieces = explode("/O=", $uname);
$org = end($pieces);
$tailpos = strpos($org, "/");
if ( $tailpos ) $org = substr($org,0,$tailpos);
return $org;
}
?>
|