0

Modify LDAP object

by
Published Apr 14, 2024

Modify an existing LDAP object identified by it's distinguished name. wrapper around https://ldap3.readthedocs.io/en/latest/modify.html

Script ldap Verified

The script

Submitted by simon594 Python3
Verified 786 days ago
1
import ldap3
2
import json
3
import ssl
4

5
ldap = dict
6

7
def connect(ldap) -> ldap3.Connection:
8
    if ldap.get("ssl_verify", None) == False:
9
        tls_config = ldap3.Tls(validate=ssl.CERT_REQUIRED) 
10
    else: 
11
        tls_config = ldap3.Tls(validate=ssl.CERT_NONE) 
12
    ldap_server = ldap3.Server(ldap['server'], get_info=ldap3.ALL, use_ssl=ldap['use_ssl'], tls=tls_config)
13
    return ldap3.Connection(ldap_server, ldap['bind_user'], ldap['bind_password'], auto_bind=True, client_strategy=ldap3.RESTARTABLE)
14

15
def main(ldap: ldap, distinguished_name: str, modifications:dict[str,list]):
16
    ldap_conn = connect(ldap)
17
    ldap_conn.modify(distinguished_name, modifications)
18
    return ldap_conn.result