Projet

Général

Profil

0001-ldap-add-page_size-configuration-option-65605.patch

Benjamin Dauvergne, 23 mai 2022 16:20

Télécharger (2,84 ko)

Voir les différences:

Subject: [PATCH] ldap: add page_size configuration option (#65605)

 src/authentic2/backends/ldap_backend.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
src/authentic2/backends/ldap_backend.py
543 543
        # https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap.html#ldap-controls
544 544
        'use_controls': False,
545 545
        'ppolicy_dn': '',
546
        # default page size for SimplePagedSearch extension
547
        'page_size': 100,
546 548
    }
547 549
    _REQUIRED = ('url', 'basedn')
548 550
    _TO_ITERABLE = ('url', 'groupsu', 'groupstaff', 'groupactive')
......
1609 1611
        return [(a, '%s (LDAP)' % a) for a in sorted(names)]
1610 1612

  
1611 1613
    @classmethod
1612
    def paged_search(cls, conn, *args, **kwargs):
1613
        COOKIE = ''
1614
        PAGE_SIZE = 100
1615
        CRITICALITY = True
1616
        first_pass = True
1617
        pg_ctrl = SimplePagedResultsControl(CRITICALITY, PAGE_SIZE, COOKIE)
1618
        while first_pass or pg_ctrl.cookie:
1619
            first_pass = False
1614
    def paged_search(cls, block, conn, *args, **kwargs):
1615
        page_size = block.get('page_size', 100)
1616
        pg_ctrl = SimplePagedResultsControl(criticality=True, size=page_size, cookie='')
1617
        while True:
1620 1618
            msgid = conn.search_ext(*args, serverctrls=[pg_ctrl], **kwargs)
1621 1619
            dummy_result_type, data, msgid, serverctrls = conn.result3(msgid)
1622 1620
            pg_ctrl.cookie = serverctrls[0].cookie
1623 1621
            yield from cls.normalize_ldap_results(data)
1622
            if not pg_ctrl.cookie:
1623
                break
1624 1624

  
1625 1625
    @classmethod
1626 1626
    def get_users_for_block(cls, block):
......
1634 1634
        user_filter = cls.get_sync_ldap_user_filter(block)
1635 1635
        attribute_names = cls.get_ldap_attributes_names(block)
1636 1636
        results = cls.paged_search(
1637
            conn, user_basedn, ldap.SCOPE_SUBTREE, user_filter, attrlist=attribute_names
1637
            block, conn, user_basedn, ldap.SCOPE_SUBTREE, user_filter, attrlist=attribute_names
1638 1638
        )
1639 1639
        backend = cls()
1640 1640
        for dn, attrs in results:
......
1700 1700
            )
1701 1701
            user_filter = cls.get_sync_ldap_user_filter(block)
1702 1702
            results = cls.paged_search(
1703
                conn, basedn, ldap.SCOPE_SUBTREE, user_filter, attrlist=attribute_names
1703
                block, conn, basedn, ldap.SCOPE_SUBTREE, user_filter, attrlist=attribute_names
1704 1704
            )
1705 1705
            for dn, attrs in results:
1706 1706
                data = attrs.copy()
1707
-