Files
stand/auth/krbldap.py
T

27 lines
752 B
Python

import gssapi
from ldap3 import GSSAPI, NONE, ROUND_ROBIN, SASL, Connection, Server, ServerPool
def Konnection(hosts, username, password):
server_pool = make_server_pool(hosts)
creds = make_creds(username, password)
return Connection(
server_pool,
authentication=SASL,
sasl_mechanism=GSSAPI,
sasl_credentials=(None, None, creds)
)
def make_server_pool(hosts):
servers = [Server(host, get_info=NONE, connect_timeout=3) for host in hosts]
return ServerPool(servers, ROUND_ROBIN, active=3, exhaust=True)
def make_creds(username, password):
user = gssapi.Name(base=username, name_type=gssapi.NameType.user)
return gssapi.raw.acquire_cred_with_password(user, password.encode()).creds