|
11 | 11 | ]
|
12 | 12 |
|
13 | 13 | # Imports from python-ldap 2.4+
|
14 |
| -import ldap.controls |
15 |
| -from ldap.controls import RequestControl,ResponseControl,ValueLessRequestControl,KNOWN_RESPONSE_CONTROLS |
| 14 | +from ldap.controls import ( |
| 15 | + ResponseControl, ValueLessRequestControl, KNOWN_RESPONSE_CONTROLS |
| 16 | +) |
16 | 17 |
|
17 | 18 | # Imports from pyasn1
|
18 | 19 | from pyasn1.type import tag,namedtype,namedval,univ,constraint
|
19 |
| -from pyasn1.codec.ber import encoder,decoder |
20 |
| -from pyasn1_modules.rfc2251 import LDAPDN |
| 20 | +from pyasn1.codec.der import decoder |
21 | 21 |
|
22 | 22 |
|
23 | 23 | class PasswordPolicyWarning(univ.Choice):
|
@@ -70,25 +70,22 @@ def __init__(self,criticality=False):
|
70 | 70 |
|
71 | 71 | def decodeControlValue(self,encodedControlValue):
|
72 | 72 | ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue())
|
| 73 | + self.timeBeforeExpiration = None |
| 74 | + self.graceAuthNsRemaining = None |
| 75 | + self.error = None |
| 76 | + |
73 | 77 | warning = ppolicyValue.getComponentByName('warning')
|
74 |
| - if not warning.hasValue(): |
75 |
| - self.timeBeforeExpiration,self.graceAuthNsRemaining = None,None |
76 |
| - else: |
77 |
| - timeBeforeExpiration = warning.getComponentByName('timeBeforeExpiration') |
78 |
| - if timeBeforeExpiration.hasValue(): |
79 |
| - self.timeBeforeExpiration = int(timeBeforeExpiration) |
80 |
| - else: |
81 |
| - self.timeBeforeExpiration = None |
82 |
| - graceAuthNsRemaining = warning.getComponentByName('graceAuthNsRemaining') |
83 |
| - if graceAuthNsRemaining.hasValue(): |
84 |
| - self.graceAuthNsRemaining = int(graceAuthNsRemaining) |
85 |
| - else: |
86 |
| - self.graceAuthNsRemaining = None |
| 78 | + if warning.hasValue(): |
| 79 | + if 'timeBeforeExpiration' in warning: |
| 80 | + self.timeBeforeExpiration = int( |
| 81 | + warning.getComponentByName('timeBeforeExpiration')) |
| 82 | + if 'graceAuthNsRemaining' in warning: |
| 83 | + self.graceAuthNsRemaining = int( |
| 84 | + warning.getComponentByName('graceAuthNsRemaining')) |
| 85 | + |
87 | 86 | error = ppolicyValue.getComponentByName('error')
|
88 | 87 | if error.hasValue():
|
89 | 88 | self.error = int(error)
|
90 |
| - else: |
91 |
| - self.error = None |
92 | 89 |
|
93 | 90 |
|
94 | 91 | KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl
|
0 commit comments