[root@domU ]# ldapadd -x -D "cn=Manager,dc=unisonis,dc=com" -W -f
unisonis.ldif
Enter LDAP Password:
adding new entry "dc=unisonis,dc=com"
adding new entry "cn=Manager,dc=unisonis,dc=com"
步骤 7:下一步是用示例条目填充 LDAP 目录。我们使用三个小丑的信息(灵感来源于 LDAP 文章 linux.com/TUTORIALS/LinuxTutorialLDAP.html">http://www.yolinux.com/TUTORIALS/LinuxTutorialLDAP.html):
[root@domU ]# cat stooges.ldif; # to conserve space, we show the LDAP data for
only one of the three stooges
dn: ou=MemberGroupA,dc=unisonis,dc=com
ou: MemberGroupA
objectClass: top
objectClass: organizationalUnit
description: Members of MemberGroupA
dn: ou=MemberGroupB,dc=unisonis,dc=com
ou: MemberGroupB
objectClass: top
objectClass: organizationalUnit
description: Members of MemberGroupB
dn: cn=Larry Fine,ou=MemberGroupA,dc=unisonis,dc=com
ou: MemberGroupA
o: stooges
cn: Larry Fine
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
mail: LFine@unisonis.com
givenname: Larry
sn: Fine
uid: larry
homePostalAddress: 15 Cherry Ln. Plano TX 78888
postalAddress: 215 Fitzhugh Ave.
l: Dallas
st: TX
postalcode: 75226
telephoneNumber: (800)555-1212
homePhone: 800-555-1313
facsimileTelephoneNumber: 800-555-1414
userPassword: larrysecret
title: Account Executive
destinationindicator: /bios/images/lfine.jpg
def __init__(self, ldap_host=None, ldap_base_dn=None, mgr_cred=None,
mgr_passwd=None):
if not ldap_host:
ldap_host = LDAP_HOST
if not ldap_base_dn:
ldap_base_dn = LDAP_BASE_DN
if not mgr_cred:
mgr_cred = MGR_CRED
if not mgr_passwd:
mgr_passwd = MGR_PASSWD
self.ldapconn = ldap.open(ldap_host)
self.ldapconn.simple_bind(mgr_cred, mgr_passwd)
self.ldap_base_dn = ldap_base_dn
def list_stooges(self, stooge_filter=None, attrib=None):
if not stooge_filter:
stooge_filter = STOOGE_FILTER
s = self.ldapconn.search_s(self.ldap_base_dn, ldap.SCOPE_SUBTREE,
stooge_filter, attrib)
print "Here is the complete list of stooges:"
stooge_list = []
for stooge in s:
attrib_dict = stooge[1]
for a in attrib:
out = "%s: %s" % (a, attrib_dict[a])
print out
stooge_list.append(out)
return stooge_list