添加條目

添加條目postfix.ldif

[root@linux src]# ldapadd -x -D "cn=manager,dc=example,dc=net" -f postfix.ldif -w chen
adding new entry "ou=people,dc=example,dc=net"

adding new entry "ou=postfix,dc=example,dc=net"

adding new entry "cn=courier, ou=postfix, dc=example,dc=net"

[root@linux src]# ldapsearch -x -D 'cn=manager,dc=example,dc=net' -b 'dc=example,dc=net' 'objectclass=*' namingContexts -w chen
version: 2

#
# filter: objectclass=*
# requesting: namingContexts
#

# example, net
dn: dc=example,dc=net

# System, example, net
dn: ou=System, dc=example,dc=net

# postfix, system, example, net
dn: ou=postfix, ou=system, dc=example,dc=net

# people, example, net
dn: ou=people,dc=example,dc=net

# postfix, example, net
dn: ou=postfix,dc=example,dc=net

# courier, postfix, example, net
dn: cn=courier, ou=postfix, dc=example,dc=net

# search result
search: 2
result: 0 Success

# numResponses: 7
# numEntries: 6
[root@linux src]# 

[root@linux src]# ldapsearch -x -D 'cn=manager,dc=example,dc=net' -b 'dc=example,dc=net' 'objectclass=*' -w chen
version: 2

#
# filter: objectclass=*
# requesting: ALL
#

# example, net
dn: dc=example,dc=net
objectClass: person
objectClass: organization
cn: example
sn: example
o: example.net
description:: VG9wIGxldmVsIG9mIGRpcmVjdG9yeSA=

# System, example, net
dn: ou=System, dc=example,dc=net
userPassword:: cGFzc3dvcmQ=
ou: system
objectClass: organizationalUnit

# postfix, system, example, net
dn: ou=postfix, ou=system, dc=example,dc=net
ou: postfix
objectClass: organizationalUnit

# people, example, net
dn: ou=people,dc=example,dc=net
ou: people
objectClass: organizationalUnit

# postfix, example, net
dn: ou=postfix,dc=example,dc=net
ou: postfix
objectClass: organizationalUnit

# courier, postfix, example, net
dn: cn=courier, ou=postfix, dc=example,dc=net
objectClass: person
cn: courier
sn: courier

# search result
search: 2
result: 0 Success

# numResponses: 7
# numEntries: 6
[root@linux src]#

		

添加用戶users.ldif

[root@linux src]# ldapadd -x -D "cn=manager,dc=example,dc=net" -f users.ldif -w chen
adding new entry "uid=chen,ou=postfix,dc=example,dc=net"

[root@linux src]# ldapsearch -x -D 'cn=manager,dc=example,dc=net' -b 'dc=example,dc=net' 'cn=chen' -w chen
version: 2

#
# filter: cn=chen
# requesting: ALL
#

# chen, postfix, example, net
dn: uid=chen,ou=postfix,dc=example,dc=net
uid: chen
cn: chen
sn: chen
mail: chen@example.net
uidNumber: 1001
gidNumber: 1001
mailHost: mail.example.net
homeDirectory: /home/chen
mailMessageStore: /home/chen/maildir/
mailQuota: 200000000s,20000c
mailbox: chen/maildir/
objectClass: qmailuser
objectClass: couriermailaccount
objectClass: person

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
[root@linux src]#
		

使用kunmail.schema

[root@linux docbook]# cat kunmail.ldif
dn: cn=chen, ou=kunmail, dc=example,dc=net
objectClass: top
objectClass: person
objectClass: kunmailUser
sn: kun
cn: kunmail
userNo: 1
userName: chen@example.net
userUid: 1000
userGid: 1000
userHome: /home/chen
userMaildir: chen/Maildir
userQuota: 200000000s,20000c
userClearpw: chen
userFullname: neo chen
		
[root@linux docbook]# ldapadd -x -D'cn=manager,dc=example,dc=net' -w chen -f kunmail.ldif
adding new entry "cn=chen, ou=kunmail, dc=example,dc=net"

[root@linux docbook]#

[root@linux docbook]# ldapsearch -x -D 'cn=manager,dc=example,dc=net' -b 'dc=example,dc=net' 'objectclass=*' -w chen
version: 2

#
# filter: objectclass=*
# requesting: ALL
#

# example, net
dn: dc=example,dc=net
dc: example
objectClass: dcObject
objectClass: organization
description: kunmail system made by YuCa Studio.
o: YuCa Studio.

# admin, example, net
dn: ou=admin, dc=example,dc=net
ou: admin
objectClass: top
objectClass: organizationalUnit

# kunmail, example, net
dn: ou=kunmail, dc=example,dc=net
ou: kunmail
objectClass: top
objectClass: organizationalUnit

# kunmail, admin, example, net
dn: cn=kunmail, ou=admin, dc=example,dc=net
userPassword:: Y3oyMDA0
objectClass: top
objectClass: person
sn: kun
cn: kunmail

# chen, kunmail, example, net
dn: cn=chen, ou=kunmail, dc=example,dc=net
objectClass: top
objectClass: person
objectClass: kunmailUser
sn: kun
cn: kunmail
userNo: 1
userName: chen@example.net
userUid: 1000
userGid: 1000
userHome: /home/chen
userMaildir: chen/Maildir
userQuota:: MjAwMDAwMDAwcywyMDAwMGMg
userClearpw: chen
userFullname: neo chen

# search result
search: 2
result: 0 Success

# numResponses: 6
# numEntries: 5
[root@linux docbook]#
		

測試

[root@linux docbook]# ldapsearch -x -D 'cn=kunmail,ou=admin,dc=example,dc=net' -b 'dc=example,dc=net' 'cn=*' -w cz2004        version: 2

#
# filter: cn=*
# requesting: ALL
#

# kunmail, admin, example, net
dn: cn=kunmail, ou=admin, dc=example,dc=net
userPassword:: Y3oyMDA0
objectClass: top
objectClass: person
sn: kun
cn: kunmail

# chen, kunmail, example, net
dn: cn=chen, ou=kunmail, dc=example,dc=net
objectClass: top
objectClass: person
objectClass: kunmailUser
sn: kun
cn: kunmail
userNo: 1
userName: chen@example.net
userUid: 1000
userGid: 1000
userHome: /home/chen
userMaildir: chen/Maildir
userQuota:: MjAwMDAwMDAwcywyMDAwMGMg
userClearpw: chen
userFullname: neo chen

# search result
search: 2
result: 0 Success

# numResponses: 3
# numEntries: 2
[root@linux docbook]#

	

創建.ldif 檔案時,建議最好手工輸入。不要使用複製,粘貼方法。

這裡暫時使用qmail的schema有時間我會做一個postfix.schema標準的並且支持Foxmail,Outlook.

在添加過程中.ldif檔案難免會出一些錯誤,這時會用到刪除命令ldapdelete

[root@linux docbook]# ldapdelete -x -D'cn=manager,dc=example,dc=net' -w chen 'cn=chen, ou=kunmail, dc=example,dc=net'