How to use the ldaptor.protocols.pureldap function in ldaptor

To help you get started, we’ve selected a few ldaptor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / ldaptor / ldaptor / protocols / ldap / ldapsyntax.py View on Github external
del a
        rdn = distinguishedname.RelativeDistinguishedName(rdn)
        dn = distinguishedname.DistinguishedName(
            listOfRDNs=(rdn,) + self.dn.split())

        ldapAttrs = []
        for attrType, values in attributes:
            ldapAttrType = pureldap.LDAPAttributeDescription(attrType)
            lst = []
            for value in values:
                if (isinstance(value, six.text_type)):
                    value = value.encode('utf-8')
                lst.append(pureldap.LDAPAttributeValue(value))
            ldapValues = pureber.BERSet(lst)
            ldapAttrs.append((ldapAttrType, ldapValues))
        op = pureldap.LDAPAddRequest(
            entry=dn,
            attributes=ldapAttrs)
        d = self.client.send(op)
        d.addCallback(self._cbAddDone, dn)
        return d
github twisted / ldaptor / ldaptor / protocols / ldap / ldapsyntax.py View on Github external
controls=None,
               return_controls=False):
        self._checkState()
        d = defer.Deferred()
        if filterObject is None and filterText is None:
            filterObject = pureldap.LDAPFilterMatchAll
        elif filterObject is None and filterText is not None:
            filterObject = ldapfilter.parseFilter(filterText)
        elif filterObject is not None and filterText is None:
            pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        if attributes is None:
            attributes = ['1.1']

        results = []
        if callback is None:
            cb = results.append
        else:
            cb = callback
        try:
            op = pureldap.LDAPSearchRequest(
                baseObject=self.dn,
                scope=scope,
                derefAliases=derefAliases,
github JackOfMostTrades / bluebox / evil_dc / ldap / evil_server.py View on Github external
def findDomain(filt):
    if isinstance(filt, pureldap.LDAPFilter_and):
        for x in filt:
            d = findDomain(x)
            if d != None: return d
    if isinstance(filt, pureldap.LDAPFilter_equalityMatch):
        if (filt.attributeDesc.value == 'DnsDomain'):
            return filt.assertionValue.value
    return None
github JackOfMostTrades / bluebox / evil_dc / ldap / evil_server.py View on Github external
def findDomain(filt):
    if isinstance(filt, pureldap.LDAPFilter_and):
        for x in filt:
            d = findDomain(x)
            if d != None: return d
    if isinstance(filt, pureldap.LDAPFilter_equalityMatch):
        if (filt.attributeDesc.value == 'DnsDomain'):
            return filt.assertionValue.value
    return None
github twisted / ldaptor / ldaptor / protocols / ldap / svcbindproxy.py View on Github external
pureldap.LDAPFilter_equalityMatch(attributeDesc=pureldap.LDAPAttributeDescription('objectClass'),
                                              assertionValue=pureldap.LDAPAssertionValue('serviceSecurityObject')),
            pureldap.LDAPFilter_equalityMatch(attributeDesc=pureldap.LDAPAttributeDescription('owner'),
                                              assertionValue=pureldap.LDAPAssertionValue(request.dn)),
            pureldap.LDAPFilter_equalityMatch(attributeDesc=pureldap.LDAPAttributeDescription('cn'),
                                              assertionValue=pureldap.LDAPAssertionValue(serviceName)),

            pureldap.LDAPFilter_or([
            # no time
            pureldap.LDAPFilter_not(pureldap.LDAPFilter_present('validFrom')),
            # or already valid
            pureldap.LDAPFilter_lessOrEqual(attributeDesc=pureldap.LDAPAttributeDescription('validFrom'),
                                            assertionValue=pureldap.LDAPAssertionValue(timestamp)),
            ]),

            pureldap.LDAPFilter_or([
            # no time
            pureldap.LDAPFilter_not(pureldap.LDAPFilter_present('validUntil')),
            # or still valid
            pureldap.LDAPFilter_greaterOrEqual(attributeDesc=pureldap.LDAPAttributeDescription('validUntil'),
                                               assertionValue=pureldap.LDAPAssertionValue(timestamp)),
            ]),

            ]),
                             attributes=('1.1',))

        def _gotEntries(entries):
            if not entries:
                return None
            assert len(entries)==1 #TODO
            e = entries[0]
            d = e.bind(request.auth)
github twisted / ldaptor / ldaptor / protocols / ldap / merger.py View on Github external
fail_LDAPDelRequest = pureldap.LDAPDelResponse

    def handle_LDAPDelRequest(self, request, controls, reply):
         raise ldaperrors.LDAPUnwillingToPerform()

    fail_LDAPAddRequest = pureldap.LDAPAddResponse

    def handle_LDAPAddRequest(self, request, controls, reply):
        raise ldaperrors.LDAPUnwillingToPerform()

    fail_LDAPModifyDNRequest = pureldap.LDAPModifyDNResponse

    def handle_LDAPModifyDNRequest(self, request, controls, reply):
         raise ldaperrors.LDAPUnwillingToPerform()

    fail_LDAPModifyRequest = pureldap.LDAPModifyResponse

    def handle_LDAPModifyRequest(self, request, controls, reply):
        raise ldaperrors.LDAPUnwillingToPerform()

    fail_LDAPExtendedRequest = pureldap.LDAPExtendedResponse

    def handle_LDAPExtendedRequest(self, request, controls, reply):
         raise ldaperrors.LDAPUnwillingToPerform()

if __name__ == '__main__':
    from twisted.internet import protocol
    from twisted.python import log
    import sys
    log.startLogging(sys.stderr)

    configs = [LDAPConfig(serviceLocationOverrides={"": ('localhost', 38942)}),
github twisted / ldaptor / ldaptor / apps / webui / search.py View on Github external
def _search(proto, base):
            baseEntry = ldapsyntax.LDAPEntry(client=proto,
                                             dn=base)
            d=baseEntry.search(scope=pureldap.LDAP_SCOPE_baseObject,
                               sizeLimit=1)
            def _cb(result, proto):
                proto.unbind()
                return result
            d.addBoth(_cb, proto)
            return d
        d.addCallback(_search, iwebui.ICurrentDN(context))
github twisted / ldaptor / ldaptor / entryhelpers.py View on Github external
pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        # choose iterator: base/children/subtree
        if scope == pureldap.LDAP_SCOPE_wholeSubtree:
            iterator = self.subtree
        elif scope == pureldap.LDAP_SCOPE_singleLevel:
            iterator = self.children
        elif scope == pureldap.LDAP_SCOPE_baseObject:
            def iterateSelf(callback):
                callback(self)
                return defer.succeed(None)

            iterator = iterateSelf
        else:
            raise ldaperrors.LDAPProtocolError('unknown search scope: %r' % scope)

        results = []
        if callback is None:
            matchCallback = results.append
        else:
            matchCallback = callback

        # gather results, send them
        def _tryMatch(entry):
github twisted / ldaptor / ldaptor / protocols / ldap / ldapsyntax.py View on Github external
self._checkState()
        d = defer.Deferred()
        if filterObject is None and filterText is None:
            filterObject = pureldap.LDAPFilterMatchAll
        elif filterObject is None and filterText is not None:
            filterObject = ldapfilter.parseFilter(filterText)
        elif filterObject is not None and filterText is None:
            pass
        elif filterObject is not None and filterText is not None:
            f = ldapfilter.parseFilter(filterText)
            filterObject = pureldap.LDAPFilter_and((f, filterObject))

        if scope is None:
            scope = pureldap.LDAP_SCOPE_wholeSubtree
        if derefAliases is None:
            derefAliases = pureldap.LDAP_DEREF_neverDerefAliases

        if attributes is None:
            attributes = ['1.1']

        results = []
        if callback is None:
            cb = results.append
        else:
            cb = callback
        try:
            op = pureldap.LDAPSearchRequest(
                baseObject=self.dn,
                scope=scope,
                derefAliases=derefAliases,
                sizeLimit=sizeLimit,
                timeLimit=timeLimit,