当前位置: 首页>>代码示例>>PHP>>正文


PHP ldap_modify函数代码示例

本文整理汇总了PHP中ldap_modify函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_modify函数的具体用法?PHP ldap_modify怎么用?PHP ldap_modify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ldap_modify函数的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
//.........这里部分代码省略.........
开发者ID:microcosmx,项目名称:experiments,代码行数:101,代码来源:Entry.php

示例2: update

 /**
  * Update LDAP registry
  *
  * @param  string|Zend_Ldap_Dn $dn
  * @param  array               $entry
  * @return Zend_Ldap                  Provides a fluid interface
  * @throws Zend_Ldap_Exception
  */
 public function update($dn, array $entry)
 {
     if (!$dn instanceof Zend_Ldap_Dn) {
         $dn = Zend_Ldap_Dn::factory($dn, null);
     }
     self::prepareLdapEntryArray($entry);
     $rdnParts = $dn->getRdn(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
     foreach ($rdnParts as $key => $value) {
         $value = Zend_Ldap_Dn::unescapeValue($value);
         if (array_key_exists($key, $entry) && !in_array($value, $entry[$key])) {
             $entry[$key] = array_merge(array($value), $entry[$key]);
         }
     }
     $adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory', 'objectguid', 'usnchanged', 'usncreated', 'whenchanged', 'whencreated');
     foreach ($adAttributes as $attr) {
         if (array_key_exists($attr, $entry)) {
             unset($entry[$attr]);
         }
     }
     if (count($entry) > 0) {
         $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry);
         if ($isModified === false) {
             /**
              * @see Zend_Ldap_Exception
              */
             #require_once 'Zend/Ldap/Exception.php';
             throw new Zend_Ldap_Exception($this, 'updating: ' . $dn->toString());
         }
     }
     return $this;
 }
开发者ID:jpbender,项目名称:mage_virtual,代码行数:39,代码来源:Ldap.php

示例3: modifyLdapEntry

 /**
 * modify attributes of ldap entry
 *
 * @param string $dn DN of entry
 * @param array $attributes should follow the structure of ldap_add functions
 *   entry array: http://us.php.net/manual/en/function.ldap-add.php
      $attributes["attribute1"] = "value";
      $attributes["attribute2"][0] = "value1";
      $attributes["attribute2"][1] = "value2";
 
  @return TRUE on success FALSE on error
 */
 function modifyLdapEntry($dn, $attributes = array(), $old_attributes = FALSE)
 {
     $this->connectAndBindIfNotAlready();
     if (!$old_attributes) {
         $result = @ldap_read($this->connection, $dn, 'objectClass=*');
         if (!$result) {
             $error = "LDAP Server ldap_read(%dn) in LdapServer::modifyLdapEntry() Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str ";
             $tokens = array('%dn' => $dn, '%sid' => $this->sid, '%ldap_errno' => ldap_errno($this->connection), '%ldap_err2str' => ldap_err2str(ldap_errno($this->connection)));
             watchdog('ldap_server', $error, $tokens, WATCHDOG_ERROR);
             return FALSE;
         }
         $entries = ldap_get_entries($this->connection, $result);
         if (is_array($entries) && $entries['count'] == 1) {
             $old_attributes = $entries[0];
         }
     }
     $attributes = $this->removeUnchangedAttributes($attributes, $old_attributes);
     foreach ($attributes as $key => $cur_val) {
         $old_value = FALSE;
         $key_lcase = drupal_strtolower($key);
         if (isset($old_attributes[$key_lcase])) {
             if ($old_attributes[$key_lcase]['count'] == 1) {
                 $old_value = $old_attributes[$key_lcase][0];
             } else {
                 unset($old_attributes[$key_lcase]['count']);
                 $old_value = $old_attributes[$key_lcase];
             }
         }
         if ($cur_val == '' && $old_value != '') {
             // remove enpty attributes
             unset($attributes[$key]);
             $result = @ldap_mod_del($this->connection, $dn, array($key_lcase => $old_value));
             if (!$result) {
                 $error = "LDAP Server ldap_mod_del(%dn) in LdapServer::modifyLdapEntry() Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str ";
                 $tokens = array('%dn' => $dn, '%sid' => $this->sid, '%ldap_errno' => ldap_errno($this->connection), '%ldap_err2str' => ldap_err2str(ldap_errno($this->connection)));
                 watchdog('ldap_server', $error, $tokens, WATCHDOG_ERROR);
                 return FALSE;
             }
         } elseif (is_array($cur_val)) {
             foreach ($cur_val as $mv_key => $mv_cur_val) {
                 if ($mv_cur_val == '') {
                     unset($attributes[$key][$mv_key]);
                     // remove empty values in multivalues attributes
                 } else {
                     $attributes[$key][$mv_key] = $mv_cur_val;
                 }
             }
         }
     }
     if (count($attributes) > 0) {
         $result = @ldap_modify($this->connection, $dn, $attributes);
         if (!$result) {
             $error = "LDAP Server ldap_modify(%dn) in LdapServer::modifyLdapEntry() Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str ";
             $tokens = array('%dn' => $dn, '%sid' => $this->sid, '%ldap_errno' => ldap_errno($this->connection), '%ldap_err2str' => ldap_err2str(ldap_errno($this->connection)));
             watchdog('ldap_server', $error, $tokens, WATCHDOG_ERROR);
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:tierce,项目名称:ppbe,代码行数:72,代码来源:LdapServer.class.php

示例4: updateExternalDB

 /**
  * Update user information in the external authentication database.
  * Return true if successful.
  *
  * @param User $user
  * @return bool
  * @access public
  */
 function updateExternalDB($user)
 {
     global $wgLDAPUpdateLDAP, $wgLDAPWikiDN, $wgLDAPWikiPassword;
     global $wgLDAPSearchStrings;
     if (!$wgLDAPUpdateLDAP) {
         return true;
     }
     $this->email = $user->getEmail();
     $this->realname = $user->getRealName();
     $this->nickname = $user->getOption('nickname');
     $this->language = $user->getOption('language');
     $tmpuserdn = $wgLDAPSearchStrings[$_SESSION['wsDomain']];
     $userdn = str_replace("USER-NAME", $user->getName(), $tmpuserdn);
     echo $userdn;
     $ldapconn = $this->connect();
     if ($ldapconn) {
         ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
         $bind = @ldap_bind($ldapconn, $wgLDAPWikiDN, $wgLDAPWikiPassword);
         if (!$bind) {
             return false;
         }
         if ('' != $this->email) {
             $values["mail"] = $this->email;
         }
         if ('' != $this->nickname) {
             $values["displayname"] = $this->nickname;
         }
         if ('' != $this->realname) {
             $values["cn"] = $this->realname;
         }
         if ('' != $this->language) {
             $values["preferredlanguage"] = $this->language;
         }
         if (0 != sizeof($values) && ldap_modify($ldapconn, $userdn, $values)) {
             @ldap_unbind();
             return true;
         } else {
             @ldap_unbind();
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:BackupTheBerlios,项目名称:enotifwiki,代码行数:52,代码来源:LdapAuthentication.php

示例5: modify

 /**
  * Modifies an entry and return a true or false result
  *
  * @param   string  $dn         The DN which contains the attribute you want to modify
  * @param   string  $attribute  The attribute values you want to modify
  *
  * @return  mixed  result of comparison (true, false, -1 on error)
  *
  * @since   12.1
  */
 public function modify($dn, $attribute)
 {
     return @ldap_modify($this->_resource, $dn, $attribute);
 }
开发者ID:WineWorld,项目名称:joomlatrialcmbg,代码行数:14,代码来源:ldap.php

示例6: modify

 /**
  * 	Modify a LDAP entry
  *	Ldap object connect and bind must have been done
  *
  *	@param	string		$dn			DN entry key
  *	@param	array		$info		Attributes array
  *	@param	string		$user		Objet user that modify
  *	@return	int						<0 if KO, >0 if OK
  */
 function modify($dn, $info, $user)
 {
     global $conf;
     dol_syslog(get_class($this) . "::modify dn=" . $dn . " info=" . join(',', $info));
     // Check parameters
     if (!$this->connection) {
         $this->error = "NotConnected";
         return -2;
     }
     if (!$this->bind) {
         $this->error = "NotConnected";
         return -3;
     }
     // Encode to LDAP page code
     $dn = $this->convFromOutputCharset($dn, $this->ldapcharset);
     foreach ($info as $key => $val) {
         if (!is_array($val)) {
             $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset);
         }
     }
     $this->dump($dn, $info);
     //print_r($info);
     $result = @ldap_modify($this->connection, $dn, $info);
     if ($result) {
         dol_syslog(get_class($this) . "::modify successfull", LOG_DEBUG);
         return 1;
     } else {
         $this->error = @ldap_error($this->connection);
         dol_syslog(get_class($this) . "::modify failed: " . $this->error, LOG_ERR);
         return -1;
     }
 }
开发者ID:Samara94,项目名称:dolibarr,代码行数:41,代码来源:ldap.class.php

示例7: update

 /**
  * {@inheritdoc}
  */
 public function update(Entry $entry)
 {
     $con = $this->connection->getResource();
     if (!@ldap_modify($con, $entry->getDn(), $entry->getAttributes())) {
         throw new LdapException(sprintf('Could not update entry "%s": %s', $entry->getDn(), ldap_error($con)));
     }
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:10,代码来源:EntryManager.php

示例8: ativa

 public static function ativa($email)
 {
     $ldap = app('ldap');
     $base_dn = env('LDAP_BASE_DN');
     $dn = "uid={$email},ou=People,{$base_dn}";
     $info = ldap_modify($ldap, $dn, ['validado' => 'TRUE']);
     ldap_close($ldap);
     return $info;
 }
开发者ID:CasaDosMeninos,项目名称:login-unico,代码行数:9,代码来源:User.php

示例9: ldapUpdate

 /**
  * The "U" in CRUD
  */
 function ldapUpdate($entry = null)
 {
     $entryDn = "uid=" . $entry['uid'] . "," . $this->baseDn;
     if ($entry) {
         if (@ldap_modify($this->ds, $entryDn, $entry)) {
             return true;
         }
     }
 }
开发者ID:stas,项目名称:intranet,代码行数:12,代码来源:ldap_user.php

示例10: AssistedLDAPModify

function AssistedLDAPModify($ldapc, $moddn, $in)
{
    // Use these variables that are outside the function
    global $app_theme;
    // Modify the entry
    $r_mod = ldap_modify($ldapc, $moddn, $in);
    // Let's see if you could make it
    if (!$r_mod) {
        echo '<div class="error">' . _("An error has ocurred trying to modify entries on the LDAP database: ") . ldap_error($ldapc) . '.<br /><br /><a href="javascript:history.back(1);">' . _("Back") . '</a></div>';
        include "../themes/{$app_theme}/footer.php";
        die;
    }
    return $r_mod;
}
开发者ID:awasthi,项目名称:aguilas,代码行数:14,代码来源:Functions.inc.php

示例11: putData

 function putData($username, $data)
 {
     global $dsconnect, $host, $binduser, $bindpass, $basecn;
     if ($data != "") {
         $data .= "ga4php:";
     }
     // set this to default to begin with
     $tokendata = false;
     // we need to track the "first" blank attribute
     $blank_attr = false;
     // we search for a username that matches what we've been passed
     $sr = ldap_search($dsconnect, "{$basecn}", "samaccountname={$username}");
     $info = ldap_get_entries($dsconnect, $sr);
     $dn = $info[0]["distinguishedname"][0];
     //echo "<pre>";
     //print_r($info);
     //echo "</pre>";
     $attr_name = false;
     for ($i = 1; $i < 15; $i++) {
         $valname = "extensionattribute{$i}";
         if (isset($info[0]["{$valname}"][0])) {
             $val = $info[0]["{$valname}"][0];
             // we are looking for an extension attribute that has a start of "ga4php"
             if (preg_match('/^ga4php.*/', $val) > 0) {
                 $attr_name = $valname;
             }
         } else {
             if ($blank_attr == false) {
                 // this will cathc the first unset extension variable name, if we need it
                 $blank_attr = "{$valname}";
             }
         }
     }
     // if the attr_name is not set, we need to set $blank_attr
     if ($attr_name == false) {
         // we use $blank_attr
         error_log("setting for {$username}, {$blank_attr}");
         $infod["{$blank_attr}"][0] = "{$data}";
     } else {
         error_log("setting for {$username}, {$attr_name}");
         $infod["{$attr_name}"][0] = "{$data}";
     }
     error_log("att end of put data for {$dn}, {$infod}");
     return ldap_modify($dsconnect, $dn, $infod);
     // even simpler!
 }
开发者ID:kphamilton,项目名称:ga4php,代码行数:46,代码来源:extend.php

示例12: updateUser

 public function updateUser($user)
 {
     if (!is_object($user) || !$user instanceof jAuthUserLDAP) {
         throw new jException('jelix~auth.ldap.object.user.unknown');
     }
     if (!($user->login != '')) {
         throw new jException('jelix~auth.ldap.user.login.unset');
     }
     $entries = $this->getAttributesLDAP($user, true);
     $connect = $this->_bindLdapUser();
     if ($connect === false) {
         return false;
     }
     $result = ldap_modify($connect, $this->_buildUserDn($user->login), $entries);
     ldap_close($connect);
     return $result;
 }
开发者ID:havefnubb,项目名称:havefnubb,代码行数:17,代码来源:ldap.auth.php

示例13: ajax_addnote

/**
 * Add a note to the existing notes
 */
function ajax_addnote($dn, $note)
{
    global $conf;
    global $LDAP_CON;
    global $FIELDS;
    header('Content-Type: text/html; charset=utf-8');
    // fetch the existing note
    $result = ldap_search($LDAP_CON, $dn, '(objectClass=inetOrgPerson)', array($FIELDS['note']));
    if (ldap_count_entries($LDAP_CON, $result)) {
        $result = ldap_get_binentries($LDAP_CON, $result);
    }
    $note = $note . "\n\n" . $result[0][$FIELDS['note']][0];
    $note = preg_replace("!\n\n\n+!", "\n\n", $note);
    $entry[$FIELDS['note']] = $note;
    ldap_modify($LDAP_CON, $dn, $entry);
    require_once dirname(__FILE__) . '/inc/smarty/plugins/modifier.noteparser.php';
    print smarty_modifier_noteparser($note);
}
开发者ID:pneff,项目名称:contagged,代码行数:21,代码来源:ajax.php

示例14: changePassword

function changePassword($username, $newpassword, $newpassword2)
{
    global $connection, $DN;
    if ($newpassword != $newpassword2) {
        return false;
    }
    $search = ldap_search($connection, $DN, "(uid=" . $username . ")", array("dn"));
    $ent = ldap_get_entries($connection, $search);
    if ($ent["count"] == 0) {
        return false;
    }
    $user_dn = $ent[0]['dn'];
    $new = array();
    $new['userPassword'] = $newpassword;
    if (ldap_modify($connection, $user_dn, $new)) {
        return true;
    } else {
        return false;
    }
}
开发者ID:audunel,项目名称:anthropos,代码行数:20,代码来源:user.functions.inc.php

示例15: 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;
     }
 }
开发者ID:Drake86cnf,项目名称:yacare,代码行数:21,代码来源:AdConnection.php


注:本文中的ldap_modify函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。