You are here

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

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

Create ldap entry.

Parameters

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 value

boolean result

1 call to LdapServer::createLdapEntry()
LdapServer::groupAddGroup in ldap_servers/LdapServer.class.php
NOT TESTED add a group entry.
1 method overrides LdapServer::createLdapEntry()
LdapServerTest::createLdapEntry in ldap_test/LdapServerTest.class.php
Create ldap entry.

File

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

Class

LdapServer
LDAP Server Class.

Code

public function createLdapEntry($attributes, $dn = NULL) {
  if (!$this->connection) {
    $this
      ->connect();
    $this
      ->bind();
  }
  if (isset($attributes['dn'])) {
    $dn = $attributes['dn'];
    unset($attributes['dn']);
  }
  elseif (!$dn) {
    return FALSE;
  }
  if (!empty($attributes['unicodePwd']) && $this->ldap_type == 'ad') {
    $attributes['unicodePwd'] = ldap_servers_convert_password_for_active_directory_unicodePwd($attributes['unicodePwd']);
  }
  $result = @ldap_add($this->connection, $dn, $attributes);
  if (!$result) {
    $error = "LDAP Server ldap_add(%dn) Error Server ID = %sid, LDAP Err No: %ldap_errno LDAP Err Message: %ldap_err2str ";
    $tokens = [
      '%dn' => $dn,
      '%sid' => $this->sid,
      '%ldap_errno' => ldap_errno($this->connection),
      '%ldap_err2str' => ldap_err2str(ldap_errno($this->connection)),
    ];
    watchdog('ldap_servers', $error, $tokens, WATCHDOG_ERROR);
  }
  return $result;
}