今回はsmbldap-toolsを使用してSambaの認証データをLDAPデータベースに格納してみます。
Asianux Server 3ではVer0.8.7のsmbldap-toolsがインストールされます。
# rpm -qa smbldap-tools
smbldap-tools-0.8.7-5AX
一方OpenLDAPはVer2.3.27が入っています。
# rpm -qa openldap
openldap-2.3.27-5.1AX
1. OpenLDAPの設定
1.1 OpenLDAPにSambaの認証データを格納する為にはsamba.schemaというLDAPスキーマが必要ですが
AsianuxではSambaとOpenLDAPをインストールすると最初から/etc/openldap/schema下に
samba.schemaが存在している状態になります。
もし/etc/openldap/schema下にsamba.schemaが存在していなければ
/usr/share/doc/samba-3.0.24/LDAPからコピーします。
1.2 /etc/openldap/slapd.confを以下のように編集します。
太字の部分が今回編集した部分になります。
・・・・・・・・・・・・・・・
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/samba.schema
・・・・・・・・・・・・・・・
access to attr=SambaLMPassword
by dn="cn=Manager,dc=my-domain,dc=com" write
by self write
by anonymous auth
by * none
access to attr=SambaNTPassword
by dn="cn=Manager,dc=my-domain,dc=com" write
by self write
by anonymous auth
by * none
access to attrs=userPassword
by dn="cn=Manager,dc=my-domain,dc=com" write
by self write
by anonymous auth
by * none
access to *
by dn="cn=Manager,dc=my-domain,dc=com" write
by * read
#######################################################################
# ldbm and/or bdb database definitions
#######################################################################
database bdb
suffix "dc=my-domain,dc=com"
rootdn "cn=Manager,dc=my-domain,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoided. See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
# rootpw secret
rootpw {MD5}n6taxNCx8LYeaASLXx1hVQ==
・・・・・・・・・・・・・・・
今回は以下の様な環境にしています。
・samba.schemaをインクルードしてSambaの認証データを格納できるようにする
・トップエントリ(suffix)はdc=my-domain,dc=com
・管理者DNはcn=Manager,dc=my-domain,dc=com
・管理者パスワードは2007@Autumn(MD5で暗号化)
※ slappasswdコマンドでMD5で暗号化されたパスワードを生成できます。
# slappasswd -h {MD5} -s 2007@Auturmn
・SambaユーザーおよびUnixユーザーの登録は管理者DNのみが可能
各ユーザーは自分自身の情報の変更は可能
1.3 slapdを起動します。
Asianuxでは起動スクリプトldapで起動できます。
# /sbin/service ldap start
あといつものようにランレベル3および5の時に自動起動するようにしておきます
# chkconfig --level 35 ldap on
2. LDAPで認証が行われるように設定
/etc/nsswitch.confを以下の様に編集します。
passwd: files ldap
shadow: files ldap
group: files ldap
/etc/ldap.confを以下の様に編集します。
# network or connect timeouts (see bind_timelimit).
host 127.0.0.1
# The distinguished name of the search base.
base dc=my-domain,dc=com
3. Samba、smbldap-toolsの設定
3.1 /etc/samba/smb.confを以下の様に編集し、LDAPに認証情報を保存するようにします
・・・・・・
ldap passwd sync = Yes
ldap delete dn = Yes
passdb backend = ldapsam:ldap://127.0.0.1
ldap admin dn = cn=Manager,dc=my-domain,dc=com
ldap suffix = dc=my-domain,dc=com
ldap user suffix = ou=Users
ldap group suffix = ou=Groups
ldap machine suffix = ou=Computers
・・・・・・
3.2 /etc/samba/smbldap.confのsuffixをLDAPの環境にあわせて変更します。
# Ex: slaveLDAP=127.0.0.1
slaveLDAP="127.0.0.1"
slavePort="389"
# Master LDAP : needed for write operations
# Ex: masterLDAP=127.0.0.1
masterLDAP="127.0.0.1"
masterPort="389"
・・・・・・・
# LDAP Suffix
# Ex: suffix=dc=IDEALX,dc=ORG
suffix="dc=my-domain,dc=com"
# Where are stored Users
# Ex: usersdn="ou=Users,dc=IDEALX,dc=ORG"
usersdn="ou=Users,${suffix}"
# Where are stored Computers
# Ex: computersdn="ou=Computers,dc=IDEALX,dc=ORG"
computersdn="ou=Computers,${suffix}"
# Where are stored Groups
# Ex groupsdn="ou=Groups,dc=IDEALX,dc=ORG"
groupsdn="ou=Groups,${suffix}"
# Where are stored HostsGroups entries (used to manage the user whom each host can login)
# Ex hostsdn="ou=HostsGroups,dc=IDEALX,dc=ORG"
hostsdn="ou=HostsGroups,${suffix}"
# Where are stored Idmap entries (used if samba is a domain member server)
# Ex idmapdn="ou=Idmap,dc=IDEALX,dc=ORG"
idmapdn="ou=Idmap,${suffix}"
# Where to store next uidNumber and gidNumber available
sambaUnixIdPooldn="sambaDomainName=OSTD98017,${suffix}"
・・・・・・
3.3 /etc/samba/smbldap_bind.confをLDAPの環境にあわせて変更します。
slavePw="2007@Autumn "
masterDN="cn=Manager,dc=my-domain,dc=com"
masterPw="2007@Autumn "
3.4 smbd、nmbdを再起動します
# /sbin/serivce smb restart
4. LDAPデータベースの初期データを作成
4.1 smbpasswdで管理DNのパスワードを登録します
# smbpasswd -w 2007@Autumn
Setting stored password for "cn=Manager,dc=my-domain,dc=com" in secrets tdb
4.2 smbldap-populateを実行しLDAPデータベースに初期データを作成します。
# smbldap-populate -a Administrator -b Guest
Using workgroup name from sambaUnixIdPooldn (smbldap.conf): sambaDomainName=SMB3
Using builtin directory structure
adding new entry: dc=my-domain,dc=com
adding new entry: ou=Users,dc=my-domain,dc=com
adding new entry: ou=Groups,dc=my-domain,dc=com
adding new entry: ou=Computers,dc=my-domain,dc=com
adding new entry: ou=HostsGroups,dc=my-domain,dc=com
adding new entry: ou=Idmap,dc=my-domain,dc=com
adding new entry: sambaDomainName=SMB3,dc=my-domain,dc=com
adding new entry: uid=Administrator,ou=Users,dc=my-domain,dc=com
adding new entry: uid=Guest,ou=Users,dc=my-domain,dc=com
adding new entry: cn=Domain Admins,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Domain Users,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Domain Guests,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Domain Computers,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Administrators,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Print Operators,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Backup Operators,ou=Groups,dc=my-domain,dc=com
adding new entry: cn=Replicators,ou=Groups,dc=my-domain,dc=com
-aはAdministratorのアカウント名、-bはGuestのアカウント名です。
(それぞれAdministrator、Guestがデフォルトなのでデフォルトのままでいい場合は
このオプションなしでもOKです)
5.smbldap-toolsによるユーザー・グループ操作
5.1 ユーザーの新規追加
smbldap-useraddで行います。
# smbldap-useradd -a -m -P smbldapuser1
Changing password for smbldapuser1
New password :
Retype new password :
-aはSambaユーザーの作成を指示するオプション(これがないとUnixユーザーのみ作成されます)、
-mはホームディレクトリを作成するオプション、
-Pはユーザー作成時にパスワードの設定も行うオプションです。
追加したユーザーの情報はsmbldap-usershowで確認できます。
# smbldap-usershow smbldapuser1
dn: uid=smbldapuser1,ou=Users,dc=my-domain,dc=com
objectClass: top,inetOrgPerson,posixAccount,shadowAccount,sambaSamAccount
cn: smbldapuser1
sn: smbldapuser1
uid: smbldapuser1
uidNumber: 1001
gidNumber: 513
homeDirectory: /home/smbldapuser1
loginShell: /bin/bash
gecos: System User
description: System User
sambaSID: S-1-5-21-2139989288-483860436-2398042574-3002
displayName: System User
sambaPwdMustChange: 2147483647
sambaPasswordHistory: 0000000000000000000000000000000000000000000000000000000000000000
sambaAcctFlags: [U ]
sambaProfilePath: \\PDC-SMB3\profiles\smbldapuser1
sambaHomePath: \\PDC-SMB3\homes\smbldapuser1
sambaHomeDrive: U:
sambaPwdCanChange: 1195119027
sambaLMPassword: E9C8A1D02DEE94B093C2863AA5AEB653
sambaNTPassword: F8F2F2B4EF5492569DCC0087ACD9D77E
sambaPwdLastSet: 1195119027
userPassword: {SSHA}ehtumNjq+ns44LyP2WO80MRQTotBcWZr
またldapsearch
でも確認できます。
# extended LDIF
#
# LDAPv3
# base <dc=my-domain,dc=com> with scope subtree
# filter: (uid=smbldapuser1)
# requesting: ALL
#
# smbldapuser1, Users, my-domain.com
dn: uid=smbldapuser1,ou=Users,dc=my-domain,dc=com
objectClass: top
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
objectClass: sambaSamAccount
cn: smbldapuser1
sn: smbldapuser1
uid: smbldapuser1
uidNumber: 1001
gidNumber: 513
homeDirectory: /home/smbldapuser1
loginShell: /bin/bash
gecos: System User
description: System User
sambaSID: S-1-5-21-2139989288-483860436-2398042574-3002
displayName: System User
sambaPwdMustChange: 2147483647
sambaPasswordHistory: 0000000000000000000000000000000000000000000000000000000000000000
sambaAcctFlags: [U ]
sambaProfilePath: \\PDC-SMB3\profiles\smbldapuser1
sambaHomePath: \\PDC-SMB3\homes\smbldapuser1
sambaHomeDrive: U:
sambaPwdCanChange: 1195119027
sambaLMPassword: E9C8A1D02DEE94B093C2863AA5AEB653
sambaNTPassword: F8F2F2B4EF5492569DCC0087ACD9D77E
sambaPwdLastSet: 1195119027
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
WindowsのExplorerでこのユーザーを使用してSamba共有に対してネットワークドライブの割り当てを行い
このユーザーのSambaユーザーが作成されていることを確認します。
Asianux側で一度ログオフしてこのユーザーでログオンし直してこのユーザーのUnixユーザーが
作成されていることを確認します。
5.2 ユーザーのパスワードの変更
smbldap-passwdで変更します。
# smbldap-passwd smbldapuser1
Changing password for smbldapuser1
New password :
Retype new password
WindowsのExplorerでこのユーザーの新しいパスワードを使用してSamba共有に対してネットワークドライブ
の割り当てを行いこのユーザーのSambaユーザーとしてのパスワードが変更されていることを確認します。
Asianux側で一度ログオフしてログオンし直してこのユーザーのUnixユーザーとしてのパスワードが
変更されていることを確認します。
5.3 ユーザーの属性変更
smbldap-usermodで属性変更が可能です。(パスワードの変更も可能)
パスワードを変更する場合
# smbldap-usermod -P smbldapuser1
Changing password for smbldapuser1
New password :
Retype new password
ログインシェルを変更する場合
smbldap-usermodのオプション一覧
-d home directory
-r new username (cn, sn and dn are updated)
-u uid
-o uid can be non unique
-g gid
-G supplementary groups (comma separated)
-s shell
-N canonical name
-S surname
-P ends by invoking smbldap-passwd
For samba users:
-a add sambaSAMAccount objectclass
-e expire date ("YYYY-MM-DD HH:MM:SS")
-A can change password ? 0 if no, 1 if yes
-B must change password ? 0 if no, 1 if yes
-C sambaHomePath (SMB home share, like '\\PDC-SRV\homes')
-D sambaHomeDrive (letter associated with home share, like 'H:')
-E sambaLogonScript (DOS script to execute on login)
-F sambaProfilePath (profile directory, like '\\PDC-SRV\profiles\foo')
-H sambaAcctFlags (samba account control bits like '[NDHTUMWSLKI]')
-I disable an user. Can't be used with -H or -J
-J enable an user. Can't be used with -H or -I
-M mailAddresses (comma seperated)
-T mailToAddress (forward address) (comma seperated)
-L disable an OS user. Can't be used with -U
-U enable an OS user. Can't be used with -L
-?|-h show this help message
5.3 グループの追加・変更・参照・削除
追加はsmbdap-groupadd、変更はsmbldap-groupmod、参照はsmbldap-groupshow、
削除はsmbldap-groupdelで行います。
# smbldap-groupadd smbldapgroup1
# smbldap-groupmod -m smbldapuser1 smbldapgroup1
adding user smbldapuser1 to group smbldapgroup1
# smbldap-groupshow smbldapgroup1
dn: cn=smbldapgroup1,ou=Groups,dc=my-domain,dc=com
objectClass: posixGroup
cn: smbldapgroup1
gidNumber: 1000
memberUid: smbldapuser1
# smbldap-groupdel smbldapgroup1
5.4 ユーザーの削除
smbldap-userdelで削除します。
# smbldap-userdel smbldapuser1
# smbldap-usershow smbldapuser1
/usr/sbin/smbldap-usershow: user smbldapuser1 doesn't exist
ちなみにこのsmbldap-toolsはAsianux Server 3の売り物の一つになっているようです。
(なぜかRed Hat Enterprise Linux 5にはsmbldap-toolsが入ってない
ようなので・・・
なおsmbldap-toolsがなくてもSambaの認証データをLDAPに格納すること自体は可能です)
[参考文献]
[ThinkIT]Samba移行術:第3回:NT4.0→Samba3.0への移行(2)
[ThinkIT]Samba移行術:第4回:Sambaのユーザー管理