From ece64631a733854305e79f11bfc3da8ec240ce41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Barnouin?= Date: Thu, 4 Jan 2024 14:18:07 +0100 Subject: [PATCH] Create json to LDAP user creation script --- json2ldap.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 json2ldap.py diff --git a/json2ldap.py b/json2ldap.py new file mode 100644 index 0000000..070aebc --- /dev/null +++ b/json2ldap.py @@ -0,0 +1,28 @@ +import json +from ldap3 import Server, Connection, ALL + +serv = Server('10.54.3.60', get_info=ALL) # define an unsecure LDAP server, requesting info on DSE and schema + +conn = Connection(s, user='cn=admin,dc=nantes,dc=omero-fbi,dc=fr', password='Jps55Sk8An9y2nVL') + +if not conn.bind(): + print('error in bind', conn.result) + +data_file="user.json" + +with open(data_file, "r") as file: + json_user = json.load(file) + + ldap_user_dn = json_user["dn"] + ldap_full_username = json_user["params"]["attributes"]["uid"] + ldap_full_passwd = json_user["params"]["attributes"]["userPassword"] + ldap_givenname = json_user["params"]["attributes"]["givenName"] + ldap_surname = json_user["params"]["attributes"]["sn"] + ldap_homedir = json_user["params"]["attributes"]["homeDirectory"] + ldap_mail = json_user["params"]["attributes"]["mail"] + ldap_uid_number = json_user["params"]["attributes"]["uidNumber"] + ldap_gid_number = json_user["params"]["attributes"]["gidNumber"] + + conn.add(ldap_user_dn, ['inetOrgPerson', 'posixAccount', 'person', 'top'], {'sn': ldap_surname, 'gidNumber': ldap_gid_number, 'uidNumber': ldap_uid_number}, 'mail': ldap_mail, 'homeDirectory': ldap_homedir, 'userPassword': ldap_full_passwd, 'givenName': ldap_givenname, 'uid': ldap_full_username) + +print(c.result)