Detect if an Active Directory user account is locked using LDAP in Python

后端 未结 7 2245
挽巷
挽巷 2020-12-14 08:53

I\'m validating user logins using python\'s ldap module. When the login fails, I get a ldap.INVALID_CREDENTIALS login, but this can be either because of a wrong password or

相关标签:
7条回答
  • 2020-12-14 09:28

    I found also this list of property flags: How to use the UserAccountControl flags

    SCRIPT  0x0001  1
    ACCOUNTDISABLE  0x0002  2
    HOMEDIR_REQUIRED    0x0008  8
    LOCKOUT 0x0010  16
    PASSWD_NOTREQD  0x0020  32
    PASSWD_CANT_CHANGE 0x0040   64
    ENCRYPTED_TEXT_PWD_ALLOWED  0x0080  128
    TEMP_DUPLICATE_ACCOUNT  0x0100  256
    NORMAL_ACCOUNT  0x0200  512
    INTERDOMAIN_TRUST_ACCOUNT   0x0800  2048
    WORKSTATION_TRUST_ACCOUNT   0x1000  4096
    SERVER_TRUST_ACCOUNT    0x2000  8192
    DONT_EXPIRE_PASSWORD    0x10000 65536
    MNS_LOGON_ACCOUNT   0x20000 131072
    SMARTCARD_REQUIRED  0x40000 262144
    TRUSTED_FOR_DELEGATION  0x80000 524288
    NOT_DELEGATED   0x100000    1048576
    USE_DES_KEY_ONLY    0x200000    2097152
    DONT_REQ_PREAUTH    0x400000    4194304
    PASSWORD_EXPIRED    0x800000    8388608
    TRUSTED_TO_AUTH_FOR_DELEGATION  0x1000000   16777216
    PARTIAL_SECRETS_ACCOUNT 0x04000000      67108864
    

    You must make a binary-AND of property userAccountControl with 0x002. In order to get all locked (i.e. disabled) accounts you can use

    (&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))
    

    For operator 1.2.840.113556.1.4.803 see LDAP Matching Rules

    0 讨论(0)
提交回复
热议问题