本文整理汇总了PHP中ldap_mod_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_mod_replace函数的具体用法?PHP ldap_mod_replace怎么用?PHP ldap_mod_replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_mod_replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAccount
function addAccount($_hookValues)
{
$mailLocalAddress = $_hookValues['account_lid'] . "@" . $this->profileData['defaultDomain'];
$ds = $GLOBALS['phpgw']->common->ldapConnect();
$filter = "uid=" . $_hookValues['account_lid'];
$sri = @ldap_search($ds, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter);
if ($sri) {
$allValues = ldap_get_entries($ds, $sri);
$accountDN = $allValues[0]['dn'];
$objectClasses = $allValues[0]['objectclass'];
unset($objectClasses['count']);
} else {
return false;
}
if (!in_array('qmailUser', $objectClasses) && !in_array('qmailuser', $objectClasses)) {
$objectClasses[] = 'qmailuser';
}
// the new code for postfix+cyrus+ldap
$newData = array('mail' => $mailLocalAddress, 'accountStatus' => 'active', 'objectclass' => $objectClasses);
ldap_mod_replace($ds, $accountDN, $newData);
#print ldap_error($ds);
}
示例2: updateProfile
public static function updateProfile($numero_membre, $data)
{
$handle_ldap = self::initialize();
if (self::$isDisabled) {
self::$logger->info("Ldap is disabled, doing nothing.");
return false;
}
$membreExists = @ldap_search($handle_ldap, "cn={$numero_membre}, " . self::$conf['basedn'], "objectclass=*", array("cn", "description", "mail"));
if ($membreExists) {
$personnes = ldap_get_entries($handle_ldap, $membreExists);
$personne = $personnes[0];
$dn = $personne["dn"];
//self::$logger->debug(print_r($personne, true));
$newEmail = self::$conf['defaultEmail'];
if (isset($data['email']) && $data['email']) {
$newEmail = $data['email'];
}
$hasLdapEmail = @is_array($personne["mail"]);
$ldapData = ['mail' => [$newEmail]];
if ($hasLdapEmail) {
self::$logger->info("Replacing ldap email for #{$numero_membre}: {$newEmail}");
ldap_mod_replace($handle_ldap, $dn, $ldapData);
} else {
self::$logger->info("Adding ldap email for #{$numero_membre}: {$newEmail}");
ldap_mod_add($handle_ldap, $dn, $ldapData);
}
$err = ldap_error($handle_ldap);
if ($err != "Success") {
return $err;
}
} else {
return "Membre not found in ldap repo: #{$numero_membre}";
}
}
示例3: change_pass
function change_pass($user, $new_pass)
{
global $config;
global $ldap_connection;
get_ldap_connection($config['user'], $config['pass']);
if ($ldap_connection) {
$filter = "(sAMAccountName={$user})";
$result = ldap_search($ldap_connection, $config['domain_dn'], $filter);
ldap_sort($ldap_connection, $result, "sn");
$info = ldap_get_entries($ldap_connection, $result);
$isLocked = $info[0]["lockoutTime"];
if ($isLocked > 0) {
return msg('account_locked');
}
$userDn = $info[0]["distinguishedname"][0];
$userdata["unicodePwd"] = iconv("UTF-8", "UTF-16LE", '"' . $new_pass . '"');
$result = ldap_mod_replace($ldap_connection, $userDn, $userdata);
if (!$result) {
return msg(ldap_error($ldap_connection));
}
} else {
return msg("wrong_admin");
}
close_ldap_connection();
return "";
}
示例4: changeAttribute
/**
* changeAttribute
*
* change an attribute
*
*@param string $username
*@param array $array
*@return mixed
*/
public function changeAttribute($username, $array)
{
// array need to be keyed appropriately
$immid = $this->getPortalAttribute('uid', $username);
$immid = $immid[0];
return ldap_mod_replace($this->_portal_ds, "uid={$immid}, " . $this->_ldap['root'], $array);
}
示例5: changeOpenLDAPPwd
private function changeOpenLDAPPwd($objLdapBinding, $strUserDN, $strNewPwd)
{
include_once "sambahash.php";
$entry["sambaNTPassword"] = nt_hash($strNewPwd);
$this->logwriter->debugwrite('NT Hash:' . $entry["sambaNTPassword"]);
$entry["sambaLMPassword"] = lm_hash($strNewPwd);
$this->logwriter->debugwrite('LM Hash:' . $entry["sambaLMPassword"]);
$date = time();
$this->logwriter->debugwrite('Last Set:' . $date);
$entry["sambaPwdLastSet"] = $date;
$entry["sambaPwdMustChange"] = $date + 90 * 24 * 60 * 60;
$this->logwriter->debugwrite('Must Change:' . $entry["sambaPwdMustChange"]);
mt_srand((double) microtime() * 1000000);
$salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand());
$hash = "{SSHA}" . base64_encode(pack("H*", sha1($strNewPwd . $salt)) . $salt);
$entry["userPassword"] = $hash;
$entry["shadowLastChange"] = (int) ($date / 86400);
$this->logwriter->debugwrite('Shadow Last Change:' . $entry["shadowLastChange"]);
$res = ldap_mod_replace($objLdapBinding, $strUserDN, $entry) or $res = false;
if ($res) {
$this->success($strNewPwd);
return true;
} else {
//Failed to change user Password
$this->failure(8, array($strNewPwd, $newpass, ldap_error($objLdapBinding)));
return false;
}
}
示例6: ldap_update
function ldap_update($uid, $replace)
{
global $conn;
global $userDn;
try {
// Form the dn
$dn = "uid=" . $uid . "," . $userDn;
// Make the update
return ldap_mod_replace($conn, $dn, $replace);
} catch (Exception $e) {
return false;
}
}
示例7: changePassword
function changePassword($connection, $dn, $user)
{
global $ldap_connection;
global $ldap_error;
$result = login("cn=root,dc=cupdata,dc=com", "test");
echo $result;
echo "<br>";
echo $ldap_error;
var_dump($user);
if (ldap_mod_replace($ldap_connection, $dn, $user)) {
echo "<br>success<br>";
return 0;
} else {
echo "<br>failed<br>";
return 1;
}
}
示例8: _changePassword
/**
*/
protected function _changePassword($user, $oldpass, $newpass)
{
global $conf;
// Connect to the LDAP server.
$ds = ldap_connect($conf['kolab']['ldap']['server'], $conf['kolab']['ldap']['port']);
if (!$ds) {
throw new Passwd_Exception(_("Could not connect to LDAP server"));
}
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
// Bind anonymously, or use the phpdn user if available.
if (!empty($conf['kolab']['ldap']['phpdn'])) {
$phpdn = $conf['kolab']['ldap']['phpdn'];
$phppw = $conf['kolab']['ldap']['phppw'];
$result = @ldap_bind($ds, $phpdn, $phppw);
} else {
$result = @ldap_bind($ds);
}
if (!$result) {
throw new Passwd_Exception(_("Could not bind to LDAP server"));
}
// Make sure we're using the full user@domain format.
if (strstr($user, '@') === false) {
$user .= '@' . $conf['kolab']['imap']['maildomain'];
}
// Find the user's DN.
$result = ldap_search($ds, $conf['kolab']['ldap']['basedn'], 'mail=' . $user);
$entry = ldap_first_entry($ds, $result);
if ($entry === false) {
throw new Passwd_Exception(_("User not found."));
}
$userdn = ldap_get_dn($ds, $entry);
// Connect as the user.
$result = @ldap_bind($ds, $userdn, $old_password);
if (!$result) {
throw new Passwd_Exception(_("Incorrect old password."));
}
// And finally change the password.
$new_details['userPassword'] = '{sha}' . base64_encode(pack('H*', sha1($newpass)));
if (!ldap_mod_replace($ds, $userdn, $new_details)) {
throw new Passwd_Exception(ldap_error($ds));
}
ldap_unbind($ds);
}
示例9: change_pass
function change_pass($username)
{
global $LDAPHOST, $LDAPPORT, $ldap, $LDAPADMIN, $LDAPADMINPASS, $LDAPDATAFIELD, $LDAPLOCALDOMAIN, $LDAPDOMAIN;
if ($ldap) {
$bind = @ldap_bind($ldap, $LDAPADMIN . "@" . $LDAPLOCALDOMAIN, $LDAPADMINPASS);
if (!$bind) {
@ldap_close($ldap);
die('<p class="message">Your password is incorrect, please try again
<a href=javascript:history.back()>click here</a><br>');
}
$filter = "(sAMAccountName={$username})";
$results = ldap_search($ldap, $LDAPDOMAIN, $filter);
ldap_sort($ldap, $results, "sn");
$info = ldap_get_entries($ldap, $results);
if ($info['count'] < 1) {
@ldap_close($ldap);
die('<p class="message">Error occurred, please verify your user , <a href="javascript:history.back()">Go Back</a>');
}
$dn = $info[0]["dn"];
$stored_mail = $info[0][$LDAPDATAFIELD][0] or die('<p class="message">We could not get your info, please contact Support!');
$newPassw = genPassword("xxx0yY0yY");
$mailPass = $newPassw;
$newPassword = "\"{$newPassw}\"";
$len = strlen($newPassword);
$newPass = "";
for ($i = 0; $i < $len; $i++) {
$newPass .= "{$newPassword[$i]}";
}
$newPassword = $newPass;
$data_new["unicodePwd"][] = $newPassword;
if (ldap_mod_replace($ldap, $dn, $data_new)) {
return array(true, $stored_mail, $mailPass);
} else {
return array(false, 100, 100);
}
return array(true, $stored_mail, $mailPass);
} else {
return array(false, 0, 0);
}
// function
}
示例10: ajax_settags
/**
* Set tags for a contact
*/
function ajax_settags($dn, $tags)
{
global $conf;
global $LDAP_CON;
global $FIELDS;
if (!$FIELDS['_marker']) {
return;
}
header('Content-Type: text/html; charset=utf-8');
$tags = explode(',', $tags);
$tags = array_map('trim', $tags);
$tags = array_unique($tags);
$tags = array_diff($tags, array(''));
//strip empty ones
$entry[$FIELDS['_marker']] = $tags;
ldap_mod_replace($LDAP_CON, $dn, $entry);
foreach ($tags as $tag) {
print '<a href="index.php?marker=';
print rawurlencode($tag);
print '" class="tag">';
print htmlspecialchars($tag);
print '</a> ';
}
}
示例11: replace
/**
* Replace an entry and return a true or false result
*
* @param string $dn The DN which contains the attribute you want to replace
* @param string $attribute The attribute values you want to replace
*
* @return mixed result of comparison (true, false, -1 on error)
*
* @since 12.1
*/
public function replace($dn, $attribute)
{
return @ldap_mod_replace($this->_resource, $dn, $attribute);
}
示例12: updateAttribute
public function updateAttribute($dn, $attrib, $value)
{
$arr = array();
$arr[$attrib] = $value;
$status = ldap_mod_replace($this->conn, $dn, $arr);
if (!$status) {
$status = ldap_error($this->conn);
}
return $status;
}
示例13: ldap_first_entry
} else {
# Get objectClass values from user entry
$entry = ldap_first_entry($ldap, $search);
$ocValues = ldap_get_values($ldap, $entry, "objectClass");
# Remove 'count' key
unset($ocValues["count"]);
if (!in_array($answer_objectClass, $ocValues)) {
# Answer objectClass is not present, add it
array_push($ocValues, $answer_objectClass);
$ocValues = array_values($ocValues);
$userdata["objectClass"] = $ocValues;
}
# Question/Answer
$userdata[$answer_attribute] = '{' . $question . '}' . $answer;
# Commit modification on directory
$replace = ldap_mod_replace($ldap, $userdn, $userdata);
$errno = ldap_errno($ldap);
if ($errno) {
$result = "answermoderror";
error_log("LDAP - Modify answer (error {$errno} (" . ldap_error($ldap) . ")");
} else {
$result = "answerchanged";
}
}
}
#==============================================================================
# HTML
#==============================================================================
?>
<div class="result <?php
示例14: changeADPWD
private function changeADPWD($objLdapBinding, $strUserDN, $strNewPwd)
{
$newpassword = "\"" . $strNewPwd . "\"";
$newpass = mb_convert_encoding($newpassword, "UTF-16LE");
$entry["unicodePwd"] = $newpass;
$res = ldap_mod_replace($objLdapBinding, $strUserDN, $entry) or $res = false;
if ($res) {
$this->success($strNewPwd);
} else {
//Failed to change user Password
$this->failure(8, array($strNewPwd, $newpass, ldap_error($objLdapBinding)));
}
}
示例15: simpleQuery
/**
* Performs a request against the LDAP server
*
* The type of request (and the corresponding PHP ldap function called)
* depend on two additional parameters, added in respect to the
* DB_common interface.
*
* @param string $filter text of the request to send to the LDAP server
* @param string $action type of request to perform, defaults to search (ldap_search())
* @param array $params array of additional parameters to pass to the PHP ldap function requested
* @return result from ldap function or DB Error object if no result
*/
function simpleQuery($filter, $action = null, $params = null)
{
if ($action === null) {
$action = !empty($this->q_action) ? $this->q_action : $this->action;
}
if ($params === null) {
$params = count($this->q_params) > 0 ? $this->q_params : array();
}
if (!$this->isManip($action)) {
$base = $this->q_base ? $this->q_base : $this->base;
$attributes = array();
$attrsonly = 0;
$sizelimit = 0;
$timelimit = 0;
$deref = LDAP_DEREF_NEVER;
$sorting = '';
$sorting_method = '';
reset($params);
while (list($k, $v) = each($params)) {
if (isset(${$k})) {
${$k} = $v;
}
}
$this->sorting = $sorting;
$this->sorting_method = $sorting_method;
$this->attributes = $attributes;
# double escape char for filter: '(o=Przedsi\C4\99biorstwo)' => '(o=Przedsi\\C4\\99biorstwo)'
$filter = str_replace('\\', '\\\\', $filter);
$this->last_query = $filter;
if ($action == 'search') {
$result = @ldap_search($this->connection, $base, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);
} else {
if ($action == 'list') {
$result = @ldap_list($this->connection, $base, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);
} else {
if ($action == 'read') {
$result = @ldap_read($this->connection, $base, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);
} else {
return $this->ldapRaiseError(DB_ERROR_UNKNOWN_LDAP_ACTION);
}
}
}
if (!$result) {
return $this->ldapRaiseError();
}
} else {
# If first argument is an array, it contains the entry with DN.
if (is_array($filter)) {
$entry = $filter;
$filter = $entry["dn"];
} else {
$entry = array();
}
unset($entry["dn"]);
$attribute = '';
$value = '';
$newrdn = '';
$newparent = '';
$deleteoldrdn = false;
reset($params);
while (list($k, $v) = each($params)) {
if (isset(${$k})) {
${$k} = $v;
}
}
$this->last_query = $filter;
if ($action == 'add') {
$result = @ldap_add($this->connection, $filter, $entry);
} else {
if ($action == 'compare') {
$result = @ldap_add($this->connection, $filter, $attribute, $value);
} else {
if ($action == 'delete') {
$result = @ldap_delete($this->connection, $filter);
} else {
if ($action == 'modify') {
$result = @ldap_modify($this->connection, $filter, $entry);
} else {
if ($action == 'mod_add') {
$result = @ldap_mod_add($this->connection, $filter, $entry);
} else {
if ($action == 'mod_del') {
$result = @ldap_mod_del($this->connection, $filter, $entry);
} else {
if ($action == 'mod_replace') {
$result = @ldap_mod_replace($this->connection, $filter, $entry);
} else {
if ($action == 'rename') {
//.........这里部分代码省略.........