<!-- --><!-- --> <!-- -->
本文原创作品,如需转载请注明来源,作者:姜涛, towerjt@gmail.com
LDIF
LDIF 全称是 LDAP Data Interchange Format ,基于文本。有两种类型的 LDIF 文件:第一种是描述 Directory 条目数据的,第二种是描述更新条目的。
LDIF 由两部分组成,第一部分是前两行,版本和 dn ,后面是属性和值
第一种:
version: 1
dn: uid=bjensen, ou=people, dc=example, dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Barbara Jensen
cn: Babs Jensen
givenName: Barbara
sn: Jensen
uid: bjensen
mail: bjensen@example.com
telephoneNumber: +1 408 555 1212
description: Manager, Switching Products Division
如果值很长,可以分行,如:
description: I will be out of the
office from August 12, 2001, to September 10, 2001. If you need
assistance with the Ostrich project, please contact Steve Smith
at extension 7226.
第二种:
- 增加条目
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: add
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Barbara Jensen
cn: Babs Jensen
givenName: Barbara
sn: Jensen
uid: bjensen
mail: bjensen@example.com
telephoneNumber: +1 408 555 1212
- 删除条目
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: delete
- 修改操作
- 增加属性
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: modify
add: telephoneNumber
telephoneNumber: +1 216 555 1212
telephoneNumber: +1 408 555 1212
- 删除属性
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: modify
delete: telephoneNumber
telephoneNumber: +1 216 555 1212
或者全部删除
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: modify
delete: telephoneNumber
- 替换属性
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: modify
replace: telephoneNumber
telephoneNumber: +1 216 555 1212
telephoneNumber: +1 405 555 1212
- 多个操作可以放在一个文件里面,每个操作用 - (单破折号或者是减号)分开
dn: uid=bjensen, ou=people, dc=example, dc=com
changetype: modify
add: mail
mail: bjensen@example.com
-
delete: telephoneNumber
telephoneNumber: +1 216 555 1212
-
delete: description
-
replace: givenName
givenName: Barbara
givenName: Babs
-
LDAP server 处理一个文件类有似于事物处理的机制,只有所有操作都成功才能成功。
- 修改 DN , deleteoldrdn 注意设置
dn: uid=bjensen, ou=People, dc=example, dc=com
changetype: moddn
newrdn: uid=babsj
deleteoldrdn: 0
结果:
dn: uid=babsj, ou=People, dc=example, dc=com
uid: babsj
uid: bjensen
dn: uid=bjensen, ou=People, dc=example, dc=com
changetype: moddn
newrdn: uid=babsj
deleteoldrdn: 1
结果:
dn: uid=babsj, ou=People, dc=example, dc=com
uid: babsj
- 移动节点
dn: uid=bjensen, ou=People, dc=example, dc=com
changetype: moddn
newsuperior: ou=Terminated Employees, dc=example, dc=com