本文整理汇总了PHP中ldap_rename函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_rename函数的具体用法?PHP ldap_rename怎么用?PHP ldap_rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_rename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the entry on the directory server
*
* This will evaluate all changes made so far and send them
* to the directory server.
* Please note, that if you make changes to objectclasses wich
* have mandatory attributes set, update() will currently fail.
* Remove the entry from the server and readd it as new in such cases.
* This also will deal with problems with setting structural object classes.
*
* @param Net_LDAP2 $ldap If passed, a call to setLDAP() is issued prior update, thus switching the LDAP-server. This is for perl-ldap interface compliance
*
* @access public
* @return true|Net_LDAP2_Error
* @todo Entry rename with a DN containing special characters needs testing!
*/
public function update($ldap = null)
{
if ($ldap) {
$msg = $this->setLDAP($ldap);
if (Net_LDAP2::isError($msg)) {
return PEAR::raiseError('You passed an invalid $ldap variable to update()');
}
}
// ensure we have a valid LDAP object
$ldap =& $this->getLDAP();
if (!$ldap instanceof Net_LDAP2) {
return PEAR::raiseError("The entries LDAP object is not valid");
}
// Get and check link
$link = $ldap->getLink();
if (!is_resource($link)) {
return PEAR::raiseError("Could not update entry: internal LDAP link is invalid");
}
/*
* Delete the entry
*/
if (true === $this->_delete) {
return $ldap->delete($this);
}
/*
* New entry
*/
if (true === $this->_new) {
$msg = $ldap->add($this);
if (Net_LDAP2::isError($msg)) {
return $msg;
}
$this->_new = false;
$this->_changes['add'] = array();
$this->_changes['delete'] = array();
$this->_changes['replace'] = array();
$this->_original = $this->_attributes;
$return = true;
return $return;
}
/*
* Rename/move entry
*/
if (false == is_null($this->_newdn)) {
if ($ldap->getLDAPVersion() !== 3) {
return PEAR::raiseError("Renaming/Moving an entry is only supported in LDAPv3");
}
// make dn relative to parent (needed for ldap rename)
$parent = Net_LDAP2_Util::ldap_explode_dn($this->_newdn, array('casefolding' => 'none', 'reverse' => false, 'onlyvalues' => false));
if (Net_LDAP2::isError($parent)) {
return $parent;
}
$child = array_shift($parent);
// maybe the dn consist of a multivalued RDN, we must build the dn in this case
// because the $child-RDN is an array!
if (is_array($child)) {
$child = Net_LDAP2_Util::canonical_dn($child);
}
$parent = Net_LDAP2_Util::canonical_dn($parent);
// rename/move
if (false == @ldap_rename($link, $this->_dn, $child, $parent, true)) {
return PEAR::raiseError("Entry not renamed: " . @ldap_error($link), @ldap_errno($link));
}
// reflect changes to local copy
$this->_dn = $this->_newdn;
$this->_newdn = null;
}
/*
* Carry out modifications to the entry
*/
// ADD
foreach ($this->_changes["add"] as $attr => $value) {
// if attribute exists, add new values
if ($this->exists($attr)) {
if (false === @ldap_mod_add($link, $this->dn(), array($attr => $value))) {
return PEAR::raiseError("Could not add new values to attribute {$attr}: " . @ldap_error($link), @ldap_errno($link));
}
} else {
// new attribute
if (false === @ldap_modify($link, $this->dn(), array($attr => $value))) {
return PEAR::raiseError("Could not add new attribute {$attr}: " . @ldap_error($link), @ldap_errno($link));
}
}
// all went well here, I guess
//.........这里部分代码省略.........
示例2: UserMod
public function UserMod($username, $attributes = array())
{
// Clone the attributes array
$attr = array_merge($attributes, array());
$Usr = $this->UserGet($username);
if ($Usr) {
$OldCn = $Usr['cn'];
$NewCn = $attr['cn'];
if ($NewCn == $OldCn) {
// Same CN, no need to pass it as an argument
unset($attr['cn']);
} else {
// Rename user
ldap_rename($this->conn, 'CN=' . $OldCn . ',CN=Users,' . $this->BaseDn, 'CN=' . $NewCn, null, true);
unset($attr['cn']);
}
return ldap_modify($this->conn, $this->GetUserDnByCn($NewCn), $attr);
} else {
return;
}
}
示例3: moveuser
function moveuser()
{
$u = new user($_POST["userid"]);
$dn = $u->dn;
$gplist = $u->Groups_list();
if (preg_match("#^(.+?),#", $dn, $re)) {
$newRdn = $re[1];
} else {
$newRdn = "cn={$_POST["userid"]}";
}
$ldap = new clladp();
$newParent = "ou=users,ou={$_POST["nextou"]},dc=organizations,{$ldap->suffix}";
if (!ldap_rename($ldap->ldap_connection, $dn, $newRdn, $newParent, true)) {
echo 'Error number ' . ldap_errno($ldap->ldap_connection) . "\nAction:LDAP Ldap_rename\ndn:{$dn} -> {$newRdn},{$newParent}\n" . ldap_err2str(ldap_errno($ldap->ldap_connection));
return;
}
while (list($gid, $name) = each($gplist)) {
$gp = new groups($gid);
$gp->DeleteUserFromThisGroup($_POST["userid"]);
}
}
示例4: update
/**
* Updates the entry on the directory server.
*
* This will evaluate all changes made so far and send them to the
* directory server.
*
* If you make changes to objectclasses wich have mandatory attributes set,
* update() will currently fail. Remove the entry from the server and readd
* it as new in such cases. This also will deal with problems with setting
* structural object classes.
*
* @todo Entry rename with a DN containing special characters needs testing!
*
* @throws Horde_Ldap_Exception
*/
public function update()
{
/* Ensure we have a valid LDAP object. */
$ldap = $this->getLDAP();
/* Get and check link. */
$link = $ldap->getLink();
if (!is_resource($link)) {
throw new Horde_Ldap_Exception('Could not update entry: internal LDAP link is invalid');
}
/* Delete the entry. */
if ($this->_delete) {
return $ldap->delete($this);
}
/* New entry. */
if ($this->_new) {
$ldap->add($this);
$this->_new = false;
$this->_changes['add'] = array();
$this->_changes['delete'] = array();
$this->_changes['replace'] = array();
$this->_original = $this->_attributes;
return;
}
/* Rename/move entry. */
if (!is_null($this->_newdn)) {
if ($ldap->getVersion() != 3) {
throw new Horde_Ldap_Exception('Renaming/Moving an entry is only supported in LDAPv3');
}
/* Make DN relative to parent (needed for LDAP rename). */
$parent = Horde_Ldap_Util::explodeDN($this->_newdn, array('casefolding' => 'none', 'reverse' => false, 'onlyvalues' => false));
$child = array_shift($parent);
/* Maybe the DN consist of a multivalued RDN, we must build the DN
* in this case because the $child RDN is an array. */
if (is_array($child)) {
$child = Horde_Ldap_Util::canonicalDN($child);
}
$parent = Horde_Ldap_Util::canonicalDN($parent);
/* Rename/move. */
if (!@ldap_rename($link, $this->_dn, $child, $parent, true)) {
throw new Horde_Ldap_Exception('Entry not renamed: ' . @ldap_error($link), @ldap_errno($link));
}
/* Reflect changes to local copy. */
$this->_dn = $this->_newdn;
$this->_newdn = null;
}
/* Carry out modifications to the entry. */
foreach ($this->_changes['add'] as $attr => $value) {
/* If attribute exists, add new values. */
if ($this->exists($attr)) {
if (!@ldap_mod_add($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not add new values to attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
} else {
/* New attribute. */
if (!@ldap_modify($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not add new attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
}
unset($this->_changes['add'][$attr]);
}
foreach ($this->_changes['delete'] as $attr => $value) {
/* In LDAPv3 you need to specify the old values for deleting. */
if (is_null($value) && $ldap->getVersion() == 3) {
$value = $this->_original[$attr];
}
if (!@ldap_mod_del($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not delete attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
unset($this->_changes['delete'][$attr]);
}
foreach ($this->_changes['replace'] as $attr => $value) {
if (!@ldap_modify($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not replace attribute ' . $attr . ' values: ' . @ldap_error($link), @ldap_errno($link));
}
unset($this->_changes['replace'][$attr]);
}
/* All went well, so $_attributes (local copy) becomes $_original
* (server). */
$this->_original = $this->_attributes;
}
示例5: syncGroup
//.........这里部分代码省略.........
} else {
if (!is_array($value) && $value != '') {
$entry[$key] = $value;
}
}
}
$result = ldap_add($conn, $dn, $entry);
if ($result !== true) {
$result = ldap_add($conn, $dn, $entry);
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['added'];
return true;
}
}
$ldapinfo = null;
$count = $entry ? ldap_count_entries($conn, $entry) : 0;
if ($count > 0) {
$firstentry = ldap_first_entry($conn, $entry);
$attr = ldap_get_attributes($conn, $firstentry);
if (!empty($attr) && $attr['count'] > 0) {
foreach ($reqattr as $key) {
unset($attr[$key]['count']);
if (isset($attr[$key][0])) {
if (count($attr[$key]) <= 1) {
$ldapinfo[$key] = $attr[$key][0];
} else {
$ldapinfo[$key] = $attr[$key];
}
} else {
$ldapinfo[$key] = null;
}
}
}
}
// If there was no database entry, and there was no ldap entry, nothing to do
if (empty($dbinfo) && empty($ldapinfo)) {
return true;
}
// If there was no database entry, but there was an ldap entry, delete the ldap entry
if (!empty($ldapinfo) && empty($dbinfo)) {
$dn = "cn=" . $ldapinfo['cn'] . ",ou=groups," . $hubLDAPBaseDN;
$result = ldap_delete($conn, $dn);
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['deleted'];
return true;
}
}
// Otherwise update the ldap entry
$entry = array();
if (!empty($ldapinfo['memberUid']) && !is_array($ldapinfo['memberUid'])) {
$ldapinfo['memberUid'] = array($ldapinfo['memberUid']);
}
foreach ($dbinfo as $key => $value) {
if ($ldapinfo[$key] != $dbinfo[$key]) {
if ($dbinfo[$key] === null) {
$entry[$key] = array();
} else {
$entry[$key] = $dbinfo[$key];
}
}
}
if (empty($entry)) {
++self::$success['unchanged'];
return true;
}
$dn = "cn=" . $ldapinfo['cn'] . ",ou=groups," . $hubLDAPBaseDN;
// See if we're changing cn...if so, we need to do a rename
if (array_key_exists('cn', $entry)) {
$result = ldap_rename($conn, $dn, 'cn=' . $entry['cn'], 'ou=groups,' . $hubLDAPBaseDN, true);
// Set aside new uid and unset from attributes needing to be changed
$newCn = $entry['cn'];
unset($entry['cn']);
// See if we have any items left
if (empty($entry)) {
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['modified'];
return true;
}
}
// Build new dn
$dn = "cn=" . $newCn . ",ou=groups," . $hubLDAPBaseDN;
}
// Now do the modify
$result = ldap_modify($conn, $dn, $entry);
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['modified'];
return true;
}
}
示例6: rename
/**
* Modify the name of an entry
*
* The entry specified by $dn is renamed/moved. The new RDN is specified by $newrdn and the
* parent/superior entry is specified by $newparent. If the parameter $deleteoldrdn is TRUE
* the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished
* values of the entry.
*
* @link http://www.php.net/ldap_rename
* @param string $dn The entry to be renamed/moved
* @param string $newrdn The new RDN
* @param string $newparent The DN of the new parent
* @param boolean $deleteoldrdn Do we delete the old RDN?
* @return boolean Success
*/
function rename($dn, $newrdn, $newparent, $deleteoldrdn)
{
if ($this->version != 3) {
$this->ldapErrno = -1;
$this->ldapError = "ldap_rename requires version 3 of the LDAP protocol";
return false;
}
if (@ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn)) {
return true;
}
$this->setErrVars();
return false;
}
示例7: rename
/**
* Rename the entry
*
* @param string $dn The DN of the entry at the moment
* @param string $newdn The DN of the entry should be (only cn=newvalue)
* @param string $newparent The full DN of the parent (null by default)
* @param boolean $deleteolddn Delete the old values (default)
*
* @return boolean Result of operation
*
* @since 12.1
*/
public function rename($dn, $newdn, $newparent, $deleteolddn)
{
return @ldap_rename($this->_resource, $dn, $newdn, $newparent, $deleteolddn);
}
示例8: rename
/**
* Renames a LDAP entity.
*
* @throws \gossi\ldap\LdapException If the rename fails.
* @param String $dn The distinguished name of a LDAP entity.
* @param String $newrdn The new RDN.
* @param String $newparent The new parent/superior entry.
* @param boolean $deleteoldrdn If true the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished values of the entry.
* @return boolean Returns true on success or false on failure.
*/
public function rename($dn, $newrdn, $newparent, $deleteoldrdn)
{
$success = ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn);
if (ldap_errno($this->conn)) {
throw new LdapException(ldap_error($this->conn), ldap_errno($this->conn));
}
return $success;
}
示例9: simpleQuery
//.........这里部分代码省略.........
$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') {
$result = @ldap_rename($this->connection, $filter, $newrdn, $newparent, $deleteoldrdn);
} else {
return $this->ldapRaiseError(DB_ERROR_UNKNOWN_LDAP_ACTION);
}
}
}
}
}
}
}
}
if (!$result) {
return $this->ldapRaiseError();
}
}
$this->freeQuery();
return $result;
}
示例10:
<?php
F3::call(":ldap_search");
$cn = "mahmut";
$cn_new = "murat";
echo "<hr /><b>cn = {$cn} kullanicisi \"{$cn_new}\" ile rename ediliyor ...</b><br />";
$r = @ldap_rename(F3::get('LDAP.conn'), "cn={$cn}," . F3::get('LDAP.ou'), "cn={$cn_new}", NULL, TRUE);
echo $r ? "Basarili" : "UYARI: boyle bir kayit bulunamadi";
echo "<hr />Dizinlerin guncel hali...<br />";
F3::call(":ldap_search");
ldap_close(F3::get('LDAP.conn'));
示例11: saveExtension
/**
* Save an extension to the LDAP tree
*
* @param string $account Account to which the user should be added
*
* @param string $extension Extension to be saved
*
* @param array $details Phone numbers, PIN, options, etc to be saved
*
* @return TRUE on success, PEAR::Error object on error
* @throws Shout_Exception
*/
public function saveExtension($account, $extension, $details)
{
// Check permissions
parent::saveExtension($account, $extension, $details);
// FIXME: Fix and uncomment the below
// // Check to ensure the extension is unique within this account
// $filter = "(&(objectClass=AstVoicemailMailbox)(context=$account))";
// $reqattrs = array('dn', $ldapKey);
// $res = @ldap_search($this->_LDAP, $this->_params['basedn'],
// $filter, $reqattrs);
// if ($res === false) {
// $msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP),
// ldap_error($this->_LDAP));
// Horde::log($msg, 'ERR');
// throw new Shout_Exception(_("Error while searching the directory. Details have been logged for the administrator."));
// }
// if (($res['count'] != 1) ||
// ($res['count'] != 0 &&
// !in_array($res[0][$ldapKey], $details[$appKey]))) {
// throw new Shout_Exception(_("Duplicate extension found. Not saving changes."));
// }
// FIXME: Quote these strings
$uid = $extension . '@' . $account;
$entry = array('objectClass' => array('top', 'account', 'AsteriskVoicemail', 'AsteriskUser'), 'uid' => $uid, 'cn' => $details['name'], 'AstVoicemailEmail' => $details['email'], 'AstVoicemailMailbox' => $extension, 'AstVoicemailPassword' => $details['mailboxpin'], 'AstContext' => $account);
$rdn = 'uid=' . $uid;
$dn = $rdn . ',' . $this->_params['basedn'];
if (!empty($details['oldextension'])) {
// This is a change to an existing extension
// First, identify the DN to modify
// FIXME: Quote these strings
$olddn = $this->_getExtensionDn($account, $extension);
// If the extension has changed we need to perform an object rename
if ($extension != $details['oldextension']) {
$res = ldap_rename($this->_LDAP, $olddn, $rdn, $this->_params['basedn'], true);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
}
// Now apply the changes
// Avoid changing the objectClass, just in case
unset($entry['objectClass']);
$res = ldap_modify($this->_LDAP, $dn, $entry);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
return true;
} else {
// This is an add of a new extension
$res = ldap_add($this->_LDAP, $dn, $entry);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
return true;
}
// Catch-all. We should not get here.
throw new Shout_Exception(_("Unspecified error."));
}
示例12: save
//.........这里部分代码省略.........
I2CE::raiseError("Trying to save a child node in LDAP where parent is not in LDAP");
return false;
}
$parentFormObj->populate();
if (!($base_dn = $parentFormObj->getAttribute('ldap_dn'))) {
I2CE::raiseError("No DN for parent");
return false;
}
}
if (!$base_dn) {
I2CE::raiseError("No base dn is set");
return false;
}
$dn = vsprintf($printf, $printf_vals) . ',' . $base_dn;
$attributes = array();
if (!$options->setIfIsSet($attributes, "save/attributes", true) || !is_array($attributes) || count($attributes) == 0) {
I2CE::raiseError("No attributes set under " . $options->getPath(false) . '/save/attributes');
return false;
}
$details = array();
foreach ($attributes as $attribute => $attribute_def) {
$val = false;
if (is_string($attribute_def)) {
if (($fieldObj = $formObj->getField($attribute_def)) instanceof I2CE_FormField) {
$val = $fieldObj->getDBValue();
}
} else {
if (!is_array($attribute_def)) {
continue;
} else {
if (array_key_exists('eval', $attribute_def) && is_string($attribute_def['eval'] = $attribute_def['eval']) && strlen($attribute_def['eval']) > 0) {
$data = array();
foreach ($formObj->getFieldNames() as $field) {
if (!($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
$data[$field] = null;
continue;
}
$data[$field] = $fieldObj->getDBValue();
}
@eval('$val = ' . $attribute_def['eval'] . ';');
} else {
if (array_key_exists('printf', $attribute_def) && is_string($printf = $attribute_def['printf']) && strlen($printf) > 0 && array_key_exists('printf_args', $attribute_def) && is_array($printf_args = $attribute_def['printf_args']) && count($printf_args) > 0) {
$printf_vals = array();
foreach ($printf_args as $arg => $field) {
if (($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
$dbval = $fieldObj->getDBValue();
} else {
$dbval = '';
}
$printf_vals[$arg] = $dbval;
}
$val = vsprintf($printf, $printf_vals);
}
}
}
}
if ($val === false || !is_scalar($val) || is_string($val) && strlen(trim($val)) == 0) {
continue;
}
$details[$attribute] = $val;
}
if ($id != '0') {
if ($old_dn != $dn) {
$new_basedn = ldap_explode_dn($dn, 0);
unset($new_basedn['count']);
$new_rdn = array_shift($new_basedn);
$new_basedn = implode(",", $new_basedn);
if (!@ldap_rename($connection, $old_dn, $new_rdn, $new_basedn, false)) {
I2CE::raiseError("Could not rename {$old_dn} to {$dn} with {$new_rdn} and {$new_basedn}");
return false;
}
}
if (!@ldap_modify($connection, $dn, $details)) {
I2CE::raiseError("Could not modify {$dn} with detail: " . print_r($details, true));
return false;
}
} else {
$details['objectClass'] = $objectClass;
if (!@ldap_add($connection, $dn, $details)) {
I2CE::raiseError("Could not add {$dn} with detail: " . print_r($details, true));
return false;
}
$r1 = @ldap_read($connection, $dn, 'objectClass=' . $objectClass, array($read_id));
if (!$r1) {
I2CE::raiseError("Could not read newly saved form under {$dn}");
return false;
}
if (!($entry = ldap_first_entry($connection, $r1))) {
I2CE::raiseError("no entry under {$dn} for reading id after save");
return false;
}
$result = $this->getEntryAttributes($connection, $entry, array('id' => $read_id), false);
if (!array_key_exists('id', $result) || !$result['id']) {
I2CE::raiseError("Could not read id attribute {$read_id} after save");
return false;
}
$formObj->setId($result['id']);
}
return true;
}
示例13: ldap_rename
/**
* Wrapper for ldap_rename()
*/
protected function ldap_rename($dn, $newrdn, $newparent = null, $deleteoldrdn = true)
{
$this->_debug("C: Rename [dn: {$dn}] [dn: {$newrdn}]");
if (!ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn)) {
$this->_debug("S: " . ldap_error($this->conn));
return false;
}
$this->_debug("S: OK");
return true;
}
示例14: renameCN
/**
* Renames an object's CN.
* @param string $oldCN The CN to rename.
* @param string $newCN The new CN.
* @return bool True if successful, False otherwise.
*/
function renameCN($oldCN, $newCN)
{
if ($oldCN == NULL || $oldCN == "") {
return false;
}
if ($newCN == NULL || $newCN == "") {
return false;
}
$oldDN = $this->getDN($oldCN);
$newCN = "CN={$newCN}";
$newParent = preg_replace("/CN={$oldCN},/", "", $oldDN);
return ldap_rename($this->_conn, $oldDN, $newCN, $newParent, true);
}
示例15: modify_entry_attributes
private function modify_entry_attributes($subject_dn, $attributes)
{
if (is_array($attributes['rename']) && !empty($attributes['rename'])) {
$olddn = $attributes['rename']['dn'];
$newrdn = $attributes['rename']['new_rdn'];
$new_parent = $attributes['rename']['new_parent'];
$this->_debug("C: Rename {$olddn} to {$newrdn},{$new_parent}");
// Note: for some reason the operation fails if RDN contains special characters
// and last argument of ldap_rename() is set to TRUE. That's why we use FALSE.
// However, we need to modify RDN attribute value later, otherwise it
// will contain an array of previous and current values
for ($i = 1; $i >= 0; $i--) {
$result = ldap_rename($this->conn, $olddn, $newrdn, $new_parent, $i == 1);
if ($result) {
break;
}
}
if ($result) {
$this->_debug("S: OK");
if ($new_parent) {
$subject_dn = $newrdn . ',' . $new_parent;
} else {
$old_parent_dn_components = ldap_explode_dn($olddn, 0);
unset($old_parent_dn_components["count"]);
$old_rdn = array_shift($old_parent_dn_components);
$old_parent_dn = implode(",", $old_parent_dn_components);
$subject_dn = $newrdn . ',' . $old_parent_dn;
}
// modify RDN attribute value, see note above
if (!$i && empty($attributes['replace'][$attr])) {
list($attr, $val) = explode('=', $newrdn, 2);
$attributes['replace'][$attr] = self::quote_string($val, true, true);
}
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to rename {$olddn} to {$newrdn},{$new_parent}. " . ldap_error($this->conn));
return false;
}
}
if (is_array($attributes['replace']) && !empty($attributes['replace'])) {
$this->_debug("C: Mod-Replace {$subject_dn}: " . json_encode($attributes['replace']));
$result = ldap_mod_replace($this->conn, $subject_dn, $attributes['replace']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to replace attributes on {$subject_dn}: " . json_encode($attributes['replace']));
return false;
}
}
if (is_array($attributes['del']) && !empty($attributes['del'])) {
$this->_debug("C: Mod-Delete {$subject_dn}: " . json_encode($attributes['del']));
$result = ldap_mod_del($this->conn, $subject_dn, $attributes['del']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to delete attributes on {$subject_dn}: " . json_encode($attributes['del']));
return false;
}
}
if (is_array($attributes['add']) && !empty($attributes['add'])) {
$this->_debug("C: Mod-Add {$subject_dn}: " . json_encode($attributes['add']));
$result = ldap_mod_add($this->conn, $subject_dn, $attributes['add']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to add attributes on {$subject_dn}: " . json_encode($attributes['add']));
return false;
}
}
return true;
}