当前所在位置:FreeBSD使用大全>>
FreeBSD连载(67):配置samba(2)
 
作者:王波
 
除了登录脚本之外,Windows NT中为了支持移动用户在不同地点进行漫游,也提供了针对每个用户的描述其使用环境的Profile文件,Samba服务器也可以通过logon path来支持对windows客户机这种漫游能力的支持。这样当Windows客户机使用漫游功能的时候,客户机会自动将用户的配置文件保存到服务器上,此后每次登录进域的时候都重新下载这个配置文件,设置Windows桌面环境。

# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
;   wins support = yes

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
#       Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z
 
# WINS Proxy - Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one  WINS Server on the network. The default is NO.
;   wins proxy = yes
 
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The built-in default for versions 1.9.17 is yes,
# this has been changed in version 1.9.18 to no.
   dns proxy = no
 
 

  上面的这些选项是用于设置NetBIOS名字解析方式,wins support选项使得nmdb能对外表现为一个NBNS服务器。wins server用于指定一个外部名字服务器的地址(可以为NT上的wins服务器或另一个Samba服务器),使得nmbd能用做NBNS客户端,通过访问该wins名字服务器解析NetBIOS名字。 

  此外,还有一些不使用名字服务器进行解析的NetBIOS客户,如果名字服务器位于另一个子网上,那么它们就无法正确解析名字,而Samba可以使用wins proxy帮助它们使用名字服务器解析地址。例如一个WINS服务器在另一个子网上,本地子网内的Samba服务器配置了wins server的地址,其他Windows客户没有设置wins服务器地址,它们使用b-node广播方式查询名字,在这台Samba服务器设置了wins proxy能力之后,它就能代替wins服务器回应客户请求。因此要用作wins代理,就必须本身能使用名字服务器进行解析,就要求先设置wins server参数。

  此外,NetBIOS名字解析也可以扩展到通过DNS查询进行帮助,使用dns proxy设置就能让Samba 服务器通过dns进行查询,回应NetBIOS名字查询请求。


[homes]个人目录共享

#============================ Share Definitions ==============================
[homes]
   comment = Home Directories
   browseable = no
   writable = yes
 
 

  [homes]部分使得每个Unix用户通过SMB客户登录上来的时候,可以共享使用他自己的个人目录。这个共享资源具备特别属性,当用户登录上之后,共享名就不是homes,而是被服务器映射为用户自己的标识符。

  设置这个特别的共享选项,就允许每个用户访问自己的个人目录,而不必为每个用户都配置一个共享资源部分。正由于系统会自动映射,因此就不需要定义要共享的文件目录路径,而在其它文件资源共享选项中,都需要使用path参数进行定义。

  由于Samba系统会自动将homes共享名改变为用户的个人标识符,因此要设定browseable=no ,设置homes本身这个名字不出现在资源列表中。writable为用户写权限设置,由于是在用户的个人目录下,用户可以具备写权限。


[netlogon]与[Profiles]

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
;   comment = Network Logon Service
;   path = /usr/local/samba/lib/netlogon
;   guest ok = yes
;   writable = no
;   share modes = no
 
 

  当允许Samba服务器支持客户的网络登录功能之后(设置domain logon),就需要设置[netlogon] 部分(删除注释符号),为guest用户打开登录路径的访问权限,以保证每个用户都能访问其自己的登录脚本。由于需要使用guest对应的Unix帐户访问登录脚本,这个登录路径及其下面的脚本文件都要允许该Unix帐号可以读取。

  建立这个目录之后,要设定正确的权限,并且创建这个目录下对应各个计算机或用户的登录脚本,以提供给客户正确的登录脚本。

# Un-comment the following to provide a specific roving profile share
# the default is to use the user's home directory
;[Profiles]
;    path = /usr/local/samba/profiles
;    browseable = no
;    guest ok = yes
 
 

  当支持Windows计算机漫游能力时,可以设定[Profiles]部分,并为相应的路径建立目录,及分配权限。来为Window计算机用户设置桌面环境。


[Printers]打印机设置

# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
   comment = All Printers
   path = /var/spool/samba
   browseable = no
# Set public = yes to allow user 'guest account' to print
   guest ok = no
   writable = no
   printable = yes
 
 

  这个部分就用于设置将printcap中定义的所有打印机使用的相关设置,缺省情况下允许所有的合法客户使用所有的打印机。BSD风格的打印系统,不需要任何设置就能正确共享所有的打印机,当然也可以使用printer参数指定具体的打印机以提供共享。而path参数定义的是打印机缓冲区的位置。guest ok、writeable用于设置正确的权限,而printable用于设置打印属性。

  由于Windows的打印驱动已经将要打印的文件转化为打印机支持的那种描述语言,因此这些打印文件不再需要任何过滤器进行转换。因此需要在printcap中定义一个不使用任何过滤器、直接将打印文档输出到打印机端口的打印机选项。


其他专有共享目录

# This one is useful for people to share files
;[tmp]
;   comment = Temporary file space
;   path = /tmp
;   read only = no
;   public = yes
 
# A publicly accessible directory, but read only, except for people in
# the "staff" group
;[public]
;   comment = Public Stuff
;   path = /home/samba
;   public = yes
;   writable = yes
;   printable = no
;   write list = @staff
 
# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
;   comment = Fred's Printer
;   valid users = fred
;   path = /homes/fred
;   printer = freds_printer
;   public = no
;   writable = no
;   printable = yes
 
# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
;   comment = Fred's Service
;   path = /usr/somewhere/private
;   valid users = fred
;   public = no
;   writable = yes
;   printable = no
 
# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
;  comment = PC Directories
;  path = /usr/pc/%m
;  public = no
;  writable = yes
 
# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
;   path = /usr/somewhere/else/public
;   public = yes
;   only guest = yes
;   writable = yes
;   printable = no
 
# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
;   comment = Mary's and Fred's stuff
;   path = /usr/somewhere/shared
;   valid users = mary fred
;   public = no
;   writable = yes
;   printable = no
;   create mask = 0765
 
 

  此后,缺省smb.conf中给出了一些设定各种共享文件资源、打印机资源的例子,例如设置特定打印机的 [fredprn],设置私人文件共享资源的[freddir]和[myshare],使用宏为多个用户设置共享的[pchome],提供公共访问的[public]和[tmp],FreeBSD的管理员可以根据具体情况,根据这些设置例子设置相应的共享资源,并设置相应的访问权限,以保护文件系统不被非法访问。

  需要注意的是,当使用valid user用来设置合法访问用户时,或者使用wirte list定义具备写权限的用户时,都可以使用@staff的形式使用Unix的组名,这样凡是属于该staff组成员的用户,都会具备相应权限。

  从这些例子中可以看到[global]用于设定全局参数,不会出现在资源列表中,[homes]用于设定个人目录共享,其共享的名字映射为个人标识符而非homes,[printers]设定打印机共享,将共享所有的打印机名字,除了这些标题的共享名字与标题不同之外,其他每个标题都将代表一个共享资源的名字。

  当更改设置之后,可以重新启动Samba服务器,提供新的共享服务了。但在重新启动服务器之前,最好使用 Samba软件包中提供的测试软件,检查一下设置是否正确。这些小工具程序包括检查smb.conf设置的testparm ,检查打印机名字的正确性的程序testprn,用于进行NetBIOS名字解析的nmblookup等。


使用swat配置samba

  samba 2.0提供了一个能够通过浏览器来配置samba的工具──swat。它是一个专用www服务器,使用inetd 来启动,然后经过认证,可以允许用户通过浏览器来配置smb.conf。为了达到这个目的,首先要为swat分配一个固定的端口,这个工作可以通过在/etc/services中增加一行来完成:

swat    901/tcp
 
 

  出于安全的考虑,应该使用1024以下的端口,这是因为非root用户也能占用1024以上的端口,如果使用 1024之上的端口,可能在某些情况下,普通用户就可能通过欺骗的方法获得管理员的口令。

  为了启动swat,需要在inetd.conf中增加一个入口,并重起inetd:

swat  stream    tcp  nowait   root /usr/local/sbin/swat     swat
 
 

  然后就能使用Netscape等浏览器来配置samba了,为了避免认证口令通过网络传输,应该在本地启动浏览器(并进一步可以使用tcp_wrapper提供保护)。输入URL为:http://localhost:901 /,浏览器将提示用户名和口令对用户进行认证,可以输入任意一个Unix用户进入swat页面,但普通用户只能读取 samba设置,而不能更改,为了设置samba,必须使用root用户进行认证。一些功能简单的浏览器不支持浏览器方式的用户认证,就无法使用swat设置Samba。

  由于改变smb.conf对于系统安全有严重的影响,因此使用swat一定要小心。为了防止进行swat认证时root密码被窃听,不应该在远程启动浏览器进行设置,应该在控制台或本地安全网络内进行设置。而且一旦设置完毕,应该立即退出浏览器,因为浏览器在内存中保存用户的认证信息,直到浏览器退出。

  注意,swat将删除原有smb.conf中的全部注释,并重新安排各个设置项的位置,因此应该在使用swat 设置之前备份原有的smb.conf。而且swat只是提供了一个容易使用的设置界面,并不能保证设置一定就是正确的,因此还是要在理解smb.conf的基础上才能正确设置。

  swat提供7个不同功能的页面,提供管理员访问。主页面HOME,提供了对Samba文档的连接,用于管理员实时查看相关手册;GLOBALS页面提供对smb.conf中[globals]部分中的各个参数进行设置;SHARES 用于选择、增加、删除各个共享资源,查看并更改其设置选项;PRINTERS用于设置打印机选项;STATUS 用于检查当前Samba服务器的状态,包括客户计算机的连接状态和用户的连接信息,管理员可以使用它来重新启动 Samba,这样就能在更改设置之后使新设置生效;VIEW用于查看当前设置的smb.conf的内容;PASSWORD 用于管理加密口令,提供加密认证情况下增加和管理用户,并可以保持Unix和Windows NT的口令一致,这个功能只在使用了加密口令功能之后才有用,更改的口令将直接保存在/usr/local/private目录下的smbpasswd 文件中。PASSWORD功能将不但更改smb.conf,还将更改Samba使用的口令选项,因此对于使用加密口令认证方式的系统,最为有用。

  使用SWAT,设置Samba就非常容易,不再需要手工编辑设置文件,而可以直接使用浏览器更改设置,并重新启动Samba服务器。

未完,待续。。。  
 
来源:http://freebsd.online.ha.cn/

声明:本站的文章和软件是本人从网上收集整理的(除本人的作品之外),所有版权属于作者,
如有侵犯您的权益,请指出,本站将立即改正,谢谢.

Copyright 2000 www.newok.com