Ejemplo n.º 1
0
    def _lookup(self, dn):
        if not self.dn.contains(dn):
            raise ldaperrors.LDAPNoSuchObject(dn)
        if dn == self.dn:
            return defer.succeed(self)

        for c in self._children.values():
            if c.dn.contains(dn):
                return c.lookup(dn)

        raise ldaperrors.LDAPNoSuchObject(dn)
Ejemplo n.º 2
0
 def _deleteChild(self, rdn):
     if not isinstance(rdn, distinguishedname.RelativeDistinguishedName):
         rdn = distinguishedname.RelativeDistinguishedName(stringValue=rdn)
     for c in self._sync_children():
         if c.dn.split()[0] == rdn:
             return c.delete()
     raise ldaperrors.LDAPNoSuchObject(rdn.getText())
Ejemplo n.º 3
0
 def test_exception_with_dn(self):
     """Exception with a distinguished name"""
     dn = distinguishedname.DistinguishedName(
         stringValue='dc=example,dc=org')
     exception = ldaperrors.LDAPNoSuchObject(dn)
     self.assertEqual(exception.toWire(),
                      b'noSuchObject: dc=example,dc=org')
Ejemplo n.º 4
0
 def _deleteChild(self, rdn):
     if not isinstance(rdn, distinguishedname.RelativeDistinguishedName):
         rdn = distinguishedname.RelativeDistinguishedName(stringValue=rdn)
     rdn_str = rdn.toWire()
     try:
         return self._children.pop(rdn_str)
     except KeyError:
         raise ldaperrors.LDAPNoSuchObject(rdn)
Ejemplo n.º 5
0
    def lookup(self, dn):
        dn = distinguishedname.DistinguishedName(dn)
        if not self.dn.contains(dn):
            return defer.fail(ldaperrors.LDAPNoSuchObject(dn))
        if dn == self.dn:
            return defer.succeed(self)

        it = dn.split()
        me = self.dn.split()
        assert len(it) > len(me)
        assert ((len(me) == 0) or (it[-len(me):] == me))
        rdn = it[-len(me)-1]
        path = os.path.join(self.path, '%s.dir' % rdn)
        entry = os.path.join(self.path, '%s.ldif' % rdn)
        if not os.path.isdir(path) and not os.path.isfile(entry):
            return defer.fail(ldaperrors.LDAPNoSuchObject(dn))
        else:
            childDN = distinguishedname.DistinguishedName(listOfRDNs=(rdn,)+me)
            c = self.__class__(path, childDN)
            return c.lookup(dn)
Ejemplo n.º 6
0
def bind(dn, password):
    query = ldap_dn_to_dict(dn)
    uid = query.get('uid', '')

    user = get_user_by_uid(uid)
    if not user:
        raise ldaperrors.LDAPNoSuchObject(dn)

    try:
        confirm_login_allowed(user, password)
    except login_exceptions.Inactive:
        raise ldaperrors.LDAPNoSuchObject(dn)
    except login_exceptions.Invalid:
        raise ldaperrors.LDAPInvalidCredentials()
    except login_exceptions.TooManyLoginAttempts:
        raise ldaperrors.LDAPInvalidCredentials('tooManyLoginAttempts')
    except login_exceptions.PasswordExpired:
        raise ldaperrors.LDAPInvalidCredentials('passwordExpiration')

    return user, get_user_info_dict(user.user_info, attributes=[])