Commit 55b60726 authored by Recteur LP's avatar Recteur LP
Browse files

rename settings template and open socket to ldap only if needed

parent 15fa1bbe
......@@ -19,19 +19,23 @@ class ldapauth2():
"LDAP auth module"
def __init__(self, config):
# Get Auth method in config file if none set go to simgle user mode
if 'ldap' in config:
if 'server' not in config['ldap']:
returnerror("No ldap server in config")
elif 'port' not in config['ldap']:
returnerror("No ldap port in config")
self.config = config
self.ld = ldap.initialize('ldap://' + self.config['ldap']['server'] + ':' + self.config['ldap']['port'])
self.ld.protocol_version = config['ldap']['version']
self.ld.set_option(ldap.OPT_REFERRALS, 0)
self.ld.simple_bind_s(self.config['ldap']['user'], self.config['ldap']['password'])
if config:
if 'ldap' in config:
if 'server' not in config['ldap']:
returnerror("No ldap server in config")
elif 'port' not in config['ldap']:
returnerror("No ldap port in config")
self.config = config
self.ld = ldap.initialize('ldap://' + self.config['ldap']['server'] + ':' + self.config['ldap']['port'])
self.ld.protocol_version = config['ldap']['version']
self.ld.set_option(ldap.OPT_REFERRALS, 0)
self.ld.simple_bind_s(self.config['ldap']['user'], self.config['ldap']['password'])
def __del__(self):
self.ld.unbind_s()
try:
self.ld.unbind_s()
except:
pass
def __getresults(self, filter):
results = self.ld.search_s(self.config['ldap']['basedn'],ldap.SCOPE_SUBTREE,filter)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment