Skip to content

Commit

Permalink
a bit of PEP-8 for ldap.sasl
Browse files Browse the repository at this point in the history
  • Loading branch information
stroeder authored and Petr Viktorin committed Nov 22, 2017
1 parent 4944d99 commit e8eb3ee
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions Lib/ldap/sasl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
from ldap import __version__

if __debug__:
# Tracing is only supported in debugging mode
import traceback
from ldap import _trace_level,_trace_file,_trace_stack_limit
# Tracing is only supported in debugging mode
from ldap import _trace_level, _trace_file


# These are the SASL callback id's , as defined in sasl.h
CB_USER = 0x4001
CB_AUTHNAME = 0x4002
CB_LANGUAGE = 0x4003
CB_PASS = 0x4004
CB_ECHOPROMPT = 0x4005
CB_NOECHOPROMPT= 0x4006
CB_GETREALM = 0x4008
CB_USER = 0x4001
CB_AUTHNAME = 0x4002
CB_LANGUAGE = 0x4003
CB_PASS = 0x4004
CB_ECHOPROMPT = 0x4005
CB_NOECHOPROMPT = 0x4006
CB_GETREALM = 0x4008


class sasl:
"""This class handles SASL interactions for authentication.
Expand All @@ -35,15 +36,15 @@ class sasl:
specific SASL authentication mechanisms, this method can be
overridden"""

def __init__(self,cb_value_dict,mech):
def __init__(self, cb_value_dict, mech):
""" The (generic) base class takes a cb_value_dictionary of
question-answer pairs. Questions are specified by the respective
SASL callback id's. The mech argument is a string that specifies
the SASL mechaninsm to be uesd."""
self.cb_value_dict = cb_value_dict or {}
self.mech = mech

def callback(self,cb_id,challenge,prompt,defresult):
def callback(self, cb_id, challenge, prompt, defresult):
""" The callback method will be called by the sasl_bind_s()
method several times. Each time it will provide the id, which
tells us what kind of information is requested (the CB_ ...
Expand All @@ -61,46 +62,54 @@ def callback(self,cb_id,challenge,prompt,defresult):

# The following print command might be useful for debugging
# new sasl mechanisms. So it is left here
cb_result = self.cb_value_dict.get(cb_id,defresult) or ''
cb_result = self.cb_value_dict.get(cb_id, defresult) or ''
if __debug__:
if _trace_level>=1:
_trace_file.write("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n" % (
cb_id, challenge, prompt, repr(defresult), repr(self.cb_value_dict.get(cb_result))
))
if _trace_level >= 1:
_trace_file.write("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n" % (
cb_id,
challenge,
prompt,
repr(defresult),
repr(self.cb_value_dict.get(cb_result))
))
return cb_result


class cram_md5(sasl):
"""This class handles SASL CRAM-MD5 authentication."""

def __init__(self,authc_id, password, authz_id=""):
auth_dict = {CB_AUTHNAME:authc_id, CB_PASS:password,
CB_USER:authz_id}
sasl.__init__(self,auth_dict,"CRAM-MD5")
def __init__(self, authc_id, password, authz_id=""):
auth_dict = {
CB_AUTHNAME: authc_id,
CB_PASS: password,
CB_USER: authz_id,
}
sasl.__init__(self, auth_dict, "CRAM-MD5")


class digest_md5(sasl):
"""This class handles SASL DIGEST-MD5 authentication."""

def __init__(self,authc_id, password, authz_id=""):
auth_dict = {CB_AUTHNAME:authc_id, CB_PASS:password,
CB_USER:authz_id}
sasl.__init__(self,auth_dict,"DIGEST-MD5")
def __init__(self, authc_id, password, authz_id=""):
auth_dict = {
CB_AUTHNAME: authc_id,
CB_PASS: password,
CB_USER: authz_id,
}
sasl.__init__(self, auth_dict, "DIGEST-MD5")


class gssapi(sasl):
"""This class handles SASL GSSAPI (i.e. Kerberos V)
authentication."""

def __init__(self,authz_id=""):
sasl.__init__(self, {CB_USER:authz_id},"GSSAPI")
def __init__(self, authz_id=""):
sasl.__init__(self, {CB_USER: authz_id}, "GSSAPI")


class external(sasl):
"""This class handles SASL EXTERNAL authentication
(i.e. X.509 client certificate)"""

def __init__(self,authz_id=""):
sasl.__init__(self, {CB_USER:authz_id},"EXTERNAL")


def __init__(self, authz_id=""):
sasl.__init__(self, {CB_USER: authz_id}, "EXTERNAL")

0 comments on commit e8eb3ee

Please sign in to comment.