OpenLDAPのインストール

OpenLDAP を IPv6環境で検証してみた

OpenLDAP とは ディレクトリ情報を扱う LDAPのオープンソース版です
一言でいえばデータベースですが データを階層的に配置できネットワーク分散配置も可能です
Windowsの認証機構に使われている Active Directoryも LDAPベースとなっています

検証環境
CPU PhenomII X4 e905 (2.5GHz)
メモリ 8GB
OS Linux-2.6.35.3 amd64
GCC gcc-4.5.2
glibc glibc-2.13
BerkeleyDB db-5.1.25.NC
OpenLDAP 2.4.23

OpenLDAPのインストール

OpenLDAPから最新のソースコードを取得して ビルド用ディレクトリに展開します
IPv6環境 CyrusSASL BerkeleyDB iODBCドライバ など必要な環境は構築済とします

$ tar -xzf openldap-stable-20100719.tgz
$ cd openldap-2.4.23
$ ./configure --prefix=/usr --libdir=/usr/lib64 --localstatedir=/var --with-cyrus-sasl --with-odbc=iodbc --with-tls=yes --enable-overlays=yes --enable-wrappers ac_cv_lib_sasl2_sasl_client_init=yes
〜
checking number of arguments of ctime_r... 2
checking number of arguments of gethostbyname_r... 6
checking number of arguments of gethostbyaddr_r... 8
checking db.h usability... yes
checking db.h presence... yes
checking for db.h... yes
checking for Berkeley DB major version in db.h... 5
checking for Berkeley DB minor version in db.h... 1
checking if Berkeley DB version supported by BDB/HDB backends... yes
checking for Berkeley DB link (default)... no
configure: error: BDB/HDB: BerkeleyDB not available
$
 

エラーが出てますが まずオプションの説明から
ac_cv_lib_sasl2_sasl_client_init=yes は SASL2 を導入された場合に指定が必要です
–enable-ipv6 は明示しなくても自動的に認識されるので不要でした

エラーでは BerkeleyDBが認識されていないようです
READMEを見れば分かりますが バージョン 4.4 4.5 4.6 4.7 4.8 しか受け付けないのです

現在導入している バージョンは 5.1 従って configureで弾かれたわけです
ここでは人柱的な目的で あえてインストールを強行してみます
configureファイルをエディッタで編集して

28781 echo $ECHO_N "checking for Berkeley DB link (default)... $ECHO_C" >&6; }
28782 if test "${ol_cv_db_none+set}" = set; then
28783   echo $ECHO_N "(cached) $ECHO_C" >&&6
28784 else
28785 
28786         ol_DB_LIB=-ldb
28787         ol_LIBS=$LIBS
28788         LIBS="$ol_DB_LIB $LTHREAD_LIBS $LIBS"
28789 
 

Berkeley DB link (default) の確認項目の部分で
ol_DB_LIB= だったのを ol_DB_LIB=-ldb と強制設定します

28856         LIBS="$ol_LIBS"
28857 
28858 fi
28859 { echo "$as_me:$LINENO: result: $ol_cv_db_none" >&5
28860 echo "${ECHO_T}$ol_cv_db_none" >&6; }
28861 
28862         if test $ol_cv_db_none = yes ; then
28863                 ol_cv_lib_db=-ldb
28864         fi
28865 fi
28866 
28867 
 

また $ol_cv_db_none = yes 判定のときに
ol_cv_lib_db=yes だったのを ol_cv_lib_db=-ldb と修正しています

再度同じオプションで configure すると

$ ./configure --prefix=/usr --libdir=/usr/lib64 --localstatedir=/var --with-cyrus-sasl --with-odbc=iodbc --with-tls=yes --enable-overlays=yes --enable-wrappers ac_cv_lib_sasl2_sasl_client_init=yes
〜
config.status: executing depfiles commands
config.status: executing default commands
Making servers/slapd/backends.c
    Add config ...
    Add ldif ...
    Add monitor ...
    Add bdb ...
    Add hdb ...
    Add relay ...
Making servers/slapd/overlays/statover.c
    Add accesslog ...
    Add auditlog ...
    Add collect ...
    Add constraint ...
    Add dds ...
    Add deref ...
    Add dyngroup ...
    Add dynlist ...
    Add memberof ...
    Add ppolicy ...
    Add pcache ...
    Add refint ...
    Add retcode ...
    Add rwm ...
    Add seqmod ...
    Add sssvlv ...
    Add syncprov ...
    Add translucent ...
    Add unique ...
    Add valsort ...
Please run "make depend" to build dependencies
$
 

configureはパスしました bdbが認識されています
(もう少しよい方法があるのかもしれませんが)

$ make depend
〜
  Entering subdirectory man5
make[3]: Entering directory `/home/admin/openldap-2.4.23/doc/man/man5'
make[3]: Nothing to be done for `depend'.
make[3]: Leaving directory `/home/admin/openldap-2.4.23/doc/man/man5'
 
  Entering subdirectory man8
make[3]: Entering directory `/home/admin/openldap-2.4.23/doc/man/man8'
make[3]: Nothing to be done for `depend'.
make[3]: Leaving directory `/home/admin/openldap-2.4.23/doc/man/man8'
 
make[2]: Leaving directory `/home/admin/openldap-2.4.23/doc/man'
 
make[1]: Leaving directory `/home/admin/openldap-2.4.23/doc'

$ make
〜
make[3]: Leaving directory `/home/admin/openldap-2.4.23/doc/man/man8'
 
make[2]: Leaving directory `/home/admin/openldap-2.4.23/doc/man'
 
make[1]: Leaving directory `/home/admin/openldap-2.4.23/doc'
 
$ su
# make install
〜
installing slapschema.8 in /usr/share/man/man8
installing slaptest.8 in /usr/share/man/man8
make[3]: Leaving directory `/home/admin/openldap-2.4.23/doc/man/man8'
 
make[2]: Leaving directory `/home/admin/openldap-2.4.23/doc/man'
 
make[1]: Leaving directory `/home/admin/openldap-2.4.23/doc'
 
#
 

ここで インストール完了 と思ったらおかしな挙動がありました
下記の hello.c をコンパイルしようとしたところ

#include 

int main ()
{
  printf ( "Hello\n" );
  return ( 0 );
}
 
$ gcc -o hello -lldap hello.c
usr/binutils/2.21/amd64/bin/amd64-gnu-linux-ld: warning: liblber-2.4.so.2, needed by /usr/lib64/libldap.so, not found (try using -rpath or -rpath-link)
/usr/binutils/2.21/amd64/bin/amd64-gnu-linux-ld: warning: libresolv.so.2, needed by /usr/lib64/libldap.so, not found (try using -rpath or -rpath-link)
/usr/binutils/2.21/amd64/bin/amd64-gnu-linux-ld: warning: libsasl2.so.2, needed by /usr/lib64/libldap.so, not found (try using -rpath or -rpath-link)
/usr/lib64/libldap.so: undefined reference to `ber_memfree_x'
/usr/lib64/libldap.so: undefined reference to `ber_init2'
/usr/lib64/libldap.so: undefined reference to `ber_get_stringbv'
/usr/lib64/libldap.so: undefined reference to `ber_int_sb_close'
/usr/lib64/libldap.so: undefined reference to `ber_memvfree'
/usr/lib64/libldap.so: undefined reference to `ber_skip_data'
/usr/lib64/libldap.so: undefined reference to `ber_peek_tag'
/usr/lib64/libldap.so: undefined reference to `ber_printf'
/usr/lib64/libldap.so: undefined reference to `ber_flatten2'
/usr/lib64/libldap.so: undefined reference to `ber_pvt_sb_buf_init'
/usr/lib64/libldap.so: undefined reference to `ber_bvarray_free'
〜
/usr/lib64/libldap.so: undefined reference to `sasl_client_new'
/usr/lib64/libldap.so: undefined reference to `__res_query@GLIBC_2.2.5'
/usr/lib64/libldap.so: undefined reference to `ber_rewind'
/usr/lib64/libldap.so: undefined reference to `ber_sockbuf_free'
/usr/lib64/libldap.so: undefined reference to `ber_pvt_sb_do_write'
collect2: ld はステータス 1 で終了しました
$
 

エラーが出るでは ありませんか
インストールされた libldap-2.4.so.2.5.6 libldap_r-2.4.so.2.5.6 liblber-2.4.so.2.5.6
ファイルに 実行属性が付与されてないためリンクに失敗していたのです

OpenLDAPパッケージに問題があったのか 検証システム側に問題があるのかいまいち不明ですが

$ su
# chmod +x /usr/lib64/libldap-2.4.so.2.5.6
# chmod +x /usr/lib64/libldap_r-2.4.so.2.5.6
# chmod +x /usr/lib64/liblber-2.4.so.2.5.6
# exit
$ gcc -o hello -lldap hello.c
/usr/binutils/2.21/amd64/bin/amd64-gnu-linux-ld: warning: libresolv.so.2, needed by /usr/lib64/liblber.so, not found (try using -rpath or -rpath-link)
$
 

警告は残りましたが コンパイルはできました

警告は リンカに -rpath-link /usr/glibc/2.9/amd64/lib
の設定が必要である旨のメッセージで 検証システム側の問題っぽいです

とにかく インストールが完了したので コンフィグファイルを初期設定します
/usr/etc/openldap/ 配下に ldap.conf slapd.conf の2ファイルをとりあえず設定します

まず ldap.conf から これは クライアント(からサーバに接続するための)設定です

#
# LDAP Defaults
#

include /usr/etc/openldap/schema/collective.schema
include /usr/etc/openldap/schema/corba.schema
include /usr/etc/openldap/schema/core.schema
include /usr/etc/openldap/schema/cosine.schema
include /usr/etc/openldap/schema/duaconf.schema
include /usr/etc/openldap/schema/dyngroup.schema
include /usr/etc/openldap/schema/inetorgperson.schema
include /usr/etc/openldap/schema/java.schema
include /usr/etc/openldap/schema/misc.schema
include /usr/etc/openldap/schema/nis.schema
include /usr/etc/openldap/schema/openldap.schema
include /usr/etc/openldap/schema/pmi.schema
include /usr/etc/openldap/schema/ppolicy.schema

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

host            fe80::1***:****:****:***a%eth0
base            dc=mydomain
rootbinddn      cn=Manager,dc=mydomain

#BASE   dc=example,dc=com
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT      12
#TIMELIMIT      15
#DEREF          never
 

追加した箇所は include がたくさん並んでいる行で ありったけのスキーマをとりあえず読み込みます
初期設定した箇所は host base rootbinddn の行です
hostは 一部伏字にしていますが IPv6アドレスを設定し IPv6接続するようにしています
rootbinddn は root権限でLDAPにアクセスする際に代わりに指定アカウントのアクセスになります
指定アカウントに対するパスワードは /usr/etc/openldap/ldap.secret に平文で保存します

# touch /usr/etc/openldap/ldap.secret
# chmod 600 /usr/etc/openldap/ldap.secret
# cat >> /usr/etc/openldap/ldap.secret
(ここにパスワード指定)
(ここで Ctrl+D を押す)
#
 

次に slapd.conf を設定します これはサーバ側の設定となります

 1 #
 2 # See slapd.conf(5) for details on configuration options.
 3 # This file should NOT be world readable.
 4 #
 5 include         /usr/etc/openldap/schema/core.schema
 6 include         /usr/etc/openldap/schema/corba.schema
 7 include         /usr/etc/openldap/schema/cosine.schema
 8 include         /usr/etc/openldap/schema/duaconf.schema
 9 include         /usr/etc/openldap/schema/dyngroup.schema
10 include         /usr/etc/openldap/schema/inetorgperson.schema
11 include         /usr/etc/openldap/schema/java.schema
12 include         /usr/etc/openldap/schema/misc.schema
13 include         /usr/etc/openldap/schema/nis.schema
14 include         /usr/etc/openldap/schema/openldap.schema
15 include         /usr/etc/openldap/schema/pmi.schema
16 include         /usr/etc/openldap/schema/ppolicy.schema
17 
 

まず include部分で core.schemaだけ元々記載されていた箇所にありったけ追記しています

57 #
58 # rootdn can always read and write EVERYTHING!
59 access to attrs=userPassword
60     by self write
61     by dn="cn=Manager,dc=mydomain" write
62     by anonymous auth
63     by * none
64 
65 access to *
66     by self write
67     by dn="cn=Manager,dc=mydomain" write
68     by * read
69 
70 #######################################################################
71 # BDB database definitions
72 #######################################################################
73 
74 database        bdb
75 suffix          "dc=mydomain"
76 rootdn          "cn=Manager,dc=mydomain"
77 # Cleartext passwords, especially for the rootdn, should
78 # be avoid.  See slappasswd(8) and slapd.conf(5) for details.
79 # Use of strong authentication encouraged.
80 rootpw          {MD5}*************************
 

また アクセスポリシーも設定しています
userPassword属性のみ LDAP管理者権限必要で それ以外は次の一文のとおりです
全読み取り可能 エントリと結び付いたユーザは書き込みも可能 LDAP管理者は全書き込み可能

BDB database definitions の部分では DBバックエンドの設定を行っています
バックエンドに BerkeleyDBを使う指定や 管理者権限の指定も行います

rootpw は 管理者権限のパスワードを指定します
{MD5}で暗号化パスワードを指定(上の例は伏字)しますが 平文指定も可能です
MD5暗号化文字列は 下記のコマンドで取得できます

# slappasswd -s パスワード指定 -h {MD5}
{MD5}************************
#
 

次に DBバックエンドの設定です
BerkeleyDB を使うという設定はしましたが どこにデータベース領域があるのでしょうか
/var/openldap-data にあります

# ls /var/openldap-data/
DB_CONFIG.example
 

未設定です DB_CONFIG.exampleという BerkeleyDB設定形式のコンフィグファイルの雛型があります
これを DB_CONFIG にコピーして編集します

# $OpenLDAP: pkg/ldap/servers/slapd/DB_CONFIG,v 1.3.2.4 2007/12/18 11:53:27 ghenry Exp $
# Example DB_CONFIG file for use with slapd(8) BDB/HDB databases.
#
# See the Oracle Berkeley DB documentation
#   
# for detail description of DB_CONFIG syntax and semantics.
#
# Hints can also be found in the OpenLDAP Software FAQ
#       
# in particular:
#   

# Note: most DB_CONFIG settings will take effect only upon rebuilding
# the DB environment.

# one 0.25 GB cache
set_cachesize 0 268435456 1

# Data Directory
#set_data_dir db

# Transaction Log settings
set_lg_regionmax 262144
set_lg_bsize 2097152
#set_lg_dir logs
set_lg_max 10485760

# Note: special DB_CONFIG flags are no longer needed for "quick"
# slapadd(8) or slapindex(8) access (see their -q option). 
 

BerkeleyDBの バージョン5を強引に使っているため 上記の バージョン4 設定が
どこまで有効で適切かが現時点では分かりません 下記解説は バージョン4 32bit版での目安です

set_cachesize は キャッシュ数と 1つあたりのサイズを指定します
物理メモリの 1/4以上 を指定します
set_lg_regionmax は ファイル名のキャッシュです 4MB以上 set_cachesizeの 1/1024 が推奨です
set_lg_bsize トランザクションログの書き込みバッファサイズで 2MB程度がよいらしいです
set_lg_max トランザクションログの最大サイズを指定します set_lg_bsizeの 4倍以上を指定します

最後に スタートストップスクリプトを作っておきます
検証環境は Gentooベースですので /etc/init.d/openldap のファイルを作成します

#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header$

#depend() {
#       after firewall
#}

start() {
        ebegin "Starting OpenLDAP"
        start-stop-daemon --start --quiet --exec /usr/libexec/slapd
        eend $?
}

stop() {
        ebegin "Stopping OpenLDAP"
        start-stop-daemon --stop --quiet --pidfile /var/run/slapd.pid
        eend $?
}
 

動作確認を兼ねて 接続検証をしてみます

# /etc/init.d/openldap start
* Starting OpenLDAP ...                                                  [ ok ]
#
 

別ホストの Linuxから接続してみます

$ ldapsearch -h fe80::1e**:****:****:***a%eth0 -b '' -x -D 'cn=Manager,dc=mydomain' -w パスワード
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# search result
search: 2
result: 32 No such object

# numResponses: 1
$
 

No such object と表示されるのは エントリが未登録のためですが
LDAPサーバへの IPv6接続としては成功しています

ついでなので LDAP認証化に備えてエントリを登録しておきます

$ ldapadd -h fe80::1e**:****:****:***a%eth0 -x -D 'cn=Manager,dc=mydomain' -w パスワード
dn: dc=mydomain
objectClass: dcObject
objectClass: organization
dc: mydomain
o: mydomain

dn: cn=Manager,dc=mydomain
objectclass: organizationalRole
cn: Manager

dn: ou=People,dc=mydomain
objectClass: organizationalUnit
ou: People

dn: ou=Group,dc=mydomain
objectClass: organizationalUnit
ou: Group
(ここで Ctrl+Dを押す)
$
 

先ほどの ldapsearch や LDAPサーバ側に戻って slapcat(root権限必要) のコマンドを使って
エントリが正常に登録できたことが確認できます

とりあえず BerkeleyDB も動作しているようです (後に何かの不具合出るかも…)

IPv6サーバツールへ戻る