顯示具有 samba 標籤的文章。 顯示所有文章
顯示具有 samba 標籤的文章。 顯示所有文章

星期五, 8月 17, 2007

samba使用tdb database file儲存重要資訊

在samba中,使用到許多tdb的檔案儲存系統的一些重要資訊或是runtime資訊。這些檔案會方在兩個地方,可以透過下列方法知道兩個放置tdb database file的位置,首先是samba的一些機密資訊:

smbd -b |grep PRIVATE_DIR

這些tdb database file最好定期備份,以便在系統運作出現錯誤時可以進行回復,samba套件提供了一個工具[wiki:tdbbackup tdbbackup]可以幫助我們備份這些檔案。這些檔案在samba的文件稱為presistent TDB file。

另外,samba在執行時期的資訊放在:

smbd -b|grep LOCKDIR

這些檔案在samba文件稱為temporary TDB file。

以下分別列出presistent TDB file以及temporary TDB file的名稱與功能:
  • Presistent TDB file
    • account_policy: Samba/NT account policy settings, includes password expiration settings.
    • group_mapping: apping table from Windows groups/SID to UNIX groups.
    • ntdrivers: Stores per-printer installed driver information.
    • ntforms: Stores per-printer installed forms information.
    • ntprinters: Stores the per-printer devmode configuration settings.
    • passdb: Exists only when the tdbsam passwd backend is used. This file stores the SambaSAMAccount information. Note: This file requires that user POSIX account information is availble from either the /etc/passwd file, or from an alternative system source.
    • registry: Read-only Samba database of a Windows registry skeleton that provides support for exporting various database tables via the winreg RPCs.
    • secrets: This file stores the Workgroup/Domain/Machine SID, the LDAP directory update password, and a further collection of critical environmental data that is necessary for Samba to operate correctly. This file contains very sensitive information that must be protected. It is stored in the PRIVARE_DIR directory.
    • share_info: Stores per-share ACL information
    • winbindd_idmap: Winbindd's local IDMAP database.
  • Temporal TDB file
    • brlock: Byte-range locking information. 不需要備份
    • connections: A temporary cache for current connection information used to enforce max connections. 不需要備份
    • eventlog/*tdb: Records of eventlog entries. In most circumstances this is just a cache of system logs. 不需要備份
    • gencache: Generic caching database for dead WINS servers and trusted domain data. 不需要備份
    • login_cache: A temporary cache for login information, in particular bad password attempts. 不需要備份
    • messages: Temporary storage of messages being processed by smbd. 不需要備份
    • netsamlogon_cache: Caches user net_info_3 structure data from net_samlogon requests (as a domain member). 不需要備份
    • perfmon/*.tdb: Performance counter information. 不需要備份
    • printing/*.tdb: Cached output from lpq command created on a per-print-service basis. 不需要備份
    • schannel_store: A confidential file, stored in the PRIVATE_DIR, containing crytographic connection information so that clients that have temporarily disconnected can reconnect without needing to renegotiate the connection setup process. 不需要備份
    • sessionid: Temporary cache for miscellaneous session information and for utmp handling. 不需要備份
    • unexpected: Stores packets received for which no process is actively listening. 不需要備份
    • winbindd_cache: Cache of Identity information received from an NT4 domain or from ADS. Includes user lists, etc. 需要備份

星期四, 8月 09, 2007

trace samba source code 心得筆記 6

在smb.conf設定檔中,可以分成多個service。每個service可以擁有各自的設定。其中有一個設定稱為vfs objects,此設定是用來套用stackable VFS功能到該service上。
所謂的stackable VFS功能指的是在進行檔案存取時,samba額外對該service進行的處理動作,這是在samba的第3版之後才加入的新功能。你可以在一個service上套用多個vfs modules,samba混根據smb.conf設定檔案所列出的先後順序,依序套用所列的vfs module。在samba套件中也有幾個vfs objects可以使用,這些module放在samba安裝目錄下的lib目錄中(/usr/lib/samba/vfs或是/usr/local/samba/lib/vfs):

audit
這個vfs module可以將存取檔案的紀錄寫到syslog中,

default_quota
default_quota可以設定user或是group的quota。

extd_audit
這個module原則上與audit一樣,除了將檔案存取紀錄寫到syslog中,還會寫一份到samba本身的log檔。

recycle
這個module是模擬Windows上的資源回收筒的功能,也就是刪除sambaer server上的檔案時,samba會將你刪除的檔案搬移到一個隱藏目錄中,預設是.recycle目錄,不過也可以透過repository選項設定要當作資源回收筒的路徑。

有些vfs module可能很簡單,有些則有選項可供設定。其設定的語法是以
module: option = value
的格式來指定所要設定的選項,例如指定資源回收筒的路徑為/tmp:

[myshare]
vfs objects = recycle
recycle: repository = /tmp

如果選項的設定值不只一個,而是有多個所形成的list,則每個設定值之間用應逗號隔開。例如:
[myshare]
vfs objects = access_control
access_control: allow_host = pc1
access_control: deny_host = pc2, pc3

當你自行開發vfs module時,samba已經有提供處理上述vfs module選項的相關function。在 loadparm.c檔案中,有許多有關選項處理的function。其中

const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def)
以及
const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def)

是兩個可以用來得到service的選項設定值或設定列表的function。其中,
snum是連線id,可以透過SNUM(conn)取得。
type就是vfs module的名稱,例如:recycle, access_control。
option是指定要讀取的選項名稱,例如:repository, allow_host, deny_host。
def是預設值,也就是在smb.conf中沒有針對該選項進行設定時,vfs module預設要採用的設定值。

而lp_parm_const_string()與lp_parm_string_list()兩個差別在於,不管設定值的個數有幾個,t_string()會將所有選項(包含分隔選項的逗號)當作一個字串傳回,而lp_parm_string_list()則會將每個選項以一個字串儲存,所以會傳回一個字串陣列。例如:
lp_parm_const_string(SNUM(conn), "access_control", "allow_host", NULL) => "pc1"
lp_parm_const_string(SNUM(conn), "access_control", "deny_host", NULL) => "pc2, pc3"
lp_parm_string_list(SNUM(conn), "access_control", "allow_host", NULL) => {"pc1"}
lp_parm_tring_list(SNUM(conn), "access_control", "deny_host", NULL) => {"pc2", "pc3"}

星期三, 8月 08, 2007

trace samba source code 心得筆記 5

samba 的設定檔smb.conf基本上可以分成幾個部份,每個部份都是由中括號[]為開頭,負責定義一個samba所提供的service,例如:[global]、[printers]、[homes]等等。
其中[global]這個service是比較特殊的,其定義了套用於整個samba server的種種設定。由於samb a server的設定選項非常繁多,所以如果沒有寫在smb.conf檔案中,則該選項會採用samba的預設值。

要看目前samba的系統設定,可以輸入

testparm

觀看系統設定概要。
若要得到完整的系統設定,可以輸入

testparm -v

smb.conf所使用的設定格式也很簡單,採用以 = 隔開的key/value pair方式。若在一行設定前面加上 ; 的話,則samba server會將這一行視為註解。
以下為一簡單的設定檔範例:

[global]
netbios name = mypc
workgroup = mygroup

[homes]
read only = No
browseable = No
create mask = 0600
directory mask = 0700


[usb_storage]
path = /media/disk
admin users = jacky
write list = jacky
read only = No

星期二, 8月 07, 2007

trace samba source code 心得筆記 4

用windows client在測試與samba server連線時,發現windows會將之前的資訊cache起來,所以如果是DFS referral則不會再重新發TRANSACT2_GET_DFS_REFERRAL請求,跟samba server要檔案真正所在位置的資訊,而是直接利用其cache的資訊對檔案真正所在的samba server發出request。

trace samba source code 心得筆記 3

在smaba source code中有許多debug message可供除錯時使用,並且將debug message分成0~10等級。
在samba設定檔smb.conf中,有一個log level選項,主要是用來控制debug message的列印等級。其設定方式為

log level = n

n即為samba執行時的global debug等級。
此外,samba執行時的等級可以根據不同的class給予不同的等級,方便我們進行除錯。其設定方式也是透過log level的選項,

log level = global_level class1:class_level1 class2:class_level2 ...

如此,DEBUG()就可以根據global debug level以及class debug level,決定是否要輸出debug訊息。

目前在samba 3.0.24版中,根據debug.h檔案所列共有下列幾種:
TDB、PRINTDRIVERS、LANMAN、SMB、RPC_PARSE、RPC_SRV、RPC_CLI、PASSDB、SAM、AUTH、WINBIND、VFS、IDMAP、QUOTA、ACLS、LOCKING、MSDFS、DMAPI。

但是,根據實測結果,目前PRINTDRIVERS、LANMAN、SMB、SAM並不支援class level debugging。

trace samba source code 心得筆記 2

要追蹤samba的程式流程或是要找出錯誤發生的原因,可以利用

smbd -i -dn > debug.txt

將samba以interactive模式執行,如此smaba只會有一個process而不會額外fork出其他process。並且將執行過程的debug訊息導到debug.txt檔案,n的數值為0到10,數值越大debug訊息越詳細。

trace samba source cdoe 心得筆記 1

解開samba source code package後,在examples/VFS目錄中,有提供三個檔案
configure.in
install-sh
makefile.in
方便programmer開發自己的samba VFS module。
只要系統安裝了autoconf package後,並將上述三個檔案以及所開發的samba VFS module的原始程式放在同一個目錄,接著在command line輸入autoconf,系統就會自動產生出相對應的configure script。
接下來只要再輸入

./configure --with-samba-source=samba source code所在目錄路徑

例如:./configure --with-samba-source=/home/zhuang/samba-3.0.24/source
就可以自動產生出編譯samba VFS module的Makefile了。

自動掛載網路芳鄰的目錄

在Linux中,要自動掛載網路芳鄰的目錄,可以利用/etc/fstab來達到此功能。
在/etc/fstab檔案中,設定一下要掛載的網路芳鄰的路徑、掛載點以及一些帳號密碼等就可以了。格式為:

網路芳鄰路徑 本機掛載點 smbfs 帳號密碼及權限設定

可參考下例:

//pc1/movie /media/movie smbfs credentials=/etc/credentials.txt,iocharset=utf8,codepage=cp950,rw,uid=1000,gid=1000

第一部份:
//pc1/movie就是在網路芳鄰裡,電腦名稱為pc1所分享出來的目錄movie

第二部分:
/media/movie就是要將目錄掛載到此路徑,方便之後使用

第三部分:
smbfs就是用來怪在網路芳鄰的檔案系統名稱

第四部分:
這部分的設定會因為所分享的電腦設定不同而有所不同。但大致上需要
credentials是設定連線到pc1所需的帳號密碼資訊是存放在檔案/etc/credentials.txt中,檔案內容格式為
username=使用者名稱
password=密碼

接下來的iocharset以及codepage則是分別設定在Linux上以及Windows上所使用的語言設定。這部分則必須根據電腦所使用的設定跟著改變,以免檔案名稱呈現亂碼。

最後的rw,uid-1000,gid=1000則是將掛載進來的目錄設定為可讀寫,並且將掛載點的使用者與群組設定為某個使用者與群組(在這裡均為1000)。