LDAP+SambaでPDCを構築する方法です。

# apt-get install samba-doc smbldap-tools

設定は基本的には/usr/share/doc/smbldap-tools/README.Debian.gzに書かれています。

LDAPのSamba用スキーマをインストールします。

# zcat /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz > /etc/ldap/schema/samba.schema

samba.schemaを/etc/ldap/slapd.confに追記します。

include       /etc/ldap/schema/samba.schema

性能向上のために、ldapのDBにインデックスをはります。同様にslapd.confに追記。

 index         uid,uidNumber,gidNumber,memberUid       eq index         cn,mail,surname,givenname               eq,subinitial

index sambaSID eq index sambaPrimaryGroupSID eq index sambaDomainName eq

パスワードへのアクセスを変更

 access to attribute=userPassword

 access to attrs=userPassword,sambaNTPassword,sambaLMPassword

に変更

で、LDAPサーバを再起動します。

# /etc/init.d/slapd restart

Sambaの設定です。 /etc/samba/smb.confのすでにある設定項目を変更

...

 passdb backend = ldapsam:ldap://127.0.0.1/

obey pam restrictions = no passwd program = /usr/sbin/smbldap-passwd %u passwd chat = Newpassword %n\n Retypenewpassword* %n\n

さらに以下をGlobalの最後に追記

 os level = 64preferred master = Yes

domain master = Yes

ldap suffix = dc=hoge,dc=net

ldap machine suffix = ou=Computers

ldap user suffix = ou=Users

ldap group suffix = ou=Groups

ldap admin dn = cn=admin,dc=hoge,dc=net

ldap passwd sync = Yes

ldap ssl = No

*all*authentication*tokens*updated*

add user script = /usr/sbin/smbldap-useradd -m "%u"

ldap delete dn = Yes

delete user script = /usr/sbin/smbldap-userdel "%u"

add machine script = /usr/sbin/smbldap-useradd -w "%u"

add group script = /usr/sbin/smbldap-groupadd -p "%g"

delete group script = /usr/sbin/smbldap-groupdel "%g"

add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"

delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"

set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"

#======================= Share Definitions =======================

次にsmbldap-toolsの設定。これはsambaのユーザ管理などのツールで、パスワードをUnixユーザと同期させたりできます。 まずは設定

# zcat /usr/share/doc/smbldap-tools/examples/smbldap.conf.gz > /etc/smbldap-tools/smbldap.conf
# cp /usr/share/doc/smbldap-tools/examples/smbldap_bind.conf /etc/smbldap-tools/smbldap_bind.conf

/etc/smbldap-tools/にできたファイルを適宜変更します。 smbldap.confのSIDは

# net getlocalsid

コマンドで取得できます。(Sambaを起動しておく必要あり?) あと、ldapTLSは、今回はTLSを使用しないので"0"にします。 smbldap_bind.confにはadminのdnとパスワードを記述します。 最後に初期データ投入

# smbldap-populate -u 2000 -g 2000

-u -g でUID,GIDのスタート値を設定できます。 ユーザの追加は

# smbldap-useradd -a -N "hoge name" -u 2001 hogehoge

といった感じ

暗号化パスワードの生成

LDAPブラウザなどで直接ユーザのパスワードを変更したい場合、暗号化したパスワードが必要になるときがあります。

暗号化パスワードを生成したい場合は以下のようにして生成できます。

# slappasswd -h {CRYPT}

{CRYPT}は{md5}や{SMD5}などを指定。