Add any LDAP controls to the specified LDIF.

@param string $ldif
@return string
172719
protected function addControlsToString($ldif)
    {
        foreach ($this->controls as $control) {
            $value = $control->getOid().' '.$control->getCriticality();
            if (!is_null($control->getValue())) {
                $value .= ' '.$control->getValue();
            }
            $ldif .= $this->getLdifLine(Ldif::DIRECTIVE_CONTROL, $value);
        }

        return $ldif;
    }
774887
protected function rolesSearch($user, $userDN)
    {

        // query whether or not roles DN or filter has been set
        if ($this->rolesDN === null || $this->roleFilter === null) {
            return;
        }

        // load the default group name and the LDAP connection
        $groupName = Util::DEFAULT_GROUP_NAME;
        $ldapConnection = $this->ldapConnect();

        // replace the {0} placeholder with the username of the user
        $this->roleFilter = preg_replace("/\{0\}/", "$user", $this->roleFilter);

        // replace the {1} placeholder with the distiniguished name of the user
        $this->roleFilter = preg_replace("/\{1\}/", "$userDN", $this->roleFilter);

        // search for the roles using the roleFilter and get the first entry
        $search = ldap_search($ldapConnection, $this->rolesDN, $this->roleFilter);
        $entry = ldap_first_entry($ldapConnection, $search);

        do {
            // get the distinguished name of the entry and extract the common names out of it
            $dn = ldap_get_dn($ldapConnection, $entry);
            $roleArray = $this->extractCNFromDN($dn);

            // add every returned CN to the roles
            foreach ($roleArray as $role) {
                $this->addRole($groupName, $role);
            }

            // continue as long as there are entries still left from the search
        } while ($entry = ldap_next_entry($ldapConnection, $entry));
    }
380548
def _bind(self):
        """"""
        ldap_client = self._connect()
        try:
            ldap_client.simple_bind_s(self.binddn, self.bindpassword)
        except Exception as e:
            ldap_client.unbind_s()
            self._exception_handler(e)
        return ldap_client
1277823
public function search($dn, $filter, array $fields)
    {
        if ($this->suppressErrors) {
            return @ldap_search($this->getConnection(), $dn, $filter, $fields);
        }

        return ldap_search($this->getConnection(), $dn, $filter, $fields);
    }
153436
public LdapNameBuilder add(String name) {
        Assert.notNull(name, "name must not be null");

        return add(LdapUtils.newLdapName(name));
    }
768298
def bind
            conn = Net::LDAP.new :host => @config[:server],
                                 :port => @config[:port],
                                 :base => @config[:base]
            if @config[:encryption]
               conn.encryption @config[:encryption]
            end
            
            raise "Anonymous Bind is disabled" if @config[:password] == "" && !(@config[:anonymous_bind])
            
            conn.auth "#{@config[:username]}@#{@config[:domain]}", @config[:password]
            
            begin
                Timeout::timeout(10){
                    if conn.bind
                        return conn
                    else
                        raise 'Query User Rejected'
                    end
                }
            rescue Timeout::Error
                raise 'Unable to connect to LDAP Server'
            rescue Errno::ECONNRESET
              if @config[:allow_fallback]
                @config[:port] = @config[:allow_fallback]
                @config[:encryption] = false
                return Adauth::Connection.new(@config).bind
              end
            end
        end
468525
protected function _ldap($id,$pw) {
		$port=(int)($this->args['port']?:389);
		$filter=$this->args['filter']=$this->args['filter']?:"uid=".$id;
		$this->args['attr']=$this->args['attr']?:["uid"];
		array_walk($this->args['attr'],
		function($attr)use(&$filter,$id) {
			$filter=str_ireplace($attr."=*",$attr."=".$id,$filter);});
		$dc=@ldap_connect($this->args['dc'],$port);
		if ($dc &&
			ldap_set_option($dc,LDAP_OPT_PROTOCOL_VERSION,3) &&
			ldap_set_option($dc,LDAP_OPT_REFERRALS,0) &&
			ldap_bind($dc,$this->args['rdn'],$this->args['pw']) &&
			($result=ldap_search($dc,$this->args['base_dn'],
				$filter,$this->args['attr'])) &&
			ldap_count_entries($dc,$result) &&
			($info=ldap_get_entries($dc,$result)) &&
			$info['count']==1 &&
			@ldap_bind($dc,$info[0]['dn'],$pw) &&
			@ldap_close($dc)) {
			return in_array($id,(array_map(function($value){return $value[0];},
				array_intersect_key($info[0],
					array_flip($this->args['attr'])))),TRUE);
		}
		user_error(self::E_LDAP,E_USER_ERROR);
	}
256475
public function getLdapUserRequiredAttributes($direction = LDAP_USER_PROV_DIRECTION_ALL, $ldap_context = NULL) {

    $attributes_map = array();
    $required_attributes = array();
    if ($this->drupalAcctProvisionServer) {
      $prov_events = $this->ldapContextToProvEvents($ldap_context);
      $attributes_map = $this->getSynchMappings($direction, $prov_events);
      $required_attributes = array();
      foreach ($attributes_map as $detail) {
        if (count(array_intersect($prov_events, $detail['prov_events']))) {
          // Add the attribute to our array.
          if ($detail['ldap_attr']) {
            ldap_servers_token_extract_attributes($required_attributes,  $detail['ldap_attr']);
          }
        }
      }
    }
    return $required_attributes;
  }
335486
public function delete($dn) {
    if (!$this->connection) {
      $this->connect();
      $this->bind();
    }
    $result = @ldap_delete($this->connection, $dn);
    if (!$result) {
      $error = "LDAP Server delete(%dn) in LdapServer::delete() 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 $result;
  }
90872
protected function _getConditionsForEmployee($id = null) {
		$conditions = [];
		if (empty($id)) {
			return $conditions;
		}

		$id = (string)$id;
		if (ctype_digit($id)) {
			$conditions[$this->alias . '.id'] = $id;
		} elseif (isGuid($id)) {
			$conditions[$this->alias . '.' . CAKE_LDAP_LDAP_ATTRIBUTE_OBJECT_GUID] = $id;
		} else {
			$conditions[$this->alias . '.' . CAKE_LDAP_LDAP_ATTRIBUTE_DISTINGUISHED_NAME] = $id;
		}

		return $conditions;
	}
448948
public function setLdap(Zend_Ldap $ldap)
    {
        $this->_ldap = $ldap;

        $this->setOptions(array($ldap->getOptions()));

        return $this;
    }
302425
public function ldap()
    {
        if (is_null($this->ldapRequests)) {
            $this->ldapRequests = new System\LdapRequests($this->client);
        }

        return $this->ldapRequests;
    }
1093694
protected function _bindLdapAdminUser()
    {
        $connect = $this->_getLinkId();
        if (!$connect) {
            jLog::log('ldapdao: impossible to connect to ldap', 'auth');
            return false;
        }

        if ($this->_params['adminUserDn'] == '') {
            $bind = ldap_bind($connect);
        } else {
            $bind = ldap_bind($connect, $this->_params['adminUserDn'], $this->_params['adminPassword']);
        }
        if (!$bind) {
            if ($this->_params['adminUserDn'] == '') {
                jLog::log('ldapdao: impossible to authenticate to ldap as anonymous admin user', 'auth');
            } else {
                jLog::log('ldapdao: impossible to authenticate to ldap with admin user '.$this->_params['adminUserDn'], 'auth');
            }
            ldap_close($connect);
            return false;
        }
        return $connect;
    }
1295634
public function addEntry($dn, $data)
    {
        $data = $this->normalizeData($data);

        if (! (@ldap_add($this->connection, $dn, $data))) {
            $code = @ldap_errno($this->connection);
            throw new PersistenceException(
                sprintf(
                    'Could not add entry %s: Ldap Error Code=%s - %s',
                    $dn,
                    $code,
                    ldap_err2str($code)
                )
            );
        }
    }
782081
private function search(AbstractFilter $filter)
    {
        if ($this->ldapSearchOptions) {
            $ldapResource = $this->ldap->getResource();
            foreach ($this->ldapSearchOptions as $name => $options) {
                ldap_set_option($ldapResource, $name, $options);
            }
        }

        return $this->ldap->searchEntries($filter, null, Ldap::SEARCH_SCOPE_SUB, $this->entryAttributesToFetch);
    }
174262
protected function parseCommonDirectives($dn)
    {
        $changeType = null;
        $controls = [];

        $this->nextLine();
        while ($this->isCommonDirective()) {
            if ($this->isComment()) {
                $this->nextLine();
                continue;
            // We need to exit the loop completely in this case...
            } elseif ($this->isEndOfLdif() || $this->isStartOfEntry()) {
                break;
            } elseif ($this->isCommonDirective()) {
                list($key, $value) = $this->getKeyAndValue($this->currentLine());

                if ($key == Ldif::DIRECTIVE_CHANGETYPE && is_null($changeType)) {
                    $changeType = $value;
                } elseif ($key == Ldif::DIRECTIVE_CHANGETYPE && !is_null($changeType)) {
                    $this->throwException('The changetype directive has already been defined');
                } else {
                    $controls[] = $this->getLdapControl($value);
                }
            }
            $this->nextLine();
        }
        $changeType = $changeType ?: LdifEntryInterface::TYPE_ADD;
        $entry = $this->getLdifEntryObject($dn, $changeType);

        foreach ($controls as $control) {
            $entry->addControl($control);
        }

        return $entry;
    }
1037930
private void importLdif(String ldif, Object target) throws LDAPException
  {
    if (ldif != null)
    {
      InputStream stream = target.getClass().getResourceAsStream(ldif);

      if (stream != null)
      {
        LDIFReader reader = new LDIFReader(stream);

        directoryServer.importFromLDIF(true, reader);
      }
      else
      {
        throw new RuntimeException("could not find ldif ".concat(ldif));
      }
    }
  }