Exemplo n.º 1
0
 def sasl_bind_s(self,
                 dn,
                 mechanism,
                 cred,
                 serverctrls=None,
                 clientctrls=None):
     """
 sasl_bind_s(dn, mechanism, cred [,serverctrls=None[,clientctrls=None]]) -> int|str
 """
     return self._ldap_call(self._l.sasl_bind_s, dn, mechanism, cred,
                            RequestControlTuples(serverctrls),
                            RequestControlTuples(clientctrls))
Exemplo n.º 2
0
 def sasl_interactive_bind_s(self,
                             who,
                             auth,
                             serverctrls=None,
                             clientctrls=None,
                             sasl_flags=ldap.SASL_QUIET):
     """
 sasl_interactive_bind_s(who, auth [,serverctrls=None[,clientctrls=None[,sasl_flags=ldap.SASL_QUIET]]]) -> None
 """
     return self._ldap_call(self._l.sasl_interactive_bind_s, who, auth,
                            RequestControlTuples(serverctrls),
                            RequestControlTuples(clientctrls), sasl_flags)
Exemplo n.º 3
0
 def delete_ext(self,dn,serverctrls=None,clientctrls=None):
   """
   delete(dn) -> int
   delete_s(dn) -> None
   delete_ext(dn[,serverctrls=None[,clientctrls=None]]) -> int
   delete_ext_s(dn[,serverctrls=None[,clientctrls=None]]) -> tuple
       Performs an LDAP delete operation on dn. The asynchronous
       form returns the message id of the initiated request, and the
       result can be obtained from a subsequent call to result().
   """
   dn = self._bytesify_input('dn', dn)
   return self._ldap_call(self._l.delete_ext,dn,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 4
0
 def cancel(self,cancelid,serverctrls=None,clientctrls=None):
   """
   cancel(cancelid[,serverctrls=None[,clientctrls=None]]) -> int
       Send cancels extended operation for an LDAP operation specified by cancelid.
       The cancelid should be the message id of an outstanding LDAP operation as returned
       by the asynchronous methods search(), modify() etc.  The caller
       can expect that the result of an abandoned operation will not be
       returned from a future call to result().
       In opposite to abandon() this extended operation gets an result from
       the server and thus should be preferred if the server supports it.
   """
   return self._ldap_call(self._l.cancel,cancelid,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 5
0
  def search_ext(self,base,scope,filterstr='(objectClass=*)',attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
    """
    search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int
    search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]])
    search_st(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]])
    search_ext(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])
    search_ext_s(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])

        Perform an LDAP search operation, with base as the DN of
        the entry at which to start the search, scope being one of
        SCOPE_BASE (to search the object itself), SCOPE_ONELEVEL
        (to search the object's immediate children), or SCOPE_SUBTREE
        (to search the object and all its descendants).

        filter is a string representation of the filter to
        apply in the search (see RFC 4515).

        Each result tuple is of the form (dn,entry), where dn is a
        string containing the DN (distinguished name) of the entry, and
        entry is a dictionary containing the attributes.
        Attributes types are used as string dictionary keys and attribute
        values are stored in a list as dictionary value.

        The DN in dn is extracted using the underlying ldap_get_dn(),
        which may raise an exception of 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=None

        clientctrls=None

        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 time.

        The amount of search results retrieved can be limited with the
        sizelimit parameter if non-zero.
    """
    return self._ldap_call(
      self._l.search_ext,
      base,scope,filterstr,
      attrlist,attrsonly,
      RequestControlTuples(serverctrls),
      RequestControlTuples(clientctrls),
      timeout,sizelimit,
    )
Exemplo n.º 6
0
 def abandon_ext(self, msgid, serverctrls=None, clientctrls=None):
     """
 abandon_ext(msgid[,serverctrls=None[,clientctrls=None]]) -> None
 abandon(msgid) -> None
     Abandons or cancels an LDAP operation in progress. The msgid should
     be the message id of an outstanding LDAP operation as returned
     by the asynchronous methods search(), modify() etc.  The caller
     can expect that the result of an abandoned operation will not be
     returned from a future call to result().
 """
     return self._ldap_call(self._l.abandon_ext, msgid,
                            RequestControlTuples(serverctrls),
                            RequestControlTuples(clientctrls))
Exemplo n.º 7
0
 def modify_ext(self,dn,modlist,serverctrls=None,clientctrls=None):
   """
   modify_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
   """
   dn = self._bytesify_input(dn)
   modlist = self._bytesify_modlist(modlist, with_opcode=True)
   return self._ldap_call(self._l.modify_ext,dn,modlist,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 8
0
  def unbind_ext(self,serverctrls=None,clientctrls=None):
    """
    unbind() -> int
    unbind_s() -> None
    unbind_ext() -> int
    unbind_ext_s() -> None
        This call is used to unbind from the directory, terminate
        the current association, and free resources. Once called, the
        connection to the LDAP server is closed and the LDAP object
        is invalid. Further invocation of methods on the object will
        yield an exception.

        The unbind and unbind_s methods are identical, and are
        synchronous in nature
    """
    return self._ldap_call(self._l.unbind_ext,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 9
0
 def simple_bind(self,who=None,cred=None,serverctrls=None,clientctrls=None):
   """
   simple_bind([who='' [,cred='']]) -> int
   """
   if PY2:
       who = self._bytesify_input('who', who)
       cred = self._bytesify_input('cred', cred)
   return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 10
0
    def extop(self, extreq, serverctrls=None, clientctrls=None):
        """
    extop(extreq[,serverctrls=None[,clientctrls=None]]]) -> int
    extop_s(extreq[,serverctrls=None[,clientctrls=None[,extop_resp_class=None]]]]) ->
        (respoid,respvalue)
        Performs an LDAP extended operation. The asynchronous
        form returns the message id of the initiated request, and the
        result can be obtained from a subsequent call to extop_result().
        The extreq is an instance of class ldap.extop.ExtendedRequest.

        If argument extop_resp_class is set to a sub-class of
        ldap.extop.ExtendedResponse this class is used to return an
        object of this class instead of a raw BER value in respvalue.
    """
        return self._ldap_call(self._l.extop, extreq.requestName,
                               extreq.encodedRequestValue(),
                               RequestControlTuples(serverctrls),
                               RequestControlTuples(clientctrls))
Exemplo n.º 11
0
 def add_ext(self,dn,modlist,serverctrls=None,clientctrls=None):
   """
   add_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
       This function adds a new entry with a distinguished name
       specified by dn which means it must not already exist.
       The parameter modlist is similar to the one passed to modify(),
       except that no operation integer need be included in the tuples.
   """
   return self._ldap_call(self._l.add_ext,dn,modlist,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 12
0
    def compare_ext(self, dn, attr, value, serverctrls=None, clientctrls=None):
        """
    compare_ext(dn, attr, value [,serverctrls=None[,clientctrls=None]]) -> int
    compare_ext_s(dn, attr, value [,serverctrls=None[,clientctrls=None]]) -> int
    compare(dn, attr, value) -> int
    compare_s(dn, attr, value) -> int
        Perform an LDAP comparison between the attribute named attr of
        entry dn, and the value value. The synchronous form returns 0
        for false, or 1 for true.  The asynchronous form returns the
        message id of the initiates request, and the result of the
        asynchronous compare can be obtained using result().

        Note that this latter technique yields the answer by raising
        the exception objects COMPARE_TRUE or COMPARE_FALSE.

        A design bug in the library prevents value from containing
        nul characters.
    """
        return self._ldap_call(self._l.compare_ext, dn, attr, value,
                               RequestControlTuples(serverctrls),
                               RequestControlTuples(clientctrls))
Exemplo n.º 13
0
    def rename(self,
               dn,
               newrdn,
               newsuperior=None,
               delold=1,
               serverctrls=None,
               clientctrls=None):
        """
    rename(dn, newrdn [, newsuperior=None [,delold=1][,serverctrls=None[,clientctrls=None]]]) -> int
    rename_s(dn, newrdn [, newsuperior=None] [,delold=1][,serverctrls=None[,clientctrls=None]]) -> None
        Perform a rename entry operation. These routines take dn, the
        DN of the entry whose RDN is to be changed, newrdn, the
        new RDN, and newsuperior, the new parent DN, to give to the entry.
        If newsuperior is None then only the RDN is modified.
        The optional parameter delold is used to specify whether the
        old RDN should be kept as an attribute of the entry or not.
        The asynchronous version returns the initiated message id.

        This actually corresponds to the rename* routines in the
        LDAP-EXT C API library.
    """
        return self._ldap_call(self._l.rename, dn, newrdn, newsuperior, delold,
                               RequestControlTuples(serverctrls),
                               RequestControlTuples(clientctrls))
Exemplo n.º 14
0
 def set_option(self, option, invalue):
     if option == ldap.OPT_SERVER_CONTROLS or option == ldap.OPT_CLIENT_CONTROLS:
         invalue = RequestControlTuples(invalue)
     return self._ldap_call(self._l.set_option, option, invalue)
Exemplo n.º 15
0
 def passwd(self, user, oldpw, newpw, serverctrls=None, clientctrls=None):
     return self._ldap_call(self._l.passwd, user, oldpw, newpw,
                            RequestControlTuples(serverctrls),
                            RequestControlTuples(clientctrls))
Exemplo n.º 16
0
# Switch off processing .ldaprc or ldap.conf before importing _ldap
os.environ['LDAPNOINIT'] = '1'

from slapdtest import SlapdTestCase, requires_tls

import ldap
from ldap.controls import RequestControlTuples
from ldap.controls.pagedresults import SimplePagedResultsControl
from ldap.controls.openldap import SearchNoOpControl
from ldap.ldapobject import SimpleLDAPObject

SENTINEL = object()

TEST_CTRL = RequestControlTuples([
    # with BER data
    SimplePagedResultsControl(criticality=0, size=5, cookie=b'cookie'),
    # value-less
    SearchNoOpControl(criticality=1),
])
TEST_CTRL_EXPECTED = [
    TEST_CTRL[0],
    # get_option returns empty bytes
    (TEST_CTRL[1][0], TEST_CTRL[1][1], b''),
]


class BaseTestOptions:
    """Common tests for getting/setting options

    Used in subclasses below
    """
    def get_option(self, option):
Exemplo n.º 17
0
 def passwd(self,user,oldpw,newpw,serverctrls=None,clientctrls=None):
   if PY2:
       user = self._bytesify_input('user', user)
       oldpw = self._bytesify_input('oldpw', oldpw)
       newpw = self._bytesify_input('newpw', newpw)
   return self._ldap_call(self._l.passwd,user,oldpw,newpw,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 18
0
 def passwd(self,user,oldpw,newpw,serverctrls=None,clientctrls=None):
   user, oldpw, newpw = self._bytesify_inputs(user, oldpw, newpw)
   return self._ldap_call(self._l.passwd,user,oldpw,newpw,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 19
0
 def modify_ext(self,dn,modlist,serverctrls=None,clientctrls=None):
   """
   modify_ext(dn, modlist[,serverctrls=None[,clientctrls=None]]) -> int
   """
   return self._ldap_call(self._l.modify_ext,dn,modlist,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
Exemplo n.º 20
0
 def simple_bind(self,who='',cred='',serverctrls=None,clientctrls=None):
   """
   simple_bind([who='' [,cred='']]) -> int
   """
   return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))