13.2. samba - 網路芳鄰,資源分享程式

Last Update: 2003年 1月25日 周六 12時24分45秒 CST

samba 是一個能把您的 Unix 電腦和其他 MS Windows 電腦相互共享資源的軟體。

samba 提供有關於資源分享的三個功能。 包括 smbd,執行了它,就可以使這台 Unix 能夠共享資源給其他的電腦,而 smbclient 就是讓這台 Unix 去存取其他電腦的資源了,最後一個 smbmount,則是類似 MS Windwos 下『網路磁碟機』的功能,可以讓您把其他電腦的資源 掛在自己的檔案系統下。

安裝 net/samba

設定檔修改 /usr/local/etc/smb.conf, 才算完整支援中文,在 [global] 中找到 for Traditional Chinese Users 的設定區,將 client code page=950 前面的 ; 拿掉 ,不要動 coding system=cap,並在後面加上 valid chars = 0xb9

[global]
# for Traditional Chinese Users
client code page=950
; coding system=cap
valid chars = 0xb9

關於 valid chars = 0xb9,這個好像是很久前遇過的一個小問題, 如果您在 smb.conf 中設定 "workgroup = 電腦", 這時候用網芳去瀏覽會發現出現的是 "鄒腦", 電=0xb971 鄒=0xb951 q=0x71 Q=0x51, samba 在遇到 0xb9 後,自動把下一個字元轉成大寫了, 如果設定 valid chars = 0xb9 就會正常。

而這邊會出現 coding system=cap 則是天大的錯誤, 十分容易誤導使用者,以下摘錄 smb.conf.5

coding system (G)

  This parameter is used to determine how incoming Shift-JIS Japanese
  characters are mapped from the incoming client code page used by the
  client, into file names in the UNIX filesystem. Only useful if client
  code page is set to 932 (Japanese Shift-JIS). The options are :

      * CAP - Convert an incoming Shift-JIS character to the 3 byte
        hex representation used by the Columbia AppleTalk Program (CAP),
    i.e. :AB. This is used for compatibility between Samba and CAP.

Default: coding system = <empty value>

在網芳上的名稱通常都要自己加上 netbios name = Elf,其中的 Elf 就是網芳上的名稱。

另一個 samba 的中文問題是 smb.conf 不能設定某些字為 Section,例如:

;[設計與科技] 
[計與科技] 
  comment= 設計與科技 
  browseable = yes 
  path = /home/design 
  read only = yes 
  guest ok = yes

因為 "設" 的第二個字元是 "]" 與 samba 的 Section 字元衝突, 所以解決的方法就是去修改 source/param/param.c

--- params.c.orig  Mon May 12 19:46:29 2003
+++ params.c    Mon May 12 20:37:24 2003
@@ -297,6 +297,15 @@
           i = end + 1;
           c = EatWhitespace( InFile );
           }
+        else if ( c > 0x80 )
+          {
+          bufr[i++] = c;
+          end = i;
+          c = mygetc( InFile );
+          bufr[i++] = c;
+          end = i;
+          c = mygetc( InFile );
+          }
         else                            /* All others copy verbatim.        */
           {
           bufr[i++] = c;

samba 大部分的程式都有中文問題,需要更多人去 patch, 像是 smbclient 去看 MicroSoft 的中文資料夾會是底線(_)。

Note: samba 是用TCP/IP通訊協定,所以在 MS Windows端的電腦也要裝上TCP/IP協定,不然就不能用囉。

而 samba 3.x 的部分可以透過 samba-devel 來安裝, 但是預設沒有支援 I18N,所以必須透過以下的方式來安裝:

# cd /usr/ports/net/samba-devel
# make -DWITH_LIBICONV all install clean
mangling method = hash
unicode = on
dos charset = UCS-2LE
unix charset = CP950
display charset = CP950

WWW: http://www.samba.org/

Online Book - Using Samba: http://www.oreilly.com/catalog/samba/

如果要方便的使用網芳上的東西,就要裝 smbfs 這個軟體,在 net/smbfs 底下,裝好後還需要重編 kernel, 將 options LIBMCHAINoptions LIBICONV 編進去才行。 4.5-RELEASE 之後已經不需要安裝 smbfs 和重新編譯 kernel 了。

然後只要用 smbutil view //user@host 找到要的分享名稱, 再用 mount_smbfs -I host-ip //user@host/share /smb/node 就可以方便的使用網芳囉。目前中文的 host 或是 share 會有問題。