Wednesday, July 23, 2014

Django/Python-ldap Ldap Question Adding Entries

I'm trying to add entries via a form post in django, I have the following code and its really not django specific but it is python-ldap specific.


I'm trying to add entries with python ldap. I'm getting a naming convention error. My code is

    import ldap 
    import ldap.modlist as modlist
    
    LOGIN = "" 
    PASSWORD = '' 
    LDAP_URL = "ldap://127.0.0.1:389" 
    user='grant'
    l = ldap.initialize(LDAP_URL) 
    l.bind(LOGIN, PASSWORD) 
    dn="ou=Enki Users,dc=enki,dc=local" 
    
    attrs = {}
    attrs['objectclass'] = ['top','organizationalRole','simpleSecurityObject']
    attrs['cn'] = 'test'
    attrs['userPassword'] = 'test'
    attrs['description'] = 'User object for replication using slurpd'
    
    # Convert our dict to nice syntax for the add-function using modlist-module
    ldif = modlist.addModlist(attrs)
    
    # Do the actual synchronous add-operation to the ldapserver
    l.add_s(dn,ldif)
    
    # Its nice to the server to disconnect and free resources when done
    l.unbind_s()

The error is:

    ldap.NAMING_VIOLATION: {'info': "00002099: NameErr: DSID-0305109C, problem 2005 (NAMING_VIOLATION), data 0, best match of:\n\t'dc=enki,dc=local'\n", 'desc': 'Naming violation'}



The code that runs but doesn't insert the user into the correc organizational unit is the following code. However even though it runs I can't find the user in active directory. Please help me find whats wrong. I'm basically making a django webform for user management.

    import ldap 
    import ldap.modlist as modlist
    
    LOGIN = "" 
    PASSWORD = '' 
    LDAP_URL = "ldap://127.0.0.1:389" 
    user='grant'
    l = ldap.initialize(LDAP_URL) 
    l.bind(LOGIN, PASSWORD) 

    dn="cn=test,ou=Enki Users,dc=enki,dc=local" 
    
    attrs = {}
    attrs['objectclass'] = ['top','organizationalRole','simpleSecurityObject']
    attrs['cn'] = 'test'
    attrs['userPassword'] = 'test'
    attrs['description'] = 'User object for replication using slurpd'
    
    # Convert our dict to nice syntax for the add-function using modlist-module
    ldif = modlist.addModlist(attrs)
    
    # Do the actual synchronous add-operation to the ldapserver
    l.add_s(dn,ldif)
    
    # Its nice to the server to disconnect and free resources when done
    l.unbind_s()

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a2400449-3f68-4f9c-9d8e-b2d94d0d69f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment