diff --git a/lam/lib/ldap.php b/lam/lib/ldap.php index 3fda9385..979cbb37 100644 --- a/lam/lib/ldap.php +++ b/lam/lib/ldap.php @@ -154,7 +154,21 @@ class Ldap{ function close() { ldap_close($this->server); } - + + // searches LDAP for a specific user name + // and returns its DN entry + function search_username($name) { + // users have the attribute "posixAccount" or "sambaAccount" and uid $name + $filter = "(&(|(objectClass=posixAccount) (objectClass=sambaAccount)) (uid=$name))"; + $attrs = array(); + $sr = ldap_search($this->server, $this->conf->get_UserSuffix(), $filter, $attrs); + $info = ldap_get_entries($this->server, $sr); + // return only first DN entry + $ret = $info[0]["dn"]; + ldap_free_result($sr); + return $ret; + } + // returns the LDAP connection handle function server() { return $this->server; diff --git a/lam/lib/listgroups.php b/lam/lib/listgroups.php index 15f43413..11727e1f 100644 --- a/lam/lib/listgroups.php +++ b/lam/lib/listgroups.php @@ -29,7 +29,7 @@ include_once("ldap.php"); session_save_path("../sess"); @session_start(); -echo "hjhj\n"; +echo "listgroups\n"; echo "\n"; echo "\n"; echo "\n"; @@ -92,7 +92,25 @@ for ($i = 0; $i < sizeof($info)-1; $i++) { // ignore last entry in array which i // print all attribute entries seperated by "; " if (sizeof($info[$i][strtolower($attr_array[$k])]) > 0) { array_shift($info[$i][strtolower($attr_array[$k])]); - echo implode("; ", $info[$i][strtolower($attr_array[$k])]); + // generate links for group members + if (strtolower($attr_array[$k]) == "memberuid") { + $linklist = array(); + for ($d = 0; $d < sizeof($info[$i][strtolower($attr_array[$k])]); $d++) { + $user = $info[$i][strtolower($attr_array[$k])][$d]; // user name + $dn = $_SESSION["ldap"]->search_username($user); // DN entry + // if user was found in LDAP make link, otherwise just print name + if ($dn) { + $linklist[$d] = "" . + $info[$i][strtolower($attr_array[$k])][$d] . ""; + } + else $linklist[$d] = $user; + } + echo implode("; ", $linklist); + } + // print all other attributes + else { + echo implode("; ", $info[$i][strtolower($attr_array[$k])]); + } } echo (""); }