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


PHP ldap_compare函数代码示例

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


在下文中一共展示了ldap_compare函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: install_etape_ldap4_dist

function install_etape_ldap4_dist()
{
    $adresse_ldap = _request('adresse_ldap');
    $login_ldap = _request('login_ldap');
    $pass_ldap = _request('pass_ldap');
    $port_ldap = _request('port_ldap');
    $base_ldap = _request('base_ldap');
    $base_ldap_text = _request('base_ldap_text');
    if (!$base_ldap) {
        $base_ldap = $base_ldap_text;
    }
    echo install_debut_html();
    $ldap_link = ldap_connect($adresse_ldap, $port_ldap);
    @ldap_bind($ldap_link, $login_ldap, $pass_ldap);
    // Essayer de verifier le chemin fourni
    $r = @ldap_compare($ldap_link, $base_ldap, "objectClass", "");
    $fail = ldap_errno($ldap_link) == 32;
    if ($fail) {
        echo info_etape(_T('info_chemin_acces_annuaire')), info_progression_etape(3, 'etape_ldap', 'install/', true), "<div class='error'><p><b>" . _T('avis_operation_echec') . "</b></p><p>" . _T('avis_chemin_invalide_1'), " (<tt>" . htmlspecialchars($base_ldap) . "</tt>) " . _T('avis_chemin_invalide_2') . "</p></div>";
    } else {
        info_etape(_T('info_reglage_ldap'));
        echo info_progression_etape(4, 'etape_ldap', 'install/');
        $statuts = liste_statuts_ldap();
        $statut_ldap = defined('_INSTALL_STATUT_LDAP') ? _INSTALL_STATUT_LDAP : $GLOBALS['liste_des_statuts']['info_redacteurs'];
        $res = install_propager(array('adresse_ldap', 'port_ldap', 'login_ldap', 'pass_ldap', 'protocole_ldap', 'tls_ldap')) . "<input type='hidden' name='etape' value='ldap5' />" . "<input type='hidden' name='base_ldap' value='" . htmlentities($base_ldap) . "' />" . fieldset(_T('info_statut_utilisateurs_1'), array('statut_ldap' => array('label' => _T('info_statut_utilisateurs_2') . '<br />', 'valeur' => $statut_ldap, 'alternatives' => $statuts))) . install_ldap_correspondances() . bouton_suivant();
        echo generer_form_ecrire('install', $res);
    }
    echo install_fin_html();
}
开发者ID:nursit,项目名称:SPIP,代码行数:29,代码来源:etape_ldap4.php

示例2: ldap_search_user

/**
 * Finds if user belongs to group, recursively if requested
 * Private function for this LDAP module only.
 *
 * @param string $ldap_group LDAP group to check
 * @param string $userdn User Distinguished Name
 * @param int $depth Recursion depth (used in recursion, stops at configured maximum depth)
 *
 * @return array Array of server names to be used for LDAP.
 */
function ldap_search_user($ldap_group, $userdn, $depth = -1)
{
    global $ds, $config;
    $compare = ldap_compare($ds, $ldap_group, $config['auth_ldap_groupmemberattr'], $userdn);
    if ($compare === TRUE) {
        return TRUE;
        // Member found, return TRUE
    } elseif ($config['auth_ldap_recursive'] === true && $depth < $config['auth_ldap_recursive_maxdepth']) {
        $depth++;
        //$filter = "(&(objectClass=group)(memberOf=". $ldap_group ."))";
        $filter_params = array();
        $filter_params[] = ldap_filter_create('objectClass', 'group');
        $filter_params[] = ldap_filter_create('memberOf', $ldap_group);
        $filter = ldap_filter_combine($filter_params);
        print_debug("LDAP[UserSearch][{$depth}][Comparing: " . $ldap_group . "][" . $config['auth_ldap_groupmemberattr'] . "={$userdn}][Filter: {$filter}]");
        $ldap_search = ldap_search($ds, trim($config['auth_ldap_groupbase'], ', '), $filter, array($config['auth_ldap_attr']['dn']));
        $ldap_results = ldap_get_entries($ds, $ldap_search);
        array_shift($ldap_results);
        // Chop off "count" array entry
        foreach ($ldap_results as $element) {
            print_debug("LDAP[UserSearch][{$depth}][Comparing: " . $element[$config['auth_ldap_attr']['dn']][0] . "][" . $config['auth_ldap_groupmemberattr'] . "={$userdn}]");
            $result = ldap_search_user($element[$config['auth_ldap_attr']['dn']][0], $userdn, $depth);
            if ($result === TRUE) {
                return TRUE;
                // Member found, return TRUE
            }
        }
        return FALSE;
        // Not found, return FALSE.
    } else {
        return FALSE;
        // Recursion disabled or reached maximum depth, return FALSE.
    }
}
开发者ID:Natolumin,项目名称:observium,代码行数:44,代码来源:ldap.inc.php

示例3: authenticate

function authenticate($username, $password)
{
    global $config;
    $ds = @ldap_connect($config['auth_ldap_server'], $config['auth_ldap_port']);
    if ($ds) {
        if ($config['auth_ldap_version']) {
            ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
        }
        if (ldap_bind($ds, $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'], $password)) {
            if (!$config['auth_ldap_group']) {
                return 1;
            } else {
                if (ldap_compare($ds, $config['auth_ldap_group'], 'memberUid', $username)) {
                    return 1;
                }
            }
        }
    } else {
        # FIXME return a warning that LDAP couldn't connect?
    }
    return 0;
}
开发者ID:kyrisu,项目名称:observernms,代码行数:22,代码来源:ldap.inc.php

示例4: compare

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

示例5: get_userlist

function get_userlist()
{
    global $config, $ldap_connection;
    $userlist = array();
    $filter = '(' . $config['auth_ldap_prefix'] . '*)';
    $search = ldap_search($ldap_connection, trim($config['auth_ldap_suffix'], ','), $filter);
    $entries = ldap_get_entries($ldap_connection, $search);
    if ($entries['count']) {
        foreach ($entries as $entry) {
            $username = $entry['uid'][0];
            $realname = $entry['cn'][0];
            $user_id = $entry['uidnumber'][0];
            $email = $entry[$config['auth_ldap_emailattr']][0];
            $ldap_groups = get_group_list();
            foreach ($ldap_groups as $ldap_group) {
                $ldap_comparison = ldap_compare($ldap_connection, $ldap_group, $config['auth_ldap_groupmemberattr'], get_membername($username));
                if (!isset($config['auth_ldap_group']) || $ldap_comparison === true) {
                    $userlist[] = array('username' => $username, 'realname' => $realname, 'user_id' => $user_id, 'email' => $email);
                }
            }
        }
    }
    return $userlist;
}
开发者ID:Tatermen,项目名称:librenms,代码行数:24,代码来源:ldap.inc.php

示例6: ldap_mod_replace

ldap_mod_replace($ds, $dn, $entry);
/* ### SEARCH ### */
$dn = "o=My Company, c=USs";
echo "\nSearch " . $dn;
$filter = "(|(sn=jeantet)(givenname=jeantet*))";
$justthese = array("ou", "sn", "givenname", "mail");
$cookie = 'cookie';
ldap_control_paged_result($ds, 23, true, $cookie);
$sr = ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
echo "\n\t" . $info["count"] . " entries returned";
// ldap_control_paged_result_response($ds, $sr, $cookie);
/* ### COMPARE ### */
$dn = "cn=Matti Meikku, ou=My Unit, o=My Company, c=FI";
echo "\nCompare " . $dn;
// Préparation des données
$value = "secretpassword";
$attr = "password";
// Comparaison des valeurs
$r = ldap_compare($ds, $dn, $attr, $value);
if ($r === -1) {
    echo "Error: " . ldap_error($ds);
} elseif ($r === true) {
    echo "\n\tCompare true.";
} elseif ($r === false) {
    echo "\n\tCompare false !";
}
/* ### LDAP CLOSE / UNBIND ### */
echo "\nUnbind ";
ldap_unbind($ds);
echo "\n";
开发者ID:postfix,项目名称:ldapserver,代码行数:31,代码来源:full.php

示例7: compare

 /**
  * Compare the value of attribute found in entry specified with $dn
  * 
  * Used to compare the value of attr to the value of same attribute in the LDAP directory
  * entry specified with $dn.
  * 
  * Returns TRUE if value matches, otherwise returns FALSE. Returns -1 on error.
  * 
  * @link http://www.php.net/ldap_compare
  * @param string $dn The DN which we are comparing
  * @param string $attr The attribute to check
  * @param string $value The value to check for
  * @return mixed
  */
 function compare($dn, $attr, $value)
 {
     $result = @ldap_compare($this->connection, $dn, $attr, $value);
     if ($result === -1) {
         $this->setErrVars();
     }
     return $result;
 }
开发者ID:ruNovel,项目名称:sams2,代码行数:22,代码来源:ldap.php

示例8: compare

 /**
  * {@inheritdoc}
  */
 public function compare($dn, $attribute, $value)
 {
     return ldap_compare($this->getConnection(), $dn, $attribute, $value);
 }
开发者ID:adldap2,项目名称:adldap2,代码行数:7,代码来源:Ldap.php

示例9: ldap_compare

 /**
  * Wrapper function for ldap_compare().
  *
  * @param resource $link_identifier
  *   An LDAP link identifier.
  * @param string $dn
  *   The distinguished name of an LDAP entity.
  * @param string $attribute
  *   The attribute name.
  * @param string $value
  *   The compared value.
  *
  * @return boolean
  *   Returns TRUE if value matches otherwise returns FALSE.
  *
  * @throw SimpleLdapException
  */
 public static function ldap_compare($link_identifier, $dn, $attribute, $value)
 {
     // Devel debugging.
     if (variable_get('simple_ldap_devel', FALSE)) {
         dpm(__FUNCTION__);
         dpm(array('$dn' => $dn, '$attribute' => $attribute, '$value' => $value));
     }
     // Wrapped function call.
     $return = @ldap_compare($link_identifier, $dn, $attribute, $value);
     // Debugging.
     if (variable_get('simple_ldap_debug', FALSE)) {
         $message = __FUNCTION__ . '($link_identifier = @link_identifier, $dn = @dn, $attribute = @attribute, $value = @value) returns @return';
         $variables = array('@link_identifier' => print_r($link_identifier, TRUE), '@dn' => print_r($dn, TRUE), '@attribute' => print_r($attribute, TRUE), '@value' => print_r($value, TRUE), '@return' => print_r($return, TRUE));
         watchdog('simple_ldap', $message, $variables, WATCHDOG_DEBUG);
     }
     // Error handling.
     if ($return == -1) {
         throw new SimpleLdapException($link_identifier);
     }
     return $return;
 }
开发者ID:vidiecan,项目名称:drupal_simple_ldap,代码行数:38,代码来源:SimpleLdap.class.php

示例10: compare

 /**
  * @link http://php.net/manual/en/function.ldap-compare.php
  * @param $linkIdentifier
  * @param $dn
  * @param $attribute
  * @param $value
  * @return mixed
  */
 public function compare($linkIdentifier, $dn, $attribute, $value)
 {
     return ldap_compare($linkIdentifier, $dn, $attribute, $value);
 }
开发者ID:CarnegieLearningWeb,项目名称:ldap-orm-bundle,代码行数:12,代码来源:Core.php

示例11: ldapauth_authenticate

function ldapauth_authenticate($username, $password, &$mail)
{
    logger('ldapauth: Searching user ' . $username . '.');
    $ldap_server = get_config('ldapauth', 'ldap_server');
    $ldap_binddn = get_config('ldapauth', 'ldap_binddn');
    $ldap_bindpw = get_config('ldapauth', 'ldap_bindpw');
    $ldap_searchdn = get_config('ldapauth', 'ldap_searchdn');
    $ldap_userattr = get_config('ldapauth', 'ldap_userattr');
    $ldap_group = get_config('ldapauth', 'ldap_group');
    if (empty($password)) {
        logger('ldapauth: Empty Password not allowed.');
        return false;
    }
    if (!function_exists('ldap_connect') || empty($ldap_server)) {
        logger('ldapauth: PHP-LDAP fail or no server set.');
        return false;
    }
    $connect = @ldap_connect($ldap_server);
    if (!$connect) {
        logger('ldapauth: Unable to connect to server');
        return false;
    }
    @ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
    @ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
    if (@ldap_bind($connect, $ldap_binddn, $ldap_bindpw) === false) {
        logger('ldapauth: Unable to bind to server. Check credentials of binddn.');
        return false;
    }
    $res = @ldap_search($connect, $ldap_searchdn, $ldap_userattr . '=' . $username, array('mail'));
    if (!$res) {
        logger('ldapauth: User ' . $username . ' not found.');
        return false;
    }
    $id = @ldap_first_entry($connect, $res);
    if (!$id) {
        logger('ldapauth: User ' . $username . ' found but unable to load data.');
        return false;
    }
    // get primary email
    $mail = '';
    $attrs = @ldap_get_attributes($connect, $id);
    if ($attrs['count'] && $attrs['mail']) {
        if (is_array($attrs['mail'])) {
            $mail = $attrs['mail'][0];
        } else {
            $mail = $attrs['mail'];
        }
    }
    $dn = @ldap_get_dn($connect, $id);
    if (!@ldap_bind($connect, $dn, $password)) {
        logger('ldapauth: User ' . $username . ' provided wrong credentials.');
        return false;
    }
    if (empty($ldap_group)) {
        logger('ldapauth: User ' . $username . ' authenticated.');
        return true;
    }
    $r = @ldap_compare($connect, $ldap_group, 'member', $dn);
    if ($r === -1) {
        $err = @ldap_error($connect);
        $eno = @ldap_errno($connect);
        @ldap_close($connect);
        if ($eno === 32) {
            logger('ldapauth: access control group Does Not Exist');
            return false;
        } elseif ($eno === 16) {
            logger('ldapauth: membership attribute does not exist in access control group');
            return false;
        } else {
            logger('ldapauth: error: ' . $err);
            return false;
        }
    } elseif ($r === false) {
        logger('ldapauth: User ' . $username . ' is not in the allowed group.');
        @ldap_close($connect);
        return false;
    }
    //    logger('ldapauth: User '.$username.' authenticated and in allowed group.');
    return true;
}
开发者ID:royalterra,项目名称:hubzilla-addons,代码行数:80,代码来源:ldapauth.php

示例12: ldap_connect_and_bind

<?php

require "connect.inc";
$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
insert_dummy_data($link, $base);
var_dump(ldap_compare($link, "cn=userA,{$base}", "sn", "testSN1"), ldap_compare($link, "cn=userA,{$base}", "telephoneNumber", "yy-yy-yy-yy-yy"));
?>
===DONE===
开发者ID:gleamingthecube,项目名称:php,代码行数:8,代码来源:ext_ldap_tests_ldap_compare_basic.php

示例13: compare

	/**
	 * Compare an entry and return the result
	 *
	 * @param   string  $dn         The distinguished name of the attribute to compare
	 * @param   string  $attribute  The attribute name/key
	 * @param   string  $value      The compared value of the attribute (case insensitive)
	 *
	 * @return  boolean   True if value matches otherwise returns False.
	 *
	 * @since   1.0
	 * @throws  SHLdapException
	 */
	public function compare($dn, $attribute, $value)
	{
		$this->operationAllowed();

		// Do the Ldap compare operation
		$result = @ldap_compare($this->resource, $dn, $attribute, $value);

		if ($result === -1)
		{
			// A error in the Ldap compare operation occurred
			throw new SHLdapException($this->getErrorCode(), 10131, JText::_('LIB_SHLDAP_ERR_10131'));
		}

		return $result;
	}
开发者ID:BillVGN,项目名称:PortalPRP,代码行数:27,代码来源:ldap.php

示例14: compare

 /**
  * @param string $dn
  * @param string $attribute
  * @param mixed  $value
  * @return bool
  * @throws UnavailableException
  * @throws ReadFailureException
  */
 public function compare($dn, $attribute, $value)
 {
     $this->checkBound();
     if (-1 === ($result = ldap_compare($this->link, $dn, $attribute, $value))) {
         throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link));
     }
     return $result;
 }
开发者ID:daverandom,项目名称:ldapi,代码行数:16,代码来源:Directory.php

示例15: queryLDAP

/**
 * This function queries the LDAP server to determine whether a given user and
 * group combination exists. This function returns an array of groups the given
 * user belongs to
 *
 * @param array $groupsInConfig
 *
 * @author Andrew Darwin <andrew.p.darwin@jpl.nasa.gov>
 * @author Delvison Castillo
 */
function queryLDAP($groupsInConfig)
{
    $groupsUserBelongsTo = array();
    global $ldapAddress;
    global $ldapPort;
    global $useLDAP;
    //LDAP QUERIES HERE
    if (!$useLDAP) {
        $groupsUserBelongsTo = array("public");
        return $groupsUserBelongsTo;
    }
    if ($ldapAddress == "" || $ldapPort == "") {
        return null;
    }
    $ldap = ldap_connect($ldapAddress, $ldapPort);
    logMessage("queryLDAP() Tried to connect to LDAP and got the following " . "object: {$ldap}");
    //$bindedLDAP = ldap_bind($ldap); //binded for read access
    if ($ldap && ldap_bind($ldap)) {
        logMessage("queryLDAP() is beginning to query groups from config");
        foreach ($groupsInConfig as $group) {
            // prepare data
            $dn = getLDAPQueryDN($group);
            $value = getLDAPQueryValue();
            $attr = getLDAPQueryAttribute();
            logMessage("queryLDAP() prepared a query with dn: {$dn}, value: " . "{$value}, and attr: {$attr}");
            $query = ldap_compare($ldap, $dn, $attr, $value);
            logMessage("queryLDAP(): The query returned: " . ($query ? "true" : "false"));
            if ($query === -1) {
                //AN ERROR HAS OCCURED
                $groupsUserBelongsTo = array("LDAP Error");
                logMessage("LDAP ERROR");
            } else {
                if ($query) {
                    array_push($groupsUserBelongsTo, $group);
                    logMessage("queryLDAP() pushed group: {$group} to list of groups " . "the user belongs to");
                }
            }
        }
    } else {
        $groupsUserBelongsTo = array("Invalid LDAP Connection");
    }
    return $groupsUserBelongsTo;
}
开发者ID:RichardRanft,项目名称:cash,代码行数:53,代码来源:functions.php


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