From be7f871ce78fb1b262450dbfc627ff8254bfb8e8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 27 Jun 2025 15:38:38 +0200 Subject: [PATCH] Added replacement by OID --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index e421e5d..5a09454 100755 --- a/main.py +++ b/main.py @@ -163,12 +163,25 @@ def main(): norm_existing = [normalize(v) for v in existing] norm_encoded = normalize(encoded) + # Extract OID from definition (assumes it is the first word in parentheses) + def extract_oid(ldif: str) -> str: + return ldif.split()[0].strip('(') + + oid = extract_oid(atdef) + + # Normalize existing if norm_encoded in norm_existing: print(f"â„šī¸ AttributeType exists → REPLACE: {atdef}") conn.modify_s(schema_dn, [ (ldap.MOD_REPLACE, 'olcAttributeTypes', [encoded]) ]) print(f"🔄 Replaced AttributeType: {atdef}") + elif any(oid in entry.decode() for entry in existing): + print(f"âš ī¸ AttributeType with same OID ({oid}) exists → REPLACE: {atdef}") + conn.modify_s(schema_dn, [ + (ldap.MOD_REPLACE, 'olcAttributeTypes', [encoded]) + ]) + print(f"🔄 Replaced AttributeType (OID match): {atdef}") else: print(f"➕ AttributeType fehlt → ADD: {atdef}") conn.modify_s(schema_dn, [ @@ -176,6 +189,7 @@ def main(): ]) print(f"➕ Added AttributeType: {atdef}") + except ldap.LDAPError as e: print(f"❌ LDAP error for AttributeType '{atdef}': {e}", file=sys.stderr) sys.exit(1)