Esempio n. 1
0
 /**
  */
 protected function _changePassword($user, $oldpass, $newpass)
 {
     parent::_changePassword($user, $oldpass, $newpass);
     // Get existing user information.
     $entry = $this->_ldap->getEntry($this->_userdn);
     // Return if the user is not a Samba user.
     if (!in_array($this->_params['smb_objectclass'], $entry->getValue('objectClass', 'all'))) {
         return;
     }
     // Crypt_CHAP is not PSR-0 compatible.
     require_once 'Crypt/CHAP.php';
     $hash = new Crypt_CHAP_MSv2();
     $hash->password = $newpass;
     $lmpasswd = Horde_String::upper(bin2hex($hash->lmPasswordHash()));
     $ntpasswd = Horde_String::upper(bin2hex($hash->ntPasswordHash()));
     $settime = time();
     if (!is_null($this->_params['pw_expire_time'])) {
         // 24 hours/day * 60 min/hour * 60 secs/min = 86400 seconds/day
         $expiretime = $settime + $this->_params['pw_expire_time'] * 86400;
     } else {
         // This is NT's version of infinity time:
         // http://lists.samba.org/archive/samba/2004-January/078175.html
         $expiretime = 2147483647;
     }
     // All changes must succeed or fail together.  Attributes with
     // null name are not updated.
     $changes = array();
     if (!is_null($this->_params['lm_attribute'])) {
         $changes[$this->_params['lm_attribute']] = $lmpasswd;
     }
     if (!is_null($this->_params['nt_attribute'])) {
         $changes[$this->_params['nt_attribute']] = $ntpasswd;
     }
     if (!is_null($this->_params['pw_set_attribute'])) {
         $changes[$this->_params['pw_set_attribute']] = $settime;
     }
     if (!is_null($this->_params['pw_expire_attribute'])) {
         $changes[$this->_params['pw_expire_attribute']] = $expiretime;
     }
     if (count($changes) > 0) {
         try {
             $entry->replace($changes, true);
             $entry->update();
         } catch (Horde_Ldap_Exception $e) {
             throw new Passwd_Exception($e);
         }
     }
 }
 /**
  * Returns the content object of the attribute.
  *
  * @param mixed $contentObjectAttribute Class eZContentObjectAttribute.
  *
  * @return array
  */
 public function objectAttributeContent($contentObjectAttribute)
 {
     $data = $contentObjectAttribute->attribute('data_text');
     if ($data != '') {
         require_once 'Crypt/CHAP.php';
         $crypt = new Crypt_CHAP_MSv2();
         $crypt->password = $data;
         $ntPass = bin2hex($crypt->ntPasswordHash());
         $lmPass = bin2hex($crypt->lmPasswordHash());
         $result = array('plain' => $data, 'nt' => $ntPass, 'nt_prefix' => '0x' . $ntPass, 'lm' => $lmPass, 'lm_prefix' => '0x' . $lmPass);
     } else {
         $result = array('plain' => '', 'nt' => '', 'nt_prefix' => '', 'lm' => '', 'lm_prefix' => '');
     }
     return $result;
 }