Score:0

Comparing ldap object attributes from different LDAP servers

pt flag

I have one requirement like...I need to write a python script which will compare objects between two ldap servers residing in two different servers (server A and server B) and list out the discrepancies if found any. Ideally the cn, posix attributes like uidNumber, gidNumber,homeDir, loginshell attributes. So the script should find out the discrepancies if any and write it to CSV. Could anyone please help me? Thanks in advance

I have written some of it ,

#!/usr/bin/python3

from ldap3 import Server, Connection, SUBTREE,  core

import csv
import argparse
import time

# Global Variables

t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
serverA_uid_number = ''
serverA_cn = ''
serverB_uid_number = ''
uid = ''
common_name = ''
serverB_Sync = True
serverA_Sync = True
csvwriter = ''
filename_1 = "serverA_serverB-{}.csv".format(timestamp)
filename_2 = "serverB_serverA-{}.csv".format(timestamp)
serverA_server = Server('serverA-ldap-eb.abc.com', port=636, use_ssl=True)
serverB_server = Server('serverB-ldap-eb.abc.com', port=636, use_ssl=True)

# Argument parser
parser = argparse.ArgumentParser(description="serverA-serverB Synchronization and vice versa")
parser.add_argument("-g", "--serverA", help="serverA to serverB Synchronization", action="store_true")
parser.add_argument("-r", "--serverB", help="serverB to serverA Synchronization", action="store_true")
args = parser.parse_args()


def get_list_of_serverA_users():
    fields = ['Distinguished name', 'Comman Name', 'serverA UID Number', 'serverB UID Number', 'Synchronization']
    csvfile = open(filename_1, 'a+', newline='')
    csvwriter = csv.writer(csvfile)
    csvwriter.writerow(fields)

    try:
        c = Connection(serverA_server, user='cn=test1',
                       password='LDAP')
        c.bind()
        c.search(search_base='o=asml', search_filter='(objectClass=Person)', search_scope=SUBTREE,
                 attributes=['cn', 'uidNumber', 'gidNumber','homeDirectory', 'fullName', 'loginShell'],
                 paged_size=5, size_limit=1000)

        for entry in c.response:
            distinguished_name =  entry['dn']
            attributes_dict = entry['attributes']
            serverA_cn = ''.join(map(str, list(attributes_dict['cn'])))
            serverA_uid_number = attributes_dict['uidNumber']
            serverA_gid_number = attributes_dict['gidNumber']
            serverA_homedirectory = attributes_dict['homeDirectory']
            serverA_fullname = attributes_dict['fullName']
            serverA_loginshell = attributes_dict['loginshell']

now this above variable from ServerA needs to be comapre with object attributes from ServerB.

djdomi avatar
za flag
powershell is your friend! get-aduser and export-csv can do this native
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.