本文整理汇总了PHP中ldap_free_result函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_free_result函数的具体用法?PHP ldap_free_result怎么用?PHP ldap_free_result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_free_result函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search_uidspip
function search_uidspip ($filter,$ldap_server, $ldap_port, $dn) {
global $ldap_grp_attr;
// LDAP attributs
$ldap_grp_attr = array (
"cn",
"memberuid" );
$ds = @ldap_connect ( $ldap_server, $ldap_port );
if ( $ds ) {
$r = @ldap_bind ( $ds ); // Bind anonyme
if ($r) {
$result=@ldap_list ($ds, $dn["groups"], $filter, $ldap_grp_attr);
if ($result) {
$info = ldap_get_entries( $ds, $result );
if ($info["count"]) {
// Stockage des logins des membres des classes
// dans le tableau $ret
$init=0;
for ($loop=0; $loop < $info["count"]; $loop++) {
$group=split ("[\_\]",$info[$loop]["cn"][0],2);
for ( $i = 0; $i < $info[$loop]["memberuid"]["count"]; $i++ ) {
$ret[$init]["uid"] = $info[$loop]["memberuid"][$i];
$ret[$init]["cat"] = $group[0];
$init++;
}
}
}
ldap_free_result ( $result );
}
}
@ldap_close ( $ds );
}
return $ret;
}
示例2: checkGroupMembership
/**
* Validate group membership
*
* Searches the LDAP server for group membership of the
* supplied username. Quotes all LDAP filter meta characters in
* the user name before querying the LDAP server.
*
* @param string Distinguished Name of the authenticated User
* @return boolean
*/
public function checkGroupMembership($user)
{
if (!is_resource($this->_resource)) {
$this->connect();
}
$userDn = $this->_getAccountDn($user);
foreach ($this->_options['groups'] as $group) {
// make filter
$filter = sprintf('(&(%s=%s)(%s=%s)%s)', $this->_options['groupAttr'], $group, $this->_options['memberAttr'], $this->_quoteFilterString($userDn), $this->_options['groupFilter']);
// make search base dn
$search_basedn = $this->_options['groupDn'];
if ($search_basedn != '' && substr($search_basedn, -1) != ',') {
$search_basedn .= ',';
}
$search_basedn .= $this->_options['baseDn'];
$func_params = array($this->_resource, $search_basedn, $filter, array($this->_options['memberAttr']));
$func_name = 'ldap_search';
//echo "Searching with $func_name and filter $filter in $search_basedn";
// search
if (($result_id = @call_user_func_array($func_name, $func_params)) != false) {
if (@ldap_count_entries($this->_resource, $result_id) == 1) {
@ldap_free_result($result_id);
//echo 'User is member of group';
return true;
}
}
}
// default
throw new Zend_Ldap_Exception(null, 'User is NOT member of any group!', BDBLdap::LDAP_USER_NOT_MEMBER_OF_GROUP);
return false;
}
示例3: login
function login($uid, $pwd, $ip = 0)
{
$this->groups = array();
$this->uid = $uid;
if (!($ds = ldap_connect($this->host))) {
return false;
}
if (!($r = @ldap_bind($ds, "uid={$uid},{$this->basedn}", $pwd))) {
ldap_unbind($ds);
sess_log(LOG_LOGIN, 0, "uid={$uid},{$this->basedn}", 0);
return false;
}
$filter = "(&(objectclass=posixGroup)(memberuid={$uid}))";
$retvals = array("cn");
$sr = ldap_search($ds, $this->basedn, $filter, $retvals);
$entries = ldap_get_entries($ds, $sr);
$this->groups = array();
for ($i = 0; $i < $entries["count"]; $i++) {
for ($j = 0; $j < $entries[$i]["cn"]["count"]; $j++) {
$this->groups[] = $entries[$i]["cn"][$j];
}
}
ldap_free_result($sr);
ldap_unbind($ds);
// print_r( $this->groups );
sess_log(LOG_LOGIN, 0, "uid={$uid},{$this->basedn}", 1);
return true;
}
示例4: _free
/**
* free and close the bound ressources
*/
function _free()
{
if (isset($this->_sr) and is_resource($this->_sr)) {
ldap_free_result($this->_sr);
}
if (isset($this->_ldap) and is_resource($this->_ldap)) {
ldap_close($this->_ldap);
}
unset($this->_sr);
unset($this->_ldap);
}
示例5: studentid2uid
public function studentid2uid($pStudentId)
{
if (empty($pStudentId)) {
throw new Exception("No parameter given", E_PARAM);
}
$dn = LDAP_OU . ", " . LDAP_O . ", " . LDAP_C;
$filter = "(&(objectclass=" . LDAP_OBJECTCLASS_STUDENT . ")(" . LDAP_ATTRIBUTE_STUDID . "=" . $pStudentId . "))";
$search = ldap_search($this->ldap_conn, $dn, $filter, array("uid"));
$entry = ldap_first_entry($this->ldap_conn, $search);
$result = @ldap_get_values($this->ldap_conn, $entry, "uid");
ldap_free_result($search);
return $result[0];
}
示例6: __destruct
public function __destruct()
{
$con = $this->connection->getResource();
$this->connection = null;
if (null === $this->search || false === $this->search) {
return;
}
$success = ldap_free_result($this->search);
$this->search = null;
if (!$success) {
throw new LdapException(sprintf('Could not free results: %s', ldap_error($con)));
}
}
示例7: ldapSearchUser
function ldapSearchUser($filter, $required)
{
global $AUTHCFG;
$conn = ldapConnectServer();
if ($conn == NULL) {
return NULL;
}
$ident = @ldap_search($conn, $AUTHCFG['ldap_basedn'], $filter, $required);
if ($ident) {
$result = ldap_get_entries($conn, $ident);
ldap_free_result($ident);
}
ldap_unbind($conn);
return $result;
}
示例8: execute
/**
* {@inheritdoc}
*/
public function execute(LdapOperationInterface $operation)
{
$allEntries = [];
/** @var QueryOperation $operation */
$this->paging()->setIsEnabled($this->shouldUsePaging($operation));
$this->paging()->start($operation->getPageSize(), $operation->getSizeLimit());
do {
$this->paging()->next();
$result = @call_user_func($operation->getLdapFunction(), $this->connection->getConnection(), ...$operation->getArguments());
$allEntries = $this->processSearchResult($result, $allEntries);
$this->paging()->update($result);
} while ($this->paging()->isActive());
$this->paging()->end();
@ldap_free_result($result);
return $allEntries;
}
示例9: getValuesFromCas
public function getValuesFromCas($cas)
{
$result = ldap_search($this->conn, "ou=People,o=cwru.edu,o=isp", "uid=" . $cas);
if ($entries = ldap_first_entry($this->conn, $result)) {
$firstName = ldap_get_values($this->conn, $entries, "givenName");
$surname = ldap_get_values($this->conn, $entries, "SN");
$mail = ldap_get_values($this->conn, $entries, "mail");
ldap_free_result($result);
$return['firstName'] = $firstName[0];
$return['lastName'] = $surname[0];
$return['mail'] = $mail[0];
return $return;
} else {
return false;
}
}
示例10: search
public function search(array $params)
{
$this->connect();
$ref = array('base_dn' => '', 'filter' => '');
if (count($diff = array_diff_key($ref, $params))) {
throw new \Exception(sprintf('You must defined %s', print_r($diff, true)));
}
$attrs = isset($params['attrs']) ? $params['attrs'] : array();
$this->info(sprintf('ldap_search base_dn %s, filter %s', print_r($params['base_dn'], true), print_r($params['filter'], true)));
$search = @ldap_search($this->ress, $params['base_dn'], $params['filter'], $attrs);
$this->checkLdapError();
if ($search) {
$entries = ldap_get_entries($this->ress, $search);
@ldap_free_result($search);
return is_array($entries) ? $entries : false;
}
return false;
}
示例11: find
/**
* {@inheritdoc}
*/
public function find($dn, $query, $filter = '*')
{
if (!is_array($filter)) {
$filter = array($filter);
}
$search = ldap_search($this->connection, $dn, $query, $filter);
if (false === $search) {
throw new LdapException(ldap_error($this->connection));
}
$infos = ldap_get_entries($this->connection, $search);
if (false === @ldap_free_result($search)) {
throw new LdapException(ldap_error($this->connection));
}
if (0 === $infos['count']) {
return;
}
return $infos;
}
示例12: phamm_search
/**
* Generic LDAP search
*
* @author Alessandro De Zorzi <adezorzi@rhx.it>
*
* @todo add attrsonly, sizelimit, timelimit
*
* @param string $base_dn
* @param string $filter
* @param array $attributes
* @return array $entries
**/
static function phamm_search($base_dn, $filter, $attributes = null, $sort = null)
{
global $connect;
// Do a LDAP search
if (isset($attributes)) {
$search = ldap_search($connect, $base_dn, $filter, $attributes);
} else {
$search = ldap_search($connect, $base_dn, $filter);
}
// Order the results if possible
if (version_compare(phpversion(), "4.2.0", ">=")) {
ldap_sort($connect, $search, $sort);
}
// Get entries
$entries = ldap_get_entries($connect, $search);
// Free the memory
ldap_free_result($search);
// Return the entry
return $entries;
}
示例13: ldap_authenticate
function ldap_authenticate($user_id, $password)
{
$ldap_server = LDAP_SERVER;
$ldap_port = LDAP_PORT;
$ldap_id = LDAP_ID;
$ldap_pwd = LDAP_PWD;
$ldap_root_dn = LDAP_DN;
$ldap_proto = LDAP_PROTOCOL;
//$ldap_user = '(&(lmaccessstatusid=active)(uid=' . $user_id . '))';
$ldap_user = '(uid=' . $user_id . ')';
$ldapconn = ldap_connect($ldap_server, $ldap_port);
if (!$ldapconn) {
error_report_show("login.php", LDAP_CONNECTION_FAILED);
}
if (!ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, $ldap_proto)) {
error_report_show("login.php", LDAP_CONNECTION_FAILED);
}
$ldapbind = ldap_bind($ldapconn, $ldap_id, $ldap_pwd);
if (!$ldapbind) {
error_report_show("login.php", INVALID_LOGIN);
}
$ldapsearch = ldap_search($ldapconn, $ldap_root_dn, $ldap_user);
$ldapentries = ldap_get_entries($ldapconn, $ldapsearch);
$authenticated = false;
if ($ldapentries) {
# Try to authenticate to each until we get a match
for ($i = 0; $i < $ldapentries['count']; $i++) {
$dn = $ldapentries[$i]['dn'];
# Attempt to bind with the DN and password
if (@ldap_bind($ldapconn, $dn, $password)) {
$authenticated = true;
break;
}
}
}
ldap_close($ldapconn);
ldap_free_result($ldapsearch);
return $authenticated;
}
示例14: getChildrenDns
/**
* Retrieve the immediate children DNs of the given $parentDn
*
* This method is used in recursive methods like {@see delete()}
* or {@see copy()}
*
* @param string|Dn $parentDn
* @throws Exception\LdapException
* @return array of DNs
*/
protected function getChildrenDns($parentDn)
{
if ($parentDn instanceof Dn) {
$parentDn = $parentDn->toString();
}
$children = array();
ErrorHandler::start(E_WARNING);
$search = ldap_list($this->getResource(), $parentDn, '(objectClass=*)', array('dn'));
for ($entry = ldap_first_entry($this->getResource(), $search); $entry !== false; $entry = ldap_next_entry($this->getResource(), $entry)) {
$childDn = ldap_get_dn($this->getResource(), $entry);
if ($childDn === false) {
ErrorHandler::stop();
throw new Exception\LdapException($this, 'getting dn');
}
$children[] = $childDn;
}
ldap_free_result($search);
ErrorHandler::stop();
return $children;
}
示例15: getUserData
/**
* Return user info
*
* Returns info about the given user needs to contain
* at least these fields:
*
* name string full name of the user
* mail string email addres of the user
* grps array list of groups the user is in
*
* This LDAP specific function returns the following
* addional fields:
*
* dn string distinguished name (DN)
* uid string Posix User ID
* inbind bool for internal use - avoid loop in binding
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Trouble
* @author Dan Allen <dan.j.allen@gmail.com>
* @author <evaldas.auryla@pheur.org>
* @author Stephane Chazelas <stephane.chazelas@emerson.com>
* @return array containing user data or false
*/
function getUserData($user, $inbind = false)
{
global $conf;
if (!$this->_openLDAP()) {
return false;
}
// force superuser bind if wanted and not bound as superuser yet
if ($this->cnf['binddn'] && $this->cnf['bindpw'] && $this->bound < 2) {
// use superuser credentials
if (!@ldap_bind($this->con, $this->cnf['binddn'], $this->cnf['bindpw'])) {
if ($this->cnf['debug']) {
msg('LDAP bind as superuser: ' . htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__);
}
return false;
}
$this->bound = 2;
} elseif ($this->bound == 0 && !$inbind) {
// in some cases getUserData is called outside the authentication workflow
// eg. for sending email notification on subscribed pages. This data might not
// be accessible anonymously, so we try to rebind the current user here
$pass = PMA_blowfish_decrypt($_SESSION[DOKU_COOKIE]['auth']['pass'], auth_cookiesalt());
$this->checkPass($_SESSION[DOKU_COOKIE]['auth']['user'], $pass);
}
$info['user'] = $user;
$info['server'] = $this->cnf['server'];
//get info for given user
$base = $this->_makeFilter($this->cnf['usertree'], $info);
if (!empty($this->cnf['userfilter'])) {
$filter = $this->_makeFilter($this->cnf['userfilter'], $info);
} else {
$filter = "(ObjectClass=*)";
}
$sr = $this->_ldapsearch($this->con, $base, $filter, $this->cnf['userscope']);
$result = @ldap_get_entries($this->con, $sr);
if ($this->cnf['debug']) {
msg('LDAP user search: ' . htmlspecialchars(ldap_error($this->con)), 0, __LINE__, __FILE__);
msg('LDAP search at: ' . htmlspecialchars($base . ' ' . $filter), 0, __LINE__, __FILE__);
}
// Don't accept more or less than one response
if (!is_array($result) || $result['count'] != 1) {
return false;
//user not found
}
$user_result = $result[0];
ldap_free_result($sr);
// general user info
$info['dn'] = $user_result['dn'];
$info['gid'] = $user_result['gidnumber'][0];
$info['mail'] = $user_result['mail'][0];
$info['name'] = $user_result['cn'][0];
$info['grps'] = array();
// overwrite if other attribs are specified.
if (is_array($this->cnf['mapping'])) {
foreach ($this->cnf['mapping'] as $localkey => $key) {
if (is_array($key)) {
// use regexp to clean up user_result
list($key, $regexp) = each($key);
if ($user_result[$key]) {
foreach ($user_result[$key] as $grp) {
if (preg_match($regexp, $grp, $match)) {
if ($localkey == 'grps') {
$info[$localkey][] = $match[1];
} else {
$info[$localkey] = $match[1];
}
}
}
}
} else {
$info[$localkey] = $user_result[$key][0];
}
}
}
$user_result = array_merge($info, $user_result);
//get groups for given user if grouptree is given
if ($this->cnf['grouptree'] || $this->cnf['groupfilter']) {
//.........这里部分代码省略.........