Contents LDAP SCL Interface Previous Next

_SEARCH

Searches and retrieves information from an LDAP directory.

Syntax

_SEARCH(filter, attribs, results);

filter
Character, input.
Specifies search criteria which determine that the entries are to be added to the entry list returned by the search.

attribs
SCL list, input.
Specifies in an SCL list the names of the attributes to be returned in the search results for each entry that matches the search criteria. A value of 0 or "" indicates that all attributes are to be returned.

results
SCL list, output.
Returns the results of the search.

Details

When invoked on an LDAPSERVICES instance, the _SEARCH method allows you to select and retrieve entries from an LDAP directory.

The content returned in the results parameter is a list of SCL lists containing the entries, attributes, and values that match the search criteria. Each entry in the entry list contains a sublist in the following format:

Item Type Value
1 Character Distinguished name of entry.
2 Numeric Number of attributes and values in entry.
3 SCL list Attribute name and values.
... SCL list Attribute name and values.
num_attrs+2 SCL list Attribute name and values.

The SCL list that contains the attribute names and values (see item 3 above) has the following format:

Item Type Value
1 Character Attribute name
2 Numeric Number of values returned for this attribute
3 Character Attribute value
... Character Attribute value
num_values+2 Character Attribute value

Examples

For a single LDAP directory entry, the following example returns four attributes and the values of those attributes.

/* list of attributes to be returned */
attribs = makelist();
rc = insertc(attribs, "uid", -1);
rc = insertc(attribs, "mail", -1);
rc = insertc(attribs, "roomnumber", -1);
rc = insertc(attribs, "employeenumber", -1);

r = makelist(); /* results returned in r */
rc = ds._SEARCH('cn=John Smith', attribs, r);

The following example searches an LDAP directory and extracts from the search results the attribute names and all the values of those attributes.

results=makelist();
rc = dirInst._SEARCH(filter, attribs, results);

total_entries = listlen(results);

do i = 1 to total_entries;

   /* each list in results is entry matching criteria */
   entry = getiteml(results, i);

   /* distinguished name */
   dn = getitemc(entry, 1);

   /* total number of attributes returned */
   attribNum = getitemn(entry, 2);

   do k= 3 to (attribNum+2);

      /* each attribute is its own list, get first attrib  */
      attrib = getiteml(entry, k);

      /* name of attribute */
      attribname = getitemc(attrib,1 );

      /* number of values */
      numValues = getitemn(attrib, 2);

      /* retrieve values */
      do z = 3 to (numValues + 2);
         value = getitemc(attrib, z);
      end;
   end;
end; 

Contents LDAP SCL Interface Previous Next