本連載では今までさまざまなソフトウェアとLDAPの連携を紹介してきたわけですが、
エントリの追加
リスト1のようなLDIFファイルが存在した場合を考えてみましょう。
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: example
dn: ou=People,dc=example,dc=com
objectClass: organizationalUnit
ou: People
dn: cn=suzuki,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
sn: suzuki
cn: suzuki
mail: suzuki@example.com
dn: cn=tanaka,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
sn: tanaka
cn: tanaka
mail: tanaka@example.com
mail: a.tanaka@example.com
このエントリをLDAPサーバに追加するためには、
% ldapadd -x -D "cn=Manager,dc=example,dc=com" -w secret -f orig.ldif
すでにご存じの方もいらっしゃるかもしれませんが、
% ldapadd -x -D "cn=Manager,dc=example,dc=com" -w secret < orig.ldif
これをうまく使えば、
% lv -Ou8 orig.ldif | ldapadd -x -D "cn=Manager,dc=example,dc=com" -w secret
または
% nkf -w orig.ldif | ldapadd -x -D "cn=Manager,dc=example,dc=com" -w secret
また、
ldapmodifyコマンドは文字通りエントリを編集するために使われますが、
% ldapmodify -a -x -D "cn=Manager,dc=example,dc=com" -w secret -f orig.ldif
エントリの編集
orig.
もっとも基本的な方法はldapmodifyコマンドを使用することです。ldapaddコマンド同様、
dn: cn=suzuki,ou=People,dc=example,dc=com
objectClass: inetOrgPerson
sn: suzuki
cn: suzuki
mail: suzu@example.com
ldapmodifyコマンドを使用し、
% ldapmodify -x -D "cn=Manager,dc=example,dc=com" -w secret -f new1.ldif
この方法では、
dn: cn=tanaka,ou=People,dc=example,dc=com
changetype: modify
replace: mail
mail: suzu@example.com
% ldapmodify -x -D "cn=Manager,dc=example,dc=com" -w secret -f new2.ldif
このように、
dn: cn=tanaka,ou=People,dc=example,dc=com
changetype: modify
add: mail
mail: newaddress@example.com
リスト4のLDIFを日本語で説明するとすれば、
- dn: cn=tanaka,ou=People,dc=example,dc=com をこれから編集
- 変更内容はmodify
- mail属性を追加
- mail属性の内容はnewaddress@example.
com
同様に、
dn: cn=tanaka,ou=People,dc=example,dc=com
changetype: modify
replace: mail
mail: replace1@example.com
mail: replace2@example.com
この場合、
次はchangetypeにaddを指定した例です。実質ldapaddと同じ挙動となります。
dn: cn=tanaka2,ou=People,dc=example,dc=com
changetype: add
objectClass: inetOrgPerson
sn: tanaka2
cn: tanaka2
mail: tanaka2@example.com
次はエントリの一部を削除する場合です。これにより、
dn: cn=tanaka,ou=People,dc=example,dc=com
changetype: modify
delete: mail
mail: a.tanaka@example.com
今までの操作を1つにまとめることも可能です。その場合は次のように、
dn: cn=tanaka,ou=People,dc=example,dc=com
changetype: modify
replace: sn
sn: New Name
-
add: mail
mail: new@example.com
これらの用法に関してはldapmodifyコマンドのマニュアルにも記載されていますので、
DNの編集:ldapmodrdn
エントリの中身だけではなく、
dn: cn=tanaka,ou=People,dc=example,dc=com
というDNを
dn: cn=Taro Tanaka,ou=People,dc=example,dc=com
に変更するためには、
ldapmodrdn -x -D "cn=Manager,dc=example,dc=com" -w secret -r 'cn=tanaka,ou=People,dc=example,dc=com' 'cn=Taro Tanaka'
GUIツール
大量のデータ登録に際しては、
それぞれ長所、
GQ
http://gq-project.org/比較的昔から存在するツールで、
使用するためには、
% ./configure % make # make install


phpLDAPadmin
http://phpldapadmin.sourceforge.net/こちらは文字通り、
そのため、

Luma
http://luma.sourceforge.net/LumaはPythonスクリプトによるGUIツールです。Qtに依存しますので、
たとえばスキーマブラウザを使用すると、
# ./install.py --prefix=/usr/local


JXplorer
http://www.jxplorer.org/JXplorerはJavaで記述されたクライアントツールです。当然WindowsやMacでも動作するのがメリットです。動作についてもJREなどのランタイム環境が必要となります。こちらも日本語やスキーマブラウザに対応しています。

LDAP Explorer Tool
http://sourceforge.net/projects/ldaptoolこちらはGQ同様、
(必要に応じてGNUmakefile.configを編集)
% make
# make install

GUIツールのまとめ
これらのツールの簡単な機能比較表を作ってみました。ただし内容はあくまでも筆者の主観ですので、
名称 | 多機能 | 導入のしやすさ | 日本語対応 | 依存ソフトウェアなど |
---|---|---|---|---|
GQ | △ | ○ | ○ | GTK+ |
phpLDAPadmin | ○ | △ | ○ | PHP, Apacheなど |
Luma | ◎ | △ | ○ | Python, PyQtなど |
JXplorer | ○ | ○ | ○ | Java |
LDAP Explorer Tool | △ | ○ | × | GTK+ |
最後に
今回はldapmodifyコマンドを筆頭に、