2006/04/11

What Is A Permission, by Keith Brown

http://www.pluralsight.com/wiki/default.aspx/Keith.GuideBook.WhatIsAPermission


Throughout my discussions of access control and ACLs in this book, I will often talk about permissions as numbers. For example, I might talk about 0x1FF as being a set of permissions, or granting "permission 1 and 2" to someone. What I'm doing is being very generic and using literal access masks or numbered permissions. I'm not specifying just what types of objects I'm talking about; I'm just talking about how access control works for all different types of objects.


So let's make this concrete and look at some examples of permissions for some specific types of objects in Windows. Let's start with, oh, a registry key. Peeking at a Win32 header file called winnt.h shows us the following1:

 // excerpt from winnt.h
#define KEY_QUERY_VALUE (0x00000001)
#define KEY_SET_VALUE (0x00000002)
#define KEY_CREATE_SUB_KEY (0x00000004)
#define KEY_ENUMERATE_SUB_KEYS (0x00000008)
#define KEY_NOTIFY (0x00000010)
#define KEY_CREATE_LINK (0x00000020)

Let's also look at the permission definitions for a thread:

 // excerpt from winnt.h
#define THREAD_TERMINATE (0x00000001)
#define THREAD_SUSPEND_RESUME (0x00000002)
#define THREAD_GET_CONTEXT (0x00000008)
#define THREAD_SET_CONTEXT (0x00000010)
#define THREAD_SET_INFORMATION (0x00000020)
#define THREAD_QUERY_INFORMATION (0x00000040)
#define THREAD_SET_THREAD_TOKEN (0x00000080)
#define THREAD_IMPERSONATE (0x00000100)
#define THREAD_DIRECT_IMPERSONATION (0x00000200)

If you wanted to grant Alice permission to create a new registry key under some existing key, you'd edit the existing key's DACL and add an ACE ( What Is An Access Control List ) that grants Alice the KEY_CREATE_SUB_KEY permission. Pretty simple. But look at those permissions again and tell me how you'd grant Alice the permission to delete the key she just created!


That's right, the registry subsystem doesn't bother defining a permission for deleting a key. That's because it's such a common permission (most secure objects can be deleted) that it's included as part of a standard set of permissions that are common across all types of objects. Here are the standard permissions that are allowed to be put in an ACL:

 // excerpt from winnt.h
#define DELETE (0x00010000L)
#define READ_CONTROL (0x00020000L)
#define WRITE_DAC (0x00040000L)
#define WRITE_OWNER (0x00080000L)
#define SYNCHRONIZE (0x00100000L)

Compare the numerical layout of the standard permissions to the specific permissions defined for registry keys. Note how the standard permissions all fall in the upper word of the 32 bit mask, while the specific permissions are defined in the lower word. Notice the same technique is used for the thread permissions. You see, each class of object is allowed to define up to 16 specific permissions, and they must all be in that lower word, so they don't conflict with permissions Microsoft has already defined for all objects, such as the standard permissions shown above.


The standard permissions are really quite straightforward. Let me briefly explain what they mean. READ_CONTROL ("Read Permissions") controls whether you can read the owner and DACL in the object's security descriptor. If you don't have this permission, you're not even allowed to see what permissions you do have! WRITE_DAC ("Write Permissions") and WRITE_OWNER ("Take Ownership") say whether you're allowed to change the object's DACL or take ownership of the object by changing the owner SID to be your own SID (for more detail, see What Is Ownership ). SYNCHRONIZE says whether you can wait on an object (this is most often used with synchronization objects such as a mutex or semaphore). By limiting SYNCHRONIZE access, you can prevent an untrusted user from grabbing a mutex that your program depends on and deadlocking you. And DELETE is pretty obvious.


Let's say you want to grant Alice permission to read a registry key. It'd make sense to grant her a combination of the following:



  • KEY_QUERY_VALUE
  • KEY_ENUMERATE_SUB_KEYS
  • KEY_NOTIFY
  • READ_CONTROL

If you binary OR these values together, you'll end up with 0x00020019. This would be the access mask you'd put into the ACE ( What Is An Access Control List ) to grant Alice read access to the key. For an example of code that modifies an ACL programmatically, check out How To Program ACLs .


Look at the following access mask and try to figure out what it means: 0x00130000. The answer is in the following footnote2. Now try to decode this one: 0x00000001. Surely this one is easier! Oh wait, I didn't tell you what type of object we're talking about. I mean, if it were a registry key, this would be KEY_QUERY_VALUE -a fairly benign permission to grant, at least compared to THREAD_TERMINATE! You see, given a random permission mask, you really can't tell what it means unless you know the type of object to which it applies, unless it simply consists of standard permissions, which are defined centrally for all objects.


With this in mind, think about a permission mask that would be generic enough to grant read permission to any type of object in the system, including registry keys and threads. For a registry key, we'd want 0x00020019, as we calculated earlier for Alice. But for a thread, it'd be 0x00020048. That's a very different mask. As you can see, because no two types of objects can be expected to have the same sorts of permissions, at first glance it'd be impossible to treat objects polymorphically with respect to permissions. But if you look a bit further into winnt.h, you'll find the following rather interesting definitions:

 // excerpt from winnt.h
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
#define GENERIC_EXECUTE (0x20000000L)
#define GENERIC_ALL (0x10000000L)

What do you think would happen if you added an ACE to a registry key's DACL that granted Alice GENERIC_READ? Think about it for a moment. If you guessed that the system would convert the access mask from 0x80000000 to 0x00020019 before storing the new DACL in the metadata for the registry key, then you'd be correct. You see, each class of object in Windows defines a mapping from these four generic permissions onto standard and specific permissions. This allows us to make statements like, "By default, I'd like to grant full control to SYSTEM and myself for any object I create. Oh and I'd also like Alice to have read access as well." Here's a text representation of just such a DACL:

 grant SYSTEM 0x10000000
grant Keith 0x10000000
grant Alice 0x80000000

It turns out that Windows makes a statement like this for every process! You see, inside the token ( What Is A Token ) is a default owner and DACL that are used whenever you create new objects3. For example, if you were to create a thread, how would the system know what the DACL for that thread should look like? Well, it looks at this default DACL that's tucked away inside your token.


Here's what a default DACL would look like for me on my laptop4:

 grant SYSTEM 0x10000000
grant Keith 0x10000000

So by default, any new threads that I create, or semaphores, shared memory sections and so on, start life with DACLs that specifically grant my account and SYSTEM full control. Nobody else will be able to touch the objects I create, barring specially privileged users such as administrators ( What Is A Privilege ). Note that hierarchical systems like the file system and registry instead use ACL inheritance to come up with a default DACL; this ensures that permissions remain consistent through the branches of the hierarchy. See What Is ACL Inheritance for the details.


The default DACL is one of the few mutable bits of data in a token. In most cases you shouldn't ever need to change this DACL, as it's already about as tightly secured as it can be. If you ever find the need to adjust it, you'll want to look at the Win32 function SetTokenInformation.




  1. I've omitted three permissions that are specific to 64-bit Windows for brevity.
  2. DELETE, READ_CONTROL, and SYNCHRONIZE.
  3. By "objects" I mean any object that has a security descriptor ( What Is A Security Descriptor ), such as a process, thread, mutex, etc.
  4. If you want to do this experiment, you should download the Token Dump component from my website. I don't know of any built-in tool that shows this information.

2006/04/06

美國富豪唐納川普一手策劃熱門的真人實境秀 - Apprentice (誰是接班人)

2004年美國最熱門的真人實境秀『誰是接班人』,是由經歷金融風暴又鹹魚翻身的美國富豪唐納川普所一手策劃的全新節目。在節目中,川普找來十六位參賽者,每週進行比賽。題目由全美五百大企業提供,包括從路邊賣檸檬汁到廣告企劃,非常多元。

比賽的方式十分簡單,十六位參賽者分成兩組,每星期要想辦法解決川普所出的難題,輸的一方要淘汰一名組員。最後勝利者,可以獲得任職於川普旗下公司的機會,而且年薪高達六位數美金。

繼第一季創造了"You're fired."的名言之後,川普在第二季請出財富雜誌前五百大企業,給予參賽者比第一季更嚴酷、更高難度的行銷挑戰,包括為年營業額上千億的電子公司上電視現場推銷產品、幫知名牙膏大廠在一周內開發出新口味、建立行銷通路等,更多想像不到的商場致勝秘訣從第二季一一登場。這次總計十八人參賽,有長春藤名校的高材生,也有連高中都沒畢業的小老闆。他們每星期想辦法解決川普所出的難題,輸的一方要淘汰一名組員。最後勝利者,同樣可以獲得負責川普旗下公司的機會,年薪高達六位數美金。這些參賽者再度引爆精采的職場爭鬥戰!

Apprentice Theme: "for the love of money"-The O'Jays

The Apprentice Rules: http://www.theapprenticerules.com/

The Apprentice Blog: http://www.theapprenticeblog.com/

Official site for season 2: http://www.nbc.com/nbc/The_Apprentice_2

Official site for season 3: http://www.nbc.com/nbc/The_Apprentice_3

Official site for season 4: http://www.nbc.com/The_Apprentice_4

2006/03/13

Problem:: VS2005 - The current identity does not have write access to temporary file...

I finally powered up again with my newly purchased dual-core laptop, which also enables me to refresh software installations that I've been wanting to do for a long time.  As I'm putting things back together, I kept running into this error with my projects:

The current identity (xxx\ASPNET) does not have write access to 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Here's a quick fix to the problem (do this only to your dev box):

1. From the framework directory (Usually c:\windows\microsoft.net\framework\v2.0.50727\Config), modify machine.config:

<processModel userName="SYSTEM" password="autoGenerated"/>

2. Execute this command:


> aspnet_regiis -ga "ASPNET"

By applying MS's Web updates (often times including security patches), or putting you box into domain (which I am), the security constriant of your windows install drive got stricted.  If you read the prompt from aspnet_regiis carefully, switch -ga is granting the daemon user access to the IIS metabsae and other directories used by ASP.NET, which is exactly what I'm looking to do..

Further Reading:
Microsoft's KB: http://support.microsoft.com/kb/315158/

2006/02/15

Subversion for Windows 安裝指南

PDF download: Subversion for Windows 安装指南

this post is an updated version from Huanlin Tsai's revision 1.41 (http://huanlin.dyndns.org:8080/techshare/articles/2004061303/svn_install.htm)

摘要: 版本控制在軟體工程的領域中隸屬於軟體建構管理(Configuration Management)的範疇,是軟體開發流程當中相當基本且重要的一環,因此版本控制系統可說是開發人員必備的工具之一。本文將介紹一個開放原始碼的版本控制系統:Subversion,說明相關工具的安裝步驟,並且透過實例操作示範如何在Visual Studio .NET 2003裡面對專案進行版本管理。

Subversion 是一個自由/開放源碼的版本控制系統,也就是說 Subversion 管理著隨時間改變的檔案,這些檔案放置在一個中央檔案庫(repository) 中,這個檔案庫,很像一個尋常的檔案伺服器,不過它會記住每一次檔案的變動。這樣你就可以把檔案回復到舊的版本,或是瀏覽檔案的變動歷程,許多人會把版本控制系統想像成某種“時光機器”。

本文目的:

  • 在 Windows 2003 Server 上安裝及設定 Subversion,以便於團隊成員透過 Internet 協同開發軟體專案,並有版本控管功能。
  • 在用戶端安裝 Subversion 的 Client-side 工具:TortoiseSVN,可以整合與檔案總管整合在一起,利用 GUI 方式提供了建立檔案庫、以及匯入、匯出等功能。

本文提供一個簡易的安裝指南,說明在 Windows 環境下安裝 Subversion 伺服器的步驟,以及 TortoiseSVN 用戶端工具的安裝步驟。


1. 簡介

Subversion 是一個版本控制系統,它是根據 CVS(Concurrent Versions System)的功能為基礎來設計,但是改進了一些 CVS 的缺點,例如:在CVS中搬移檔案目錄很不方便,Subverion 則連目錄的異動都納入版本管理;此外,它也增加了其他的功能,例如:不可分割的送交(如同資料庫交易的概念,送交多個檔案時,若有任何一個檔案失敗,則這次送交的所有檔案都不會進入檔案庫中)、支援多種網路協定、一致的檔案差異比對(不管什麼檔案類型,均使用二進位差異比對方式)等等。

由於目前手邊查到的 Subversion 文件,主要都是針對 Unix用戶來撰寫,所以這份文件特地針對 Windows環境下安裝 Subversion 的步驟來說明,希望透過這份文件,能夠幫助你很快的把Subversion安裝起來。

在安裝過程中,會需要輸入一些命令列的指令,本文不會詳細解釋某些指令的用途和意義,因此你除了要熟悉 DOS 的基本指令,還應該隨時查閱 Subversion 的電子書(有中文版),以了解 Subverion 命令列工具的使用方法。圖形化介面雖然方便,但是熟悉命令列工具的使用,才能讓你得到完全的自由。

1.1 基本觀念

如果你缺乏版本控制系統的基本觀念,就算能夠順利安裝好 Subversion,可能安裝完成後就不知道下一步怎麼做了。這裡只簡單的提一點必要的基礎觀念,記住你最終還是得閱讀 Subversion 的官方文件。

1.2 作業環境與軟體版本

以下是本文件使用的作業環境與軟體版本

  • Windows 2003 Server with SP1
  • Apache HTTP Server v2.0.55
  • Subversion v1.2.3
  • TortoiseSVN 1.2.6 build 4786
2. 安裝與建立 Subversion 伺服器

請準備一台穩定的機器,作為 Subversion 的伺服器。

2.1 安裝 Apache HTTP Server

http://httpd.apache.org/ 下載 Apache HTTP Server 2.0 版 for Windows 的安裝程式,我下載的檔案是 apache_2.0.50-win32-x86-no_ssl.msi。

下載之後直接安裝,安裝過程很簡單,就不贅述了,但安裝之前請先檢查你的電腦是否有安裝 IIS,由於 Apache 預設使用 80 port,會跟 IIS 的網站衝突,你必須把 IIS 的 Web 站台關閉,再安裝 Apache HTTP Server。

安裝完成以後,開啟瀏覽器,瀏覽網址 http://localhost/ 看看有沒有出現安裝成功的網頁。

2.2 安裝 Subversion

1. http://subversion.tigris.org/下載最新版的 Subversion,你可以下載 .zip 或者打包好的自動安裝程式,我下載的是檔案svn-1.2.3-setup.exe。

2. 下載後直接安裝,安裝過程都是下一步,沒什麼特別的。在此Windows安裝版增加了Apache modules的選項,必要的環境變數都幫你設定好了。

2.2.1 手動安裝Apache modules

以下步驟敘述手動安裝Apache modules的程序(如果你下載的是 .zip 檔,就要自行設定)。
  1. 把 $SVN_Install/bin/目錄下的 mod_dav_svn.so、 mod_authz_svn.so複製到 $Apache2_Install/modules/目錄下。
  2. 把 $SVN_Install/bin/目錄下所有的dll檔複製到 $Apache2_Install/bin/。
  3. 接著用文書編輯器開啟 Apache HTTP Server 的 httpd.conf(在 /conf/ 目錄下),尋找一堆 LoadModule 指令,先找到以下兩行:
    #LoadModule dav_module modules/mod_dav.so #LoadModule
    dav_fs_module modules/mod_dav_fs.so 把前面dav_svn_module的 '#' 字元刪除,然後把下面幾行文字加到這群 LoadModule
    指令的後面: LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module
    modules/mod_authz_svn.so

  4. 重新啟動 Apache HTTP Server。

    問題排除: 如果 Apache HTTP Server 無法啟動,請依下列步驟檢查:
    1. 檢查 Subversion 的路徑是否有在系統的%PATH% 環境變數裡面。
    2. 檢查你加入 httpd.conf 裡的項目是否正確,記住 mod_dav_svn.so 和 mod_authz_svn.so必須在其他 mod_dav*.so 模組之後載入。
    3. 檢查你加入的檔案。若dll檔沒有在正確位置,將無法正常啟動。

2.3 設定 Subversion 檔案庫的路徑

現在要設定Apache http.config檔中 SVN URL 路徑與檔案庫實體路徑的對應關係。對應的方式有兩種,分別是 SVNPath 與 SVNParentPath。

2.3.1 SVNPath

SVNPath 適合用來個別指定檔案庫的路徑,語法是:

DAV svn SVNPath /absolute/path/to/repository

其中 "/svn/repos_name" 就是用戶端存取特定檔案庫的 URI(Uniform Resource Indentifier),SVNPath 後面指定的路徑則是檔案庫的絕對路徑,假設我們的檔案庫實際存放的路徑是 d:\svn\MyProject,並且希望用戶端使用 http://myserver/svn/myprj 的 URL 來存取檔案庫,那麼要加入 httpd.conf 的內容就是:

DAV svn SVNPath d:\svn\MyProject

注意 Location 標籤後面的 /svn/myprj 的第一個斜線不可少!

2.3.2 SVNParentPath

如果你的檔案庫都集中放在某個目錄之下,例如:d:\svn,那你就可以使用 SVNParentPath 的方式指定檔案庫的根路徑,例如:

DAV svn SVNParentPath d:\svn

這表示可以讓任何人都可以透過 http://myserver/svn/<檔案庫名稱> 的方式,存取位於 d:\svn 這個目錄以下的所有檔案庫。也就是說,這個設定動作只需要一次,如果使用SVNPath,你必須為各個檔案庫分別指定對應的路徑。

以上兩種設定方式都可以,方便起見,這裡我用 SVNParentPath 來統一指定所有檔案庫的父層 URL 路徑。

將 的設定加到 Apache HTTP Server 的 httpd.conf 檔尾就行了。接著便可以開始建立檔案庫。


2.4 建立Subversion檔案庫

假設我們要把所有的檔案庫都放在 d:\svn 目錄下,現在要建立一個測試用的檔案庫,名稱叫做 repository,指令為:

md d:\svn svnadmin create d:\svn\repository

命令執行完後,檢查看看 d:\svn\repository 目錄底下產生了哪些目錄和檔案。

警告:檔案庫絕對不可以在建立在任何遠端的儲存媒體上,例如:網路磁碟機。


這時候你已經建立了一個檔案庫,你可以先在本機用瀏覽器測試一下,網址輸入http://localhost/svn/repository,看看能不能看到檔案庫的內容,正常的話應該像下圖一樣。

如果以上的測試可以通過,應該就行了。如果你還想要測試一下能不能從檔案庫取出整個工作複本,可以執行下列指令(非必要):

c: cd\temp svn co http://localhost/svn WholeRepos

上述指令會切換到一個暫時的目錄 c:\temp,然後從檔案庫取出整個工作複本。最後一行指令是要 svn.exe 執行 check out 動作(縮寫 co),如果正確的話,應該會顯示 "Checked out revision 0." 的訊息,此時 /svn/
這個檔案庫底下的所有檔案目錄都已經取出,並且複製一份到c:\temp\WholeRepos 目錄下了。

問題排除 : 如果顯示的錯誤訊息是:svn: PROPFIND request failed on '/svn/repository'

svn: PROPFIND of '/svn/repository': 405 Method Not Allowed (http://localhost)

請檢查 Apache HTTP Server 的 httpd.conf 檔案裡面的 標籤所定義的位置是否跟你指定的URL
樣式相同,注意一定要完全相同,以上面的例子而言,你的 httpd.conf 的最後面應該會有以下文字:


DAV svn SVNPath 指向檔案庫的絕對路徑

如果顯示的錯誤訊息是: svn: PROPFIND request failed on '/svn svn: Could not open the requested SVN filesystem

那表示在 /svn 對應的實體目錄(即 d:/svn)下找不到所指定的目錄。

註:PROPFIND 是給 WebDAV 用的 HTTP method,用來從資源中取得屬性。


測試完畢就可以把 WholeRepos 這個目錄整個刪掉了。

到目前為止,可以確定檔案庫已經建立完成,接下來就可以匯入專案了。

2.4.1 匯入專案

不用急著把你現有的正式專案匯入檔案庫,先建立一個用來測試的專案目錄就好了。我們先在 c:/temp 底下建一個 ProjectA 的專案目錄結構,參考下面的指令:

c:\
md temp
cd\temp
md ProjectA
md ProjectA\trunk
md ProjectA\branches
md ProjectA\tags
svn import . http://localhost/svn
-m "Initial repository layout"

提示: 本文在執行 svn 命令時,都是使用 http 協定的方式,這樣我們可以確知 Subversion 與 Apache HTTP Server 的設定無誤,其他人就可以透過 Internet 存取檔案庫。當然你也可以用其他的協定,例如:file:///,如果使用 file 協定,最後一行指令就變成:

svn import . file:///d:/svn -m "Initial repository layout"


命令執行無誤的話,應會看到如下的畫面:

這時候 ProjectA 這個專案已經匯入檔案庫了,也就是說,其他使用者可以開始存取這個檔案庫的專案取出文件和程式碼了。你可以參考 Subversion 的官方手冊中關於 svn.exe 這個用戶端命令列工具的使用方法,多練習一下取出檔案、加入檔案、以及存入檔案等指令。萬一練習的過程中發生錯誤,或者檔案庫弄亂了,你可以把整個檔案庫的目錄砍掉,回到 2.4 節重新做一遍。

以下會進一步討論檔案庫和專案目錄結構的安排方式,如果你急著想試試看用戶端如何存取 Subversion 檔案庫,可以先跳到2.6 節或第 3 節。

2.5 檔案庫與專案的配置方式

延續前面的範例,如果你再匯入其他專案,例如 ProjectB,那麼整個檔案庫的結構會變成這樣:

/svn/repository/ +-- ProjectA/ +-- ProjectB/

也就是說 repository 這個檔案庫裡面包含了兩個專案。

如果你希望為每個專案建立一個檔案庫,那麼在 2.4 節中建立檔案庫的指令就變成:

md d:\svn svnadmin create d:\svn\ProjectA
svnadmin create d:\svn\ProjectB

這樣就變成有兩個檔案庫了,檔案庫名稱分別是 ProjectA 與 ProjectB。


提示 : 如果專案之間有共享的檔案,建議把這些相關的專案放進同一個檔案庫;如果專案之間彼此毫無關係,那就採用一個檔案庫放一個專案的方式,這種方式等於專案就是檔案庫。

第一種方式有個比較奇怪的「功能」你應該要知道,就是一個專案的 check in 動作,也會令其他專案的檔案的修訂版次遞增 ,如果這不是你想要的,請選擇第二種方式,即一個檔案庫只存放一個專案。

2.5.1 專案的目錄結構

這裡補充說明一下 ProjectA 的目錄結構。在 ProjectA 專案的根目錄下建立的 trunk、branches、和 tags 這三個目錄是有特別意義的,它們的作用分別是:

  • trunk 目錄用來存份目前專案正在進行開發的程式檔案和文件 (又稱為主線,即 mainline)
  • branches 用來存放主線的各個仍在發展中的分支;
  • tags 則用來存放已經不再變動的分支,也就是其中的檔案不會再修改了。

這是 Subverion 官方手冊建議的目錄結構安排方式,你可以自己決定要不要用這種配置方式,詳細說明請參考官方手冊的第五章,子標題為 "Choosing a Repository Layout"。

提示 : 目錄名稱建議盡量不要用中文名稱,這樣在使用命令列時比較方便,也比較不會有問題。


2.6 使用 Windows 網域帳戶驗證

照著前面的步驟做,你會發現存取檔案庫時都不用輸入帳號密碼,這是因為我們之前的設定沒有啟用身分驗證的功能。但是我們通常不希望所有人都能任意存取你的檔案庫,免得重要資產外洩,或者資料被破壞,因此了解如何加入身分驗證也是必要的。

Serversion 提供了多種驗證使用者身份的方式,這裡只介紹 Windows 身分驗證的方式,這種方式很適合用在開發團隊成員都在區域網路內的情況。請依下列步驟進行:


  1. 取得 SSPI 模組,下載網址為 http://tortoisesvn.tigris.org/mod_auth_sspi.zip
    英文說明在此:http://tortoisesvn.sourceforge.net/node/137
    http://tortoisesvn.sourceforge.net/docs/release/TortoiseSVN_en/ch03.html#tsvn-serversetup-apache-5
  2. 把 zip 裡面的 mod_auth_sspi.so 解壓縮到 modules 目錄下。
  3. 把下面這行加入到 Apache 的 httpd.conf 裡面:LoadModule sspi_auth_module modules/mod_auth_sspi.so
    注意上面加入的這行一定要放在下面這行的前面:LoadModule auth_module modules/mod_auth.so

  4. 修改httpd.conf 的設定如下:
    <Location /svn> DAV
    svn SVNParentPath d:/svn
    AuthType SSPI AuthName "Subversion 檔案庫"
    Require valid-user
    SSPIAuth On
    SSPIAuthoritative On
    SSPIDomain
    SSPIOfferBasic On

    其中 就是你的 Windows 網域控制器的電腦名稱(例如:WIN2KDC),注意兩邊的括號不用保留。如果你的環境沒有網域控制器,就維持原來的就行了。在我的環境下,我發現即使有網域控制器,但是這裡不去設定它,還是能夠正常的驗證使用者身分。
  5. 重新啟動 Apache。

現在開啟瀏覽器,輸入網址 http://127.0.0.1/svn/repository 看看,你預期應該會看到如下的驗證畫面:

若沒有出現這個畫面,而是直接顯示檔案庫內容,怎麼回事?

因為我們現在是使用 Windows 帳戶驗證,你目前已經登入這台機器了,而你要存取的也是本機的資源,換句話說,你的身分已經被驗證過了,所以就不會再要求你輸入帳號跟密碼,這是採用
SSPI 網域驗證的好處。

那麼,如果你的同事 John 的電腦有加入網域,但是他平時都是登入本機,而非登入網域,在存取檔案庫時會不會要求輸入帳號密碼?答案是如果 John 登入他本機的帳號和密碼跟他在網域使用者的帳號密碼完全一樣的話,就無需再輸入密碼;相反的,如果登入本機的使用者帳號和密碼與網域使用者帳號密碼不同,第一次存取時就必須輸入密碼。

你可以在別台機器上,用一個網域裡沒有的使用者帳號去存取 Subverion 檔案庫,如果正確的話,應該就會出現要求輸入帳號密碼的視窗。

以上還只是最基本的設定,如果你希望做些進階的設定,例如允許所有人都可以檢視檔案庫的內容,但是不能修改;或者要加入 SSL 加密機制,建議您參考 [TortoiseSVN 官方文件] 的第三章。


提示 : 啟用身分驗證之後,你會發現用命令列工具 svn.exe 存取檔案庫時,如果是用 http:// 協定,有些子命令(subcommand)執行時會出現 "authorization failed" 的錯誤,這時候你可以在
svn 命令中加入 --username 和 --password 來提供使用者名稱和密碼,例如:


svn co http://myserver/svn/ --username michael --password guesswhat

或者你也可以改用 file:/// 協定。

3. 安裝用戶端:TortoiseSVN

現在你已經有一個可以在http存取Subversion 的伺服器,可以試著在其他電腦上存取檔案庫了。如果你習慣使用命令列工具,那就只要在用戶端電腦上安裝 Subversion 就行了,存取檔案庫都是透過命令列工具(主要是 svn.exe)。這裡要介紹的是一個專門為 Windows 作業系統設計的 Subversion 用戶端:TortoiseSVN(以下簡稱 TSVN)。

3.1 安裝 TortoiseSVN

  1. 到 http://tortoisesvn.tigris.org 下載最新的安裝程式,下載後直接安裝。安裝過程大都是按下一步,只有在問你安裝完成後會要求你重新開機。
  2. 到 http://tortoisesvn.tigris.org 下載繁體中文的語言包(language pack),請注意語言包的版本應該要跟你安裝的 TSVN 版本相同,否則最好不要安裝。語言包裝完之後,用檔案總管在 Windows 桌面上或任何一個資料夾上點一下滑鼠右鍵,選擇 TortoiseSVN -> Settings 以開啟設定視窗,在 "Main" 頁夾中更改 Language 設定為「中文(繁體)」,再按「確定」鈕即可。
  3. 如果你是透過 proxy server 存取 Internet,請在 TSVN 的設定視窗中,切到「網路」頁夾,然後輸入你的 proxy server 相關資訊,否則你將無法存取位於 Internet 上的檔案庫。

安裝完成之後,在任何目錄名稱上點一下滑鼠右鍵都可以看到 TSVN 的功能選項,這也是 TSVN 方便的地方,它不用跟開發工具整合,而是跟作業系統整合在一起,這樣不管你用什麼開發工具,都可以輕鬆的使用 TSVN 來存取檔案庫。

接下來你可以用 TSVN 練習一下存取之前建立好的檔案庫,試著把你現有的專案匯入檔案庫中,並且在用戶端使用 TSVN 執行取出、存入、更新等動作。

TSVN 雖然是用戶端工具,不過它也提供了建立檔案庫、以及匯入、匯出等功能,因此安裝在伺服器端也挺方便的。

4. 結語

按照本文說明的安裝步驟,希望能讓你順利在 Windows 環境下把 Subversion 安裝起來。但是安裝成功以後,真正的工作要才開始,如果你沒有花點時間閱讀 Subversion 的相關文件,在使用版本控制系統的過程中,一定會碰到許多問題。

在正式將你的專案加入 Subversion 檔案庫之前,建議您多考慮一下:

  • 檔案庫的配置方式。究竟要為每一個專案建立一個檔案庫,還是把多個專案放進同一個檔案庫裡?
  • 專案目錄的結構。你要依照官方手冊的方式,在專案的根目錄下建立 trunk、branches、和 tags 嗎?
  • 哪些東西要放進檔案庫裡?

前兩個問題你可以參考 [Subversion電子書第五章] 的建議,再衡量自己的需求來決定。你不見得要依照官方的建議,第一次也許採用最單純的配置方式會比較好,例如:一個檔案庫就只放一個專案,而且只把程式的原始碼 放進檔案庫,也不去分主線支線了,因此專案的目錄結構可以很單純,程式原始碼的根目錄就是專案的根目錄。自己動手做過幾次以後,再去觀察檔案庫的內容,就會比較有感覺了,然後再來考慮自己團隊的需求,自然就能找到最適合自己團隊的配置方式了。

後記

原始發表人:蔡煥麟

延伸閱讀:

SCM: Good beginner intro in Chinese, by Jedi

版本控制系統不祇可以幫助妳追蹤修訂手上的工作進度,讓妳在千鈞一髮之際還能拾回過往辛苦的結晶,甚至能夠讓妳跟其他人協同工作、合作無間。

一般人聽到「版本控制系統 (Version Control System, VCS) 」或者「修訂版控制系統 (Revision Control System, RCS) 」,總會覺得那是寫程式的怪物們纔會去用的東西、祇有程式碼纔會被放在那樣的環境裡開發。然而隨著資訊量持續增加,每個人在日常生活中必須要掌握、處理的的資訊也越來越繁雜,不管是為了做專題、報告、寫論文乃至於翻譯等,祇要是長時間持續產出的工作,也都逐漸需要有版本管理系統的協助,纔能夠事半功倍了。.....

2006/02/11

Install OSX Tiger on Intel Boxes - VMWare rocks!

Many of the guides for installing OSX Tiger are complicated and use linux. You can install OSX using public-domain free windows only tools.

If you wish to install OSX tiger to your intel machine or usb drive, you can follow these few steps. Be careful because you can kill your hard drive if you are not careful.

You will need either a seperate hard drive (seperate partition will not do) or an external hard drive. Whatever extra hard drive you use will be completely replaced by osx and you will lose all information on that drive.

1. Authorized users should obtain the OSX files from Apple. It is illegal to obtain them from torrent sites by searching under the following keywords: "VMWare files for patched Mac OS X Tiger Intel"
2. Unrar these files to the root of your C: drive
3. Download Forensic Acquisition Utilities
4. Unzip these files and copy dd.exe to the root of c: drive as well

Note: the dd.exe program is used to write the image to your spare hard drive or external hard drive. The command is the following:

dd if=c:\tiger-x86-flat.img of=\\.\PhysicalDriveSomething


PhysicalDriveSomething
should be replaced with your real physicaldrive (PhysicalDrive1, PhysicalDrive2, etc.). What your hard drives or usb drives are labelled is not always obvious. So I use WMI to figure this out. If you don't need it, don't get it. It's free... and it may prevent you from killing your wrong hard drive.

5. Download WMI Tools from Microsoft
6. Open WMI Browser Object
7. Allow block content and click the OKs until it loads
8. Select Win32_SystemPartitions.PartComponent in the left column
9. In the right column right-click on the drive device id (Disk #0, Partition #0, etc) and select Go to Object
10. The device window will open and click the associations tab
11. Exploring with this tool you should be able to match drive letters (Win32_LogicalDisk.DeviceID="C:") to each physicaldisk reference (Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0")

12. Now that you know the physicaldrive label for your extra internal or external drive, you can drop to the root of your c: drive and run the command. Be sure to replace the physicaldrive text with the physical drive you determined above. If you use the wrong one, you will erase your primary hard drive.

dd if=c:\tiger-x86-flat.img of=\\.\PhysicalDrive

13. The command will appear to hang but you will notice your extra harddrive cranking away. It's going to do this for 15min to hours. Just let it run.
14. Once it is done, reboot and set the osx drive to your boot drive through your bios.
15. If your hardware is compatable, you should boot to OSX.

If you need to debug, I recommend these forums.

This wiki is also excellent:
http://wiki.osx86project.org/wiki/index.php/Main_Page

UNEASYsilence was one of the first to report on the OSX on intel hack... and is still a good source for updated news on the topic.

2006/01/24

十種不可追隨的領袖 (老闆)

應徵工作時,固然老闆有權選擇夥計的權利。但千萬別忘記,夥計也有選擇老闆的權利。

一生當中,你我能有幾次錯誤的選擇呢?畢業後,若你遇人不淑,連續換了三、五個工作,成功的機會便已大為減低了。因此,慎選值得追隨的老闆,是一生當中少數幾個最重要的個人決策之一。

我們無法知道誰才是值得追隨的老闆,但卻有能力判斷誰是不值得追隨的老闆。以下列出的十種特質,可當做求職,或在職期間對老闆評估的參考。

1.【沒有成功經驗的老闆】
如果你的老闆在商場已闖盪多年,經營的企業少說也有三、五家以上,但卻沒有一次真正成功的經驗,他經常沾沾自喜地說:「我經歷過太多事情了,像我這樣垮下去又能站起來的人也不多,畢竟我有我獨到之處。」那你就應該開始懷疑自己的選擇了。

是的,他是有獨到之處。能夠連續幾次從失敗中再站起來,的確不是一件易事。相反地,若連續數次都未能竟其全功,想必他個人有某些重大的缺點,因為壞運氣不會都落在某一個人身上。

若你的老闆屬於此一類型,那你就必須仔細探討他多次失敗的原因。一個沒有成功經驗的老闆,你怎能肯定他這一次一定會成功。除非你能替他帶來好運。

2.【事必躬親的老闆】
「每一件事情我不經手就一定會出差錯。」這是很多老闆經常掛在嘴上的一句話,也是他們引以為豪的一件事。

事實上,這是老闆自己造成的後果。如果老闆事不問大小皆要親自參與,他怎能期待屬下能獨立呢?無法獨立的屬下自然出錯的機會就大,特別是當事必躬親的老闆不在場的時候。

如果你不希望永遠處在一家名不見經傳的小公司,便最好選擇一位懂得授權的老闆,不要在意公司目前的規模大小。

除此之外,事必躬親的老闆也無法留位真正的人才。一位有創意,有擔當的人才絕不希望老板常相左右。同樣地,一家留不住人才的公司,你怎能期望它有良好的績效呢?

3.【魚與熊掌都想兼得的老闆】
天下沒有白吃的午餐。又要馬兒好,又要馬兒不吃草,這種老闆祇能稱之為不知何所取,不知何所捨的老闆。

如果你曾在公司佈告欄上看到這類公告:「明日中央民意代表選擇,本公司員工自由上班。」那你就應該開始準備履歷表,另謀高就了。

自由上班是個很好的主意。一來上班的員工可免領加班費。其次,偷懶不上班的員工,休假這一天必是寢食難安。最後,這是揪出壞傢伙的天大良機。

魚與熊掌都想兼得的老闆,通常是魚與熊掌都得不到,也是經常「因小失大」的老闆。成功的老闆應該懂得什麼是放長線釣大魚。抓雞不願蝕把米的老闆,到最後一定是兩手空空的。

知所取,知所捨是成功必須具備的一個條件,「難以」割捨是件很痛若的事。如果你的老闆一直無法克服這個痛苦,便是你該三思的時候了。

4.【朝令夕改的老闆】
積極是一種美德,有耐性卻也不是不件壞事。企業環境不斷地變化,公司決策當然也需相應地改變。然而任何決策的成敗,均需經過相當時間的證明。

如果老闆只有積極,但缺乏耐心的美德,你花費許多時間所策劃的案子,他在實行三天之後就可以將之取消。或者花費數個月醞釀的計劃,往往因為訪客的一句話而告全盤推翻。更令人沮喪的是,根據老闆指示而作成的計劃,往往石沈大海一樣擱在老闆的抽屜。

當然,這類老闆會將他的作法解釋為當機立斷。這種老闆永遠不會了解,不戶決策也是一種決策。你會發現,公司上上下下都很忙,忙著收拾殘局,忙著在挖東牆補西牆。老闆一天到晚都在提出新藥方,但他永遠不會相信,有些疾病祇有時間可以治癒。

5.【喜新厭舊的老闆】
除非是一家百年老店,否則在公司內部總可以見到幾位開國元老。如果你沒有發現這類國寶級的員工,很可能他們在江山底定之後就被杯酒釋兵權了。

與這類老闆共事,通常有段蜜月期,長則半年,短則三週。其固定的模式如下:

一進公司之後,老闆便經常在你面前數說一些資深員工那裡不好,那裡不是。

到了蜜月期的高峰,一定會有其他新進員工加入公司(這類公司通常員工流動率極高),老闆就開始在你面前誇讚新進入員多麼優秀。在蜜月期後段(如果你的蜜月期夠長的話),你經常會聽到老闆提及那位員工不能用,不適合公司。

當然,這段期間你可以見到幾幕戲劇化的離職事件。當然,最後同樣的故事會發生在你身上。

而在你遞出辭呈,或者老闆以某種婉轉的方式請你走路時,他會告訴你,我們以後還是好朋友。

這類老闆不能客觀地評估員工的績效。即使你做好九十九件事,但第一百件事搞砸了,你就很難在老闆面前再有翻身的機會,除非你能保證,你的工作績效永遠令老闆滿意,否則你應隨時有走路的心理準備。

6.【感情生活複雜的老闆】
才子風流就是一條鐵律。這類老闆將最寶貴的時間耗費在感情糾紛的處理,當然就無法冷靜地經營企業。此外,如果你是已婚男性,長久跟隨這類老闆,夫妻必會反目。如果你是女性,不管已婚或是未婚,對妳將來的幸福亦會有負面的影響。

7.【言行不一致的老闆】
這類老闆最常說的一句話是:「賺這麼多錢對我並沒有什麼意義。」企業最重要的任務之一就是追求利潤,利潤是公司生存的唯一命脈,又何必刻意加以否認呢?

或許你有機會與這類老闆共餐。在一盤雞肉上桌之後,老闆會忙著為你們挾菜。到頭來你將發現,骨頭特別多的部位都在員工面前,老闆卻津津有味地享受他為自己所保留的雞腿。

在這類公司,依照公司章程,如果中午休息時間一個小時,老闆通常會在休息五十分鐘的時間,進進出出,發出許多噪音將熟睡的員工吵醒,然後再笑容可掬地說:「大家繼續睡啊!還有十分鐘。」

只要假以時日,這類言行不一致的老闆必然無所遁形。當然,若你也是抱著真真假假,假假真真的人生觀,那也無妨。

8.【喜歡甜言蜜語的老闆】
這類老闆通常分不清何者為善意的批評,何者為惡意的攻訐。更分不清何者為真心的讚美,何者為別有居心的諂媚。

當然,我們不能期望老闆聽到批評時還能心花怒放,因為不願接受批評是人的天性,但若是善意的批評妨礙了員工在公司的發展,則人人噤若寒蟬。長久下來,除非老闆能發掘所有的問題,否則公司的經營缺失必定永遠不能獲得改善。

更重要地,這種環境具有反淘汰的作用。小人當道,正直的員工不受重用,公司內多的是瞞上欺下之徒,固守原則的員工便一心求去。如此,振衰起敝之日便遙遙無期。

生活的壓力很容易讓人向這種環境妥協。如果你有足夠的儲蓄足以維持轉業期間的生活所需,如果你的個性尚稱正直,便應該重新衡量自己的去處。

9.【多疑的老闆】
通常這類老闆都有慘痛的經驗,一朝被蛇咬,終生見繩驚。

如果你是分公司的主管,你經常會在非上班的時間接到這類老闆的電話。如果你是基層職員,這類老闆會經常在你面前表示他對你上司的關切。如果你是老闆身邊的左右手,則你和老闆的關係必定是非親則故。

這類老闆主持的公司,通常沒有上軌道的制度。原因之一是這類老闆尚未精明到可設計一套足以防弊的制度(當然別人可代為設計,然而老闆絕不信任別人設計的制度)。其次老闆所持的觀念是人治勝過法治。

跟隨這種老闆,心理負擔之重可想而知。更嚴重的是,經常有無處可申的不白之冤。

10.【心胸狹窄的老闆】
如果你是一位老闆,正在看這篇文章,而且已怒火中燒了,那你就要歸為心胸狹窄的老闆。

除非這類老闆是位雄才大略之士(可能嗎?),否則其手下必定找不出大將之才,因為這類老闆眼中容不下足以與他搶風頭的屬下。

如果你已離職,有空記得與老同事敘敘舊。你將發現,公司許多弊端都是你惹的禍,你會成為百口莫辯的代罪羔羊。

這類老闆為數不多,假使你不幸碰到了,也祇能自求多福了。

如果你還是無法評估你的老闆,就再多觀察老闆經常往來的朋友,他們與你之間沒有任何利害關係。物以類聚,從老闆的朋友那裡,你或許可獲得一些啟示。

假使你的老闆並未具有上述十項特質中的任何一項,那你便是個幸運兒。我要勸你好好珍惜這份工作,祇要好好的努力,你的成就一定會與你的付出成正比。

在上述十項特質當中,如果你的老闆具備三項以下,你仍可安心工作,但記得找機會去影響他。如果你的老闆具有四到六項的特質,我勸你多花一點時間充實自己,並隨時留意報上的徵人啟事。如果你的老闆具有七項以上的特質,我唯一的勸告是:走為上策。


Further Reading:

自慢:社長的成長學習筆記 ISBN:9789861248479

Mercury簡易改裝

有同好有一樣的困擾 - 如何使用自己的data logging軟體,因此寫了這篇來分享我的簡易改裝。 Background 雲豆子 MERCURY roaster 烘豆機的設計是使用自行開發的軟體,來:1. 操控風門/火力; 2. data logging/自動烘焙。 ...