NetBSDのpkgsrcを用いたOpenLDAP Server構築(古い記事)はこちらを参照のこと。
今回は、FreeBSDを用いたOpenLDAP Serverを建てることを目標にする。 なお、実際には、Installに関してはおそらくどのPlatformでも同様で、Install後の設定ファイルなどの配置が異なるだけだと思われる。
至極簡単。
で良い。
なお、FreeBSDでpkgでinstallした場合、通常 ldap が利用するUID/GIDは、389/389 となる。
FreeBSDの場合、各種設定ファイルは、/usr/local/etc/openldap 下に配置される。
起動時にOpenLDAP Serverを動作させるには、/etc/rc.confに以下を記載する。
slapd_enable="YES" #slapd_flags='-h "ldapi:///var/run/openldap/ldapi/ ldap://0.0.0.0/"' # ←おそらく不要 #slapd_sockets="/var/run/openldap/ldapi" # ←おそらく不要
OpenLDAP関連の設定は
で行う。
#######################################################################
# OpenLDAP slapd Configuration File.
# See slapd.conf(5) for details on configuration options.
# Database Schema
include /usr/local/etc/openldap/schema/core.schema
include /usr/local/etc/openldap/schema/cosine.schema
include /usr/local/etc/openldap/schema/inetorgperson.schema
include /usr/local/etc/openldap/schema/nis.schema
include /usr/local/etc/openldap/schema/mail.schema
# mail.schema/postLDAPadmin.schemaは別途追加する
# System File
pidfile /var/run/openldap/slapd.pid
argsfile /var/run/openldap/slapd.args
# Allow LDAPv2 client connections. This is NOT the default.
allow bind_v2
#######################################################################
# Load dynamic backend modules:
modulepath /usr/local/libexec/openldap
moduleload back_mdb
# moduleload back_ldap
moduleload back_monitor
moduleload syncprov # 必要に応じて
#######################################################################
# syslog
# loglevel 0 is not output openldap log.
# log is output for syslog (local4.*)
#loglevel 960
loglevel 256
#######################################################################
# Access Control List.
access to dn.subtree="ou=vmail,o=example" attrs=userPassword
by self write
by anonymous auth
by * none
access to *
by self write
by * read
#######################################################################
# MDB database definitions
#######################################################################
database mdb
maxsize 1073741824
suffix "o=example.net"
rootdn "cn=Manager,o=example"
rootpw secret
directory /var/db/openldap-data
index objectClass eq,pres
index ou,cn,mail,surname,givenname eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub
index nisMapName,nisMapEntry eq,pres,sub
#######################################################################
# Replication ( Share )
index entryCSN,entryUUID eq
# Replication ( Provider )
overlay syncprov
syncprov-sessionlog 100
serverID 1
# Replication ( Consumer )
#syncrepl rid=001
# provider=ldap://xxx.xxx.xxx.xxx
# bindmethod=simple
# binddn="cn=Manager,o=example"
# credentials=secret
# searchbase="o=example"
# schemachecking=on
# type=refreshAndPersist
# retry="10 +"
#syncrepl rid=002
# provider=ldap://xxx.xxx.xxx.yyy
# bindmethod=simple
# binddn="cn=Manager,o=example"
# credentials=secret
# searchbase="o=example"
# schemachecking=on
# type=refreshAndPersist
# retry="10 +"
#mirrormode on
上記slapd.conf内のrootpwには、RootDNのパスワードを入力する必要がある。 このパスワードは、以下の方法で作成する。
$ /usr/pkg/sbin/slappasswd -h [CRYPT|MD5|SMD5|SSHA|SHA] -s secret
標準のHASH方式はSSHAなので、slappasswd -s secretでパスワードを作成すればOK
$ slappasswd -s 12345678
{SSHA}tTTZQEwu7eair4ISCNmxrS/U2Qn8laHO
$
この結果を貼り付ければok
ここまで問題がなければ、
# service slapd onestart
でslapd(OpenLDAP Server)が起動する。
とにかくまず、LDAPを動かすために必要な最小限のデータは登録しなければならない。 何はともあれ、基本ディレクトリと、その管理者を登録する。
基本ディレクトリ構造は以下の通り
この構造に合わせたLDIFファイルを作成する
dn: o=example, c=net objectClass: organization o: example dn: cn=Manager, o=example, c=net objectClass: organizationalRole cn: Manager
その後、以下のコマンドを入力して、DataをLDAP Serverに投入する
$ ldapadd -x -D "cn=Manager, o=example" -W -f init.ldif Enter LDAP Password: adding new entry "o=example" adding new entry "cn=Manager, o=example"
これで最小限の設定は終了。あとはApplication毎の設定を投入するだけ。
ldapadd -x -h localhost -D "cn=Manager,o=example" -w 12345654321 -f LDIF-file
ldapsearch -x -h localhost -b '' -s base +
ldapsearch -x -h localhost -b 'dc=example.net,ou=vmail,o=example' uid=test1
slapindex -v -b o=example -f /usr/pkg/etc/openldap/slapd.conf