首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

将 LDAP 目录用于 Samba 认证-配置 OpenLDAP-2

将 LDAP 目录用于 Samba 认证-配置 OpenLDAP-2

步骤 3:创建 ldap.conf与 /etc/openldap/slapd.conf 相比,/etc/openldap/ldap.conf 相对简单些。ldap.conf 由 OpenLDAP 客户机和库使用。警告:在一些 LDAP 配置中,服务器上出现了两个ldap.conf文件:/etc/ldap.conf(由 PAM 使用)和 /etc/openldap/ldap.conf(由 LDAP 客户机和库使用);不要混淆这两者。
1
2
3
4
5
6
7
8
9
# /etc/openldap/ldap.conf
# LDAP defaults for clients and libraries
# At a minimum, HOST and BASE need to be set
# See man ldap.conf for further settings and options

HOST 127.0.0.1
BASE dc=syroidmanor, dc=com

# ends




其它可用于 ldap.conf 的选项包括搜索超时、最大返回搜索大小、连接端口(如果不是缺省的话)和用于通过 Cyrus SASL 进行连接的几个安全性特性。注:每个用户都可以通过创建 .ldaprc 并将它放置在自己的主目录中来指定唯一的设置。管理员也可以通过强制 LDAP 只读取 /etc/openldap/ldap.conf 文件来覆盖这个选项。
步骤 4:启动服务器最后,启动 OpenLDAP 服务器。在基于 Red Hat 的系统上,输入 /etc/init.d/ldap start。服务器启动时应该有错误或声明。如果不是这样:
  • 验证您装入了正确的模式并满足了所有依赖性。
  • 验证 /var/lib/ldap 存在并由被指派运行服务器的用户/组(在 Red Hat 下是 ldap.ldap)所拥有。
  • 对所有配置文件的拼写、正确的“dn”项等进行复核。
  • 着手阅读 LDAP 文档(man ldapinfo slapd 和  是三个不错的起点)。
初始项既然 LDAP 服务器已经在运行了,是用一些初始项填充目录的时候了。有两种进行这一操作的方法:
  • 一,使用我们在本教程先前部分下载并安装的 smbldap-tools 脚本。
  • 二,创建文本文件(base.ldif)并用 ldapadd 命令添加项。
我们将从 smbldap-tools 方法入手……
使用 smbldap-populate.pl根据第 2 章中提供的安装指示信息,首先用“cd”命令进入 /usr/local/sbin。您会在那里找到一个名为 mkntpwd.tar.gz 的文件。进行下列操作以解压缩、构建和编译程序:
1
2
3
4
5
6
7
8
9
10
[root@thor sbin]# tar xvzf mkntpwd.tar.gz
[root@thor sbin]# cd mkntpwd
[root@thor sbin]# make
[root@thor sbin]# make install
# Note: this will place the built executable in /sbin;
# I prefer all my smbldap files together in one place,
# so the following further steps are required.
[root@thor sbin]# cd .. && rm -rf ./mkntpwd (remove the directory
so the file can be copied back)
[root@thor sbin]# mv /sbin/mkntpwd /usr/local/sbin




现在,在您喜欢的文本编辑器里打开 /usr/local/sbin/smbldap_conf.pm,然后开始编辑。您将找到略少于一页的指示信息(## Configuration Start here),它确切地指出了哪些项需要更改。如果您已经脱离了本章先前讨论的组织单元,则必须更改 $usersdn、$computersdn 和 $groupsdn 项。此外:
  • 在 $binddn 下输入 dn=Manager而不是“manager”(如果您采用本教程中所使用的示例的话;关键在于确保与所有 LDAP 和 SMBLDAP 工具配置文件上的大小写匹配)。
  • 不要忘记对 $_userSmbHome/$_userProfile 节中使用的任何反斜杠进行转义操作(“\\”)。
  • 确保到 smbpasswd 的路径是正确的(我的项读取 /usr/local/samba/bin/smbpasswd)。
  • 检查所有属于 UID、GID 等的项,以确保所用的项与您的用户/组编号约定匹配。
最后,执行 smbldap-populate.pl。如果配置是正确的,脚本将输出一串“adding entry...”资料,并且用一组基本对象填充目录。如果得到任何“credential”或“cannot bind”错误,则说明 smbldap_conf.pm 中某处存在拼写错误 ― 回头重新检查您的项。
用 LDIF 文件进行手工填充OpenLDAP 当然可以满足那些喜欢手工执行操作的管理员。填充 LDAP 目录的第二种方法是使用 LDIF 文件。LDIF 文件是文本文件,具有多个遵循特定格式的项。下面是两个样本目录对象项。
1
2
3
4
5
6
7
8
9
dn: dc=syroidmanor,dc=com
objectClass: domain
dc: syroidmanor

dn: ou=Users,dc=syroidmanor,dc=com
objectClass: top
objectClass: organizationalUnit
ou: Users
description: System Users




用上述格式创建一个名为 base.ldif 的文件并创建您希望的对象。将该文件保存到您所选择的目录,然后执行下列命令:
1
2
[root@thor root]# ldapadd -x -h localhost -D "cn=Manager,dc=syroidmanor,dc=com"
-f /root/base.ldif -W




系统将提示您输入“Manager”的密码(在所提供的示例中是“secret”),如果文件中没有语法错误,则用该文件的内容填充目录。
输入 man ldapadd                     以获取上述选项开关作用的说明。可在                    一章获取样本 base.ldif 文件。
为 PAM 认证配置 LDAP如果您选择使用 PAM(请牢记先前的警告 ― PAM 与 Samba 和加密密码的合作并不好),则需要配置 LDAP 以使用 PAM 进行用户认证(这是个与使用 LDAP 认证 Samba 用户截然不同的问题)。幸运的是,在 Red Hat 下这个过程很简单,因为有捆绑的程序:/usr/sbin/authconfig/usr/sbin/authconfig。
作为 root 用户,从命令行或终端窗口,输入 authconfig 并选择下列选项/复选框:
  • Cache Information
  • Use LDAP
  • “不要”选择 Use TLS ― 除非您彻底了解您的安全认证协议,否则启动和运行 TLS 是一个痛苦的过程
  • Your Server 是 127.0.0.1(除非 LDAP 服务器物理上位于另一个系统上)
  • Base DN: dc=syroidmanor,dc=com
  • Use Shadow Passwords
  • Use MD5 Passwords
  • Use LDAP Authentication
  • 再次选择,Server: 127.0.0.1
  • Base DN: dc=syroidmanor,dc=com
Cache Information 选项意味着使用 nscd(名称服务高速缓存守护程序,Name Service Caching Daemon)服务;它高速缓存频繁使用的 LDAP 请求。在最后一个对话框上选择 OK 将自动启动 nscd 守护程序。最后一个难题是编辑/etc/ldap.conf 文件。
编辑 /etc/ldap.conf正如本章先前部分所提到的,当使用 PAM 认证时,LDAP 使用另一个 ldap.conf 文件。打开您喜欢的文本编辑器并将下列内容添加到 /etc/ldap.conf 中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# /etc/ldap.conf
# LDAP authentication configuration
# last modified, 4/15/02, TMS
host 127.0.0.1
# your LDAP server
base dc=syroidmanor,dc=com
# your DN search base
# point the nss modules to the correct search base
nss_base_passwd   dc=syroidmanor,dc=com?sub
nss_base_shadow   dc=syroidmanor,dc=com?sub
nss_base_group     ou=Groups,dc=syroidmanor,dc=com?one
ssl no
pam_passwd  md5
# ends




在上述示例中,因为目录树的组织而使用了“?sub”查询选项;我们选择分离出“ou=Computers”和“ou=Users”。有关 ?sub 和 ?one 选项的更多详细信息,请在因特网上搜索 RFC2307。还可获得一份 PDF 文档,它解释了 PAM 和 NSS 背后的概念和实现;请参阅                    一章以获取更多信息。
测试最后,关键时刻到来了 ― 这一切都有效吗?
转到包含 SMBLDAP Perl 脚本的目录;所提供的示例在 /usr/local/sbin 中。使用 smbldap-tools 创建新用户时输入下列命令:
1
2
3
4
5
6
7
8
[root@thor sbin]# ./smbldap-useradd.pl -m testuser2
adding new entry "uid=testuser2,ou=Users,dc=syroidmanor,dc=com"
[root@thor sbin]# ./smbldap-passwd.pl testuser2
Changing password for testuser2
New password :
Retype new password :
all authentication tokens updated successfully
[root@thor sbin]#




现在,尝试用刚才创建的帐户从另一台计算机登录到系统上。如果正确地配置了一切,则应该正确地认证您:
1
2
3
4
5
[tom@phaedrus tom]$ ssh testuser2@thor
testuser2@thor's password:
Last login: Thu Apr 25 11:28:24 2002 from 192.168.1.100
[testuser2@thor testuser2]$ id
uid=1000(testuser2) gid=100(users) groups=100(users)




现在,让我们转过头来研究一下等价的 Samba 端。
返回列表