Contents LDAP Interface Previous Next

LDAPS_SEARCH

Searches and retrieves information from the specified LDAP directory.

Syntax

CALL LDAPS_SEARCH(lHandle, sHandle, filter, attributes, numEntries, rc);

lHandle
Numeric, input.
Specifies the connection handle returned by the LDAPS_OPEN CALL routine. The connection handle identifies the open connection to use when searching the LDAP server.

sHandle
Numeric, output.
Returns the search handle that identifies the list of entries returned in the search. The search handle is used in subsequent CALL routines to access the search results. The search handle remains valid until it is closed with the LDAPS_FREE or LDAPS_CLOSE CALL routine.

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

attributes
Character, input.
Specifies the attributes to return along with each entry that matches the search criteria. If more than one attribute is specified, the attributes must be separated by blank spaces, as follows:
attrs = "objectclass sasdeliverytransport sasnamevalueinclusionfilter";
Specifying a null string indicates that all available attributes are to be returned, as follows:
attrs =   ""

numEntries
Numeric, output.
Returns the total number of result entries found during the search.

rc
Numeric, output.
Receives a return code that indicates success or failure.

Details

The LDAPS_SEARCH CALL routine selects and retrieves entries from a specified LDAP directory. A search handle is returned so that information about specific entries and attributes can be obtained. The search information identified by the search handle can be used until it is explicitly freed using the LDAPS_FREE call routine or until the connection is closed using the LDAPS_CLOSE call routine.

Examples

The following example returns a list of entries on the LDAP server that match the values of the specified filter. The list of entries returned from the search includes the values of two attributes for each matching entry.

filter="(&(saschannelcn=DeleteTest)(objectclass=*))";
attrs="description objectclass";
rc=0;
numEntries=0;
sHandle=0;
call LDAPS_SEARCH(lhandle, sHandle, filter, attrs, numEntries, rc);

The following example prints to the SAS log the names and values of all attributes in all entries in a given LDAP directory.

call LDAPS_SEARCH(lhandle, sHandle, filter, attribs, numEntries, rc);
do entryIndex = 1 to numEntries;

   numAttributes = 0;
   entryName='';

   /* retrieve entry indexed by integer entryIndex */
   call ldaps_entry(sHandle, entryIndex, entryName, numAttributes, rc);
   put 'Entry name is ' entryName;
   put 'Number of attributes returned is ' numAttributes;

   do attrIndex = 1 to numAttributes;
     call ldaps_attrname
            (sHandle,entryIndex, attrIndex, attribName, numValues, rc);

     do attrValueIndex = 1 to numValues;
       call ldaps_attrvalue
             (sHandle, entryIndex, attrindex, attrValueIndex, value, rc);
       put "Attribute value is " value;
     end;
  end;
end;

Contents LDAP Interface Previous Next