uncloud-mravi/meow-payv1/ldaptest.py
Nico Schottelius 94633d6cc8 move uncloud a layer up
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
2020-02-23 14:07:37 +01:00

28 lines
745 B
Python

import ldap3
from ldap3 import Server, Connection, ObjectDef, Reader, ALL
import os
import sys
def is_valid_ldap_user(username, password):
server = Server("ldaps://ldap1.ungleich.ch")
is_valid = False
try:
conn = Connection(server, 'cn={},ou=users,dc=ungleich,dc=ch'.format(username), password, auto_bind=True)
is_valid = True
except Exception as e:
print("user: {}".format(e))
try:
conn = Connection(server, 'uid={},ou=customer,dc=ungleich,dc=ch'.format(username), password, auto_bind=True)
is_valid = True
except Exception as e:
print("customer: {}".format(e))
return is_valid
if __name__ == '__main__':
print(is_valid_ldap_user(sys.argv[1], sys.argv[2]))