コマンドの使い方

中身の確認

 ldapsearch -h localhost -x -b 'dc=bike,dc=oa,dc=net' '(objectclass=*)'

rootならば

 slapcat

パスワードの作り方

 # slappasswd -h '{CRYPT}' -c %s
 New password:
 Re-enter new password:
 {CRYPT}VyrUNOYqqmf5A

追加

foo.ldif

 dn: uid=foo,ou=People,dc=bike,dc=oa,dc=net
 uid: foo
 objectclass: posixAccount
 objectclass: shadowAccount
 objectclass: posixGroup
 uidNumber: 1100
 gidNumber: 1100
 gecos: foo,,,
 homeDirectory: /home/foo
 loginShell: /bin/bash
 cn: foo bar
 userPassword: {CRYPT}rKd94.TaoAN0Y
 shadowLastChange: 10953
 shadowMin: 0
 shadowMax: 9999
 shadowWarning: 7
 ldapadd -x -D 'cn=admin,dc=bike,dc=oa,dc=net' -W -f foo.ldif
 ldapsearch -h localhost -x -b 'dc=bike,dc=oa,dc=net' uid=foo

利用者権限で検索

 ldapsearch  -x -D 'uid=foo,ou=People,dc=bike,dc=oa,dc=net' -W -b 'dc=bike,dc=oa,dc=net'

利用者権限でパスワード変更

 ldappasswd  -x -D 'uid=foo,ou=People,dc=bike,dc=oa,dc=net' -W 'uid=foo,ou=People,dc=bike,dc=oa,dc=net' -S

削除

 ldapdelete   -x   -D 'cn=admin,dc=bike,dc=oa,dc=net'  "uid=root,ou=People,dc=bike,dc=oa,dc=net" -W

dnの一覧を取る

 slapcat | ruby -n -e 'puts $1 if /dn:(.*)$/.match($_)'
 slapcat | ruby -n -e 'print "#{$1} " if /dn:(.*)$/.match($_)'

パスワード・シャドウldap変換スクリプト

 #!/usr/bin/ruby
 shadow=Hash.new
 File.open('/etc/shadow'){|f|
   while a=f.gets
     b=a.split(':')
     shadow[b.shift]=b
   end
 }
 File.open('/etc/passwd'){|f|
   while a=f.gets
     uid,userpassword,uidnumber,gidnumber,gecos,homedirectory,loginshell=a.split(':')
     puts "dn: uid=#{uid},ou=People,dc=bike,dc=oa,dc=net,dc=jjj"
     puts "uid: #{uid}"
     puts "objectclass: posixAccount"
     puts "objectclass: shadowAccount"
     puts "objectclass: inetOrgPerson"
     puts "objectclass: posixGroup"
     puts "uidNumber: #{uidnumber}"
     puts "gidNumber: #{gidnumber}"
     if gecos != ""
       puts "gecos: #{gecos}"
     else
       puts "gecos: #{uid}"
     end
     puts "homeDirectory: #{homedirectory}"
     puts "loginShell: #{loginshell}"
     puts "userPassword: {CRYPT}#{shadow[uid][0]}"
     puts "shadowLastChange: #{shadow[uid][1]}"
     puts "shadowMin: #{shadow[uid][2]}"
     puts "shadowMax: #{shadow[uid][3]}"
     puts "shadowWarning: #{shadow[uid][4]}"
     puts "mail: #{uid}@bike.oa.net.jjj"
     puts "cn: #{uid}"
     puts "sn: #{uid}"
     puts
   end
 }

sn: cn:を適当に処理してしまった本来はgecosから生成すべき(無いときがあるから今回は無視)

アドレス帳の使い方

http://www.asi.co.jp/info/unix/ldap.html

パスワードの切り替え

debian3.0系列

以下は /etc/pam.d/common-* シリーズを書き換えればよい(おそらくredhat系列を意識して書き直したものであると考えられる)

/etc/pam_ldap.confの以下を確認
 host 127.0.0.1
 base dc=bike,dc=oa,dc=net
 pam_password crypt
/etc/pam.d/passwdに以下を追加
 password   sufficient pam_ldap.so
 password   required   pam_unix.so nullok obscure min=4 max=8 md5
/etc/nsswitch.confを以下のように変更
 passwd:         compat ldap
 group:          compat ldap
 shadow:         compat ldap
/etc/libnss-ldap.confに以下を追加
 base dc=bike,dc=oa,dc=net
 host 127.0.0.1
 rootbinddn cn=admin,dc=bike,dc=oa,dc=net

ここで、ログインを可能とするためにはuserPasswordフィールドを読めないといけませんが、現在はanonymousの設定になっているためであるからして /etc/ldap.secretにrootのパスワードを入れておく。また、パスワードがばれないために 600にする

 # touch /etc/ldap.secret
 # chmod 600 /etc/ldap.secret
 # echo ルートのパスワード > /etc/ldap.secret
確認方法
 id foo
/etc/pam.d/loginに以下を追加

このままではidだけ存在してホームディレクトリがない状態になるので

 session required pam_mkhomedir.so skel=/etc/skel/ umask=0022

これ動かない・・・たぶんパーミッションの問題だろう・・・

sshの時には /etc/pam.d/sshに記載すること。

apacheでのユーザdir

apache-userdirldap 1.5
パッチが必要だそうだ。(涙
http://horde.net/~jwm/software/mod_ldap_userdir/

 Installation Instructions: 
 gzip -dc mod_ldap_userdir-1.1.1.tar.gz | tar xf - 
 cd mod_ldap_userdir-1.1.1 
 ./configure --with-activate 
 make 
 make install 
 If your LDAP server runs OpenLDAP 1.x, you need to add the posixAccount schema definition. Add the contents of posixAccount-objectclass to your slapd.oc.conf and restart your LDAP server. OpenLDAP 2.x (and most other LDAP servers) ship with this schema predefined. 
 The &#39;user-ldif&#39; file contains a sample user ldif. Modify it to your liking and say ldapadd -D your-root-dn -w your-root-dn-password < ldif 
 You are *strongly* encouraged to read up on the LDAP config-file directives in the DIRECTIVES file, included with the distribution. At bare minimum, you&#39;ll need to have LDAPUserDir, LDAPUserDirDNInfo, and LDAPUserDirBaseDN configuration directives in your httpd.conf.
 
 A set of basic mod_ldap_userdir configuration directives would look like:
 
 LDAPUserDir public_html 
 LDAPUserDirDNInfo cn=your-dn,dc=example,dc=com dnpass 
 LDAPUserDirBaseDN ou=People,dc=example,dc=com 
 Of course, you will need to update these configuration directives with the proper values for your environment.
basic認証
 LoadModule auth_ldap_module /usr/lib/apache/1.3/auth_ldap.so
 <Directory />
    Options SymLinksIfOwnerMatch
    AllowOverride None
    AuthName        "Please Enter Your Password"
    AuthType        Basic
    AuthLDAPURL ldap://katana.bike.oa.net:389/ou=People,dc=bike,dc=oa,dc=net
    Require valid-user
 </Directory>

レプリカ

マスタslapd.confに

        replica host=slave.example.com:389
                binddn="cn=Replicator,dc=bike,dc=oa,dc=net"
                bindmethod=simple credentials=secret

を追加する