15
15
from ldap import __version__
16
16
17
17
if __debug__ :
18
- # Tracing is only supported in debugging mode
19
- import traceback
20
- from ldap import _trace_level , _trace_file , _trace_stack_limit
18
+ # Tracing is only supported in debugging mode
19
+ from ldap import _trace_level , _trace_file
20
+
21
21
22
22
# These are the SASL callback id's , as defined in sasl.h
23
- CB_USER = 0x4001
24
- CB_AUTHNAME = 0x4002
25
- CB_LANGUAGE = 0x4003
26
- CB_PASS = 0x4004
27
- CB_ECHOPROMPT = 0x4005
28
- CB_NOECHOPROMPT = 0x4006
29
- CB_GETREALM = 0x4008
23
+ CB_USER = 0x4001
24
+ CB_AUTHNAME = 0x4002
25
+ CB_LANGUAGE = 0x4003
26
+ CB_PASS = 0x4004
27
+ CB_ECHOPROMPT = 0x4005
28
+ CB_NOECHOPROMPT = 0x4006
29
+ CB_GETREALM = 0x4008
30
+
30
31
31
32
class sasl :
32
33
"""This class handles SASL interactions for authentication.
@@ -35,15 +36,15 @@ class sasl:
35
36
specific SASL authentication mechanisms, this method can be
36
37
overridden"""
37
38
38
- def __init__ (self ,cb_value_dict ,mech ):
39
+ def __init__ (self , cb_value_dict , mech ):
39
40
""" The (generic) base class takes a cb_value_dictionary of
40
41
question-answer pairs. Questions are specified by the respective
41
42
SASL callback id's. The mech argument is a string that specifies
42
43
the SASL mechaninsm to be uesd."""
43
44
self .cb_value_dict = cb_value_dict or {}
44
45
self .mech = mech
45
46
46
- def callback (self ,cb_id ,challenge ,prompt ,defresult ):
47
+ def callback (self , cb_id , challenge , prompt , defresult ):
47
48
""" The callback method will be called by the sasl_bind_s()
48
49
method several times. Each time it will provide the id, which
49
50
tells us what kind of information is requested (the CB_ ...
@@ -61,46 +62,54 @@ def callback(self,cb_id,challenge,prompt,defresult):
61
62
62
63
# The following print command might be useful for debugging
63
64
# new sasl mechanisms. So it is left here
64
- cb_result = self .cb_value_dict .get (cb_id ,defresult ) or ''
65
+ cb_result = self .cb_value_dict .get (cb_id , defresult ) or ''
65
66
if __debug__ :
66
- if _trace_level >= 1 :
67
- _trace_file .write ("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n -> %s\n " % (
68
- cb_id , challenge , prompt , repr (defresult ), repr (self .cb_value_dict .get (cb_result ))
69
- ))
67
+ if _trace_level >= 1 :
68
+ _trace_file .write ("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n -> %s\n " % (
69
+ cb_id ,
70
+ challenge ,
71
+ prompt ,
72
+ repr (defresult ),
73
+ repr (self .cb_value_dict .get (cb_result ))
74
+ ))
70
75
return cb_result
71
76
72
77
73
78
class cram_md5 (sasl ):
74
79
"""This class handles SASL CRAM-MD5 authentication."""
75
80
76
- def __init__ (self ,authc_id , password , authz_id = "" ):
77
- auth_dict = {CB_AUTHNAME :authc_id , CB_PASS :password ,
78
- CB_USER :authz_id }
79
- sasl .__init__ (self ,auth_dict ,"CRAM-MD5" )
81
+ def __init__ (self , authc_id , password , authz_id = "" ):
82
+ auth_dict = {
83
+ CB_AUTHNAME : authc_id ,
84
+ CB_PASS : password ,
85
+ CB_USER : authz_id ,
86
+ }
87
+ sasl .__init__ (self , auth_dict , "CRAM-MD5" )
80
88
81
89
82
90
class digest_md5 (sasl ):
83
91
"""This class handles SASL DIGEST-MD5 authentication."""
84
92
85
- def __init__ (self ,authc_id , password , authz_id = "" ):
86
- auth_dict = {CB_AUTHNAME :authc_id , CB_PASS :password ,
87
- CB_USER :authz_id }
88
- sasl .__init__ (self ,auth_dict ,"DIGEST-MD5" )
93
+ def __init__ (self , authc_id , password , authz_id = "" ):
94
+ auth_dict = {
95
+ CB_AUTHNAME : authc_id ,
96
+ CB_PASS : password ,
97
+ CB_USER : authz_id ,
98
+ }
99
+ sasl .__init__ (self , auth_dict , "DIGEST-MD5" )
89
100
90
101
91
102
class gssapi (sasl ):
92
103
"""This class handles SASL GSSAPI (i.e. Kerberos V)
93
104
authentication."""
94
105
95
- def __init__ (self ,authz_id = "" ):
96
- sasl .__init__ (self , {CB_USER :authz_id },"GSSAPI" )
106
+ def __init__ (self , authz_id = "" ):
107
+ sasl .__init__ (self , {CB_USER : authz_id }, "GSSAPI" )
97
108
98
109
99
110
class external (sasl ):
100
111
"""This class handles SASL EXTERNAL authentication
101
112
(i.e. X.509 client certificate)"""
102
113
103
- def __init__ (self ,authz_id = "" ):
104
- sasl .__init__ (self , {CB_USER :authz_id },"EXTERNAL" )
105
-
106
-
114
+ def __init__ (self , authz_id = "" ):
115
+ sasl .__init__ (self , {CB_USER : authz_id }, "EXTERNAL" )
0 commit comments