samba 2.2.4 日本語版のインストール
2003-03-03 作成 福島
2003-05-06 更新 福島
2003-06-23 更新 福島
2003-07-14 更新 福島
2003-08-15 更新 福島
2004-02-03 更新 福島
$ tar xzf samba-2.2.4-ja-1.0.tar.gz
$ cd samba-2.2.4-ja-1.0/source
samba-2.2.4-ja-1.0/source$ ./configure --enable-debug \
	--with-pam         \
	--with-pam_smbpass \
	--with-quotas      \
	--with-i18n-swat   \
	--with-smbmount      smbmount は Linux だけのオプションらしい※1
samba-2.2.4-ja-1.0/source$ make
samba-2.2.4-ja-1.0/source$ su
samba-2.2.4-ja-1.0/source# make install
ついでに smbprint をコピーします (印刷が不要ならコピーも不要)
samba-2.2.4-ja-1.0/source# cp -p ./packaging/SambaJP/smbprint /usr/local/samba/bin/.
samba-2.2.4-ja-1.0/source# chmod +x /usr/local/samba/bin/smbprint  最初から +x されているので不要
samba-2.2.4-ja-1.0/source# cd ..
samba-2.2.4-ja-1.0# vi /etc/xinetd.d/swat
| 
service swat
{
	port		= 901
	socket_type	= stream
	wait		= no
	#only_from	= localhost
	user		= root
	server		= /usr/local/samba/bin/swat
	log_on_failure	+= USERID
	disable		= no
}
 | 
samba-2.2.4-ja-1.0# cp -p packaging/RedHat/samba.pamd /etc/pam.d/samba
samba-2.2.4-ja-1.0# cp -p packaging/RedHat/smb.init /etc/rc.d/init.d/smb
samba-2.2.4-ja-1.0# vi /etc/rc.d/init.d/smb
| 
#!/bin/sh
#
# chkconfig: 345 91 35
# description: Starts and stops the Samba smbd and nmbd daemons \
#       used to provide SMB network services.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# Check that smb.conf exists.
[ -f /usr/local/samba/lib/smb.conf ] || exit 0
# See how we were called.
case "$1" in
  start)
     echo -n "Starting SMB services: "
     /usr/local/samba/bin/smbd -D
     /usr/local/samba/bin/nmbd -D
     echo
     touch /var/lock/subsys/smb
     ;;
  stop)
     echo -n "Shutting down SMB services: "
     kill `/bin/cat /usr/local/samba/var/locks/smbd.pid`
     kill `/bin/cat /usr/local/samba/var/locks/nmbd.pid`
     rm -f /var/lock/subsys/smb
     echo ""
     ;;
  status)
     status smbd
     status nmbd
     ;;
  restart)
     echo -n "Restarting SMB services: "
     $0 stop
     $0 start
     echo "done."
     ;;
  *)
     echo "Usage: smb {start|stop|restart|status}"
     exit 1
esac
 | 
samba-2.2.4-ja-1.0# chkconfig --add smb
ここで下記の smb.conf を作成すために swat を起動 (必要が無ければ省略)
http://SambaHost:901/
samba-2.2.4-ja-1.0# cp -p packaging/RedHat/smb.conf /usr/local/samba/lib/.
samba-2.2.4-ja-1.0# vi /usr/local/samba/lib/smb.conf
| 
# Global parameters
[global]
	netbios name = FILESERV01	# 公開するサーバ名
	workgroup = SAMBAGROUP	# ※2
	encrypt passwords = Yes	# 平文ではないパスワードを使用する (smbpasswd ファイルを必要とする)
	unix password sync = True	# Windows クライアントからパスワードの変更があったときに Unix パスワードをそれに同期させる ※5
	passwd program = /usr/bin/passwd %u
	passwd chat = "*ew*password* %n\n *ew*password* %n\n *successfully*"	# RedHat7.2 の passwd コマンドはこうなります
	domain logons = Yes		# NT ドメインを採用する
	preferred master = True	# マスターブラウザに立候補する
	domain master = True		# ドメインマスターになる
	create mask = 0770		# ファイルが作成されるときのパーミッション
	directory mask = 0770		# ディレクトリが作成されるときのパーミッション
	local master = Yes		# ローカルマスターブラウザ (サブネットを跨がないマスターブラウザ) になる
	os level = 32		# ローカルマスターブラウザ当選の優先度 (NT サーバーが 31 なのでそれより高くする)
	coding system = cap		# ファイル名の保持形式を CAP にする
	client code page = 932	# クライアントの文字コードを「日本語 SJIS」に指定する (NT の文字化け防止)
	debug level = 3		# デバッグ情報が多くて困るなら 0 でも可
[homes]			# ユーザの個人ディレクトリの定義
	writeable = Yes	# 自分のディレクトリなので書き込めるようにする
	browseable = No	# 自分のディレクトリは他人に見せないので No
[第一ディレクトリ]		# 表示ディレクトリ名は SJIS で記述すること
	path = /samba/dir01
	valid users = @dir01	# グループ dir01 に属すユーザだけがアクセスできる
	force group = dir01	# 作成されるファイル (及びディレクトリ) のグループを強制的に dir01 にする
	read only = No	# ユーザが書き込めるようにする
[第二ディレクトリ]		# 表示ディレクトリ名は SJIS で記述すること
	path = /samba/dir02
	valid users = @dir02
	force group = dir02
	read only = No
 | 
※5 smbpasswd コマンドを使った場合、Unix パスワードは変更されません。
   (Windows から変更すると Unix パスワードも変更されます)
   また、passwd -l コマンドでユーザをロックしても、
   Windows からパスワードを変更するとロックが外れてしまうので注意。
samba-2.2.4-ja-1.0# groupadd dir01
samba-2.2.4-ja-1.0# groupadd dir02
samba-2.2.4-ja-1.0# mkdir -m 0770 /samba/dir01
samba-2.2.4-ja-1.0# mkdir -m 0770 /samba/dir02
samba-2.2.4-ja-1.0# chgrp dir01 /samba/dir01
samba-2.2.4-ja-1.0# chgrp dir02 /samba/dir02
ユーザの作成・禁止・削除
samba-2.2.4-ja-1.0# useradd UserID	Unix ユーザを追加
samba-2.2.4-ja-1.0# passwd UserID	Samba だけのユーザなら Unix パスワードは設定しなくても良い
                                           (Windows クライアントから変更するときに設定されてしまうため)
samba-2.2.4-ja-1.0# usermod -s /sbin/nologin UserID	ユーザにシェルを与えないこと
samba-2.2.4-ja-1.0# vi /etc/group
samba-2.2.4-ja-1.0# smbpasswd -a UserID Password	smbpasswd にユーザの 1 行を追加する
samba-2.2.4-ja-1.0# smbpasswd -d UserID		ユーザの禁止
samba-2.2.4-ja-1.0# smbpasswd -e UserID		ユーザの許可
samba-2.2.4-ja-1.0# smbpasswd -x UserID		ユーザの削除 (Unix のユーザとしては削除されない)
パケットフィルタ (ipchains) が効いている場合、パケットが捨てられないようにするために
/etc/sysconfig/ipchains に
	-A input -s 192.168.1.0/24 -d 0/0 137 -p tcp -y -j ACCEPT
	-A input -s 192.168.1.0/24 -d 0/0 137 -p udp -j ACCEPT
	-A input -s 192.168.1.0/24 -d 0/0 138 -p tcp -y -j ACCEPT
	-A input -s 192.168.1.0/24 -d 0/0 138 -p udp -j ACCEPT
	-A input -s 192.168.1.0/24 -d 0/0 139 -p tcp -y -j ACCEPT
	-A input -s 192.168.1.0/24 -d 0/0 139 -p udp -j ACCEPT
を書きます。
samba-2.2.4-ja-1.0# /etc/rc.d/init.d/ipchains restart     変更を反映
Windows 9x の設定
 ・コンピュータ名(C): に自分のコンピュータ名を記入 (他の人が使っていない名前にすること)
・コンピュータ名(C): に自分のコンピュータ名を記入 (他の人が使っていない名前にすること)
ここでは Win9xClient
・ワークグループ(O): にワークグループ名を記入
 (ここでは SAMBAGROUP)※3
 ・Windows NT のドメインにログオンする(L) にチェック
・Windows NT のドメインにログオンする(L) にチェック
・Windows NT ドメイン(W): にワークグループ名を記入
 (ここでは SAMBAGROUP)※4
※2、※3、※4
ワークグループ(O): と Windows NT ドメイン(W) には同じ文字列を設定すること。(Windows ME は異なる設定でも可)
異なる文字列を設定すると、ブラウズ (コンピュータ群のリスト) と権限にズレが生じる。
ワークグループ(O): を設定しなくても、ブラウズできないだけで、コンピュータ名を指定すれば操作は可能。
CAP とは Columbia AppleTalk Package の略で、もともとは UNIX で AppleTalk を動作させるためパッケージです。
SAMBA で指定するのは、この CAP の文字コード体系を使用することを意味します。
アルゴリズムは簡単です。
コード 0x80 〜 0xFF を 16 進文字列に変更し、前に : をつけます。
7 ビットコードの場合は変換しません。
例: あ (0x82 0xa0) -> :82:a0
: (コロン) そのもののエスケープはどうやるのかと思いますが、
・Windows ではファイル名にコロンを含まない
・AppleTalk でのディレクトリセパレータが : になっている (Unix は /、Windows は \)
ので : はエスケープしないと考えます。
アルゴリズムは簡単ですが、文字列 ":82:a0" を見てこれを "あ" というファイル名と理解するには並外れた根気が必要です。
私には並外れた根気が無いので、プログラムを作成しました。
lscap
| 
#!/usr/local/bin/perl
#
# lscap version 0.3 written by fuku@rouge
#
# cap のコード体系は文字列 ":hH" を使って、「表現できない文字」を格納している。
# 時間が表現されるときにも似た文字列 (例: 23:59) が用いられるので重なるのではないか。
# cap では、7 ビットコード以外 (80 〜 FF) をエンコードしているため、時間の表現にはマッチしない。
#
use strict ;
use NKF ;
local *LS ;
open LS,"ls -C @ARGV |" ;
my @ls = <LS> ;
close LS ;
for ( my $i = 0 ; $i < @ls ; $i ++ )
	{
	my $line = $ls[$i] ;
	$line =~ s/:([8-9a-f][0-9a-f])/pack('c',hex($1))/ge ;
	$line = nkf('-e', $line) ;
	print "$line" ;
	}
 | 
一般の人 (定義が難しい) は FDclone を使ったほうが良いと思います。
※1 smbmount の使い方
samba を configure するときに --with-smbmount オプションを指定すると smbfs が使えるようになります。
smbmount とは、Linux のディレクトリツリーに Windows 機 (のディレクトリ) をマウントする機能です。
smbmount を行うと、Linux から
| 
$ ls -l /mnt/windir/
合計 6144
drwx------    1 root     root         2048  7月 13 01:46 datadir
-rwx------    1 root     root         2048  7月 12 00:48 title-1.txt
-rwx------    1 root     root         2048  7月 11 13:49 title-2.txt
 | 
という参照が可能になります。
使い方は
# mkdir /mnt/windir
# smbmount //Windows/Dir /mnt/windir -o "guest,uid=root,gid=root,fmask=700,dmask=700"
  Windows は Windows 機の名前 (IP アドレスでも可)
  Dir は公開するディレクトリ名 (Windows 機側で共有設定がしてあること)
  uid=root,gid=root は Linux にマウントするときの都合です。Windows には影響がありません。
です。(ユーザ名、パスワードを指定するほうが望ましいが、ここでは省略しています)
起動時に有効にするには、/etc/fstab に
| 
//Windows/Dir	/mnt/windir	smbfs	guest,uid=root,gid=root,fmask=700,dmask=700 0 0
 | 
を追加します。
samba の応用    (Windows だけでやろうとすると、かなり複雑な設定が必要ですが、samba だと簡単)
このようなネットワークを構築した場合
A 〜 F の端末から Samba の共有ディレクトリを使うことが出来ます。
※ samba に複数の IP アドレスを付加する以外、特殊な設定は不要です。
さらに smbmount を使用することにより、samba の共有を通して
・C の共有ディレクトリを D 〜 F の端末から
・F の共有ディレクトリを A 〜 C の端末から
それぞれ使うことが出来ます。
| |   |  | F を smbmount し、A,B,C から利用 | 
 | |   |  | C を smbmount し、D,E,F から利用 | 
 | 
・smbclient を使った印刷 (Windows の共有プリンタを Linux から印刷 -1-)
$ smbclient //NetBiosName/PrinterName Password -U UserName
smb: \> translate         CR を CRLF に変換する指定
smb: \> print sample.txt
smb: \> quit
↑を一度にやるとこう↓なる。
$ cat sample.txt | ( echo translate ; echo "print -" ; cat ) | smbclient //NetBiosName/PrinterName Password -U UserName
※ "print -" は標準入力を印刷する指定。cat でそれ (標準入力) を送り込んでいる。
・lpd から smbprint を使った印刷 (Windows の共有プリンタを Linux から印刷 -2-)
$ su
# mkdir -p /var/spool/lpd/PrinterName
# vi /etc/printcap
| PrinterName:\ # Spool Drectory
   :sd=/var/spool/lpd/PrinterName:\
 # MaXmum file size (none)
   :mx#0:\
 # Supress burst Header (no)
   :sh:\
 # lp output device
   :lp=/dev/null:\
 # Input Filter
   :if=/usr/local/samba/bin/smbprint:
 
 | 
# vi /usr/local/samba/bin/smbprint
| #!/bin/sh 
 # This script is an input filter for printcap printing on a unix machine. It
 # uses the smbclient program to print the file to the specified smb-based
 # server and service.
 # For example you could have a printcap entry like this
 #
 # smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
 #
 # which would create a unix printer called "smb" that will print via this
 # script. You will need to create the spool directory /usr/spool/smb with
 # appropriate permissions and ownerships for your system.
 
 # Set these to the server and service you wish to print to
 # In this example I have a WfWg PC called "lapland" that has a printer
 # exported called "printer" with no password.
 
 #
 # Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton)
 # so that the server, service, and password can be read from
 # a /var/spool/lpd/PRINTNAME/.config file.
 #
 # In order for this to work the /etc/printcap entry must include an
 # accounting file (af=...):
 #
 #   cdcolour:\
 #       :cm=CD IBM Colorjet on 6th:\
 #       :sd=/var/spool/lpd/cdcolour:\
 #       :af=/var/spool/lpd/cdcolour/acct:\
 #       :if=/usr/local/etc/smbprint:\
 #       :mx=0:\
 #       :lp=/dev/null:
 #
 # The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
 #   server=PC_SERVER
 #   service=PR_SHARENAME
 #   password="password"
 #
 # E.g.
 #   server=PAULS_PC
 #   service=CJET_371
 #   password=""
 
 #
 # Debugging log file, change to /dev/null if you like.
 #
 logfile=/tmp/smb-print.log  初めて動作させるときはログを出しましょう
 #logfile=/dev/null
 
 
 #
 # The last parameter to the filter is the accounting file name.
 #   Extract the directory name from the file name.
 #   Concat this with /.config to get the config file.
 #
 eval acct_file=\${$#}
 spool_dir=`dirname $acct_file`
 config_file=$spool_dir/.config
 
 # Should read the following variables set in the config file:
 #   server
 #   service
 #   password
 eval `cat $config_file`
 
 #
 # Some debugging help, change the >> to > if you want to same space.
 #
 echo "server $server, service $service, user $user" >> $logfile
 
 (
 # NOTE You may wish to add the line `echo translate' if you want automatic
 # CR/LF translation when printing.
 #       echo translate
 echo "print -"
 cat
 ) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $user -N -P >> $logfile
 
 | 
# mkdir -p /var/spool/lpd/PrinterName
# chmod 0700 /var/spool/lpd/PrinterName
# vi /var/spool/lpd/PrinterName/.config
| server=NetBiosName service=PrinterName
 password="Password"
 user=UserName
 
 | 
# /etc/rc.d/init.d/lpd start     lpd を起動
・samba の共有プリンタを Windows から印刷 (Windows の共有プリンタを Linux から印刷 -3-)
# mkdir -p /usr/local/PrinterName.q     samba が lpd に渡すファイル置き場を作成
# chmod 777 /usr/local/PrinterName.q    本当はグループ制御したいが、トラブルの元になるのでやむなく 777 にする
# vi /usr/local/samba/lib/smb.conf
| [Printer Name]                 Windows に見せるプリンタ名 (12 文字以内が吉) comment = PrintersComment  Windows でマウスを合わせた時に表示するコメント
 path = /var/spool/PrinterName.q
 print command = /usr/bin/lpr -r -PPrintCapName %s     /etc/printcap で定義したプリンタ名
 browseable    = yes
 public        = yes
 guest ok      = no
 writable      = no
 printable     = yes
 
 | 
# /etc/rc.d/init.d/smb restart       samba の再起動