email protected>> ## ## $Id: ct_ldap.inc,v 1.1.2.1 2000/04/09 19:50:32 chuck Exp $ ## ## PHPLIB Data Storage Container using a LDAP database ## class CT_Ldap { ## ## Configurable parameters ## var $ldap_host = "localhost"; var $ldap_port = 389; var $basedn = "dc=comapny, dc=com"; var $rootdn = "cn=root, dc=comapny, dc=com"; var $rootpw = "secret"; var $objclass = "phplibdata"; ## end of configuration var $ds; function ac_start() { $this->ds = ldap_connect($this->ldap_host, $this->ldap_port); if(!$this->ds) { $this->ac_halt("LDAP connect failed"); } if(!ldap_bind($this->ds, $this->rootdn, $this->rootpw)) { $this->ac_halt("LDAP bind failed"); } } function ac_halt($msg="") { echo "Session_ldap failed: ".htmlentities($msg)."

\n"; exit; } function ac_gc($gc_time, $name) { $timeout =time(); $ldapdate =date("YmdHis", $timeout - ($gc_time * 60)); $sr =ldap_search($this->ds, $this->basedn, "(&(cn=*_$name)(modifytimestamp<=$ldapdate))"); $inf =ldap_get_entries($this->ds, $sr); for ($i=0; $i<$inf["count"];$i++) { ldap_delete($this->ds, $inf[$i]["dn"]); } ldap_free_result($sr); } function ac_store($id, $name, $str) { $ret = true; $ldapdate =date("YmdHis", time()); $dn = "cn=${id}_$name, ".$this->basedn; $entry = array( "cn" => "${id}_$name", "str" => $str, "objectclass" => $this->objclass, "modifytimestamp" => $ldapdate ); if(! <email protected>($this->ds, $dn, $entry)) { if(!ldap_add($this->ds, $dn, $entry)) { $ret =false; } } return $ret; } function ac_delete($id, $name) { ldap_delete($this->ds, "cn=${id}_$name, ".$this->basedn); } function ac_get_value($id, $name) { $str =""; $sr =ldap_search($this->ds, $this->basedn, "cn=${id}_$name"); $inf =ldap_get_entries($this->ds, $sr); if ($inf["count"] > 0 && $inf[0]["str"]["count"] > 0) { $str =$inf[0]["str"][0]; } ldap_free_result($sr); return $str; } function ac_release_lock() { } function ac_get_lock() { } function ac_newid($str, $name) { return $str; } function ac_auth($username, $password) { ## we need a username and a md5() encrypted password $sr = ldap_search($this->ds, $this->basedn, "username=$username"); if(ldap_count_entries($this->ds, $sr) > 0) { $inf = ldap_get_entries($this->ds, $sr); $passmd5 = $inf[0]["password"][0]; if(md5($password) == $passmd5) { return array($inf[0]["uid"][0], $inf[0]["perms"][0]); } } return array(); } }; ?>