<s> import logging <EOL> import os <EOL> import ldap <EOL> from pushmanager . core . settings import Settings <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> os . environ [ '<STR_LIT>' ] = Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> LDAP_URL = Settings [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] <EOL> def authenticate_ldap ( username , password ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> dn = "<STR_LIT>" % ( username , Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> basedn = Settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> con = ldap . initialize ( LDAP_URL ) <EOL> con . set_option ( ldap . OPT_NETWORK_TIMEOUT , <NUM_LIT:3> ) <EOL> con . set_option ( ldap . OPT_REFERRALS , <NUM_LIT:0> ) <EOL> con . set_option ( ldap . OPT_PROTOCOL_VERSION , ldap . VERSION3 ) <EOL> con . start_tls_s ( ) <EOL> try : <EOL> con . simple_bind_s ( dn , password ) <EOL> con . search_s ( basedn , ldap . SCOPE_ONELEVEL ) <EOL> except : <EOL> return False <EOL> con . unbind_s ( ) <EOL> return True <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> return False <EOL> __all__ = [ '<STR_LIT>' ] </s>
