1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Passwd_Driver_Kolab extends Passwd_Driver
17: {
18: 19: 20: 21: 22: 23: 24: 25: 26:
27: public function changePassword($username, $old_password, $new_password)
28: {
29:
30: $ds = ldap_connect(
31: $GLOBALS['conf']['kolab']['ldap']['server'],
32: $GLOBALS['conf']['kolab']['ldap']['port']
33: );
34: if (!$ds) {
35: throw new Passwd_Exception(_("Could not connect to LDAP server"));
36: }
37:
38: ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
39:
40:
41: if (!empty($GLOBALS['conf']['kolab']['ldap']['phpdn'])) {
42: $phpdn = $GLOBALS['conf']['kolab']['ldap']['phpdn'];
43: $phppw = $GLOBALS['conf']['kolab']['ldap']['phppw'];
44: $result = @ldap_bind($ds, $phpdn, $phppw);
45: } else {
46: $result = @ldap_bind($ds);
47: }
48: if (!$result) {
49: throw new Passwd_Exception(_("Could not bind to LDAP server"));
50: }
51:
52:
53: if (strstr($username, '@') === false) {
54: $username .= '@' . $GLOBALS['conf']['kolab']['imap']['maildomain'];
55: }
56:
57:
58: $result = ldap_search(
59: $ds,
60: $GLOBALS['conf']['kolab']['ldap']['basedn'],
61: "mail=$username"
62: );
63: $entry = ldap_first_entry($ds, $result);
64: if ($entry === false) {
65: throw new Passwd_Exception(_("User not found."));
66: }
67:
68: $userdn = ldap_get_dn($ds, $entry);
69:
70:
71: $result = @ldap_bind($ds, $userdn, $old_password);
72: if (!$result) {
73: throw new Passwd_Exception(_("Incorrect old password."));
74: }
75:
76:
77: $new_details['userPassword'] = '{sha}' .
78: base64_encode(pack('H*', sha1($new_password)));
79:
80: if (!ldap_mod_replace($ds, $userdn, $new_details)) {
81: throw new Passwd_Exception(ldap_error($ds));
82: }
83:
84: ldap_unbind($ds);
85: }
86: }
87: