""""
import ldap
from ldap.controls import SimplePagedResultsControl

ldap.set_option(ldap.OPT_REFERRALS, 0)
ldap.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
connection = ldap.initialize(f"ldap://10.10.14.103")
# connection.simple_bind_s("admin", "password")
base = "dc=EPP,dc=RU"
scope = ldap.SCOPE_SUBTREE
filter = "(&(objectClass=person)(description=vasya@EPP.RU))"
attrs = ['*']
req_ctrl = SimplePagedResultsControl(criticality=True, size=1000, cookie='')
pagination_settings = SimplePagedResultsControl(criticality=True, size=1000, cookie='')
ldap_search_query = connection.search_ext(
    base, ldap.SCOPE_SUBTREE, filter, attrlist=attrs, serverctrls=[pagination_settings]
)
known_ldap_resp_ctrls = {
    SimplePagedResultsControl.controlType: SimplePagedResultsControl,
}
total_results = []
pages = 0
while True:
    pages += 1
    rtype, rdata, rmsgid, serverctrls = connection.result3(ldap_search_query,
                                                            resp_ctrl_classes=known_ldap_resp_ctrls)
    print(rdata)
    page_controls = [
        c
        for c in serverctrls
        if c.controlType == SimplePagedResultsControl.controlType
    ]
    if page_controls:
        if page_controls[0].cookie:
            # Copy cookie from response control to request control
            pagination_settings.cookie = page_controls[0].cookie
            ldap_search_query = connection.search_ext(
                base,
                ldap.SCOPE_SUBTREE,
                filter,
                attrlist=attrs,
                serverctrls=[pagination_settings]
            )
        else:
            break
    else:
        print("Warning:  Server ignores RFC 2696 control.")
        break
        """

"""
import ldap
import gssapi

user = "vasya"
password = "1234qwertY*"
mech = gssapi.Mechanism.from_name('krb5')
name = gssapi.Name(user, gssapi.NameType.user_principal_name)
creds = mech.acquire_cred_with_password(name, password)

target = "ldap/astra.epp.ru@EPP.RU"
ctx = gssapi.SecurityContext(creds, mech)
ctx_flags = gssapi.RequirementFlag.mutual_authentication | gssapi.RequirementFlag.confidentiality
ctx.initiate_security_context(target_name=target, flags=ctx_flags)

query = "(uid=user1)"
ldap_connection = ldap.initialize(f"ldap://epp.ru")
result = ctx.init_sec_context(lambda data: ldap_connection.sasl_interactive_bind_s("", gssapi.raw(data)), query)



krb = gssapi.Name('kerberos', gssapi.NameType.krb5_nt_principal_name)
"""
"""
import ldap, ldap.sasl, urllib

ldap_conn = ldap.initialize("ldap://epp.ru")

auth = ldap.sasl.gssapi()

# Bind to the LDAP server using GSSAPI authentication
ldap_conn.sasl_gssapi_bind_s('', auth)

# Check if the bind was successful
print(ldap_conn.whoami_s())
"""

"""
import logging
from abc import ABC, abstractmethod
from typing import Any, Optional, Tuple, Type

from gssapi import Name, NameType
from gssapi.exceptions import GSSError
from gssapi.raw import acquire_cred_with_password

_log = logging.getLogger(__name__)

"""


import ldap, ldap.sasl

l = ldap.initialize("ldap://epp.ru")
auth = ldap.sasl.gssapi("")
l.sasl_bind_s("", auth, cred="")


res = l.search_s("dc=nil,dc=b17",ldap.SCOPE_BASE,"(objectClass=*)")
print(res)

l.unbind()
