LDAP は、LDAP API によって実行される処理に対応するコマンド行ツールを提供しています。これらのツールでは、認証やバインド関連のパラメータなど、共通のオプションを使用できます。
ディレクトリエントリを検索し、見つかった属性と値を表示します。
ディレクトリエントリの変更、追加、削除、名前変更をします。
新規のエントリを追加します。
既存のディレクトリエントリを削除します。
既存のディレクトリエントリの名前を変更します。
ldapsearch、ldapadd、ldapmodify の各ツールは、LDAP データ交換書式 (LDIF) と呼ばれる共通の書式をサポートしています。LDIF は、ディレクトリ情報を表現するテキストベースの書式です。
ldapsearch ツールは、LDIF の書式で出力します。ldapadd ツールはこの書式のデータを処理します。また、ldapmodify ツールはこの LDIF を基本とした変更情報を使用します。
LDIF ファイルには、1 つ以上のエントリが含まれています。各エントリは空白行で区切られます。基本的なエントリ形式は次のとおりです。
[id] dn: entryDN attrtype: attrvalue ... |
id
数字のエントリ識別子 (省略可能。LDAP ツールでは使用されない)。
ディレクトリエントリの LDAP 識別名 (DN)。
LDAP 属性タイプ。cn や telephoneNumber など。
attrtype の値。
attrtype: attrvalue 行は、必要なだけ繰り返すことによって、1 つのエントリのすべての属性値を指定できます。行を継続するには、次の行の先頭に 1 文字の空白または水平タブ文字を挿入します。
たとえば、5 つの属性を持つ Joe Qwerty のエントリを含む LDIF ファイルは、次のようになります (cn と objectclass は 2 つの値を持ちます)。
dn: cn=Joseph Qwerty, o=Ultra Keyboards Inc., c=US cn: Joseph Qwerty cn: Joe Qwerty sn: Qwerty mail: jqwerty@ultra.com seeAlso: cn=Joe Qwerty, ou=Engineering Division, o=Peo ple, o=IEEE, c=US objectClass: top objectClass: person |
seeAlso の値は、「ple, ...」で始まる行の先頭に 1 文字の空白を挿入することによって、2 行に分割されています。
ディレクトリエントリを検索するには、ldapsearch(1) を使用します。ldapsearch は、LDAP ディレクトリサーバーへの接続を開き、そのディレクトリサーバーにバインドして、ディレクトリの検索を実行します。
米国の Ultra Keyboards 社に勤務する、IEEE のメンバーを検索します。
% ldapsearch -L -b "o=IEEE, o=Ultra Keyboards Inc., c=US" uid=\* |
検索結果は次のようになります。
dn: uid=jqwerty, o=IEEE, o=Ultra keyboards Inc., c=US uid: jqwerty cn: jqwerty userpassword: {crypt}somecryptedtext uidnumber: 12345 gidnumber: 123 gecos: Joseph Qwerty homedirectory: /home/jqwerty loginshell: /bin/csh objectclass: top objectclass: shadowAccount objectclass: account objectclass: posixAccount shadowlastchange: 3455 dn: uid=bhand, o=IEEE, o=Ultra keyboards Inc., c=US uid: bhand cn: bhand userpassword: {crypt}somecryptedtext uidnumber: 12347 gidnumber: 123 gecos: William Handset homedirectory: /home/bhand loginshell: /bin/csh objectclass: top objectclass: shadowAccount objectclass: account objectclass: posixAccount shadowlastchange: 3440 |
ディレクトリエントリを変更するには、ldapmodify(1) を使用します。ldapmodify は、LDAP ディレクトリサーバーとの接続を開き、そのディレクトリサーバーにバインドして、ディレクトリに対して一連の LDAP 変更処理を実行します。
ディレクトリマネージャ (パスワード enigma) としてバインドし、メールアドレス eng@ultra.com を Joe Qwerty のエントリに追加します。
% ldapmodify -D "cn=Manager, o=Ultra Keyboards Inc., \ c=US" -w enigma < modfile |
modfile の内容は次のとおりです。
dn: cn=carol,ou=People,o=Ultra Keyboards Inc.,c=US changetype: modify replace: userpassword userpassword: {crypt}mgq25KV6CE0p6 - replace: objectclass objectclass: top objectclass: shadowAccount objectclass: account objectclass: posixAccount - add: shadowlastchange shadowlastchange: 6447 - dn: cn=stephen,ou=People,o=Ultra Keyboards Inc.,c=US changetype: modify replace: userpassword userpassword: {crypt}w.4P1JPV3w.Zs - replace: objectclass objectclass: top objectclass: shadowAccount objectclass: account objectclass: posixAccount - add: shadowlastchange shadowlastchange: 6447 - dn: cn=frank,ou=People,o=Ultra Keyboards Inc.,c=US changetype: modify replace: userpassword userpassword: {crypt}mMBEaHRlf5rJQ - replace: objectclass objectclass: top objectclass: shadowAccount objectclass: account objectclass: posixAccount - add: shadowlastchange shadowlastchange: 9712 - |
ハイフンだけの行は、同一ディレクトリエントリに対する一連の変更コマンドを区切ります。空白行は、異なるディレクトリエントリを区切ります。
正常に終了すると、ldapmodify は次のようなメッセージを表示します。
# ldapmodify -D "cn=Directory Manager" -w nssecret -f domain.ldif modifying entry dc=sun,dc=com |
処理が正常に終了しなかった場合は、エラーメッセージが表示されます。
ディレクトリにエントリを追加するには、ldapadd(1) を使用します。ldapadd は、LDAP ディレクトリサーバーへの接続を開き、そのディレクトリサーバーにバインドして、ディレクトリに対して一連の LDAP 追加処理を実行します。
ディレクトリマネージャ (パスワード enigma) としてバインドし、Penny Gold と Amy Lamb のエントリを追加します。
% ldapadd -D "cn=Manager, o=Ultra Keyboards Inc., \ c=US" -w enigma < addfile |
addfile の内容は次のとおりです。
dn: cn=Penny Gold, o=Ultra Keyboards Inc., c=US changetype: add objectclass: top objectclass: person objectclass: inetOrgPerson cn: Penny Gold sn: Gold mail: pgold@ultra.com dn: cn=Amy Lamb, o=Ultra Keyboards Inc., c=US changetype: add objectclass: top objectclass: person objectclass: inetOrgPerson cn: Amy Lamb sn: Lamb mail: alamb@ultra.com |
ディレクトリからエントリを削除するには、ldapdelete(1) を使用します。ldapdelete は、LDAP ディレクトリサーバーへの接続を開き、そのディレクトリサーバーにバインドして、ディレクトリに対して 1 つ以上の LDAP エントリ削除処理を実行します。
ディレクトリマネージャ (パスワード enigma) としてバインドし、Penny Gold のエントリを削除します。
% ldapdelete -D "cn=Manager, o=Ultra Keyboards Inc., \ c=US" -w enigma "cn=Penny Gold, o=Ultra Keyboards Inc., c=US" |
ldapdelete は、正常終了時には何も表示しません。異常終了時にはエラーメッセージを表示します。
既存のディレクトリエントリの名前を変更するには、ldapmodrdn(1) を使用します。ldapmodrdn は、LDAP ディレクトリサーバーへの接続を開き、そのディレクトリサーバーにバインドして、ディレクトリに対して 1 つ以上の LDAP RDN 変更 (名前変更) 処理を実行します。
ディレクトリマネージャ (パスワード enigma) としてバインドし、RDN cn 値を、User Interface から Ergonomic に変更します。
% ldapmodrdn -r -D "cn=Manager, o=Ultra Keyboards Inc., \ c=US" -w enigma "cn=User Interface, o=Ultra Keyboards Inc., \ c=US" "cn=Ergonomic" |
ldapmodrdn は、正常終了時には何も表示しません。異常終了時にはエラーメッセージを表示します。