免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1877 | 回复: 0
打印 上一主题 下一主题

用 Linux 上的 LDAP 将 Samba 安装和配置为主域控制器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-23 16:15 |只看该作者 |倒序浏览
——
                    作者:
Keith Robertson
                 来源:
www6.software.ibm.com
     发表时间:2006-03-28   
            浏览次数:
            12183
                 字号:

  

  

        
               
         
内容摘要
本教程讲解如何使用安全的基于 LDAP 的身份验证机制将 Samba 安装和配置为主域控制器。还描述如何为基于 PAM 的身份验证配置
LDAP 服务器 OpenLDAP,以及如何用 Transport Layer Security(TLS)保护 Samba 和
OpenLDAP 之间的链路。完整的系统包括安全的文件共享和打印共享设置,以及健壮的 LDAP 服务器,这些设施支持的功能甚至超出了
Samba 的需要。另外,Windows® 客户机能够登录到作为主域控制器的 Samba
服务器,并能够根据它们的组成员关系共享自动挂装的驱动器。
        
               
         
关于本教程
本教程讲解如何使用安全的基于 LDAP 的身份验证机制将 Samba 安装和配置为主域控制器。在本教程中,我将:
  • 介绍 LDAP,讲解它如何与 Samba 集成,并讨论安全问题。
  • 介绍配置 LDAP 的步骤,包括安装 OpenLDAP 和 IDEALX LDAP Samba 工具箱;配置
    OpenLDAP 所需的 slapd.conf 文件、/etc/ldap.conf 文件和 Pluggable Authentication
    Modules(PAM);并解释如何启动 OpenLDAP。
  • 接下来,讲解如何配置 Samba,包括安装和启动 Samba 和 Logon Profile
    Generator;创建所需的目录和共享驱动器;配置 smb.conf 文件并设置 LDAP 数据库访问密码;填充数据库;添加 PAM
    和其他用户并将 Windows 工作站添加到域中;以及对不工作的 Samba 安装进行调试。
  • 最后,讨论安全问题以及如何为这个系统启用安全性,包括为 OpenLDAP、PAM 和 Samba 启用 Transport Layer Security,以及如何测试系统的安全性。

完整的系统包括安全的文件共享和打印共享设置,以及健壮的 LDAP 服务器,这些设施支持的功能甚至超出了 Samba
的需要。另外,Microsoft Windows 客户机能够登录到作为主域控制器的 Samba
服务器,并能够根据它们的组成员关系共享自动挂装的驱动器。
本教程的读者最好具有中等程度的 UNIX 或 Linux 技能和经验,并了解基本的 IP 网络概念。作者使用 Fedora Core 3
作为 Linux 发行版,但是其他 Linux 发行版或 UNIX 变体(比如 AIX、Solaris 或
HP-UX)也可以应用本教程中描述的设置。本教程中使用的所有应用程序和实用程序都是开放源码的,可以从 Linux 厂商或应用程序厂商的主页获得。



前提条件
Linux 发行版是 Fedora Core 3;但是这里描述的设置也可以应用于其他 Linux 发行版或 UNIX 变体(比如
AIX、Solaris 或 HP-UX)。这种软件可以以许多方式免费获得。建议从 Linux 厂商的 ftp 镜像站点获得预编译的版本(比如
RPM)。
下面是本教程中使用的软件的清单。不需要事先按照这张清单进行准备,因为本教程会描述如何下载和安装这些软件。
  • OpenSSL
  • OpenLDAP
  • Samba
  • Perl module Crypt::SmbHash
  • Perl module Digest::SHA1
  • Perl module IO::Socket::SSL
  • Perl module Net::SSLeay
  • IDEALX Samba LDAP 工具

注意:本教程指出了各种经过测试的软件组件的特定版本。采用以前的软件版本也可能可以,但是我不能保证会成功。一般来说,使用比本教程中使用的版本更新的软件应该没问题。



教程的网络布局
本教程中描述的网络比较小,所以很容易在您自己的家庭或实验室网络上重现这里的示例。对于这个设置,我使用一个典型的家用宽带路由器,其中内置了防火墙。下图描述了物理网络布局。
图 1. 教程的网络配置

这个 Microsoft Windows 网络包含三类用户 ——
市场营销、工程和管理。工程和市场营销用户各有一个共享的驱动器,每个组的用户可以分别将文件放在这里,供同组的其他用户查看;但是,一个组的成员不能查
看另一个组的共享驱动器上的文件。例如,市场营销职员不能查看工程驱动器上的文件。管理用户也有一个共享驱动器,只有经理能够看到这个驱动器。另外,经理
具有特殊特权,他们还能够查看工程和市场营销组的文件。
安装 LDAP
现在介绍 LDAP,讲解它如何与 Samba 集成,并讨论安全问题。
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:
  • 检查发行版是否已经安装了 OpenLDAP。在一个终端中发出以下命令:rpm -qa | grep ldap。如果没有得到响应 openldap-2.2.13(或更高的版本号),那么应该升级或安装 OpenLDAP(在下面说明)。
  • 如果还没有 OpenLDAP 2.2.13 或更高版本,那么到发行版的镜像站点并下载一个二进制包。我进入
    [color="#5c81a7"]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 工具箱:
  • 进入
    [color="#5c81a7"]IDEALX 的主页
    并下载这个工具箱的 .0.9.1 版或更高版本(smbldap-tools-.0.9.1.tgz)。
  • 在一个临时目录中,用以下命令解开这个工具箱:tar -zxf smbldap-tools-0.9.1.tgz。
  • 创建一个目录用于放置 IDEALX 脚本。在命令提示下输入:mkdir -p /var/lib/samba/sbin。然后输入:chmod -R 755 /var/lib/samba。
  • 进入 tar 命令创建的目录。输入:cd smbldap-tools-0.9.1。
  • 用以下命令将所需的脚本从临时目录复制到永久目录:cp smbldap* configure.pl /var/lib/samba/sbin。
  • 进入 /var/lib/samba/sbin 目录并依次 发出以下命令,设置正确的所属权和权限:
  • chmod 750 *
  • chmod 640 smbldap_bind.conf smbldap.conf smbldap_tools.pm
  • 现在可以安全地删除临时目录。
    IDEALX 工具箱需要一些额外的 Perl 模块,系统上可能还没有安装这些模块。本节说明如何下载和安装它们。
  • 首先,需要从 CPAN.org 下载所有必需的 Perl 模块。进入
    [color="#5c81a7"]CPAN.org
    并在搜索框中输入以下搜索字符串。
    • 搜索 Perl 模块:Crypt::SmbHash
    • 搜索 Perl 模块:Digest::SHA1
    • 搜索 Perl 模块:IO::Socket::SSL
    • 搜索 Perl 模块:Net::SSLeay
    可以从每个搜索的结果直接导航到每个模块的主页。在这四个模块的主页上,可以找到下载 Perl 模块的链接。
  • 下一步是对下载的 Perl 模块进行解压。在保存下载的四个模块的目录中,发出以下命令:tar -zxvf *.gz。
  • 最后一步是构建和安装这四个模块。进入每个新创建的目录并作为 root 发出以下命令。
  • perl Makefile.PL
  • make install
    步骤 3:配置 OpenLDAP 所需的模式、目录和密钥
    如果从 RPM 进行安装而且 Linux 发行版是 Fedora,那么应该有一个称为 /etc/openldap 的目录。在这个目录中有 OpenLDAP 的主配置文件 slapd.conf。在开始编辑这个文件之前,先执行一些预先设置操作。
    OpenLDAP 需要感知 Samba 的 LDAP 模式。为此,将 Samba 的模式复制到 /etc/openldap/schema 中。
  • 寻找 Samba 的模式。它应该在安装 Samba 的目录中。为了寻找它,输入:locate samba.schema。
  • 将它复制到 /etc/openldap/schema 中。
  • 设置正确的权限。输入:chmod 644 /etc/openldap/schema/samba.schema。
    为 LDAP 数据库创建目录。在本教程中,将这个目录命名为与域名相同。
  • 输入:mkdir -p /var/lib/ldap/somedomain.com。
  • 设置正确的权限:chmod 700 /var/lib/ldap/somedomain.com。
  • 设置正确的所属权。Fedora 应该已经在 /etc/passwd 中定义了用户 LDAP。如果在其他发行版上进行安装,那么可能需要创建这个用户。输入:chown ldap:ldap /var/lib/ldap/somedomain.com。
    最后,创建 OpenLDAP 用于 TLS 的加密密钥。为此,需要 OpenSSL。大多数 Linux 发行版附带有 OpenSSL;但是,如果还没有安装它,那么从发行版的厂商或
    [color="#5c81a7"]http://www.openssl.org/
    获得一个副本。
    本教程假设用户将不使用商业的证书机构(CA),比如 Verisign、Thawte 等。因此,需要成为自己的 CA 并签署 LDAP 服务器使用的证书。下面的步骤演示如何成为 CA 并签署证书。
  • 如果还没有这么做,那么编辑 openssl.cnf 以满足自己的特定需要。要寻找 openssl.cnf 文件,输入:locate openssl.cnf。
  • 在 openssl.cnf 所在的目录中,作为 root 发出以下命令。
    清单 1. 成为 CA 的步骤
    mkdir -p CA/certs CA/crl CA/newcerts  CA/private
    chmod 700 CA/private
    touch CA/index.txt
    echo 01 > CA/serial
  • 在编辑器中打开 openssl.cnf 并根据自己的情况修改以下参数。
    清单 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             = US
    stateOrProvinceName_default     = North Carolina
    localityName_default            = Raleigh
    0.organizationName_default      = somedomain.com
  • 用以下命令创建 CA 证书和密钥对:openssl req -nodes -config openssl.cnf -new -x509 -keyout CA/private/cakey.pem -out CA/cacert.pem -days 3650。
  • 用以下命令为 OpenLDAP 创建密钥对:
  • openssl req -config openssl.cnf -nodes -new -keyout /etc/openldap/slapd-key.pem -out slapd.csr
  • openssl ca -config openssl.cnf -out /etc/openldap/slapd-cert.pem -in slapd.csr
  • chown root:ldap /etc/openldap/slapd-key.pem
  • chmod 640 /etc/openldap/slapd-key.pem
  • chmod 644 /etc/openldap/slapd-cert.pem
  • 将 CA 的证书复制到 openldap 配置目录,这样各个应用程序就能够访问它了。
  • cp CA/cacert.pem /etc/openldap/
  • chmod 644 /etc/openldap/cacert.pem
    步骤 4:配置 slapd.conf
    OpenLDAP 提供的对应于实际 LDAP 服务器的可执行文件称为 slapd。slapd 守护进程从 slapd.conf 读取它的所有配置信息。在本节中,我提供一个加了注释的 slapd.conf 示例。对于所有带 “# MODIFY” 注释的部分,必须根据自己的情况进行修改。
    在开始进行编辑之前,为 rootdn 生成一个密码散列。要对 LDAP 服务器的目录信息树进行修改,就必须使用这个密码。
    注意:应该选择一个不同于 Linux 服务器 root 密码的密码。
  • 从命令行输入:slappasswd -h {SSHA} -s 。
  • 保存这个命令的输出,因为后面要使用它。它类似于:{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.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
    # -1 is all messages 296 is a good compromise for most debugging
    #loglevel    -1
    pidfile     /var/run/slapd.pid
    argsfile    /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
    #TLSCertificateKeyFile   /etc/openldap/slapd-key.pem
    database    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 ldap
    directory   /var/lib/ldap/somedomain.com
    # Indices to maintain for this database
    index objectClass           eq
    index cn                    pres,sub,eq
    index sn                    pres,sub,eq
    index uid                   pres,sub,eq
    index displayName           pres,sub,eq
    index uidNumber             eq
    index gidNumber             eq
    index memberUID             eq
    index sambaSID              eq
    index sambaPrimaryGroupSID  eq
    index sambaDomainName       eq
    index 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,sambaPwdMustChange
          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 correctly
    access 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 themselves
    access 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 allow
    some unix commands to work) access to attrs=cn,sambaLMPassword,sambaNTPassword,
    sambaPwdLastSet,sambaLogonTime,sambaLogoffTime,sambaKickoffTime,sambaPwdCanChange,
    sambaPwdMustChange,sambaAcctFlags,displayName,sambaHomePath,sambaHomeDrive,
    sambaLogonScript,sambaProfilePath,description,sambaUserWorkstations,sambaPrimaryGroupSID,
    sambaDomainName,sambaSID,sambaGroupType,sambaNextRid,sambaNextGroupRid,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 account
    access 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 account
    access 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 account
    access 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 account
    access 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 directory
    access 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=com
    bindpw
    # 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?one
    nss_base_passwd                ou=Computers,dc=somedomain,dc=com?one
    nss_base_shadow                ou=Users,dc=somedomain,dc=com?one
    nss_base_group                ou=Groups,dc=somedomain,dc=com?one
    ssl no
    pam_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 Windows groups
    # that have been created in your LDAP database.
    # tls_checkpeer no
    步骤 6:配置 PAM
    配置 PAM 需要点儿技巧。因此,我使用 Linux 厂商提供的实用程序替我做所有这些麻烦的工作。Fedora 提供一个命令行实用程序 authconfig,它知道如何修改所有 PAM 配置文件。其他 Linux 发行版有类似的配置实用程序,所以如果不使用 Fedora,就请参考文档。
  • 从命令行启动 authconfig。输入:authconfig。
  • 按照下图编辑第一个屏幕。
    图 2. authconfig 屏幕 1

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

    步骤 7:启动 OpenLDAP
    现在启动 LDAP 服务器。从二进制 RPM 进行安装的 Fedora 用户应该能够执行以下命令:/etc/init.d/ldap start。
    配置 Samba
    现在将注意力转到 Samba 上 —— 安装、创建目录和配置。
    步骤 1:安装 Samba
    要安装 Samba:
  • 检查发行版是否已经安装了 Samba。在一个终端中发出以下命令:rpm -qa | grep samba。如果没有得到响应 samba-3.0.14(或更高的版本号),那么应该升级或安装 Samba(在下面说明)。
  • 如果还没有 Samba 3.0.14 或更高版本,那么到
    [color="#5c81a7"]Samba 的主页
    并下载适合自己的 Linux 发行版的二进制包。Samba 套件分为四个单独的
    RPM,它们都非常有用,建议全部安装。但是,如果想节省空间,那么应该只安装 samba 和 samba-common 包。下载需要的
    samba RPM 并用以下命令安装它们:rpm -Uvh samba*。
    步骤 2:创建所需的目录
    需要创建一些目录,Samba 使用它们存储运行时数据。
  • mkdir -p /var/lib/samba/netlogon/scripts/ /var/lib/samba/printing/
  • 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 Windows 网络修改这个文件,并添加设置让 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 提供这个密码。应该使用与
    [color="#996699"]步骤 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 Windows 域控制器,因此它可以控制 Windows 客户机在登录到这个域时能够执行什么操作。这些操作包括获得存储的移动配置文件、挂装驱动器以及与时间服务器进行同步,等等。
    我们的 Samba 服务器没有存储移动配置文件,因为它们会占用一定的空间;但是,我们迫使每个登录到域中的 Microsoft Windows 客户机挂装驱动器并与时间服务器进行同步。
    在这一步中,创建一个生成 Windows 批处理文件的 Perl 脚本,这个批处理文件在用户每次登录到 BIGTIME
    域时执行。这个批处理文件导致用户的 Windows
    机器自动挂装他们的安全配置文件授权让他们访问的驱动器。对于具有许多共享驱动器和复杂的安全策略的大型组织,这种操作很有用。这个批处理文件的位置和执
    行由 smb.conf 的 netlogon 部分中的两个参数进行定义,它们是 path 和 root preexec。
    Perl 脚本如下所示。执行以下操作来安装这个 Perl 登录脚本:
  • cd /var/lib/samba/netlogon/scripts
  • 创建一个称为 logon.pl 的文件并在其中添加以下内容。
  • chmod 755 /var/lib/samba/netlogon/logon.pl
    下面是 Perl 登录脚本。
    /var/lib/samba/netlogon/logon.pl 的内容如下所示:
    清单 6. Perl 登录脚本的内容
    #!/usr/bin/perl
    use 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 IDs
    my $uid = getpwnam($ARGV[0]);
    if ($uid == /[^0-9]/){
        my $now = localtime;
        open LOG, ">>$LOG_DIR/log.netlogon";
        print LOG "$now";
        print LOG " - Error: Unknown user $ARGV[0] logged into $SERVERNAME from $ARGV[1]n";
        close LOG;
        exit(1);
    }
    # Log the logon attempt
    my $now = localtime;
    open LOG, ">>$LOG_DIR/log.netlogon";
    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 off
    print FH "@ECHO OFFrn";
    # Synchronize time between Windows 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 工具箱中所有脚本使用的重要环境变量。
  • 首先输入:cd /var/lib/samba/sbin/。
  • 编辑 smbldap_tools.pm 并对变量 smbldap_conf 和 smbldap_bind_conf 做以下修改。
    • my $smbldap_conf="/var/lib/samba/sbin/smbldap.conf";
    • my $smbldap_bind_conf="/var/lib/samba/sbin/smbldap_bind.conf";

  • 接下来,输入以下命令启动配置实用程序:./configure.pl。
  • 现在,程序会提出一系列问题,我提供了一个示例清单。一般来说,应该只需按回车键;但是,有几个重要的事项您应该知道。

    configure.pl 脚本的输出如下所示:
    清单 7. Perl 配置脚本的输出
    [root@linus sbin]# ./configure.pl
    If 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: directory 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 certificate (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 [] > somedomain.com
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    backup old configuration files:
      /var/lib/samba/sbin/smbldap.conf->/var/lib/samba/sbin/smbldap.conf.old
      /var/lib/samba/sbin/smbldap_bind.conf->/var/lib/samba/sbin/smbldap_bind.conf.old
    writing new configuration file:
      /var/lib/samba/sbin/smbldap.conf done.
      /var/lib/samba/sbin/smbldap_bind.conf done.
  • 如果不希望让密码过期,可以禁用这个特性。编辑 smbldap.conf 并注释掉以下行:defaultMaxPasswordAge="45"。
  • 执行以下三个命令来设置正确的权限和所属权:
  • chown root:root smbldap.conf smbldap_bind.conf
  • chmod 644 smbldap.conf
  • chmod 600 smbldap_bind.conf
  • 现在,在 LDAP 数据库中初始化 Samba 模式。我们将执行 IDEALX 脚本
    smbldap-populate,这个脚本将创建一个域管理员、一些必要的组和其他重要的模式元素。在执行这个脚本时,可能会看到一些警告,指出未初始
    化的变量。如果不希望看到这些警告,可以编辑所有 IDEALX 脚本,将所有 “#!/usr/bin/perl -w” 替换为 “#!/usr/bin/perl”。以下代码是 smbldap-populate 的输出示例。(注意:smbldap-populate 可能提示您输入域管理员的密码,域管理员在默认情况下称为 root。给这个用户设置的密码应该不同于
    [color="#996699"]步骤 4:配置 slapd.conf
    中使用的 rootdn 密码,也不同于 Linux 机器的 root 用户密码。)
    清单 8. 执行 IDEALX 脚本 smbldap-populate
    [root@linus sbin]# ./smbldap-populate
    Populating LDAP directory for domain BIGTIME (S-1-5-21-1030832020-2822878261-2997333186)
    (using builtin directory structure)
    LDAP config host: 127.0.0.1
    port: 389
    version: 3
    timeout: 60
    adding new entry: dc=somedomain,dc=com
    adding new entry: ou=Users,dc=somedomain,dc=com
    adding new entry: ou=Groups,dc=somedomain,dc=com
    adding new entry: ou=Computers,dc=somedomain,dc=com
    adding new entry: uid=root,ou=Users,dc=somedomain,dc=com
    adding new entry: uid=nobody,ou=Users,dc=somedomain,dc=com
    adding new entry: cn=Domain Admins,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Domain Users,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Domain Guests,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Domain Computers,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Administrators,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Account Operators,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Print Operators,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Backup Operators,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=Replicators,ou=Groups,dc=somedomain,dc=com
    adding new entry: cn=NextFreeUnixId,dc=somedomain,dc=com
    Please provide a password for the domain root:
    LDAP config host: 127.0.0.1
    port: 389
    version: 3
    timeout: 60
    Changing password for root
    New 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 服务器。看一下
    [color="#996699"]步骤 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 系统上创建用户。对于每个用户,这需要两个步骤:
  • 在系统上创建用户 ID。
  • 设置 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 Windows 工作站添加到域
    对于这个步骤,要访问您计划授予访问权的每台工作站。(以下步骤针对 Microsoft Windows XP Professional,但是也可以应用于其他 Microsoft Windows 版本。)
    作为管理员登录每台 Windows 工作站并执行以下操作:
  • 进入 Control Panel 并选择 System
  • 选择 Computer Name 选项卡。
  • 点击按钮 rename this computer or join a domain
  • 出现一个新的窗口。在这个窗口中,点击域的单选按钮并输入 BIGTIME 作为域。点击 OK
  • 在提示输入用户 ID 和密码时,输入用户 root 作为用户 ID,密码是在
    [color="#996699"]步骤 7:填充 LDAP 数据库
    中提供的密码。会提示重新启动工作站。
  • 在重新启动之后,会注意到域 BIGTIME 已经添加到了 Log on to: 选择框中。在作为
    [color="#996699"]步骤 9a:添加 PAM 用户
    中创建的域成员之一登录之前,应该决定他们处于这台工作站的本地安全层次结构的什么位置。在本教程中,我们将 BIGTIME 域中的所有 Domain Users 添加到这个工作站的 Power Users 本地组中。执行以下步骤:
  • 在登录屏幕上,从 Log on to: 选择框中选择选项 (this computer)
  • 现在作为对这个工作站有管理特权的用户登录。
  • 在登录之后,选择 Start
  • 选择 Control Panel
  • 选择 Administrative Tools
  • 选择 Computer Management
  • 进入 Local Users and Groups
  • 点击 Groups
  • 点击 Power Users
  • 点击 Add 按钮并确保 From this Location 框包含 BIGTIME
  • 点击 Advanced 按钮。
  • 点击 Find Now
  • 会提示输入域管理员的 id 和密码。输入 root 和在
    [color="#996699"]步骤 7:填充 LDAP 数据库
    中提供的密码。
  • 选择 Domain Users 并点击 OK,直到返回 Computer Management 窗口。
  • 接下来,输入配置的任何用户(boss、wally、catbert 或 dilbert)并登录工作站。
  • 工作站应该会根据用户的安全配置文件自动挂装允许用户访问的驱动器。
  • 对于网络上的每台工作站,重复步骤 1-6。
    步骤 11:快速审查
    如果一切顺利,现在应该有了一个功能完整的 Samba 服务器,它作为 MS Windows 主域控制器。如果有什么不对的地方,应该停下来进行调试,然后才能按照下一节的描述启用加密。下面列出一些诊断测试,帮助您进行调试:
    • 执行 testparm /etc/samba/smb.conf。这会检查 Samba 服务器的配置文件中是否有错误。
    • 确保 Linux 计算机可以解析在
      [color="#996699"]步骤 9a:添加 PAM 用户
      中创建的 Windows 用户(wally、dilbert 等)的组 ID。执行 groups wally。如果没有看到 engineeringDomain Users,应该检查对 ldap.conf 的修改是否正确并与 smb.conf 和 slapd.conf 中的设置完全相同。

    • [color="#5c81a7"]JXplorer
      检查 LDAP 数据库。JXplorer 是一个图形化 LDAP 数据库浏览器,可以帮助您了解 Samba 如何与数据库进行交互。例如,如果成功地添加了计算机、组或用户,那么应该会在 LDAP 服务器的目录信息树中看到它们。
    • 查看日志中的问题。查看 /var/log/samba 中的 Samba 日志和 /var/log/slapd 中的 OpenLDAP 日志。

                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5737/showart_284414.html
  • 您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP