WebLdapSearch Function

Action

Requests that a search is performed on its behalf by a server. This can be used to read attributes from a single entry, from entries immediately below a particular entry, or a whole sub tree of entries.

Include file

WebAPI.bdh

Syntax

WebLdapSearch( in  hLDAP      : number, 
               in  sBase      : string, 
               in  sAttrib    : string allownull, 
               in  sFilters   : string, 
               in  nSizeLimit : number optional, 
               in  nTimeLimit : number optional, 
               in  nFlags     : number optional, 
               out nEntries   : number optional): boolean;

Return value

  • true if the search request was completed successfully

  • false if an error occurred or no matching entries can be found

Parameter Description
hLDAP Handle to a Web connection that was created by WebLdapConnect
sBase An unambiguous name that is the base object entry relative to which the search is to be performed
sAttrib A list of the attributes to be returned from each entry that matches the search filter. There are two special values that may be used: an empty list with no attributes, and the attribute description string "*". Both of these signify that all user attributes are to be returned. (The "*" allows the client to request all user attributes in addition to specific operational attributes).
sFilters A filter that defines the conditions that must be fulfilled in order for the search to match a given entry
nSizeLimit A size limit that restricts the maximum number of entries to be returned as a result of the search (optional). A value of 0 in this field indicates that no client-requested size limit restrictions apply for the search.
nTimeLimit A time limit that restricts the maximum time (in seconds) allowed for a search (optional). A value of 0 in this field indicates that no client-requested time limit restrictions apply for the search.
nFlags

You can combine various flags for the search query (optional).

An indicator as to whether search results will contain both attribute types and values or just attribute types. Setting this flag causes only attribute types (not values) to be returned; otherwise both attribute types and values are returned. (Not set by default.)

  • WEB_LDAP_FLAG_ATTRS_ONLY

An indicator as to how alias objects (as defined in X.501) are to be handled in searching. The possible values of this flag have the following semantics:

  • WEB_LDAP_FLAG_DEREF_NEVER. Do not dereference aliases in searching or in locating the base object of the search

  • WEB_LDAP_FLAG_DEREF_SEARCHING. Dereference aliases in subordinates of the base object in searching, but not in locating the base object of the search

  • WEB_LDAP_FLAG_DEREF_FINDING. Dereference aliases in locating the base object of the search, but not when searching subordinates of the base object

  • WEB_LDAP_FLAG_DEREF_ALWAYS. Dereference aliases both in searching and in locating the base object of the search. This is the default setting

An indicator of the scope to be used for performing the search. These are:

  • WEB_LDAP_FLAG_SCOPE_BASE

  • WEB_LDAP_FLAG_SCOPE_ONELEVEL

  • WEB_LDAP_FLAG_SCOPE_SUBTREE (default)

nEntries Receives the number of entries returned by the search query (optional)

Example

const
  LDAP_SIZELIMIT := 100;
  LDAP_TIMELIMIT := 10000;
dclrand
  rsName: RndFile("Gfname.rnd", 20); 

dclfunc
  function FWebLdapPrintSearchResults(hLdap: number)
  var
    sName    : string(500);
    nEntries : number;
  begin
    nEntries := 0;

    while WebLdapNextEntry(hLdap, sName, STRING_COMPLETE, false) do
      nEntries := nEntries + 1;
      write("entry: "); write(sName); writeln;

      while WebLdapNextAttribute(hLdap, sName)do
        write(" attrib: "); write(sName); writeln;

        while WebLdapNextValue(hLdap, sName) do
          write(" value: "); write(sName); writeln;
        end;
      end;
    end;

    if (nEntries = 0) then
      write("No entries found");
      writeln;
    end;

    writeln;
  end FWebLdapPrintSearchResults; 

dcltrans 
  transaction TWebLdap 
  var
    sQuery : string(1000);
    hLdap  : number; 
  begin
    WebLdapConnect(hLdap, "standardhost", WEB_PORT_LDAP);
    WebLdapBind(hLdap, NULL, NULL);
    sQuery := "cn=" + rsName; 

    if (not WebLdapSearch(hLdap, "", NULL, sQuery, LDAP_SIZELIMIT, LDAP_TIMELIMIT)) then 
      write("LDAP Search failed"); writeln; 
    else
     FWebLdapPrintSearchResults(hLdap); 
    end;

     WebLdapDisconnect(hLdap); 
  end TWebLdap;

SilkEssential sample

LDAP.sep