Commit 5c783757 authored by Recteur LP's avatar Recteur LP

Make an anonymous bind if user/password not provided

parent 39f1b683
......@@ -16,7 +16,7 @@ except ImportError:
__name__ = "LDAP Authentification"
__description__ = "Module to authenticate user with Active Directory Server"
__version__ = "0.3.3"
__pyrmin_version__ = "0.3.1"
__pyrmin_version__ = "0.3.2"
__logo__ = "/plugins/ldapauth/img/logo.png"
__namespace__ = "ldapauth"
###################################
......@@ -31,23 +31,38 @@ class auth():
elif 'port' not in self.config:
pyrmin.returnerror("No ldap port in config")
if sys.version_info >= (3, 0):
self.connection = Connection(
Server(
self.config['server'],
port=int(self.config['port']),
use_ssl=self.config['ssl']
),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user=self.config['user'],
password=self.config['password']
)
if 'user' and 'password' in self.config:
self.connection = Connection(
Server(
self.config['server'],
port=int(self.config['port']),
use_ssl=self.config['ssl']
),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user=self.config['user'],
password=self.config['password']
)
else:
self.connection = Connection(
Server(
self.config['server'],
port=int(self.config['port']),
use_ssl=self.config['ssl']
),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True
)
else:
self.ld = ldap.initialize('ldap://' + self.config['server'] + ':' + str(self.config['port']))
self.ld.protocol_version = self.config['version']
self.ld.set_option(ldap.OPT_REFERRALS, 0)
self.ld.simple_bind_s(self.config['user'], self.config['password'])
if 'user' and 'password' in self.config:
self.ld.simple_bind_s(self.config['user'], self.config['password'])
else:
self.ld.simple_bind_s()
def __del__(self):
if sys.version_info < (3, 0):
......@@ -90,15 +105,15 @@ class auth():
if "attributes" in entry:
attrs = entry['attributes']
users.append({
"name": attrs.get('sAMAccountName', ['Guest'])[0],
"name": attrs.get(self.config['user_id'], ['Guest'])[0],
"uid": attrs.get('uidNumber', ['None'])[0]
})
else:
for dn, attrs in self.__getresults(group):
if dn and attrs:
pyrmin.log.debug(attrs.get('sAMAccountName', ['Guest'])[0])
pyrmin.log.debug(attrs.get(self.config['user_id'], ['Guest'])[0])
users.append({
"name": attrs.get('sAMAccountName', ['Guest'])[0],
"name": attrs.get(self.config['user_id'], ['Guest'])[0],
"uid": attrs.get('uidNumber', ['None'])[0]
})
return users
......@@ -110,7 +125,7 @@ class auth():
for entry in self.__getresults(filter):
if "attributes" in entry:
attrs = entry['attributes']
name = attrs.get('sAMAccountName', ['Guest'])[0]
name = attrs.get(self.config['user_id'], ['Guest'])[0]
mail = str(attrs.get('mail')[0]).lower()
gravatar_url = "https://www.gravatar.com/avatar/" + \
hashlib.md5(mail.encode('utf-8')).hexdigest() + "?"
......@@ -143,7 +158,7 @@ class auth():
else:
filter = "(&(" + self.config['user_id'] + "=" + name + ")(!(objectClass=computer)))"
for dn, attrs in self.__getresults(filter):
name = attrs.get('sAMAccountName', ['Guest'])[0]
name = attrs.get(self.config['user_id'], ['Guest'])[0]
mail = str(attrs.get('mail')[0]).decode('utf-8').lower()
gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(mail).hexdigest() + "?"
gravatar_url += urllib.urlencode({'d': "identicon", 's': str(50)})
......
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