public function addUser($userId, $credentials)
{
if (!empty($this->_params['ad'])) {
throw new Horde_Auth_Exception(__CLASS__ . ': Adding users is not supported for Active Directory.');
}
if (isset($credentials['ldap'])) {
$entry = $credentials['ldap'];
$dn = $entry['dn'];
/* Remove the dn entry from the array. */
unset($entry['dn']);
} else {
/* Try this simple default and hope it works. */
$dn = $this->_params['uid'] . '=' . $userId . ',' . $this->_params['basedn'];
$entry['cn'] = $userId;
$entry['sn'] = $userId;
$entry[$this->_params['uid']] = $userId;
$entry['objectclass'] = array_merge(array('top'), $this->_params['newuser_objectclass']);
$entry['userPassword'] = Horde_Auth::getCryptedPassword($credentials['password'], '', $this->_params['encryption'], 'true');
if ($this->_params['password_expiration'] == 'yes') {
$entry['shadowMin'] = $this->_params['minage'];
$entry['shadowMax'] = $this->_params['maxage'];
$entry['shadowWarning'] = $this->_params['warnage'];
$entry['shadowLastChange'] = floor(time() / 86400);
}
}
try {
$this->_ldap->add(Horde_Ldap_Entry::createFresh($dn, $entry));
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Auth_Exception(sprintf(__CLASS__ . ': Unable to add user "%s". This is what the server said: ', $userId) . $e->getMessage());
}
}