LDAP objects are returned by open() and initialize(). The connection is automatically unbound and closed when the LDAP object is deleted.
Most methods on LDAP objects initiate an asynchronous request to the LDAP server and return a message id that can be used later to retrieve the result with result(). Methods with names ending in `_s' are the synchronous form and wait for and return with the server's result, or with None if no data is expected.
LDAP objects, have the following methods:
This method attempts to bind with the LDAP server using either simple authentication, or Kerberos (if available). The first and most general method, bind(), takes a third parameter, method, which can currently solely be AUTH_SIMPLE.
Note that the asynchronous technique yields the answer by raising the exception objects COMPARE_TRUE or COMPARE_FALSE.
Note A design fault in the LDAP API prevents value from containing nul characters.
Each element in the list modlist should be a tuple of the form
(mod_op,mod_type,mod_vals)
,
where mod_op indicates the operation (one of MOD_ADD,
MOD_DELETE, or MOD_REPLACE),
mod_type is a string indicating the attribute type name, and
mod_vals is either a string value or a list of string values to add,
delete or replace respectively. For the delete operation, mod_vals
may be None indicating that all attributes are to be deleted.
The asynchronous method modify() returns the message ID of the initiated request.
You might want to like into sub-module ldap.modlist for generating modlist.
The msgid parameter is the integer identifier returned by that method. The identifier is guaranteed to be unique across an LDAP session, and tells the result() method to request the result of that specific operation. If a result is desired from any one of the in-progress operations, msgid should be specified as the constant RES_ANY.
The all parameter only has meaning for search() responses and is used to select whether a single entry of the search response should be returned, or to wait for all the results of the search before returning.
A search response is made up of zero or more search entries followed by a search result. If all is 0, search entries will be returned one at a time as they come in, via separate calls to result(). If all is 1, the search response will be returned in its entirety, i.e. after all entries and the final search result have been received.
For all set to 0, result tuples trickle in (with the same message id), and with the result type 'RES_SEARCH_ENTRY', until the final result which has a result type of 'RES_SEARCH_RESULT' and a (usually) empty data field. When all is set to 1, only one result is returned, with a result type of RES_SEARCH_RESULT, and all the result tuples listed in the data field.
The timeout parameter is a limit on the number of seconds that the method will wait for a response from the server. If timeout is negative (which is the default), the method will wait indefinitely for a response. The timeout can be expressed as a floating-point value, and a value of 0 effects a poll. If a timeout does occur, a TIMEOUT exception is raised, unless polling, in which case (None, None) is returned.
The result() method returns a tuple of the form
(result-type, result-data)
.
The first element, result-type is a string, being one of:
'RES_BIND', 'RES_SEARCH_ENTRY',
'RES_SEARCH_REFERENCE', 'RES_SEARCH_RESULT',
'RES_MODIFY', 'RES_ADD', 'RES_DELETE',
'RES_MODRDN', or 'RES_COMPARE'.
(The module constants RES_* are set to these strings,
for your convenience.)
If all is 0, one response at a time is returned on each call to result(), with termination indicated by result-data being an empty list.
See search() for a description of the search result's result-data, otherwise the result-data is normally meaningless.
The filterstr argument is a string representation of the filter to apply in the search.
Each result tuple is of the form (dn,attrs)
,
where dn is a string containing the DN (distinguished name) of the
entry, and attrs is a dictionary containing the attributes associated
with the entry. The keys of attrs are strings, and the associated
values are lists of strings.
The DN in dn is extracted using the underlying ldap_get_dn() function, which may raise an exception if the DN is malformed.
If attrsonly is non-zero, the values of attrs will be meaningless (they are not transmitted in the result).
The retrieved attributes can be limited with the attrlist parameter. If attrlist is None, all the attributes of each entry are returned.
serverctrls not implemented yet.
clientctrls not implemented yet.
The synchronous form with timeout, search_st() or search_ext_s(), will block for at most timeout seconds (or indefinitely if timeout is negative). A TIMEOUT exception is raised if no result is received within the specified time.
The amount of search results retrieved can be limited with the sizelimit parameter when using search_ext() or search_ext_s() (client-side search limit). If non-zero not more than sizelimit results are returned by the server.
The unbind() and unbind_s() methods are both synchronous in nature