Skip to content

RFE: Support for add and delete operations in ldif.LDIFParser.parse_change_records() #567

Description

@fager

Issue description:

LDIF files with multiple operations are not fully processed by ldif.LDIFParser.parse_change_records().

Operations of the change type "modify" are processed via handle_modify() but operations of the change type "add" or "delete" are counted but otherwise simply ignored.

Example of such an LDIF file:

version: 1

dn: cn=demo1,ou=groups,dc=example,dc=com
changetype: add
objectClass: groupOfNames
objectClass: nsMemberOf
objectClass: posixGroup
objectClass: top
cn: demo1
gidNumber: 99997


dn: cn=demo2,ou=groups,dc=example,dc=com
changetype: add
objectClass: groupOfNames
objectClass: nsMemberOf
objectClass: posixGroup
objectClass: top
cn: demo2
gidNumber: 99996


dn: cn=demo2,ou=groups,dc=example,dc=com
changetype: modify
add: description
description: Eine zweite Testgruppe


dn: cn=demo1,ou=groups,dc=example,dc=com
changetype: delete


Steps to reproduce:

Create your own LDIF parser and an import for the test file shown:

from pathlib import Path
from ldif import LDIFParser

class MyLDIFParser(LDIFParser):
    
    def __init__(self, input_file, ignored_attr_types=None, max_entries=0, process_url_schemes=None, line_sep='\n'):
        super().__init__(input_file, ignored_attr_types, max_entries, process_url_schemes, line_sep)

    def handle(self, dn, entry):
        print(f"MyLDIFParser::handle({dn})")
    
    def handle_modify(self, dn, modops, controls=None):
        print(f"MyLDIFParser::handle_modify({dn})")

def main():
    p_change = Path("test_change.ldif")
    ldifparser_change = MyLDIFParser(open(p_change), "r")
    ldifparser_change.parse_change_records()
    print(f"Changetype counter: {ldifparser_change.changetype_counter}")
    
    

if __name__ == '__main__':
    main()

Start this test:

$ ./demo.py 
MyLDIFParser::handle_modify(cn=demo2,ou=groups,dc=example,dc=com)
Changetype counter: {'add': 2, 'delete': 1, 'modify': 1, 'modrdn': 0}

Operating system:
Fedora 39

Python version:

  • Python 3.6
  • Python 3.12

python-ldap version:
3.4.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions