| JAPANESE | ENGLISH |
これは, Debian testing/unstableにおけるLDAPの設定の説明である。LDAPの基礎知識はあるものとする。いずれ基礎知識の文章も書くかもしれない.
とりあえずsimple authenticationで確認をする。
# apt-get install slapd ldap-utils nscd
databaseをldbmからbdb (ldbmの後継)に変更。woodyのにはbdbはないようなのでldbmのまま。v2のconnectionを許す。
Swap database systems from ldbm to bdb, a successor of lbdm. Woody don't provide bdm, so you should keep ldbm. Permit v2 connection.
modulepath /usr/lib/ldap moduleload back_bdb database bdb allow bind_v2 replogfile /var/lib/ldap/replog index cn,sn,uid pres,eq suffix "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" rootdn "cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp"
BASE "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" host hostname.tom.sfc.keio.ac.jp
以下コマンドで結果が返ってきたらOK
Systems working well if following commands return appropriate results.
$ ldapsearch -x "(cn=admin)" # extended LDIF # # LDAPv3 # base <> with scope sub # filter: (cn=admin) # requesting: ALL # # admin, tom.sfc.keio.ac.jp dn: cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator # search result search: 2 result: 0 Success # numResponses: 2 # numEntries: 1
hosts.allow,hosts.denyで適切なアクセス制限をかけておくと良い。
simple authenticationはなるべく使いたくないので, SASL対応にする。まず以下を熟読せよ。
Kerberosは面倒なので, DIGEST-MD5でやることにする。
# apt-get install sasl2-bin libsasl2-modules
START=yes MECHANISMS="pam"
# /etc/init.d/saslauthd start
sasl-regexpがミソ。
passsword-hashは慎重に選択する必要がある。
SASLなどで多くの認証方式を使いたい場合,例えば, APOP,CRAM-MD5/DIGEST-MD5などに対応したクライアント向けにパスワード一元管理をしたい場合, CLEARTEXTにする必要がある。しかしCLEARTEXTにすると,生のパスワードがbase64 encodeされてLDAPに格納されるため,管理者がパスワードを読めてしまう。
逆に,パスワードを暗号化して保存すると,認証形式としてはPLAINかLOGINしか扱えないので, TLSで保護する必要がある。ここではTLSを前提に作り直すことにする。
どの暗号化を使うかには, LDAPを使うアプリケーションの対応状況を考慮する必要がある。ここではqmail-ldapが対応しているSHAにしておく。
Kerberosは調べてから...。
SASLの使用にはpasswordを/etc/sasldb2に格納する方法もあるが,それでは一元管理とはいえない...。password管理のスクリプトを書けばいいのかもしれないが。
# sasl
sasl-realm TOM.SFC.KEIO.AC.JP
sasl-host hostname.tom.sfc.keio.ac.jp
sasl-regexp uid=admin,cn=TOM.SFC.KEIO.AC.JP,cn=.+ \
cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp
sasl-regexp uid=(.*),cn=TOM.SFC.KEIO.AC.JP,cn=.+ \
uid=$1,ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp
sasl-secprops none
#password-hash {CLEARTEXT}
password-hash {SHA}
ldap.confに以下を追加。
SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP
# /etc/init.d/slapd restart $ ldapsearch -LLL -s base -b "" -x supportedSaslMechanisms dn: supportedSASLMechanisms: NTLM supportedSASLMechanisms: LOGIN supportedSASLMechanisms: PLAIN supportedSASLMechanisms: ANONYMOUS supportedSASLMechanisms: DIGEST-MD5 supportedSASLMechanisms: CRAM-MD5
もしpassword-hashをCLEARTEXTにし, DIGEST-MD5などを使おうとしている場合は,ここでSASL用にadmin passwordの変更を行う。
dn: cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp changetype: modify replace: userPassword userPassword: password -
一時的なpassword作成した後, LDAPにpasswordを加える
# saslpasswd2 -u TOM.SFC.KEIO.AC.JP -c admin # ldapmodify -U admin@TOM.SFC.KEIO.AC.JP -f admin_password.ldif # rm /etc/sasldb2
こんな感じならOK passwordはbase64 encodeして格納される。
$ ldapsearch -U admin "(cn=admin)" SASL/DIGEST-MD5 authentication started Please enter your password: SASL username: admin@TOM.SFC.KEIO.AC.JP SASL SSF: 128 SASL installing layers # extended LDIF # # LDAPv3 # base <> with scope sub # filter: (cn=admin) # requesting: ALL # # admin, tom.sfc.keio.ac.jp dn: cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator userPassword: password # search result search: 4 result: 0 Success # numResponses: 2 # numEntries: 1
ここらへんはOpenLDAP入門をかなり参考にしている。後, LDAPv3, LDAP administrator-2.1 SSL-Certificate-HOWTO
http://www.linux.or.jp/JF/JFdocs/SSL-Certificates-HOWTO/x169.html
/etc/ssl以下に証明書などを作ることにした。CN (Common Name)をldap.confのhostと合わせなければならないことに注意。
# cp /usr/lib/ssl/misc/CA.sh /usr/local/sbin/CA.sh # vi /usr/local/sbin/CA.sh DAYS="-days 7300" # 20 years CATOP=/etc/ssl # cd /etc/ssl # vi openssl.cnf ディレクトリの設定やデフォルトの設定とか dir = ./ # /usr/local/sbin/CA.sh -newca # ln -s cacert.pem `openssl x509 -noout -hash < cacert.pem`.0
# openssl req -new -nodes -keyout private/hostnamekey.pem -out \
certs/hostnamereq.pem
# openssl ca -out certs/hostnamecert.pem -in \
certs/hostnamereq.pem
TLSCertificateFile /etc/ssl/certs/hostnamecert.pem TLSCertificateKeyFile /etc/ssl/private/hostnamekey.pem TLSCACertificateFile /etc/ssl/cacert.pem
TLS_CACERT /etc/ssl/cacert.pem
slapdの引数は/etc/default/slapdのSLAPD_OPTIONSに書くはずだが, -hの指定がquoteの関係かうまくいかない。よって, init.dの中身を改造した。
--- slapd.orig 2003-08-26 22:01:31.000000000 +0900
+++ slapd 2003-08-26 22:03:20.000000000 +0900
@@ -85,4 +85,5 @@
echo -n " slapd"
reason="`start-stop-daemon --start --quiet \
--pidfile \"$SLAPD_PIDFILE\" \
- --exec /usr/sbin/slapd -- $SLAPD_OPTIONS 2>&1`"
+ --exec /usr/sbin/slapd -- -h 'ldap:/// ldaps:///' $SLAPD_OPTIONS 2>&1`"
+# --exec /usr/sbin/slapd -- $SLAPD_OPTIONS 2>&1`"
}
# Start the slurpd daemon and capture the error message if any to
確認は以下のコマンドでできる。1つ目は-ZZでStartTLSが使えているかどうかの確認, 2つ目はldaps (TLSのURI表記)が使えるかどうかの確認である。
# ldapsearch -H ldap://hostname.tom.sfc.keio.ac.jp/ -x -b "" -s \
base -LLL -ZZ supportedSASLMechanisms
# ldapsearch -H ldaps://hostname.tom.sfc.keio.ac.jp/ -x -b "" -s \
base -LLL supportedSASLMechanisms
ldap-utils使用時には-ZZを付けてtlsを強制する。SASL認証形式として, LOGINやPLAINを明示的に指定する。
$ ldapsearch -ZZ -Y LOGIN "(uid=hoge)"
HOMEディレクトリに以下のファイルを置けば-Y LOGINはいらないはずだが,うまく動いていない...
SASL_MECH LOGIN
# apt-get install libpam-ldap libpam-cracklib
host hostname.tom.sfc.keio.ac.jp # The distinguished name of the search base. base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem ssl start_tls ldap_version 3
pamはあまりにはまることが多いので, symlinkすることにしました...。
We made following symbolic links, because we experienced really \
to much trouble without these links.
# cd /etc
# cp -a pam.d pam.d.orig
# cp -a /usr/share/doc/libpam-ldap/examples/pam.d .
# mv pam.d pam.d.ldap
# ln -s pam.d.ldap pam.d
sudoもldapに対応させる。
#%PAM-1.0 auth sufficient pam_ldap.so auth required pam_unix.so
ただ, libpam-ldapのexampleでは, /lib/security/pam_pwdb.soを必要とするものが多いのだが, Debianにはない。どうやらpam_unix.soと同じに見えるのだが...。まぁ,動いているから追及は後で。
# apt-get install libnss-ldap
# Your LDAP server. Must be resolvable without using LDAP. host hostname.tom.sfc.keio.ac.jp # The distinguished name of the search base. base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem ssl start_tls ldap_version 3 nss_base_passwd ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_shadow ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_group ou=Group,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one
passwd: files ldap group: files ldap shadow: files ldap
netgroupやautomounterはまだ無理みたい...。
以下を追加。
include /etc/ldap/schema/nis.schema include /etc/ldap/schema/misc.schema include /etc/ldap/schema/samba.schema include /etc/ldap/schema/qmail.schema include /etc/ldap/schema/authldap.schema
各種schemaは以下のところへ置いておく。
# vipw +:::::: 追加
+::: 追加
# apt-get install migrationtools # wget http://www.padl.com/download/MigrationTools.tgz
Debianのmigrationtoolsは, snとかをUTF-8にするコードが加わっているが、うまく動いていないようなのでOFFにする。
PADLから直接落としてきたの使って良いと思う。version新しいし。
# Default DNS domain $DEFAULT_MAIL_DOMAIN = "tom.sfc.keio.ac.jp"; # Default base $DEFAULT_BASE = "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp"; $DEFAULT_MAIL_HOST = "mail.tom.sfc.keio.ac.jp"; # turn this on to support more general object clases # such as person. #$EXTENDED_SCHEMA = 0; $EXTENDED_SCHEMA = 1; $USE_UTF8=0
個々に./migrate_passwd.pl passwd > passwd.ldifとかやってもOKだが、今回は移行ににmigration_all_nis_offline.shを使うことにした。
migration_all_nis_offline.sh,migration_all_offline.shの使うファイル以外の個所はコメントアウト。今回はpasswd,group,netgroupだけにした。
$EXTENDED_SCHEMAを指定したときに, migration_passwd.plでobjectClass: inetOrgPersonとobjectClass: accountが共にstructuralObjectなのでconflictするため、objectClass: accountはコメントアウトする。後, mailやsambaで必要となるものを追加している。
変更したmigrate_passwd.plをdata/migrate_passwd.plにおいておく。
実行は以下でOK。
# ./migration_all_nis_offline.sh
これでLDAPにNISのデータが入ったはずなので、以下のように確認する。
# ldapsearch "(uid=自分のuid)" password: 自分のpasswd
先に/etc/exportsが動くかどうか確認するのを忘れないようにする。
NFS-Howto, Automount mini-Howto
# apt-get install autofs autofs-ldap
以下を追加する。
include /etc/ldap/schema/automount.schema
参考までに, tomのauto.ldifを載せておく。
dn: ou=auto.home,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp ou: auto.home objectClass: top objectClass: organizationalUnit dn: cn=/,ou=auto.home,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp cn: / objectClass: automount automountInformation: -rw,intr,soft hostname:/exports/home/& dn: ou=auto.share,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp ou: auto.share objectClass: top objectClass: organizationalUnit dn: cn=project,ou=auto.share,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp cn: project objectClass: automount automountInformation: -rw,intr,soft hostname:/exports/project dn: cn=system,ou=auto.share,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp cn: system objectClass: automount automountInformation: -rw,intr,soft hostname:/exports/system
auto.masterも本当はLDAPに含めたいが, debianの/etc/init.d/autofsが/etc/auto.masterしか読まないので, auto.masterに以下を追加する。
/share ldap:hostname:ou=auto.share,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp \
rsize=16384,wsize=16384
/home ldap:hostname:ou=auto.home,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp \
rsize=16384,wsize=16384
autofsはldapに対応しているが, linux専用である。FreeBSD/NetBSD/Solarisなどのためにamdを動かしたい。まだ動いていないけど途中まで載せる。
$ apt-get source am-utils debian/rulesの--without-ldapを外す # apt-get build-dep am-utils $ dpkg-buildpacakge -us -uc
--- amd2ldif.orig 2003-08-12 22:45:13.000000000 +0900 +++ amd2ldif 2003-08-12 22:45:52.000000000 +0900 @@ -21,6 +21,7 @@ print "dn: cn=amdmap timestamp, $base\n"; printf "$tfmt", "cn", "amdmap timestamp"; printf "$tfmt", "objectClass", "amdMapTimestamp"; +printf "$tfmt", "amdMapName", $mapname; printf "$tfmt", "amdMapTimestamp", $time; print "\n";
# LDAP parameters ldap_base = dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp #ldap_cache_maxmem = 131072 #ldap_cache_seconds = 0 ldap_hostports = hostname:389 map_type = ldap
IMAPは143はTLSのみ, 993はSSLのみにする。POPは995のSSLのみにする。本当はPOPを110のTLSでも提供したいが, courier-popの現在の実装では使い分けができないようだ。courier-imapでは, REQUIRE_TLSは143のときしか適用されないのに, courier-popでは993のほうでも適用される。さらに,実際にはTLS接続をしない。バグかもしれない?
iso-2022-jpによる検索のために, packageを作り直す(patch for 0.42.2)。
diff -ruN courier-0.42.2.orig/debian/rules courier-0.42.2/debian/rules
--- courier-0.42.2.orig/debian/rules 2003-09-09 03:28:13.000000000 +0900
+++ courier-0.42.2/debian/rules 2003-09-09 03:31:00.000000000 +0900
@@ -69,4 +69,5 @@
--enable-userdb \
--enable-syslog=1 \
--enable-unicode \
+ --enable-unicode=iso-2022-jp,utf-8,iso-8859-1 \
--disable-root-check
check:
$ apt-get source courier-imap $ patch -p1 < courier.diff $ dpkg-buildpackage -sgpg -rfakeroot
以下をインストール。
courier-base,courier-authdaemon,courier-doc, courier-imap,courier-imap-ssl,courier-ldap courier-pop,courier-pop-ssl,courier-ssl
authmodulelist="authldap"
LDAP_SERVER localhost LDAP_PORT 389 LDAP_BASEDN dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp LDAP_BINDDN cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp LDAP_BINDPW password LDAP_MAIL mail LDAP_DOMAIN tom.sfc.keio.ac.jp LDAP_HOMEDIR homeDirectory LDAP_CLEARPW userPassword LDAP_UID uidNumber LDAP_GID gidNumber LDAP_TLS 1
いまのところauthldaprcにadmin passwdを記述しているので, permissionに気を付けること。
Currently you should be careful to the permission, because we described admin passwd in the authldaprc file.
# chmod 400 authldaprc
IMAP_CAPABILITY="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT \
THREAD=REFERENCES SORT QUOTA IDLE"
IMAP_CAPABILITY_TLS="$IMAP_CAPABILITY AUTH=PLAIN AUTH=LOGIN"
IMAP_CAPABILITY_TLS_ORIG="$IMAP_CAPABILITY_ORIG AUTH=PLAIN AUTH=LOGIN"
IMAPDSTART=YES
# cd /etc/ssl/certs # openssl x509 -in hostnamecert.pem -out hostnamecert.crt # cat ../private/hostnamekey.pem hostnamecert.crt >mail.pem
TLS_CERTFILE=/etc/ssl/certs/mail.pem IMAP_TLS_REQUIRED=1
#POP3AUTH="CRAM-MD5 CRAM-SHA1" # CLEARTEXTのときのみ POP3AUTH="" POP3AUTH_TLS="LOGIN PLAIN" POP3DSTART=YES
TLS_CERTFILE=/etc/ssl/certs/mail.pem
courier-popだけ起動しないようにする。
# update-rc.d -f courier-pop remove
qmail-ldap-1.03-20030801b.patch.gz smtp-auth-20030801.patch qmail-date-localtime.patch
を当てる。
# apt-get install qmail-src # cd /usr/src/qmail-src # tar xvzf qmail_1.03.orig.tar.gz # cd qmail-1.03 # zcat ../qmail-ldap-1.03-20030801b.patch.gz |patch -p1 # patch -p1 < ../smtp-auth-20030801.patch Makefile.rejを見てfailしたのを直す Check Makefile.rej and fix failed lines. # patch -p1 < ../qmail-data-localtime.patch
次に, debian用のpatchを当てる。debianを使っていなくても,様々な有用なpatchが当たるので,行って損はない。
# zcat ../qmail_1.03-27.diff.gz | patch -p1
conflictしたのを直す。qmail-smtpd.rejは全て無視して良い(qmail-ldapが同じ対応を違うコードで行っているようだ)
Fix conflicted lines. You can ignore qmail-smtpd.rej (because \
qmail-ldap have same functions by another code.)
# chmod 755 debina/rules
作っている環境向けにMakefileとqmail-ldap.hを変更する。
LDAPFLAGS=-DQLDAP_CLUSTER -DEXTERNAL_TODO -DDASH_EXT -DDATA_COMPRESS \
-DALTQUEUE -DDATACOMPRESS
SMTPAUTH=-DUSE_SMTPAUTH -DUSE_OLD_GREETING -DUSE_NEW_GREETING
SMTPAUTHOBJS=base64.o
SMTPAUTHINCLUDES=base64.h
LDAPLIBS=-L/usr/lib -lldap -llber
LDAPINCLUDES=-I/usr/include
ZLIB=-lz
TLS=-DTLS_REMOTE -DTLS_SMTPD
TLSINCLUDES=-I/usr/include
TLSLIBS=-L/usr/lib -lssl -lcrypto
OPENSSLBIN=/usr/bin/openssl
SHADOWLIBS=-lcrypt
DEBUG=-DDEBUG
#define UID_MAX 5000000 #define GID_MIN 80
debianize-binary-treeにauth_imapなどを加える
case `basename $1` in
elq|pinq|qail|qlist2|digest|auth_imap|auth_pop|auth_smtp) echo usr/bin;;
datemail|predate|qmail-home|qsmhook|sendmail|pbsadd|pbscheck|pbsdbd|qmail-ldaplookup|qmail-quotawarn|qmail-reply|qma
il-todo) echo usr/sbin;;
debian/docsにQLDAPINSTALLなどのdocumentを加える。
debian/rulesを変更してqmail.schemaを/etc/ldap/schema/,/usr/share/doc/qmailに追加,
ここまでの作業を全てpatchにしてみた。これはまだ動作確認していないので興味がある人向け。
qmailをインストールするのにucspi-tcpが必要なので,先にインストールする。
# apt-get install ucspi-tcp-src # /usr/src/ucspi-tcp-src # build-ucspi-tcp
qmailのパッケージ作成は,build-qmailではなく, dpkg-buildpackageした。build-qmailの存在を忘れていただけ...。
続いて/var/qmail/controlの設定。ldap固有のもののみ説明。
ldapppasswordにパスワードを格納しなければならないので, permissionを400にする。
We build qmail package by executing dpkg-buildpacakge, not by build-qmail. It's just because we forget build-qmail...
The next step is the configuration of th /var/qmail/control. Here we explain points which is specific for ldap.
We have to store passwords in ldappassword, so make it's permission 400.
# cat >ldapserver hostname.tom.sfc.keio.ac.jp # cat >ldapbasedn dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp # cat >ldapobjectclass qmailUser # cat >ldaplogin cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp # cat >ldappassword password # chmod 600 ldappassword
TLSの設定。TLS.readmeを見よ。ここではcourierの設定で作成したcertificate fileを使う。
# ln -s /etc/ssl/certs/mail.pem /var/qmail/control/cert.pem
tcp.smtp.cdbを適切に設定する。普通は信頼するIPにはRELAYCLIENT=""しておき,それ以外はSMTP-AUTHやPOP-before-SMTPのときのみrelayするようにする。
Configure tcp.smtp.cdb appropriately. In a common configuration, we should set RELAYCLIENT="" for reliable IP addresses and relay only with SMTP-AUTH and POP-before-SMTP.
127.0.0.1:allow,RELAYCLIENT="" xxx.xxx.xxx.:allow,RELAYCLIENT="" :allow
# tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
今回POPはcourierに行わせているので, qmail, qmail-smtpのみ設定する。
svtoolsはunstableにしかないみたいなので, testingで行っている場合はaptのPINの設定などをしておく。
daemontoolsは,インストールする前にドキュメントを良く読むこと!特に終了の仕方を学ばないと, qmailの設定間違っていたときに再起動繰り返したりプロセスが大量増殖したりする。
qmaildが触れるようにldappasswordのownerやpermissionを変える。
# chown qmaild:qmail ldappassword # chmod 640 ldappassword
# apt-get install daemontools-installer # cd /usr/src/daemontools-installer # build-daemontools # apt-get install svtools qmail-sv qmail-sv-smtp
ログの時刻を見るには以下のようにする
To see log clocks, execute a following command.
# tai64nlocal < /service/qmail/log/main/current
daemontools下でのSMTP-AUTHでは,以下のようにする。具体的にはqmail-smtpdの引数に/usr/bin/auth_smtpと/bin/trueを追加。
#!/bin/sh exec 2>&1 exec envdir ./env sh -c ' exec /usr/bin/softlimit -m $MEMORYLIMIT \ /usr/bin/envuidgid qmaild \ /usr/bin/tcpserver -UHRDv -x /etc/tcp.smtp.cdb $IP smtp \ /usr/sbin/qmail-smtpd /usr/bin/auth_smtp /bin/true '
POPを使っているなら, /usr/bin/checkpasswordを/usr/bin/auth_popに変更。
#!/bin/sh exec 2>&1 exec envdir ./env sh -c ' exec /usr/bin/envuidgid qmaild \ /usr/bin/tcpserver -HRDv -x /etc/tcp.pop3.cdb $IP pop-3 \ /usr/sbin/qmail-popup `hostname -f` \ /usr/bin/auth_pop \ /usr/sbin/qmail-pop3d Maildir '
LOGを取りたいときは,以下のようにする。qmail-pop3も同様。
The following configuration is to have LOGs, It's same for qmail-pop3.
# echo "LOGの番号" >> /service/qmail-smtp/env/LOGLEVEL
もし/var/log/auth.logやqmail-smtp/log/main/currentなどにauth_smtp: unable to dlopen /usr/lib/sasl2/libntlm.so.2: libcrypto.so.0.9.7: failed to map segment from shared object: Cannot allocate memoryというようなエラーが出ていたら, qmail-smtpへのメモリ割当てが足りないということである。ldapや後述のqmail-scannerなどは大量にメモリを消費するため,このようなことが起きる。
そのときは以下のようにメモリ量を指定する。メモリ量は少しずつ上げていって,エラーが出ない量を見つけるようにする。
# echo "8000000" > /service/qmail-smtp/env/MEMORYLIMIT
pbs4q + ipv6 patchを使用する。
$ cp ../pbs4q_su.c ../pbs4qimap.c ../Makefile . $ make # make install
courierのauthlibにpbs4qをくわえる。
# cd /usr/lib/courier/authlib # ln -s /usr/local/bin/pbs4q1 . # ln -s /usr/local/bin/pbs4qimap .
imapdとpop3dのAUTHMODULESの最後にそれぞれを加える。
AUTHMODULES="authdaemon pbs4qimap" AUTHMODULES_ORIG="authdaemon pbs4qimap"
AUTHMODULES="authdaemon pbs4q1" AUTHMODULES_ORIG="authdaemon pbs4q1"
authdaemon pbs4q1 pbs4qimap
qmail-smtpd/runに以下のpatchを当てる。
--- run.old 2003-09-15 02:53:50.000000000 +0900
+++ run 2003-09-15 02:53:27.000000000 +0900
@@ -4,5 +4,5 @@
exec /usr/bin/softlimit -m $MEMORYLIMIT \
/usr/bin/envuidgid qmaild \
/usr/bin/tcpserver -UHRDv -x /etc/tcp.smtp.cdb $IP smtp \
- /usr/sbin/qmail-smtpd /usr/bin/auth_smtp /bin/true
+ /usr/local/bin/pbs4q2_smtp /usr/sbin/qmail-smtpd /usr/bin/auth_smtp \
/bin/true
'
$ crontab -e # run pbs4qclean_su every hour 0 * * * * /usr/local/bin/pbs4qclean_su
# svc -dx /service/qmail-smtpdするのを忘れずに。
# apt-get install maildrop perl-suid unzip sharutils clamav \
clamav-freshclam
Time::HiResはperl-5.8.0には入っている
Qmail-Scanner: Content-Sacnner for Qmail
1.20rc3というのがあるので, sourceから入れた。
# qmail-scanner-1.20rc3 ./configure --bindir /usr/local/sbin \
--domain tom.sfc.keio.ac.jp --log-details syslog
# make
# make install
# contrib/test_installation -doit
QMAILQUEUEを追加。
# echo "/usr/local/sbni/qmail-scanner-queue.pl" > \
/service/qmail-smtp/env/QMAILQUEUE
http://www.italpro.net/mb/soft/qmhandle.html
# install -o root -g qmail -m 755 qmHandle /usr/local/bin
smtpsにしか対応していないクライアント(Winbiff2とか)に対応するために, smtpsを動かす。設定はqmailでIPv6 + TLS + SMTP-AUTH + POP3S + IMAPSを参考にして, couriertlsで行った。
基本的には, qmail-smtp-svの設定をまねる。/etc/sv/qmail-smtpの内容を/etc/sv/qmail-smtpsにコピーする。permissionに気をつける。/etc/sv/qmail-smtps/log/mainは/var/log/sv/qmail-smtpsへのシンボリックリンク
#!/bin/sh
exec 2>&1
exec envdir ./env sh -c '
exec /usr/bin/softlimit -m $MEMORYLIMIT \
/usr/bin/envuidgid qmaild \
/usr/bin/tcpserver -UHRDv -x /etc/tcp.smtp.cdb $IP smtps \
/usr/bin/couriertls -server -tcpd \
/usr/local/bin/pbs4q2_smtp /usr/sbin/qmail-smtpd /usr/bin/auth_smtp \
/bin/true
'
# touch /etc/sv/qmail-smtps/env/ALLOWPLAIN # echo > /etc/sv/qmail-smtps/env/TLS_CERTFILE /var/qmail/control/cert.pem # echo > /etc/sv/qmail-smtps/env/TLS_PROTOCOL SSL3 # echo > /etc/sv/qmail-smtps/env/TLS_STARTTLS_PROTOCOL TLS1 # echo > /etc/sv/qmail-smtps/env/TLS_VERIFYPEER NONE
Samba + OpenLDAP による Windows ドメインコントローラの構築 〜 もう Windows ドメインサーバはいらない?! 〜 がよくまとまっている。
IDEALX Contributions to the Samba project にsmbldap-toolsがある。
# wget http://www.idealx.org/prj/samba/dist/smbldap-tools-0.7.tgz # tar xvzf smbldap-tools-0.7.tgz # cd smbldap-tools-0.7 # tar xvzf mkntpwd.tar.gz # cd mkntpwd # make # make install # cd ../ # cp *.pl /usr/local/sbin/ # cp *.pm /etc/perl/
smbldap_conf.pmにpasswdを書かなければならないが, INSTALLにはsmbldap_conf.pmのpermissionを753にしろと書いてある. このファイルにpasswdを書くのは嫌である.
$UID_START = 0; $GID_START = 0; $suffix = "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp"; $usersou = q(People); $groupsou = q(Group); $binddn = "cn=admin,$suffix"; $bindpasswd = "password"; $_userLoginShell = q(/usr/local/bin/tcsh); $_userHomePrefix = q(/home/); $_defaultUserGid = 80; $_userHomeDrive = q(U:);
#access to attribute=userPassword,lmPassword,ntPassword
by dn="cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" write
by anonymous auth
by self write
by * none
# /usr/local/sbin/smbldap-passwd.pl
passwd変更できたら成功
# /usr/local/sbin/smdldap-populate.pl
testingにsamba-ja-2.2.8aja1.0+0に入ったようなのでソースを取得。
$ apt-get source samba-ja $ patch -p0 < rules.diff $ cd samba-ja-2.2.8aja1.0+0 $ debchange -v 2.2.8aja1.0-1.HOGE.1 $ dpkg-buildpackage -sgpg -rfakeroot
--- rules.orig 2003-09-09 21:48:24.000000000 +0900
+++ rules 2003-09-09 21:39:22.000000000 +0900
@@ -60,1 +60,1 @@
fi
# [ -f source/Makefile ] || (cd source && ./configure --with-fhs \
--prefix=/usr --exec-prefix=/usr --with-netatalk --with-smbmount \
--with-pam --with-syslog --with-sambabook --with-utmp)
- [ -f source/Makefile ] || (cd source && ./configure \
--host=$(DEB_HOST_GNU_TYPE)-gnu --build=$(DEB_BUILD_GNU_TYPE)-gnu \
--with-fhs --prefix=/usr --sysconfdir=/etc --with-privatedir=/etc/samba \
--with-lockdir=/var/state/samba --localstatedir=/var --with-netatalk \
--with-smbmount --with-pam --with-syslog --with-sambabook --with-utmp \
--with-readline --with-pam_smbpass --with-i18n-swat)
+ [ -f source/Makefile ] || (cd source && ./configure \
--host=$(DEB_HOST_GNU_TYPE)-gnu --build=$(DEB_BUILD_GNU_TYPE)-gnu \
--with-fhs --prefix=/usr --sysconfdir=/etc --with-privatedir=/etc/samba \
--with-lockdir=/var/state/samba --localstatedir=/var --with-netatalk \
--with-smbmount --with-pam --with-syslog --with-sambabook --with-utmp \
--with-readline --with-pam_smbpass --with-i18n-swat --with-ldapsam)
touch configure-stamp
smb.confは長いのでldapに関係あるところだけ。
ldap admin dn = cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp #ldap filter = (&(uid=%u)(objectclass=sambaAccount)) ldap port = 389 ldap server = hostname.tom.sfc.keio.ac.jp ldap ssl = on ldap suffix = dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp
admin DN用のpasswordを/etc/samba/secrets.tdbに格納する。
# smbpasswd -w password
sambaディレクトリがmountできればOKである。
# smbmount //NETBIOS NAME/user /mnt -o \
username=user,password=password
Todo
unix password sync = yes
passwd program = /usr/local/sbin/smbldap-passwd.pl -o %u
passwd chat = *New* %n\n *Retype* %n\n *success*
add user script = /usr/local/sbin/smbldap-useradd.pl %u
delete user script = /usr/local/sbin/smbldap-userdel.pl %u
os level = 64
domain master = yes
prefered master = yes
local master = yes
domain admin group = " @"Domain Admin" "
wins support = yes
domain logons = yes
[netlogon]
comment = Network Logon Service
path = /var/samba/netlogon
# guest ok = yes
# writable = no
# share modes = no
admin users = Administrator
write list = Administrator
[Profiles]
path = /var/samba/profiles
writeable = yes
browseable = no
create mode = 0600
directory mode = 0700
# guest ok = yes
Refer http://ie.samba.org/samba/ftp/beta/WHATSNEW-samba-3.0.0beta3.txt
これはまだ動いていない!!!
samba-3.0からは属性が変わっているなどがあるので, 要調査。 一応convertSambaAccountってのはあるみたい。
passdb backend = ldapsam:ldap://localhost ldap admin dn = "cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" ldap ssl = off ldap suffix = "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" ldap machine suffix = ou=Computers ldap user suffix = ou=People ldap filter = "(&(uid=*%u*)(objectclass=sambaSamAccount))"
LDAP authentication module for Apache 2.x
とりあえずは/etc/apache2/README参照のこと. 設定の種類ごとにディレクトリ分けされており,全てapache2.confによってIncludeされている.
/etc/apache2/mods-enabled/*.load /etc/apache2/mods-enebled/*.conf /etc/apache2/sites-enabled/* /etc/apache2/conf.d/* /etc/apache2/ports.conf /etc/apache2/httpd.conf
基本的に***-enabledには設定ファイルを直接置かず,***-available以下に設定ファイルを記述し,そのシンボリックリンクを***-enabledに張るというポリシーを採用しています. mods-***にはモジュール関係の設定ファイルを置いています.読み込みたいモジュールがある場合は,mods-available以下に,
LoadModule hoge_fuga.so
とか記述した****.loadファイルを置き,シンボリックリンクをmods-enabledに張ってください. sites-***にはバーチャルホスト関係の設定ファイルを置いています.現在はpear.tom.sfc.keio.ac.jpとyax.tom.sfc.keio.ac.jpが有効になっています.
LDAPによるHTTP認証を行うモジュール.apache2.0.47付属のモジュールではなくmuquitのモジュールを利用しています.
ソースは以下からダウンロードできる. http://www.muquit.com/muquit/software/mod_auth_ldap/mod_auth_ldap.tar.gz
makeにはapxs2が必要です.Debianなら以下のコマンドでインストールされる.
# apt-get install apache2-dev
あとはconfigure&makeで. configureにはldapクライアントのディレクトリとapxsのパスを指定する. --with-ldap-dirで指定したディレクトリ以下のlibディレクトリを検索するので,kenchoでは/usrを指定する. --with-apxsではapxsの実行ファイルのパスを指定する.
# cd /usr/local/src/modauthldap_apache2 # ./configure --with-ldap-dir=/usr --with-apxs=/usr/bin/apxs2 # make
このままmake installしても正常にインストールされるが, それだとapache2.0.47付属のmod_auth_ldapを上書きインストールしてしまう. これらのmod_auth_ldapは同じ名前だが設定の書き方などに一切の互換性はない. そのため,mod_auth_ldap_muquit.soと言う名前でこのモジュールをインストールする.
# cd /usr/local/scr/modauthldap_apache2
# cp .lib/mod_auth_ldap.so \
/usr/lib/apache2/modules/mod_auth_ldap_muquit.so
/etc/apache2/mods_available/に以下のファイルを作成し
auth_ldap_muquit.loadという名前で保存する.
LoadModule auth_ldap_module \
/usr/lib/apache2/modules/mod_auth_ldap_muquit.so
/etc/apache2/mods_enabled/以下にファイルへのシンボリックリンクを
張ることでこのモジュールが有効になる.
mod_auth_ldapによる認証を行いたいディレクトリで以下の設定を記述する.
<Directory /hoge/fuga>
AuthName "Required Password"
AuthType Basic
<IfModule mod_auth_ldap.c>
LDAP_Server kencho.tom.sfc.keio.ac.jp
LDAP_Port 389
Base_DN "dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp"
UID_Attr uid
LDAP_StartTLS On
</IfModule>
require valid-user
</Directory>
とりあえずこれだけ書いておけばそのディレクトリにアクセスするために LDAPによる認証が行われるようになる.
SSL/TLSによる暗号化を可能にするモジュール.apache2.0.47付属のmod_ssl.soを利用する.
/etc/apache2/mods-available/以下にあるssl.loadと
ssl.confを,/etc/apache2/mods-enabled/以下にリンクする.
% ln -s /etc/mods-available/ssl.* /etc/mods-enables/
ssl.confにはちょこっと手を加えて以下のようにしています.
<IfModule mod_ssl.c>
SSLSessionCache shm:/var/log/apache2/ssl_scache(128000)
SSLMutex file:/var/log/apache2/ssl_mutex
SSLRandomSeed startup file:/dev/urandom 512
SSLRandomSeed connect file:/dev/urandom 512
ErrorLog /var/log/apache2/ssl.log
LogLevel info
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
</IfModule>
443番ポートでhttpsを利用可能にするには以下のように設定する.
<VirtualHost 133.27.175.5:443>
SSLEngine on
SSLCertificateKeyFile /etc/ssl/private/kenchokey.pem
SSLCertificateFile /etc/ssl/certs/kenchocert.crt
SSLCACertificateFile /etc/ssl/cacert.pem
SSLCARevocationFile /etc/ssl/crl/kencho-ca.crl
...
</VirtualHost>
httpsによるアクセスのみを受け付けるようにするためにはSSLRequireSSLディレクティブを利用する. port 443のバーチャルホストで設定する.
<VirtualHost 133.27.175.5:80>
...
<Directory /share/project/0/WWW/htdocs/mrtg>
SSLRequireSSL
</Directory>
<Directory /share/project/0/WWW/htdocs/wiki>
SSLRequireSSL
</Directory>
...
</VirtualHost>
/var/log/apache2/ssl.logに書いている.
各OSでのクライアントの設定。
まず, TLSのためにserverの/etc/ssl/cacert.pemをコピーする。
# apt-get install ldap-utils libsasl2-modules openssl
BASE dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp HOST hostname.tom.sfc.keio.ac.jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem
認証テストを行う。 以下のコマンドで結果が返ってきたらOKである。 1つ目がsimple認証のテスト, 2つ目がSASL Supportのテスト, 3つ目がSASL認証のテスト (rootでやるときは自分のユーザ名を-U optionで指定すること), 4つ目がTLSのテスト, 5つ目がldaps (TLS URL)のテスト。
$ ldapsearch -x "(cn=admin)"
$ ldapsearch -LLL -s base -b "" -x supportedSaslMechanisms
$ ldapsearch -Y LOGIN "(cn=admin)"
$ ldapsearch -H ldap://hostname.tom.sfc.keio.ac.jp/ -x -b "" -s \
base -LLL -ZZ supportedSASLMechanisms
$ ldapsearch -H ldaps://hostname.tom.sfc.keio.ac.jp/ -x -b "" -s \
base -LLL supportedSASLMechanisms
% apt-get install libpam-ldap libpam-cracklib libpam-pwdfile
host hostname.tom.sfc.keio.ac.jp # The distinguished name of the search base. base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem ssl start_tls ldap_version 3
pam_ldapではpam_passwordは指定しないことに注意。
pamはあまりにはまることが多いので, symlinkすることにした。 % cd /etc % cp -a pam.d pam.d.orig % cp -a /usr/share/doc/libpam-ldap/examples/pam.d . % mv pam.d pam.d.ldap % ln -s pam.d.ldap pam.d
sudoもldapに対応させる。
#%PAM-1.0 auth sufficient pam_ldap.so auth required pam_unix.so
% apt-get install libnss-ldap nscd
debconfで設定できるようだが, 一応libnss_ldap.confは以下の通りである。
# Your LDAP server. Must be resolvable without using LDAP. host hostname.tom.sfc.keio.ac.jp # The distinguished name of the search base. base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem ssl start_tls ldap_version 3 nss_base_passwd ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_shadow ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_group ou=Group,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one
nsswitchは, 一応nisも残しておく。
passwd: files ldap nis group: files ldap nis shadow: files ldap nis
passwdとgroupの設定をする。 NISと同様。
# vipw +:::::: # vi /etc/group +:::
まず, kernelをautofsv4に対応するようにcompileしておくこと。
Enable your kernel to use autfsv4.
# apt-get install autofs autofs-ldap
/share ldap hostname:ou=auto.share,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp /home ldap hostname:ou=auto.home,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp
# /etc/init.d/autofs restart
amdはしょうがないのでNISで配っている。
# apt-get install am-utils
debconfの設定で, 全部NOと答え, other kinds of mapsの段階で,
/home amd.home /share amd.shareと設定すればOK。
一応設定されるconfigの中身を載せておく。
AM_UTILS_USE_NIS='false' AM_UTILS_MAP_OTHERS='/home amd.home /share amd.share'
[global] auto_dir = /amd log_file = syslog log_options = all,noinfo,nostats,nomap restart_mounts = yes unmount_on_exit = yes vendor = Debian
woodyにあるldap-utilsはTLSやSASL2をサポートしていないため, まずはサポートするようにパッケージを作り直す
# apt-get build-dep ldap-utils # apt-get source ldap-utils # apt-get install libsasl2-dev libssl-dev
--- debian/rules.orig Mon Sep 15 02:26:13 2003
+++ debian/rules Mon Sep 15 02:26:19 2003
@@ -15,7 +15,7 @@
--enable-multimaster --enable-phonetic --enable-rlookups \
--enable-wrappers --enable-dynamic --disable-dnssrv \
--enable-ldap --enable-ldbm --enable-shell --enable-sql \
- --enable-slurpd --enable-shared --without-tls \
+ --enable-slurpd --enable-shared --with-tls \
--prefix=/usr --localstatedir=/var/lib \
--sysconfdir=/etc --libexecdir='$${prefix}'/sbin \
--mandir='$${prefix}'/share/man --with-subdir=ldap
# dpkg -i ../ldap-utils* ../libldap2* # apt-get install sasl-bin libsasl-modules-plain
認証テストを行う。 3つ目は, -Y LOGINには対応していないので, -Y PLAINで試す。
Examine your configration. Specify -Y PLAIN instead of specifying -Y LOGIN in 3rd test, because -Y LOGIN option is not supported.
まずNFSの設定をする。
# apt-get install portmap # rpcinfo -p nfsserver # mount -t nfsserver:/mountpoint /mnt
autofs-ldapはバグがあって動かないので, testing/unstableからsourceもってきてrebuild。 http://www.apt-get.orgにはなかった。
# apt-get install devscripts # apt-get build-dep autofs # debuild
設定はtesting/unstableの項参照。
設定はtesting/unstableの項参照。
http://www.freebsd.org/releases/5.1R/annouce.html http://www.cultdeadsheep.org/FreeBSD/docs/Quick_and_dirty_FreeBSD_5_x_and_nss_ldap_mini-HOWTO.html
5.1からはNSSが組込まれている。 というか, 今までなかったのか。
まず, TLSのためにserverの/etc/ssl/cacert.pemをコピーする。
portsを最新にして, 以下をインストール。 cyrus-saslのconfigは, SASLAUTHDをONにすること。
# cd /usr/ports/security/openssl # make -DOPENSSL_OVER_WRITE install # cd /usr/ports/net/openldap21-client # make -DWITH_SASL install
BASE dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp HOST hostname.tom.sfc.keio.ac.jp SASL_SECPROPS none SASL_REALM TOM.SFC.KEIO.AC.JP TLS_CACERT /etc/ssl/cacert.pem
認証テストを行う (Debianの認証テストを参照)。
# cd /usr/ports/security/pam_ldap # make install # cd /usr/local/etc # cp ldap.conf.dist ldap.conf
pamとnssのLDAP設定は/usr/local/etc/ldap.confに書く。
host hostname.tom.sfc.keio.ac.jp base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp ldap_version 3 pam_filter objectclass=posixAccount nss_base_passwd ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_shadow ou=People,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one nss_base_group ou=Group,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp?one ssl start_tls tls_cacertfile /etc/ssl/cacert.pem sasl_secprops none sasl_realm TOM.SFC.KEIO.AC.JP
# vipw +::::::::: # vi /etc/group +:*::
FreeBSD-5.1用のpam.dの設定を書いたので置いておく (pam.d.tar.gz, pam.d.diff)。
diff -ruN pam.d.orig/ftp pam.d/ftp --- pam.d.orig/ftp Fri Sep 12 02:37:37 2003 +++ pam.d/ftp Fri Sep 12 02:36:36 2003 @@ -10,10 +10,12 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_unix.so # session diff -ruN pam.d.orig/gdm pam.d/gdm --- pam.d.orig/gdm Fri Sep 12 02:37:37 2003 +++ pam.d/gdm Fri Sep 12 02:39:21 2003 @@ -8,10 +8,12 @@ auth required pam_nologin.so no_warn #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_unix.so # session diff -ruN pam.d.orig/imap pam.d/imap --- pam.d.orig/imap Fri Sep 12 02:37:37 2003 +++ pam.d/imap Fri Sep 12 02:39:42 2003 @@ -8,4 +8,5 @@ #auth required pam_nologin.so no_warn #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass diff -ruN pam.d.orig/kde pam.d/kde --- pam.d.orig/kde Fri Sep 12 02:37:37 2003 +++ pam.d/kde Fri Sep 12 02:35:44 2003 @@ -8,12 +8,15 @@ auth required pam_nologin.so no_warn #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_unix.so # session #session optional pam_ssh.so +session sufficient pam_ldap.so session required pam_permit.so diff -ruN pam.d.orig/login pam.d/login --- pam.d.orig/login Fri Sep 12 02:37:37 2003 +++ pam.d/login Sat Sep 13 00:43:39 2003 @@ -11,12 +11,14 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass nullok # account #account required pam_krb5.so account required pam_login_access.so account required pam_securetty.so +account sufficient pam_ldap.so account required pam_unix.so # session @@ -25,4 +27,5 @@ # password #password sufficient pam_krb5.so no_warn try_first_pass -password required pam_unix.so no_warn try_first_pass +password sufficient pam_ldap.so no_warn try_first_pass +password sufficient pam_unix.so no_warn try_first_pass diff -ruN pam.d.orig/other pam.d/other --- pam.d.orig/other Fri Sep 12 02:37:37 2003 +++ pam.d/other Fri Sep 12 02:41:55 2003 @@ -10,10 +10,12 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_login_access.so account required pam_unix.so diff -ruN pam.d.orig/passwd pam.d/passwd --- pam.d.orig/passwd Fri Sep 12 02:37:37 2003 +++ pam.d/passwd Fri Sep 12 21:58:32 2003 @@ -8,4 +8,5 @@ # password #password requisite pam_passwdqc.so enforce=users +password required pam_ldap.so password required pam_unix.so no_warn try_first_pass nullok diff -ruN pam.d.orig/pop3 pam.d/pop3 --- pam.d.orig/pop3 Fri Sep 12 02:37:37 2003 +++ pam.d/pop3 Fri Sep 12 02:43:15 2003 @@ -8,4 +8,5 @@ #auth required pam_nologin.so no_warn #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass diff -ruN pam.d.orig/rexecd pam.d/rexecd --- pam.d.orig/rexecd Fri Sep 12 02:37:37 2003 +++ pam.d/rexecd Fri Sep 12 02:44:07 2003 @@ -6,10 +6,12 @@ # auth auth required pam_nologin.so no_warn +auth sufficient pam_ldap.so no_warn auth required pam_unix.so no_warn use_first_pass # account account required pam_ftpusers.so no_warn disallow +account sufficient pam_ldap.so no_warn account required pam_unix.so no_warn # session diff -ruN pam.d.orig/rsh pam.d/rsh --- pam.d.orig/rsh Fri Sep 12 02:37:37 2003 +++ pam.d/rsh Fri Sep 12 02:45:37 2003 @@ -9,6 +9,7 @@ auth required pam_rhosts.so no_warn # account +account sufficient pam_ldap.so account required pam_unix.so # session diff -ruN pam.d.orig/sshd pam.d/sshd --- pam.d.orig/sshd Fri Sep 12 02:37:37 2003 +++ pam.d/sshd Sat Sep 13 00:37:43 2003 @@ -10,10 +10,12 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_login_access.so account required pam_unix.so @@ -23,4 +25,5 @@ # password #password sufficient pam_krb5.so no_warn try_first_pass +password required pam_ldap.so no_warn try_first_pass password required pam_unix.so no_warn try_first_pass diff -ruN pam.d.orig/su pam.d/su --- pam.d.orig/su Fri Sep 12 02:37:37 2003 +++ pam.d/su Sat Sep 13 00:37:59 2003 @@ -12,10 +12,12 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn try_first_pass auth_as_self #auth required pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass nullok # account #account required pam_krb5.so +account sufficient pam_ldap.so account required pam_unix.so # session diff -ruN pam.d.orig/telnetd pam.d/telnetd --- pam.d.orig/telnetd Fri Sep 12 02:37:37 2003 +++ pam.d/telnetd Fri Sep 12 21:58:10 2003 @@ -10,11 +10,13 @@ auth requisite pam_opieaccess.so no_warn allow_local #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account #account required pam_krb5.so account required pam_login_access.so +account sufficient pam_ldap.so account required pam_unix.so # session @@ -23,4 +25,5 @@ # password #password sufficient pam_krb5.so no_warn try_first_pass +password required pam_ldap.so no_warn try_first_pass password required pam_unix.so no_warn try_first_pass diff -ruN pam.d.orig/xdm pam.d/xdm --- pam.d.orig/xdm Fri Sep 12 02:37:37 2003 +++ pam.d/xdm Fri Sep 12 02:50:38 2003 @@ -8,6 +8,7 @@ auth required pam_nologin.so no_warn #auth sufficient pam_krb5.so no_warn try_first_pass #auth sufficient pam_ssh.so no_warn try_first_pass +auth sufficient pam_ldap.so no_warn try_first_pass auth required pam_unix.so no_warn try_first_pass # account @@ -16,4 +17,5 @@ # session #session required pam_ssh.so want_agent +session sufficient pam_ldap.so want_agent session required pam_permit.so
# cd /usr/ports/net/nss_ldap # make install
nsswitchのLDAP設定は/etc/ldap.confになければいけないなので, pamの設定をsymbolic linkする。
# ln -s /usr/local/etc/ldap.conf /etc/
nsswitchの設定。
passwd: files ldap nis group: files ldap nis shadow: files ldap nis hosts: files dns
passwdとgroupの設定はNISと同様である。
nis_client_enable="YES" nisdomainname="hogehoge" amd_enable="YES" amd_flag="-a /.amd_mnt -l syslog /home amd.home /share amd.share"
# cat `cat /var/run/amd.pid`
ログインして自分のhome directoryに移動できるかを確認。 amqでstatusの確認。
# amq -ms
FreeBSD4.xにはNSSがないので, pamとNISを使うことにする。
LDAPクライアントの設定はFreeBSD-5.1の設定を参照。
cyrus-sasl2のコンパイルに失敗するが, cyrus-sasl2/work/lib/MakefileのINCLUDESに-I$(top_srcdir)/sasldbを追加すればOK (2003/09/12現在)。
# cd /usr/ports/security/pam_ldap # make install # ln -s /usr/local/lib/pam_ldap.so /usr/lib/ # cd /usr/local/etc # cp ldap.conf.dist ldap.conf
pamのLDAP設定は/usr/local/etc/ldap.confに書く。
host hostname.tom.sfc.keio.ac.jp base dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp ldap_version 3 pam_filter objectclass=posixAccount ssl start_tls tls_cacertfile /etc/ssl/cacert.pem sasl_secprops none sasl_realm TOM.SFC.KEIO.AC.JP
# vipw +::::::::: # vi /etc/group +:*::
FreeBSD-4.xでは, pamの設定ファイルは/etc/pam.dはなく/etc/pam.confである。
FreeBSD-4.x用のpam.confを書いたので置いておく (pam.conf, pam.conf.diff)。
# Configuration file for Pluggable Authentication Modules (PAM). # # This file controls the authentication methods that login and other # utilities use. See pam(8) for a description of its format. # # $FreeBSD: src/etc/pam.conf,v 1.6.2.18 2003/02/15 17:20:27 des Exp $ # # service-name module-type control-flag module-path arguments # # module-type: # auth: prompt for a password to authenticate that the user is # who they say they are, and set any credentials. # account: non-authentication based authorization, based on time, # resources, etc. # session: housekeeping before and/or after login. # password: update authentication tokens. # # control-flag: How libpam handles success or failure of the module. # required: success is required, and on failure all remaining # modules are run. # requisite: success is required, and on failure no remaining # modules are run. # sufficient: success is sufficient, and if no previous required # module failed, no remaining modules are run. # optional: ignored unless the other modules return PAM_IGNORE. # # arguments: # Passed to the module; module-specific plus some generic ones: # debug: syslog debug info. # no_warn: return no warning messages to the application. # use_first_pass: try authentication using password from the # preceding auth module. # try_first_pass: first try authentication using password from # the preceding auth module, and if that fails # prompt for a new password. # use_mapped_pass: convert cleartext password to a crypto key. # expose_account: allow printing more info about the user when # prompting. # # Each final entry must say "required" -- otherwise, things don't # work quite right. If you delete a final entry, be sure to change # "sufficient" to "required" in the entry before it. # If the user can authenticate with S/Key, that's sufficient; allow clear # password. Try kerberos, then try plain unix password. login auth sufficient pam_skey.so login auth sufficient pam_opie.so no_fake_prompts #login auth requisite pam_opieaccess.so login auth requisite pam_cleartext_pass_ok.so #login auth sufficient pam_kerberosIV.so try_first_pass #login auth sufficient pam_krb5.so try_first_pass login auth sufficient pam_ldap.so try_first_pass login auth required pam_unix.so try_first_pass login account sufficient pam_ldap.so login account required pam_unix.so login password required pam_permit.so login session required pam_permit.so # Same requirement for ftpd as login ftpd auth sufficient pam_skey.so ftpd auth sufficient pam_opie.so no_fake_prompts #ftpd auth requisite pam_opieaccess.so ftpd auth requisite pam_cleartext_pass_ok.so #ftpd auth sufficient pam_kerberosIV.so try_first_pass #ftpd auth sufficient pam_krb5.so try_first_pass ftpd auth sufficient pam_ldap.so try_first_pass ftpd auth required pam_unix.so try_first_pass # OpenSSH with PAM support requires similar modules. The session one is # a bit strange, though... sshd auth sufficient pam_skey.so sshd auth sufficient pam_opie.so no_fake_prompts #sshd auth requisite pam_opieaccess.so #sshd auth sufficient pam_kerberosIV.so try_first_pass #sshd auth sufficient pam_krb5.so try_first_pass sshd auth sufficient pam_ldap.so try_first_pass sshd auth required pam_unix.so try_first_pass sshd account required pam_unix.so sshd password required pam_permit.so sshd session required pam_permit.so # "telnetd" is for SRA authenticated telnet only. Non-SRA uses 'login' telnetd auth sufficient pam_ldap.so try_first_pass telnetd auth required pam_unix.so try_first_pass # Don't break startx xserver auth required pam_permit.so # XDM is difficult; it fails or moans unless there are modules for each # of the four management groups; auth, account, session and password. xdm auth required pam_unix.so #xdm auth sufficient pam_kerberosIV.so try_first_pass #xdm auth sufficient pam_krb5.so try_first_pass xdm auth sufficient pam_ldap.so try_first_pass xdm account required pam_unix.so try_first_pass xdm session required pam_deny.so xdm password required pam_deny.so # GDM (GNOME Display Manager) gdm auth required pam_unix.so #gdm auth sufficient pam_kerberosIV.so try_first_pass #gdm auth sufficient pam_krb5.so try_first_pass gdm auth sufficient pam_ldap.so try_first_pass gdm account required pam_unix.so try_first_pass gdm session required pam_permit.so gdm password required pam_deny.so # Mail services imap auth sufficient pam_ldap.so try_first_pass imap auth required pam_unix.so try_first_pass pop3 auth sufficient pam_ldap.so try_first_pass pop3 auth required pam_unix.so try_first_pass # If we don't match anything else, default to using getpwnam(). other auth sufficient pam_skey.so other auth sufficient pam_ldap.so try_first_pass other auth required pam_unix.so try_first_pass other account required pam_unix.so try_first_pass
--- pam.conf.orig Wed Jan 1 11:19:00 2003 +++ pam.conf Wed Jan 1 11:21:37 2003 @@ -49,7 +49,9 @@ login auth requisite pam_cleartext_pass_ok.so #login auth sufficient pam_kerberosIV.so try_first_pass #login auth sufficient pam_krb5.so try_first_pass +login auth sufficient pam_ldap.so try_first_pass login auth required pam_unix.so try_first_pass +login account sufficient pam_ldap.so login account required pam_unix.so login password required pam_permit.so login session required pam_permit.so @@ -61,6 +63,7 @@ ftpd auth requisite pam_cleartext_pass_ok.so #ftpd auth sufficient pam_kerberosIV.so try_first_pass #ftpd auth sufficient pam_krb5.so try_first_pass +ftpd auth sufficient pam_ldap.so try_first_pass ftpd auth required pam_unix.so try_first_pass # OpenSSH with PAM support requires similar modules. The session one is @@ -70,12 +73,14 @@ #sshd auth requisite pam_opieaccess.so #sshd auth sufficient pam_kerberosIV.so try_first_pass #sshd auth sufficient pam_krb5.so try_first_pass +sshd auth sufficient pam_ldap.so try_first_pass sshd auth required pam_unix.so try_first_pass sshd account required pam_unix.so sshd password required pam_permit.so sshd session required pam_permit.so # "telnetd" is for SRA authenticated telnet only. Non-SRA uses 'login' +telnetd auth sufficient pam_ldap.so try_first_pass telnetd auth required pam_unix.so try_first_pass # Don't break startx @@ -86,6 +91,7 @@ xdm auth required pam_unix.so #xdm auth sufficient pam_kerberosIV.so try_first_pass #xdm auth sufficient pam_krb5.so try_first_pass +xdm auth sufficient pam_ldap.so try_first_pass xdm account required pam_unix.so try_first_pass xdm session required pam_deny.so xdm password required pam_deny.so @@ -94,15 +100,19 @@ gdm auth required pam_unix.so #gdm auth sufficient pam_kerberosIV.so try_first_pass #gdm auth sufficient pam_krb5.so try_first_pass +gdm auth sufficient pam_ldap.so try_first_pass gdm account required pam_unix.so try_first_pass gdm session required pam_permit.so gdm password required pam_deny.so # Mail services +imap auth sufficient pam_ldap.so try_first_pass imap auth required pam_unix.so try_first_pass +pop3 auth sufficient pam_ldap.so try_first_pass pop3 auth required pam_unix.so try_first_pass # If we don't match anything else, default to using getpwnam(). other auth sufficient pam_skey.so +other auth sufficient pam_ldap.so try_first_pass other auth required pam_unix.so try_first_pass other account required pam_unix.so try_first_pass
amdはFreeBSD-5.1と一緒。
今まで設定したcourier-pop,imap,qmailのクライアント側の設定である。 基本方針は以下の通り。 問題はBecky!君。どうしようか。
詳細はhttp://www.gohome.org/wl/doc/wl-euc_toc.htmlを参照。
;; pop
(setq elmo-pop3-default-server "hostname")
(setq elmo-pop3-default-user "username")
(setq elmo-pop3-default-authenticate-type 'user)
;; pop over ssl
(setq elmo-pop3-default-stream-type 'ssl)
(setq elmo-pop3-default-port 995)
;; imap
(setq elmo-imap4-default-server "hostname")
(setq elmo-imap4-default-user "username")
(setq elmo-imap4-default-authenticate-type 'login)
;; imap over ssl
(setq elmo-imap4-default-port 993)
(setq elmo-imap4-default-stream-type 'ssl)
;; imap over tls
;(setq elmo-imap4-default-port 143)
;(setq elmo-imap4-default-stream-type 'starttls)
;; smtp
(setq wl-smtp-posting-server "hostname")
;; smtp over tls
(setq wl-smtp-connection-type 'starttls)
;; pop-before-smtp
;(setq wl-draft-send-mail-function \
'wl-draft-send-mail-with-pop-before-smtp)
;; smtp-auth
;(setq wl-smtp-posting-user "username")
;(setq wl-smtp-authenticate-type "login")
;; nntp
(setq wl-nntp-default-server "hostname")
(setq wl-nntp-default-user "username")
;; ldap
(setq wl-use-ldap 't)
(setq wl-ldap-server "hostname")
(setq wl-ldap-port 389)
(setq wl-ldap-base "base DN")
http://www.mew.org/release/info/を参照.
3ZでIMAPのフォルダリスト情報を更新
POPやIMAPはSSL対応, TLS非対応である. SMTPS(port 465)対応. SMTP-AUTH対応, APOP対応, POP受信のときのみPOP before SMTP対応 LDAP非対応
SSL対応,TLS非対応だが, SSLは25番でOK, LDAP対応, SMTP-AUTH対応
SSL対応(25番), SMTP-AUTH対応
SSL/TLS対応, SMTP-AUTH対応 認証クリアテキスト, プレーン, ログイン, CRAM-MD5, DIGEST-MD5, 匿名 IMAP,IMAPS,POP3,POP3S,APOP
SMTPがうまく使えない? 以下のようになってしまう.
<Fumihiro Kato <@tom.sfc.keio.ac.jp>: Sorry, no mailbox here by that name. (#5.1.1)
新しいことをするときは, 以下のどちらかのバックアップを行ってから 作業したほうが良い.
# tar czf ldap.tgz /var/lib/ldap
# slapcat > backup.ldap
戻すときは, 以下のどちらかの作業をすれば良い.
# rm /var/lib/ldap/* # tar xvzf ldap.tgz -C /var/lib/ # /etc/init.d/slapd restart
# rm /var/lib/ldap/* # slapadd -l backup.ldap # /etc/init.d/slapd restart
これでいいということに気付いてから作業が楽になった。
証明書の有効期限を1年にしているので、1年毎に作り直す必要がある。
# openssl ca -revoke certs/hostnamecert.pem
# openssl ca -gencrl -config /etc/ssl/openssl.cnf -out \
crl/hostname-ca.crl
# openssl ca -out certs/hostnamecert.pem -in \
certs/hostnamereq.pem
終わったら、mailなどのcert作成をやり直す。
slapd.confのindexを設定すると, それをキーとしたインデックス用のデータベースを作成 してくれるので高速に検索可能となる。 しかし, たくさん指定するとindex作成に時間がかかるので注意すること。
index cn,sn,uid,uidNumber,gidNumber,qmailUID,qmailGID,homeDirectory,mail \
pres,eq
index objectClass eq
slapd.confを変更したら,
slapindexを実行するとデータベースに反映される。
Orangesoftのwstunnel説明書を参照。
とりあえず,以下の設定でBecky2!などからメールが送ることができている。
replog /var/lib/ldap/replog replica host=slave.tom.sfc.keio.ac.jp:389 updatedn "cn=admin,dc=tom,dc=sfc,dc=keio,dc=ac,dc=jp" updateref "ldap://master.tom.sfc.keio.ac.jp/"
# openssl req -new -nodes -keyout private/hostnamekey.pem -out \
certs/hostnamereq.pem
# openssl ca -out certs/hostnamecert.pem -in \
certs/hostnamereq.pem
Active DirectoryはKerberos V5 + LDAP. samba3.0もActive Directoryの代用を目指しているらしい。
Wikiを作成した。
We created Wiki.
FYI: Documents below are include some links to Japanese documents.