File: pwdpolicy.py

package info (click to toggle)
python-ldap 3.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,368 kB
  • sloc: python: 9,560; ansic: 3,052; makefile: 139; sh: 79
file content (39 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
ldap.controls.pwdpolicy - classes for Password Policy controls
(see https://tools.ietf.org/html/draft-vchu-ldap-pwd-policy)

See https://www.python-ldap.org/ for project details.
"""

__all__ = [
  'PasswordExpiringControl',
  'PasswordExpiredControl',
]

# Imports from python-ldap 2.4+
import ldap.controls
from ldap.controls import RequestControl,ResponseControl,ValueLessRequestControl,KNOWN_RESPONSE_CONTROLS


class PasswordExpiringControl(ResponseControl):
  """
  Indicates time in seconds when password will expire
  """
  controlType = '2.16.840.1.113730.3.4.5'

  def decodeControlValue(self,encodedControlValue):
    self.gracePeriod = int(encodedControlValue)

KNOWN_RESPONSE_CONTROLS[PasswordExpiringControl.controlType] = PasswordExpiringControl


class PasswordExpiredControl(ResponseControl):
  """
  Indicates that password is expired
  """
  controlType = '2.16.840.1.113730.3.4.4'

  def decodeControlValue(self,encodedControlValue):
    self.passwordExpired = encodedControlValue=='0'

KNOWN_RESPONSE_CONTROLS[PasswordExpiredControl.controlType] = PasswordExpiredControl