You are here

public function LdapServer::dnExists in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServer.class.php \LdapServer::dnExists()

Does dn exist for this server?

Parameters

string $dn:

enum $return: = 'boolean' or 'ldap_entry'.

array $attributes: in same form as ldap_read $attributes parameter.

Return value

bool|array

4 calls to LdapServer::dnExists()
LdapServer::groupAddGroup in ldap_servers/LdapServer.class.php
NOT TESTED add a group entry.
LdapServer::groupAllMembers in ldap_servers/LdapServer.class.php
Get all members of a group.
LdapServer::userUsernameFromDn in ldap_servers/LdapServer.class.php
UserUsernameFromDn.
LdapServer::userUserToExistingLdapEntry in ldap_servers/LdapServer.class.php
1 method overrides LdapServer::dnExists()
LdapServerTest::dnExists in ldap_test/LdapServerTest.class.php
Does dn exist for this server?

File

ldap_servers/LdapServer.class.php, line 484
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class.

Code

public function dnExists($dn, $return = 'boolean', $attributes = NULL) {
  $params = [
    'base_dn' => $dn,
    'attributes' => $attributes,
    'attrsonly' => FALSE,
    'filter' => '(objectclass=*)',
    'sizelimit' => 0,
    'timelimit' => 0,
    'deref' => NULL,
  ];
  if ($return == 'boolean' || !is_array($attributes)) {
    $params['attributes'] = [
      'objectclass',
    ];
  }
  else {
    $params['attributes'] = $attributes;
  }
  $result = $this
    ->ldapQuery(LDAP_SCOPE_BASE, $params);
  if ($result !== FALSE) {
    $entries = @ldap_get_entries($this->connection, $result);
    if ($entries !== FALSE && $entries['count'] > 0) {
      return $return == 'boolean' ? TRUE : $entries[0];
    }
  }
  return FALSE;
}