搜档网
当前位置:搜档网 › samba+ldap

samba+ldap

samba+ldap
samba+ldap

LDAP 简介

LDAP 是一种流行的身份验证机制,并能作为存储个人可识别信息的存储库。和传统的基于平面文件的身份验证机制(例如/etc/passwd)相比,他有几个好处。好处之一是LDAP 能用来实现密码管理的最佳形式?? 单点登录。能够实现单点登录是因为软件应用程式能通过TCP/IP 网络针对通用的基于LDAP 的用户存储库进行远程身份验证。LDAP 身份验证方法和基于平面文件的身份验证方案正好相反,后者通常只使用一台计算机,并不是分布式的。

LDAP 将数据组织为目录信息树(directory information tree)。这个树按照分类对数据进行组织。许多LDAP 服务器使用SQL 数据库存储数据,因为这是一种自然的选择。和传统的SQL 数据库相同,LDAP 使用模式来定义数据应该放在哪里及数据应该怎么格式化。使用模式及和传统SQL 数据库的相似性是LDAP 的关键好处,因为他们大大提高了可扩展性。

集成 Samba 和 LDAP

在Samba 和LDAP 服务器之间有三个主要的集成点:

? 第一个集成点是将Samba 的模式包含到LDAP 服务器中。

? 第二个集成点是将Samba 设置为通过LDAP 服务器进行身份验证。

身份验证要利用Linux 的PAM 实用程式(Pluggable Authentication Modules)。PAM 实用程式将身份验证过程从Linux 上运行的软件应用程式抽象出来,这样应用程式就不必理解特定身份验证机制的复杂细节。因此,PAM 为软件应用程式提供了非常大的灵活性,软件应用程式只需调用身份验证API,而PAM 会决定是应该使用平面文件、LDAP 还是其他身份验证机制。

? 第三个集成点涉及一组工具,他们帮助管理Samba 的LDAP 目录信息树。这个工具箱是由第三方研发的;不过他采用GNU Public License。

安全

LDAP 的关键好处是他能够作为分布在网络上的软件应用程式的身份验证机制。这个好处的一个副作用是,在身份验证期间密码可能会通过网络传输,因此可能被截获。幸运的是,LDAP 支持SSL(Secure Sockets Layer)和TLS。

在本教程中,LDAP 服务器运行在和Samba 相同的物理服务器上;因此不必进行加密。不过,我将演示怎么对LDAP 和Samba 之间的通道进行加密,因为这相当简单,而且对于Samba 和LDAP 在不同计算机上的情况,这种措施是必要的。

本教程分为两个阶段。第一个阶段周详描述怎么在非安全模式中设置Samba 和LDAP。第一个阶段完成之后,对Samba 和LDAP 服务器之间的通道启用加密。采用两阶段方式是因为在非安全模式中往往更容易进行安装、设置和诊断问题。

设置LDAP

步骤 1:安装 OpenLDAP

要安装OpenLDAP:

1. 检查发行版是否已安装了OpenLDAP。在一个终端中发出以下命令:rpm -qa | grep ldap。如果没有得到响应openldap-

2.2.13(或更高的版本号),那么应该升级或安装OpenLDAP(在下面说明)。

2. 如果还没有OpenLDAP 2.2.13 或更高版本,那么到发行版的映像站点并下载一个二进制包。我进入

Fedora 的映像列表

并下载了openldap-2.2.13-2.i386.rpm。然后发出以下命令:rpm -Uvh openldap-2.2.13-2.i386.rpm。

步骤 2:安装 IDEALX 的 LDAP Toolkit for Samba

需要使用来自IDEALX 的一个工具箱使Samba 和LDAP 服务器之间的许多重要交互自动化。这个工具箱包含一些脚本,Samba 会自动调用他们来添加用户、修改用户、添加机器,等等。这些脚本是用Perl 编写的,也能从命令行使用。

要安装IDEALX 工具箱:

1. 进入

IDEALX 的主页

并下载这个工具箱的 .0.9.1 版或更高版本(smbldap-tools-.0.9.1.tgz)。

2. 在一个临时目录中,用以下命令解开这个工具箱:tar -zxf smbldap-tools-0.9.1.tgz。

3. 创建一个目录用于放置IDEALX 脚本。在命令提示下输入:mkdir -p /var/lib/samba/sbin。然后输入:chmod -R 755 /var/lib/samba。

4. 进入tar 命令创建的目录。输入:cd smbldap-tools-0.9.1。

5. 用以下命令将所需的脚本从临时目录复制到永久目录:cp smbldap* configure.pl /var/lib/samba/sbin。

6. 进入/var/lib/samba/sbin 目录并依次发出以下命令,设置正确的所属权和权限:

1. chmod 750 *

2. chmod 640 smbldap_bind.conf smbldap.conf smbldap_tools.pm

7. 目前能安全地删除临时目录。

IDEALX 工具箱需要一些额外的Perl 模块,系统上可能还没有安装这些模块。本节说明怎么下载和安装他们。

1. 首先,需要从https://www.sodocs.net/doc/6616179636.html, 下载所有必需的Perl 模块。进入

https://www.sodocs.net/doc/6616179636.html,

并在搜索框中输入以下搜索字符串。

o 搜索Perl 模块:Crypt::SmbHash

o 搜索Perl 模块:Digest::SHA1

o 搜索Perl 模块:IO::Socket::SSL

o 搜索Perl 模块:Net::SSLeay

能从每个搜索的结果直接导航到每个模块的主页。在这四个模块的主页上,能找到下载Perl 模块的链接。

2. 下一步是对下载的Perl 模块进行解压。在保存下载的四个模块的目录中,发出以下命令:tar -zxvf *.gz。

3. 最后一步是构建和安装这四个模块。进入每个新创建的目录并作为root 发出以下命令。

1. perl Makefile.PL

2. make install

步骤 3:设置 OpenLDAP 所需的模式、目录和密钥

如果从RPM 进行安装而且Linux 发行版是Fedora,那么应该有一个称为/etc/openldap 的目录。在这个目录中有OpenLDAP 的主设置文件slapd.conf。在开始编辑这个文件之前,先执行一些预先设置操作。OpenLDAP 需要感知Samba 的LDAP 模式。为此,将Samba 的模式复制到/etc/openldap/schema 中。

1. 寻找Samba 的模式。他应该在安装Samba 的目录中。为了寻找他,输入:locate samba.schema。

2. 将他复制到/etc/openldap/schema 中。

3. 设置正确的权限。输入:chmod 644 /etc/openldap/schema/samba.schema。为LDAP 数据库创建目录。在本教程中,将这个目录命名为和域名相同。

1. 输入:mkdir -p /var/lib/ldap/https://www.sodocs.net/doc/6616179636.html,。

2. 设置正确的权限:chmod 700 /var/lib/ldap/https://www.sodocs.net/doc/6616179636.html,。

3. 设置正确的所属权。Fedora 应该已在/etc/passwd 中定义了用户LDAP。如果在其他发行版上进行安装,那么可能需要创建这个用户。输入:chown ldap:ldap /var/lib/ldap/https://www.sodocs.net/doc/6616179636.html,。

最后,创建OpenLDAP 用于TLS 的加密密钥。为此,需要OpenSSL。大多数Linux 发行版附带有OpenSSL;不过,如果还没有安装他,那么从发行版的厂商或

https://www.sodocs.net/doc/6616179636.html,/

获得一个副本。

本教程假设用户将不使用商业的证书机构(CA),比如Verisign、Thawte 等。因此,需要成为自己的CA 并签署LDAP 服务器使用的证书。下面的步骤演示怎么成为CA 并签署证书。

1. 如果还没有这么做,那么编辑https://www.sodocs.net/doc/6616179636.html,f 以满足自己的特定需要。要寻找https://www.sodocs.net/doc/6616179636.html,f 文件,输入:locate https://www.sodocs.net/doc/6616179636.html,f。

2. 在https://www.sodocs.net/doc/6616179636.html,f 所在的目录中,作为root 发出以下命令。

清单 1. 成为 CA 的步骤

mkdir -p CA/certs CA/crl CA/newcerts CA/privatechmod 700 CA/privatetouch CA/index.txtecho 01 > CA/serial

3. 在编辑器中打开https://www.sodocs.net/doc/6616179636.html,f 并根据自己的情况修改以下参数。

清单 2. 成为 CA 的步骤

# The dir parameter is important because it tells# openssl where to find all necessary files used to# generate keys.dir = ./# default_days defines the length of time your key is valid for.default_days = 3650# default_bits is an indicator of the strength of your key. I elected# 1024 but you can choose more or less.default_bits = 1024# The following parameters should be modified to fit your# organization.countryName_default = USstateOrProvinceName_default = North CarolinalocalityName_default = https://www.sodocs.net/doc/6616179636.html,anizationName_default = https://www.sodocs.net/doc/6616179636.html,

用以下命令创建CA 证书和密钥对:openssl req -nodes -config https://www.sodocs.net/doc/6616179636.html,f -new -x509 -keyout CA/private/cakey.pem -out CA/cacert.pem -days 3650。

5. 用以下命令为OpenLDAP 创建密钥对:

1. openssl req -config https://www.sodocs.net/doc/6616179636.html,f -nodes -new -keyout /etc/openldap/slapd-key.pem -out slapd.csr

2. openssl ca -config https://www.sodocs.net/doc/6616179636.html,f -out /etc/openldap/slapd-cert.pem -in slapd.csr

3. chown root:ldap /etc/openldap/slapd-key.pem

4. chmod 640 /etc/openldap/slapd-key.pem

5. chmod 644 /etc/openldap/slapd-cert.pem

6. 将CA 的证书复制到openldap 设置目录,这样各个应用程式就能够访问他了。

1. cp CA/cacert.pem /etc/openldap/

2. chmod 644 /etc/openldap/cacert.pem

步骤 4:设置 slapd.conf

OpenLDAP 提供的对应于实际LDAP 服务器的可执行文件称为slapd。slapd 守护进程从slapd.conf 读取他的所有设置信息。在本节中,我提供一个加了注释的slapd.conf 示例。对于所有带“# MODIFY” 注释的部分,必须根据自己的情况进行修改。

在开始进行编辑之前,为rootdn 生成一个密码散列。要对LDAP 服务器的目录信息树进行修改,就必须使用这个密码。

注意:应该选择一个不同于Linux 服务器root 密码的密码。

1. 从命令行输入:slappasswd -h {SSHA} -s 。

2. 保存这个命令的输出,因为后面要使用他。他类似于:{SSHA}kCuJt72QLJ2O06nFUvdre97sHT0AxlH/。

如果在Fedora 上安装了OpenLDAP 的二进制版,slapd.conf 应该以/etc/openldap/ 形式存在。根据自己的情况修改他。

/etc/openldap/slapd.conf 的内容如下:

清单 3. slapd.conf 的内容

# See slapd.conf(5) for details on configuration options.# This file should NOT be world readable.#include /etc/openldap/schema/core.schemainclude /etc/openldap/schema/cosine.sche mainclude /etc/openldap/schema/inetorgperson.schemainclude /etc/openldap/schema/nis.schema include /etc/openldap/schema/samba.schema# -1 is all messages 296 is a good compromise for most debugging#loglevel -1pidfile /var/run/slapd.pidargsfile /var/run/slapd.args# The following three lines are related to security. Leave them commented out now.# We uncomment them and enable security *after* we have successfully tested Samba with# LDAP in an unsecured configuration. Debugging is infinitely easier without encryption# enabled.#TLSCipherSuite HIGH#TLSCertificateFile /etc/openldap/slapd-cert.pem#TLSCertifi cateKeyFile /etc/openldap/slapd-key.pemdatabase bdb# MODIFY# Modify suffix and rootdn to match your domain name.suffix "dc=somedomain,dc=com"rootdn "cn=Manager,dc=somedomain,dc=com"# MODIFY# Use the following to generate:# slappasswd -h {SSHA} -s rootpw {SSHA}kCuJt72QLJ2O06nFUvdre97sHT0AxlH/# MODIFY# The database directory MUST exist prior to running slapd AND# should only be accessible by the slapd and slap tools.# Mode 700 recommended with an owner of ldap and a group of ldapdirectory /var/lib/ldap/https://www.sodocs.net/doc/6616179636.html,# Indices to maintain for this databaseindex objectClass eqindex cn pres,sub,eqindex sn pres,sub,eqindex uid pres,sub,eqindex displayName pres,sub,eqindex uidNumber eqindex gidNumber eqindex memberUID eqindex sambaSID eqindex sambaPrimaryGroupSID eqindex sambaDomainName eqindex default sub# Access Control Entries# Note these ACEs are duplicated from the IDEALX smbldap usermanual with one exception# users can authenticate and change their password access to attrs=userPassword,sambaNTPassword,sambaLMPassword,sambaPwdLastSet,sambaPwdMustChang e by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by self write by anonymous auth by * none# some attributes need to be readable anonymously so that ’id user’ can answer correctlyaccess to attrs=objectClass,entry,gecos,homeDirectory,uid,uidNumber,gidNumber,cn,memberUid by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by * read# somme attributes can be writable by users themselvesaccess to attrs=description,telephoneNumber by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by self write by * read# some attributes need to be writable for samba (this ACE modified from original to allowsome unix commands to work) access to attrs=cn,sambaLMPassword,sambaNTPassword,sambaPwdLastSet,sambaLogonTime,sambaLogoffTi

me,sambaKickoffTime,sambaPwdCanChange,sambaPwdMustChange,sambaAcctFlags,displayName,s ambaHomePath,sambaHomeDrive,sambaLogonScript,sambaProfilePath,description,sambaUserWorkst ations,sambaPrimaryGroupSID,sambaDomainName,sambaSID,sambaGroupType,sambaNextRid,samb aNextGroupRid,sambaNextUserRid,sambaAlgorithmicRidBase,sambaLogonScript,loginShell by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by self read by * none# samba need to be able to create the samba domain accountaccess to dn.base="dc=somedomain,dc=com" by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by * none# samba need to be able to create new users accountaccess to dn="ou=Users,dc=somedomain,dc=com" by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by * none# samba need to be able to create new groups accountaccess to dn="ou=Groups,dc=somedomain,dc=com" by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by * none# samba need to be able to create new computers accountaccess to dn="ou=Computers,dc=somedomain,dc=com" by dn="uid=samba,ou=Users,dc=somedomain,dc=com" write by * none# this can be omitted but we leave it: there could be other branch# in the directoryaccess to * by self read by * none

步骤 5:设置 /etc/ldap.conf

本地系统上的LDAP 客户机使用/etc/ldap.conf 文件。这些客户机包含PAM,Samba 通过这个接口利用LDAP 服务器进行身份验证。

有时候,系统上有多个ldap.conf 实例。应该找到PAM 要使用的那一个。为此,输入:strings /lib/libnss_ldap.so.2 | grep conf。返回的值常常是/etc/ldap.conf。

在编辑器中编辑ldap.conf 并插入以下文本。修改带有“# MODIFY”注释的部分。

/etc/ldap.conf 的内容如下:

清单 4. /etc/ldap.conf 的内容

## IMPORTANT## The /etc/ldap.conf file is used by PAM. There is another ldap.conf file in## /etc/openldap.## The file, /etc/openldap/ldap.conf, is used by ldap tools, such as ldapsearch.## If you intend to use those tools you will need to add a TLS_CACERT directive to that## file also.# Your LDAP server. Must be resolvable without using LDAP.# Multiple hosts may be specified, each separated by a# space.host 127.0.0.1# MODIFY# The distinguished name of the search base.base dc=somedomain,dc=com# MODIFY# The distinguished name to bind to the server with.# We will use the root dn until we can create a lesser privileged user.binddn cn=Manager,dc=somedomain,dc=combindpw # MODIFY# Note: "ou=Users" and "ou=Groups" should match what# you entered in smb.conf for "ldap group suffix"# and "ldap user suffix"nss_base_passwd ou=Users,dc=somedomain,dc=com?onenss_base_passwd ou=Co mputers,dc=somedomain,dc=com?onenss_base_shadow ou=Users,dc=somedomain,dc=com?on enss_base_group ou=Groups,dc=somedomain,dc=com?onessl nopam_password md5# We need to tell PAM where the certificate used to authenticate the LDAP# server (i.e. is the LDAP server the one we think it is).tls_cacertfile /etc/openldap/cacert.pem# If you experience difficulty authenticating after enabling TLS, try uncommenting# the next line. You will know that you are having problems if you# issue "getent group" and do not see any of the MS 视窗系统groups# that have been created in your LDAP database.# tls_checkpeer no

步骤 6:设置 PAM

设置PAM 需要点儿技巧。因此,我使用Linux 厂商提供的实用程式替我做所有这些麻烦的工作。Fedora 提供一个命令行实用程式authconfig,他知道怎么修改所有PAM 设置文件。其他Linux 发行版有类似的设置实用程式,所以如果不使用Fedora,就请参考文件。

1. 从命令行启动authconfig。输入:authconfig。

2. 按照下图编辑第一个屏幕。

图 2. authconfig 屏幕 1

3. 按照下图编辑第二个屏幕。

图 3. authconfig 屏幕 2

步骤 7:启动 OpenLDAP

目前启动LDAP 服务器。从二进制RPM 进行安装的Fedora 用户应该能够执行以下命令:/etc/init.d/ldap start。

设置Samba

目前将注意力转到Samba 上?? 安装、创建目录和设置。

步骤 1:安装 Samba

要安装Samba:

1. 检查发行版是否已安装了Samba。在一个终端中发出以下命令:rpm -qa | grep samba。如果没有得到响应samba-3.0.14(或更高的版本号),那么应该升级或安装Samba(在下面说明)。

2. 如果还没有Samba

3.0.14 或更高版本,那么到

Samba 的主页

并下载适合自己的Linux 发行版的二进制包。Samba 套件分为四个独立的RPM,他们都非常有用,建议全部安装。不过,如果想节省空间,那么应该只安装samba 和samba-common 包。下载需要的samba RPM 并用以下命令安装他们:rpm -Uvh samba*。

步骤 2:创建所需的目录

需要创建一些目录,Samba 使用他们存储运行时数据。

1. mkdir -p /var/lib/samba/netlogon/scripts/ /var/lib/samba/printing/

2. chmod -R 755 /var/lib/samba/netlogon /var/lib/samba/printing

步骤 3:设置 smb.conf

如果在Fedora 上安装了Samba 的二进制版,应该有一个称为/etc/samba 的设置目录。这个目录包含Samba 的两个守护进程(smbd 和nmbd)所使用的各个文件。Samba 的主设置文件smb.conf 在这个目录中。我们根据自己的Microsoft 视窗系统网络修改这个文件,并添加设置让Samba 知道LDAP 后端。下面给出了带注释的这个文件。

根据自己的情况修改所有带“# MODIFY” 注释的部分。另外,Samba 手册中描述了这个设置文件中的所有指令。能通过输入man smb.conf 来查看Samba 手册。

/etc/samba/smb.conf 的内容如下:

清单 5. /etc/samba/smb.conf 的内容

# Global parameters[# Global parameters[global] # MODIFY workgroup = BIGTIME # MODIFY netbios name = linus # MODIFY server string = Linus Samba Server passdb backend = ldapsam:ldap://127.0.0.1/ # By default run with minimal logging. However, if you need to debug # 5 is a fairly verbose logging level. #log level = 5 log file = /var/log/samba/log.%m max log size = 50 time server = Yes add user script = /var/lib/samba/sbin/smbldap-useradd -a ’%u’ delete user script = /var/lib/samba/sbin/smbldap-userdel ’%u’ add group script = /var/lib/samba/sbin/smbldap-groupadd -p ’%g’ delete group script = /var/lib/samba/sbin/smbldap-groupdel ’%g’ add user to group script = /var/lib/samba/sbin/smbldap-groupmod -m ’%u’’%g’ delete user from group script =

/var/lib/samba/sbin/smbldap-groupmod -x ’%u’ ’%g’ set primary group script = /var/lib/samba/sbin/smbldap-usermod -g ’%g’ ’%u’ add machine script = /var/lib/samba/sbin/smbldap-useradd -w ’%u’ # Personally, I do not like roaming profiles because they take up too # much space on my server. As such, I disable roaming profiles by # setting the following two variables to null logon path = logon home = logon drive = H: domain logons = Yes preferred master = Yes domain master = Yes wins support = Yes # MODIFY ldap admin dn = cn=Manager,dc=somedomain,dc=com ldap group suffix = ou=Groups ldap idmap suffix = ou=Idmap ldap machine suffix = ou=Computers ldap passwd sync = Yes # MODIFY ldap suffix = dc=somedomain,dc=com ldap user suffix = ou=Users idmap backend = ldap:ldap://127.0.0.1 idmap uid = 10000-20000 idmap gid = 10000-20000 # The next three blocks define the shared drives that we will be exposing. They are all# nearly identical. The important thing to note is that all files on these drives are# readable and writeable by any user in that group.[netlogon] path = /var/lib/samba/netlogon/scripts browseable = No root preexec = /var/lib/samba/netlogon/scripts/logon.pl %U %I # MODIFY[marketing] comment = Marketing material path = /home/marketing # Any files written to this drive will have this user group. Since this is a # *shared* drive all users should have permission to read/write/remove any file. # If you do not agree you will probably want to remove the "force group" line force group = marketing read only = No create mask = 0770 directory mask = 0770 browseable = No # MODIFY[engineering] comment = Common material path = /home/engineering path = /home/marketing # Any files written to this drive will have this user group. Since this is a # *shared* drive all users should have permission to read/write/remove any file. # If you do not agree you will probably want to remove the "force group" line force group = engineering read only = No create mask = 0770 directory mask = 0770 browseable = No # MODIFY[management] comment = Management Data path = /home/management path = /home/marketing # Any files written to this drive will have this user group. Since this is a # *shared* drive all users should have permission to read/write/remove any file. # If you do not agree you will probably want to remove the "force group" line force group = management read only = No create mask = 0770 directory mask = 0770

步骤 4:设置用于访问 LDAP 数据库的 Samba 密码

Samba 需要知道rootdn 的密码,这样才能读写LDAP 服务器中的模式。执行以下命令向Samba 提供这个密码。应该使用和

步骤 4:设置 slapd.conf

中相同的密码:smbpasswd -w 。

Samba 应该做出以下响应:Setting stored password for "cn=Manager,dc=somedomain,dc=com" in secrets.tdb。

步骤 5:安装 Logon Profile Generator

我们的Samba 服务器设置为Microsoft 视窗系统域控制器,因此他能控制视窗系统客户机在登录到这个域时能够执行什么操作。这些操作包括获得存储的移动设置文件、挂装驱动器及和时间服务器进行同步,等等。

我们的Samba 服务器没有存储移动设置文件,因为他们会占用一定的空间;不过,我们迫使每个登录到域中的Microsoft 视窗系统客户机挂装驱动器并和时间服务器进行同步。

在这一步中,创建一个生成视窗系统批处理文件的Perl 脚本,这个批处理文件在用户每次登录到

BIGTIME 域时执行。这个批处理文件导致用户的视窗系统机器自动挂装他们的安全设置文件授权让他们访问的驱动器。对于具有许多共享驱动器和复杂的安全策略的大型组织,这种操作非常有用。这个批处理文件的位置和执行由smb.conf 的netlogon 部分中的两个参数进行定义,他们是path 和root preexec。Perl 脚本如下所示。执行以下操作来安装这个Perl 登录脚本:

1. cd /var/lib/samba/netlogon/scripts

2. 创建一个称为logon.pl 的文件并在其中添加以下内容。

3. chmod 755 /var/lib/samba/netlogon/logon.pl

下面是Perl 登录脚本。

/var/lib/samba/netlogon/logon.pl 的内容如下所示:

清单 6. Perl 登录脚本的内容

#!/usr/bin/perluse strict;# Set the permissions on any file we create to 640 (i.e. -rw-r--r--)umask(022); my $NETLOGON_DIR = "/var/lib/samba/netlogon/scripts";my $LOG_DIR = "/var/log/samba";my $SERVERNAME = "linus";## You will need to modify this hash to match your mountpoints.my %MOUNTPOINTS = ( "engineering" => "NET USE W: \\$SERVERNAME\engineering /YESrn", "marketing" => "NET USE W: \\$SERVERNAME\marketing /YESrn", "management" => "NET USE W: \\$SERVERNAME\management /YESrn" ); ## Make sure that there is a user name and that it contains a valid## user name string (i.e. no invalid chars).if ($#ARGV != 1 || $ARGV[0] =~ /[^a-zA-Z0-9-_]/) { exit(1);} # Make sure that the user exists and log attempts with invalid IDsmy $uid = getpwnam($ARGV[0]);if ($uid == /[^0-9]/){ my $now = localtime; open LOG, ">>$LOG_DIR/https://www.sodocs.net/doc/6616179636.html,logon"; print LOG "$now"; print LOG " - Error: Unknown user $ARGV[0] logged into $SERVERNAME from $ARGV[1]n"; close LOG; exit(1);}# Log the logon attemptmy $now = localtime;open LOG, ">>$LOG_DIR/https://www.sodocs.net/doc/6616179636.html,logon";print LOG "$now";print LOG " - User $ARGV[0] logged into $SERVERNAME from $ARGV[1]n";close LOG; ## Create a custom logon batch file.open FH, ">$NETLOGON_DIR/$ARGV[0].cmd"; # Turn echo offprint FH "@ECHO OFFrn"; # Synchronize time between 视窗系统client and Linux server.print FH "NET TIME \\$SERVERNAME /SET /YESrn"; foreach my $key (keys(%MOUNTPOINTS)) { if (isMember($ARGV[0], $key)) { # Put mount points in file print FH "$MOUNTPOINTS{$key}"; }}close FH; # Checks to see if the given user is a member of# the given group.# Returns 1 if true and 0 otherwise.sub isMember{ my ($user, $group) = @_; my ($name, $passwd, $gid, $members) = getgrnam($group); my @members = split /s+/, $members; for(@members){ if ($user eq $_) { return 1; } } return 0;}

步骤 6:启动 Samba

目前启动Samba 服务器。从二进制RPM 进行安装的Fedora 用户应该能够执行以下命令:/etc/init.d/samba start。

步骤 7:填充 LDAP 数据库

目前,用Samba 模式和一些初始值来填充LDAP 数据库。对于这个任务,能使用IDEALX 脚本来完成。首先执行设置脚本/var/lib/samba/sbin/configure.pl。这个设置脚本创建两个文件smbldap_bind.conf 和smbldap.conf,这两个文件包含IDEALX 工具箱中所有脚本使用的重要环境变量。

1. 首先输入:cd /var/lib/samba/sbin/。

2. 编辑smbldap_tools.pm 并对变量smbldap_conf 和smbldap_bind_conf 做以下修改。

o my $smbldap_conf="/var/lib/samba/sbin/smbldap.conf";

o my

$smbldap_bind_conf="/var/lib/samba/sbin/smbldap_bind.conf";

3. 接下来,输入以下命令启动设置实用程式:./configure.pl。

4. 目前,程式会提出一系列问题,我提供了一个示例清单。一般来说,应该只需按回车键;不过,有几个重要的事项你应该知道。

o 密码散列是大小写敏感的,应该和ldap.conf 的pam_password 变量中指定的散列算法匹配(见

步骤 5:设置 /etc/ldap.conf

)。

o 在本教程中,没有LDAP 从服务器,所以使用和主服务器相同的信息。

o 这个脚本所需的绑定密码和

步骤 4:设置 slapd.conf

中的rootdn 密码相同。

configure.pl 脚本的输出如下所示:

清单 7. Perl 设置脚本的输出

[root@linus sbin]# ./configure.plIf you need to change this, enter the full directory path, then press enter to continue.Smbldap-tools Configuration Directory Path [/etc/opt/IDEALX/smbldap-tools/] > /var/lib/samba/sbin-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Let’s start configuring the smbldap-tools scripts ... . workgroup name: name of the domain Samba act as a PDC workgroup name [BIGTIME] >. netbios name: netbios name of the samba controler netbios name [linus] >. logon drive: local path to which the home directory will be connected (for NT Workstations). Ex: ’H:’ logon drive [H:] >. logon home: home directory location (for Win95/98 or NT Workstation). (use %U as username) Ex:’\linus%U’logon home (press the "." character if you don’t want homeDirectory) [\linus%U] > .. logon path: directo ry where roaming profiles are stored. Ex:’\linusprofiles%U’logon path (press the "." character if you don’t want roaming profile) [\linusprofiles%U] > .. home directory prefix (use %U as username) [/home/%U] >. default users’ homeDirectory mode [700] >. default user netlogon script (use %U as username) [%U.cmd] > "" default password validation time (time in days) [45] >. ldap suffix [dc=somedomain,dc=com] >. ldap group suffix [ou=Groups] >. ldap user suffix [ou=Users] >. ldap machine suffix [ou=Computers] >. Idmap suffix [ou=Idmap] >. sambaUnixIdPooldn: object where you want to store the next uidNumber and gidNumber available for new users and groups sambaUnixIdPooldn object (relative to ${suffix}) [sambaDomainName=BIGTIME] >. ldap master server: IP adress or DNS name of the master (writable) ldap server ldap master server [127.0.0.1] >. ldap master port [389] >. ldap master bind dn [cn=Manager,dc=somedomain,dc=com] >. ldap master bind password [] >. ldap slave server: IP adress or DNS name of the slave ldap server: can also be the master one ldap slave server [127.0.0.1] >. ldap slave port [389] >. ldap slave bind dn [cn=Manager,dc=somedomain,dc=com] >. ldap slave bind password [] >. ldap tls support (1/0) [0] > 1. How to verify the server’s certific ate (none, optional or require) [require] >. CA certificate file [/var/lib/samba/sbin//ca.pem] > /etc/openldap/cacerts/cacert.pem. certificate to use to connect to the ldap server [/var/lib/samba/sbin//smbldap-tools.pem] >. key certificate to use to connect to the ldap server [/var/lib/samba/sbin//smbldap-tools.key] >. SID for domain BIGTIME: SID of the domain (can be obtained with ’net getlocalsid linus’) SID for domain BIGTIME [S-1-5-21-1030832020-2822878261-2997333186] >. unix password encryption: encryption used for unix passwords unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA) [SSHA] > MD5. default user gidNumber [513] >. default computer gidNumber [515] >. default login shell [/bin/bash] >. default skeleton

directory [/etc/skel] >. default domain name to append to mail adress [] > https://www.sodocs.net/doc/6616179636.html,-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=backup old configuration

files: /var/lib/samba/sbin/smbldap.conf->/var/lib/samba/sbin/smbldap.conf.old /var/lib/samba/sbin/smbld ap_bind.conf->/var/lib/samba/sbin/smbldap_bind.conf.oldwriting new configuration file: /var/lib/samba/sbin/smbldap.conf done. /var/lib/samba/sbin/smbldap_bind.conf done.

5. 如果不希望让密码过期,能禁用这个特性。编辑smbldap.conf 并注释掉以下行:defaultMaxPasswordAge="45"。

6. 执行以下三个命令来设置正确的权限和所属权:

1. chown root:root smbldap.conf smbldap_bind.conf

2. chmod 644 smbldap.conf

3. chmod 600 smbldap_bind.conf

7. 目前,在LDAP 数据库中初始化Samba 模式。我们将执行IDEALX 脚本smbldap-populate,这个脚本将创建一个域管理员、一些必要的组和其他重要的模式元素。在执行这个脚本时,可能会看到一些警告,指出未初始化的变量。如果不希望看到这些警告,能编辑所有IDEALX 脚本,将所有“#!/usr/bin/perl -w” 替换为“#!/usr/bin/perl”。以下代码是smbldap-populate 的输出示例。(注意:smbldap-populate 可能提示你输入域管理员的密码,域管理员在默认情况下称为root。给这个用户设置的密码应该不同于

步骤 4:设置 slapd.conf

中使用的rootdn 密码,也不同于Linux 机器的root 用户密码。)

清单 8. 执行 IDEALX 脚本 smbldap-populate

[root@linus sbin]# ./smbldap-populatePopulating LDAP directory for domain BIGTIME (S-1-5-21-1030832020-2822878261-2997333186)(using builtin directory structure) LDAP config host: 127.0.0.1port: 389version: 3timeout: 60adding new entry: dc=somedomain,dc=comadding new entry: ou=Users,dc=somedomain,dc=comadding new entry: ou=Groups,dc=somedomain,dc=comadding new entry: ou=Computers,dc=somedomain,dc=comadding new entry: uid=root,ou=Users,dc=somedomain,dc=comadding new entry: uid=nobody,ou=Users,dc=somedomain,dc=comadding new entry: cn=Domain Admins,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Domain Users,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Domain Guests,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Domain Computers,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Administrators,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Account Operators,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Print Operators,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Backup Operators,ou=Groups,dc=somedomain,dc=comadding new entry: cn=Replicators,ou=Groups,dc=somedomain,dc=comadding new entry: cn=NextFreeUnixId,dc=somedomain,dc=com Please provide a password for the domain root:LDAP config host: 127.0.0.1port: 389version: 3timeout: 60Changing password for rootNew password :Retype new password :

步骤 8:创建共享驱动器

为了给三个用户组(工程、市场营销和管理)分别创建共享驱动器,我们使用smbldap-useradd 实用程

式。这个实用程式将在/home 中创建一个目录,作为共享驱动器。还创建一个相关联的UNIX 用户组,以后使用这个组向一般用户授予访问共享驱动器的权限。作为root 执行以下命令:

清单 9. 创建 UNIX 组用于向一般用户授予访问共享驱动器的权限

cd /var/lib/samba/sbin./smbldap-groupadd engineering./smbldap-groupadd marketing./smbldap-groupadd management./smbldap-useradd -s /sbin/nologin -m -g engineering engineering./smbldap-useradd -s /sbin/nologin -m -g marketing marketing./smbldap-useradd -s /sbin/nologin -m -g management management

注意:选项“-s /sbin/nologin” 是一种安全措施,用来防止有人用这三个ID 之一登录Linux 机器。

步骤 9a:添加 PAM 用户

出于安全原因,我们迫使PAM 用非root 的DN(比如cn=Manager,dc=somedomain,dc=com)连接到LDAP 服务器。看一下

步骤 5:设置 /etc/ldap.conf

中创建的ldap.conf 文件,会看到PAM 试图使用cn=Manager,dc=somedomain,dc=com 这个dn 连接到LDAP。在这一步中,将创建一个特权比较少的用户(uid=samba,ou=Users,dc=somedomain,dc=com)。发出以下命令创建用户samba:smbldap-useradd -s /bin/false -d /dev/null -P samba。在提示输入密码时,提供一个惟一的密码。完成之后,将ldap.conf 中的binddn 更新为uid=samba,ou=Users,dc=somedomain,dc=com,将bindpw 参数更新为刚才提供的密码。

步骤 9b:添加一些用户

下一步是添加一些用户并给他们各自分配一个安全设置文件。下面这个列表列出了用户和他们的组:

? Marketing 组:catbert

? Management 组:boss

? Engineering 组:dilbert, wally

接下来,在Linux 系统上创建用户。对于每个用户,这需要两个步骤:

1. 在系统上创建用户ID。

2. 设置Samba 密码。

在默认情况下,smbldap-useradd 脚本将试图为每个用户在Linux 系统上创建一个主目录,我们使用-a 选项禁止这种做法。作为root 发出以下命令:

清单 10. 使用 -a 选项创建用户

cd /var/lib/samba/sbin./smbldap-useradd -a -G "Domain Users",engineering dilbert./smbldap-passwd dilbert./smbldap-useradd -a -G "Domain Users",engineering wally./smbldap-passwd wally./smbldap-useradd -a -G "Domain Users",marketing catbert./smbldap-passwd catbert./smbldap-useradd -a -G "Domain Users",marketing,management,engineering boss./smbldap-passwd boss

步骤 10:将 Microsoft 视窗系统工作站添加到域

对于这个步骤,要访问你计划授予访问权的每台工作站。(以下步骤针对Microsoft 视窗系统XP Professional,不过也能应用于其他Microsoft 视窗系统版本。)

作为管理员登录每台视窗系统工作站并执行以下操作:

1. 进入Control Panel并选择System。

2. 选择Computer Name选项卡。

3. 点击按钮rename this computer or join a domain。

4. 出现一个新的窗口。在这个窗口中,点击域的单选按钮并输入BIGTIME 作为域。点击OK。

5. 在提示输入用户ID 和密码时,输入用户root 作为用户ID,密码是在

步骤 7:填充 LDAP 数据库

中提供的密码。会提示重新启动工作站。

6. 在重新启动之后,会注意到域BIGTIME已添加到了Log on to:选择框中。在作为

步骤 9a:添加 PAM 用户

中创建的域成员之一登录之前,应该决定他们处于这台工作站的本地安全层次结构的什么位置。在本教程中,我们将BIGTIME域中的所有Domain Users添加到这个工作站的Power Users本地组中。执行以下步骤:

1. 在登录屏幕上,从Log on to:选择框中选择选项(this computer)。

2. 目前作为对这个工作站有管理特权的用户登录。

3. 在登录之后,选择Start。

4. 选择Control Panel。

5. 选择Administrative Tools。

6. 选择Computer Management。

7. 进入Local Users and Groups。

8. 点击Groups。

9. 点击Power Users。

10. 点击Add按钮并确保From this Location框包含BIGTIME。

11. 点击Advanced按钮。

12. 点击Find Now。

13. 会提示输入域管理员的id 和密码。输入root 和在

步骤 7:填充 LDAP 数据库

中提供的密码。

14. 选择Domain Users 并点击OK,直到返回Computer Management窗口。

7. 接下来,输入设置的所有用户(boss、wally、catbert 或dilbert)并登录工作站。

8. 工作站应该会根据用户的安全设置文件自动挂装允许用户访问的驱动器。

9. 对于网络上的每台工作站,重复步骤1-6。

步骤 11:快速审查

如果一切顺利,目前应该有了一个功能完整的Samba 服务器,他作为MS 视窗系统主域控制器。如果有什么不对的地方,应该停下来进行调试,然后才能按照下一节的描述启用加密。下面列出一些诊断测试,帮助你进行调试:

? 执行testparm /etc/samba/smb.conf。这会检查Samba 服务器的设置文件中是否有错误。? 确保Linux 计算机能解析在

步骤 9a:添加 PAM 用户

中创建的视窗系统用户(wally、dilbert 等)的组ID。执行groups wally。如果没有看到engineering和Domain Users,应该检查对ldap.conf 的修改是否正确并和smb.conf 和slapd.conf 中的设置完全相同。

? 用

JXplorer

检查LDAP 数据库。JXplorer 是个图像化LDAP 数据库浏览器,能帮助你了解Samba 怎么和数据库进行交互。例如,如果成功地添加了计算机、组或用户,那么应该会在LDAP 服务器的目录信息树中看到他们。

相关主题