2

Python ldap でエントリを追加しようとしています。命名規則エラーが発生しています。私のコードは

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()

エラーは次のとおりです。

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'}

実行されるがユーザーを正しい組織単位に挿入しないコードは、次のコードです。ただし、実行しても、アクティブディレクトリでユーザーが見つかりません。何が間違っているかを教えてください。私は基本的に、ユーザー管理用の django Web フォームを作成しています。

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()
4

1 に答える 1

0

エラーの根本的な原因は、エントリの DN の左端の属性に一致する「ネーミング属性」がエントリに含まれていないことであると推測します (この場合は ou=Enki です)。ユーザー。この命名属性をエントリに追加するには、attrs dict を入力するコードの部分に次の行を追加します。

attrs['ou'] = 'Enki ユーザー'

于 2014-08-16T03:41:48.233 に答える