Samba3ホームディレクトリの設定

■ホームディレクトリの共有の設定
 path行を追加

$ testparm -s 2>&1 | grep -A 6 "^\[homes\]"
[homes]
	comment = Home Directories
	path = /home/%U
	valid users = %S
	create mask = 0700
	directory mask = 0700
	browseable = No

$ sudo smbcontrol smbd reload-config

■[「valid user」で他のユーザからのアクセスを禁止します。

$ grep -B 6 "valid user" /etc/samba/smb.conf 

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only "username" can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S

■接続数の上限をセクションごとに設定。

$ sudo testparm -s -v 2>&1 | grep "connections"
	winbind max domain connections = 1
	max connections = 0

$ man smb.conf | grep -A 14 "max connections ("
       max connections (S)

           This option allows the number of simultaneous connections to a
           service to be limited. If max connections is greater than 0 then
           connections will be refused if this number of connections to the
           service are already open. A value of zero mean an unlimited number
           of connections may be made.

           Record lock files are used to implement this feature. The lock
           files will be stored in the directory specified by the lock
           directory option.

           Default: max connections = 0

           Example: max connections = 10

$ testparm -s 2>&1 | grep -A 6 "^\[homes\]"
[homes]
	comment = Home Directories
	path = /home/%U
	valid users = %S
	create mask = 0700
	directory mask = 0700
	max connections = 10

■IPC$についての設定が無いので追加。
 IP制限が出来ます。

$ man smb.conf | grep -A 15 "hosts deny ("
       hosts deny (S)

           The opposite of hosts allow - hosts listed here are NOT permitted
           access to services unless the specific services have their own
           lists to override this one. Where the lists conflict, the allow
           list takes precedence.

           In the event that it is necessary to deny all by default, use the
           keyword ALL (or the netmask 0.0.0.0/0) and then explicitly specify
           to the hosts allow = hosts allow parameter those hosts that should
           be permitted access.

           Default: hosts deny =  # none (i.e., no hosts specifically
           excluded)

           Example: hosts deny = 150.203.4. badhost.mynet.edu.au

$ grep -A 3 "^\[ipc" /etc/samba/smb.conf 
[ipc$]
   hosts allow = 192.168.164.0/24 192.168.1.0/24 127.0.0.1/32 EXCEPT 192.168.164.1 192.168.1.1
   hosts deny = ALL

$ testparm -s 2>&1 | grep -A 4 "^\[ipc"
[ipc$]
	hosts allow = 192.168.164.0/24, 192.168.1.0/24, 127.0.0.1/32, EXCEPT, 192.168.164.1, 192.168.1.1
	hosts deny = ALL
	available = No

$ man smb.conf | grep -A 5 "available ("
       available (S)

           This parameter lets you "turn off" a service. If available = no,
           then ALL attempts to connect to the service will fail. Such
           failures are logged.

■ユーザ制限、グループ制限
 グループの場合は、「@」を前につけます。
 許可と拒否が設定出来、拒否が優先されます。

$ testparm -s -v 2>&1 | grep "valid\|^\["
[global]
	invalid users = 
	valid users = 
[ipc$]
[homes]
	valid users = %S
[printers]
[print$]

■ファイルの読み取り禁止属性の設定
 読み取らせたくないなら置かない方がベターです。

 「delete veto files = yes」で読み取りは出来ないけど、
 削除は出来るという設定が可能です。

$ testparm -s -v 2>&1 | grep "veto\|^\["
[global]
	delete veto files = No
	veto files = 
	veto oplock files = 
[ipc$]
[homes]
[printers]
[print$]

■ファイルの隠し属性の設定
 ファイルに対しての設定、ディレクトリでは無い点に注意。

 「hide dot files」は非表示となる、UNIXの隠しファイル属性の設定
 「hide special files」はsocket、dev、fifo等を隠すかどうかの設定

$ testparm -s -v 2>&1 | grep "hide\|^\["
[global]
	hide dot files = Yes
	hide special files = No
	hide unreadable = No
	hide unwriteable files = No
	hide files = 
[ipc$]
[homes]
[printers]
[print$]

■Windowsのファイル属性の保持
 デフォルトでは。
 アーカイブ属性は引き継ぐが、隠し属性、システム属性は引き継がない。
 読み取り専用属性は所有者の書き込み権限と、その他ユーザの為の実行権を使用。

$ testparm -s -v 2>&1 | grep "map [ahs][iry]\|store dos attributes"
	map archive = Yes
	map hidden = No
	map system = No
	store dos attributes = No

■FAT互換の時刻精度の設定
 MS nmake のバグ対策に「fake directory create times = yes」とする。
 Visual Studio系のコンパイラを使うファイルがある場合のみ。

 ファイルの時間を2秒単位に四捨五入する「dos filetime resolution = yes」。
 NTFS ファイルは100 ナノ秒単位、 FAT ファイルは偶数秒単位のため。

$ testparm -s -v 2>&1 | grep "dos filetime\|fake directory create times"
	dos filetimes = Yes
	dos filetime resolution = No
	fake directory create times = No

■参考

 [NT] NTFSからFATへのファイルのコピー時に日時が変わる
 http://support.microsoft.com/kb/402160/ja

 8. その他の情報
 http://ppona.com/gpl/iodata/usl-5p/USLSRC100/daemon/samba/040924/samba-2.2.11-ja-1.0/docs/ja/htmldocs/using_samba/ch08_01.html

■シンボリックリンクの設定
 共有内はたどれるが、共有外はたどれないのがデフォルト。
 ショートカットではない。

$ testparm -s -v 2>&1 | grep "links"
	allow insecure wide links = No
	wide links = No
	follow symlinks = Yes

■Windowsの属性
 例えば、「A  SHR」はシステムドライブ直下だとよくあるファイル。

> attrib /?
ファイル属性を表示または変更します。

ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [ドライブ:][パス][ファイル名]
       [/S [/D]]

  +   属性を設定します。
  -   属性を解除します。
  R   読み取り専用属性。
  A   アーカイブ属性。
  S   システム ファイル属性。
  H   隠しファイル属性。
  [ドライブ:][パス][ファイル名]
       attrib で処理するファイルまたはフォルダを指定します。
  /S  現在のフォルダとすべてのサブフォルダの一致するファイルを
      処理します。
  /D  フォルダも処理します。


> attrib c:\boot*
A  SH      C:\boot.ini
A  SHR     C:\bootfont.bin

> dir /? | find "属性"
DIR [ドライブ:][パス][ファイル名] [/A[[:]属性]] [/B] [/C] [/D] [/L] [/N]
  /A          指定された属性のファイルを表示します。
  属性         D  ディレクトリ                R  読み取り専用
               S  システム ファイル           -  その属性以外

■ローカルじゃないって?共有でも使えますし、属性も存在します。

> attrib \\lpic3\labunix\.vimrc
    H      \\lpic3\labunix\.vimrc

■最大ユーザ数など。

> net share IPC$
共有名             IPC$
パス
注釈               Remote IPC
最大ユーザー数     制限なし
ユーザー
キャッシュ         ドキュメントの手動キャッシュ
コマンドは正常に終了しました。

> net share print$
共有名             print$
パス               C:\WINDOWS\system32\spool\drivers
注釈               プリンタ ドライバ
最大ユーザー数     制限なし
ユーザー
キャッシュ         ドキュメントの手動キャッシュ
コマンドは正常に終了しました。