X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=inc%2Fldap.inc;h=5cfc9681a4fe150f1dcb887c47f83964aa3f5529;hb=146a150c46184f161342f76afa9947bb956f5b28;hp=d70c322258f75c41c4341802e320b1261f614751;hpb=e586807dafc64c3fe152ab518599e6cf3f0f84e1;p=mirrors%2FKyberia-bloodline.git diff --git a/inc/ldap.inc b/inc/ldap.inc index d70c322..5cfc968 100644 --- a/inc/ldap.inc +++ b/inc/ldap.inc @@ -1,10 +1,3 @@ -ldif['cn'] = $uid; $this->ldif['sn'] = $uid; $this->ldif['hkid'] = $hkid; - $this->ldif['userpassword'] = "{clear}".$password; + $this->ldif['userpassword'] = "{SHA}".base64_encode(pack("H*", sha1($password))); $this->ldif['o'] = "h-k.sk"; // $this->ldif['homeDirectory'] = "/home/".$hkid; // $this->ldif['loginShell'] = "/bin/false"; @@ -65,6 +58,30 @@ class LDAPuser { } + function ldap_mysql_sync($uid,$hkid,$password) { + + $admindn = "cn=kyberia,ou=Directory Administrators,dc=h-k,dc=sk"; + $adminpw = "abcd123"; + + $this->dn = "ou=People,dc=h-k,dc=sk"; + + $this->ldif['cn'] = $uid; + $this->ldif['sn'] = $uid; + $this->ldif['hkid'] = $hkid; + $this->ldif['userpassword'] = "{SHA}".base64_encode(pack("H*", sha1($password))); + $this->ldif['o'] = "h-k.sk"; + $this->ldif['uid'] = $uid; + + $c = ldap_connect("localhost"); + $b = ldap_bind($c, $admindn, $adminpw); + $r = ldap_modify($c, "hkid=".$hkid.",".$this->dn, $this->ldif); + + system("echo \"".$uid.":".$hkid."(".ldap_error($c).")\" >> /tmp/ldapsync.log"); + + ldap_close($c); + + } + function change_pass($uid,$old_pass,$new_pass) { $c = ldap_connect("localhost"); @@ -88,15 +105,47 @@ class LDAPuser { } $b = ldap_bind($c, $this->dn, $old_pass); - echo "binding".$this->dn." with $old_pass"; +// echo "binding".$this->dn." with $old_pass"; if ($b) { - $this->ldif['userpassword'] = "{clear}".$new_pass; + $this->ldif['userpassword'] = "{SHA}".base64_encode(pack("H*", sha1($new_pass))); $mod_ret = ldap_modify($c, $this->dn, $this->ldif); return $mod_ret; } return false; +}} + + function change_pass_forced($uid,$pass) { + + $c = ldap_connect("localhost"); + $adminpw = "abcd123"; + $admindn = "cn=kyberia,ou=Directory Administrators,dc=h-k,dc=sk"; + + if ($c) { + $this->dn = "ou=People,dc=h-k,dc=sk"; + $this->values = array("dn"); + $this->filter = "hkid=".$uid; + + $sr = ldap_search($c, $this->dn, $this->filter, $this->values); + + $res = ldap_get_entries($c, $sr); + $this->dn = $res[0]["dn"]; + + if ($res['count'] != 1) { + return false; + } + + $b = ldap_bind($c, $admindn, $adminpw); +// echo "changing password to ".$this->dn.""; + if ($b) { + $this->ldif['userpassword'] = "{SHA}".base64_encode(pack("H*", sha1($pass))); + $mod_ret = ldap_modify($c, $this->dn, $this->ldif); + return $mod_ret; + } + + return false; + }} function auth($uid,$password) {