Chinaunix首页 | 论坛 | 博客
  • 博客访问: 856280
  • 博文数量: 436
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -103
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-01 09:48
个人简介

爱生活,爱IT

文章分类

全部博文(436)

文章存档

2015年(1)

2014年(2)

2013年(6)

2011年(39)

2010年(176)

2009年(30)

2008年(28)

2007年(54)

2006年(91)

2005年(9)

分类:

2007-04-22 20:02:22

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 Windows 域控制器,因此它可以控制 Windows 客户机在登录到这个域时能够执行什么操作。这些操作包括获得存储的移动配置文件、挂装驱动器以及与时间服务器进行同步,等等。
我们的 Samba 服务器没有存储移动配置文件,因为它们会占用一定的空间;但是,我们迫使每个登录到域中的 Microsoft Windows 客户机挂装驱动器并与时间服务器进行同步。
在这一步中,创建一个生成 Windows 批处理文件的 Perl 脚本,这个批处理文件在用户每次登录到 BIGTIME 域时执行。这个批处理文件导致用户的 Windows 机器自动挂装他们的安全配置文件授权让他们访问的驱动器。对于具有许多共享驱动器和复杂的安全策略的大型组织,这种操作很有用。这个批处理文件的位置和执行由 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/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 工具箱中所有脚本使用的重要环境变量。
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.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.
 
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敗R韵麓?胧 smbldap-populate 的输出示例。(注意:smbldap-populate 可能提示您输入域管理员的密码,域管理员在默认情况下称为 root。给这个用户设置的密码应该不同于 步骤 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 服务器。看一下 步骤 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 Windows 工作站添加到域
对于这个步骤,要访问您计划授予访问权的每台工作站。(以下步骤针对 Microsoft Windows XP Professional,但是也可以应用于其他 Microsoft Windows 版本。)
作为管理员登录每台 Windows 工作站并执行以下操作:
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 Windows 主域控制器。如果有什么不对的地方,应该停下来进行调试,然后才能按照下一节的描述启用加密。下面列出一些诊断测试,帮助您进行调试:
·         执行 testparm /etc/samba/smb.conf。这会检查 Samba 服务器的配置文件中是否有错误。
·         确保 Linux 计算机可以解析在 步骤 9a:添加 PAM 用户 中创建的 Windows 用户(wally、dilbert 等)的组 ID。执行 groups wally。如果没有看到 engineering Domain Users,应该检查对 ldap.conf 的修改是否正确并与 smb.conf 和 slapd.conf 中的设置完全相同。
·         用   检查 LDAP 数据库。JXplorer 是一个图形化 LDAP 数据库浏览器,可以帮助您了解 Samba 如何与数据库进行交互。例如,如果成功地添加了计算机、组或用户,那么应该会在 LDAP 服务器的目录信息树中看到它们。
·         查看日志中的问题。查看 /var/log/samba 中的 Samba 日志和 /var/log/slapd 中的 OpenLDAP 日志。
 
阅读(4075) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~