2010-10-03 104 views
1

我在理解如何授權我的程序執行特權任務時遇到問題。理解授權的問題

我讀蘋果文檔寫了這樣一段代碼:調用AuthorizationCopyRights我應該能夠執行特權任務,右後

AuthorizationRef myAuthorizationRef; 
OSStatus myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &myAuthorizationRef); 

AuthorizationItem myItem; 

myItem.name = "com.Me.myApp.test"; 
myItem.valueLength = 0; 
myItem.value = NULL; 
myItem.flags = 0; 

AuthorizationRights myRights; 

myRights.count = 1; 
myRights.items = &myItem; 

AuthorizationFlags myFlags = kAuthorizationFlagDefaults | 
kAuthorizationFlagInteractionAllowed | 
kAuthorizationFlagExtendRights; 

myStatus = AuthorizationCopyRights (myAuthorizationRef, &myRights, kAuthorizationEmptyEnvironment, myFlags, NULL); 

?我還有什麼要做的嗎?

回答

1

您請求的權利com.Me.myApp.test不是一項特權,因此獲取它並不會給您的應用程序提升權限。但是,這是一件好事 - 因爲Input Managers,您不希望您的可可應用程序具有提升的權限。這種棄用的技術允許任何人將任意代碼加載到您的應用程序中,因此如果您提升應用程序的權限,它將成爲攻擊媒介。

更安全的方法是編寫一個輔助工具。請參閱Apple的guide to secure codingusing a helper tool