Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ruhi

macrumors member
Original poster
Jun 17, 2009
70
0
I am trying to enable accessibility through my code.

Got an example source code Trust Me application.

before enabling the Accessiblity, the application prompt a dialog box for allowing access with username and password, i want to prevent this dialog box.

the code given in trust me application is as shown below :

Code:
- (void)makeProcessTrusted;
{
	//authentication based on file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Security/Conceptual/authorization_concepts/03authtasks/chapter_3_section_4.html
	
	OSStatus myStatus;
    AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
    AuthorizationRef myAuthorizationRef;
	
    myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, myFlags, &myAuthorizationRef);
	
    if (myStatus != errAuthorizationSuccess)
	{
		[self askUserToEnableAccessForAssistiveDevices];
		return;
	}
	
	AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
	AuthorizationRights myRights = {1, &myItems};
	
	myFlags = kAuthorizationFlagDefaults |
	kAuthorizationFlagInteractionAllowed |
	kAuthorizationFlagPreAuthorize |
	kAuthorizationFlagExtendRights;
	myStatus = AuthorizationCopyRights (myAuthorizationRef, &myRights, NULL, myFlags, NULL );
	
	if (myStatus != errAuthorizationSuccess)
	{
		AuthorizationFree (myAuthorizationRef, kAuthorizationFlagDefaults);
		[self askUserToEnableAccessForAssistiveDevices];
		return;
	}
	
	//we pass the path to our bundle to the agent so it can relaunch us when it makes us trusted
	char *myArguments[] = { (char *)([[[NSBundle mainBundle]bundlePath]fileSystemRepresentation]), NULL };
	
	const char *makeProcessTrustedAgentPath = [[[NSBundle bundleWithPath:[[NSBundle mainBundle]pathForAuxiliaryExecutable:@"MakeProcessTrustedAgent.app"]]executablePath]fileSystemRepresentation];
	
	myFlags = kAuthorizationFlagDefaults;
	myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef,makeProcessTrustedAgentPath,myFlags,myArguments, NULL);
	
    AuthorizationFree (myAuthorizationRef, kAuthorizationFlagDefaults);
	
    if (myStatus!= errAuthorizationSuccess)
	{
		[self askUserToEnableAccessForAssistiveDevices];
		return;
	}
	
	//due to a bug with AXMakeProcessTrusted(), we need to be relaunched before we will actually have access to UI Scripting
	[NSApp terminate:nil];
}

i want to enable accessibility for my application but i dnt want it to show any authorization dialog box.

Please help.

Thanks,
ruhi.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
So how is that supposed to work? You want to make your application a "trusted" application without the user saying so? What if the user doesn't trust you?

Wouldn't that be a great OS feature if any key logger could run without the user having a say?
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
You are doing two different things here.

One you are asking the user to turn on the Accessibility features of Mac OS X, if they are not turned on already. This requires an Admin access to do so, since you are modifying the system services.

This is separate from having UI Scripting features in your app, which cocoa provides largely "for free" since it is a very large application framework with lots of built-in functionality including UI Scripting.

You app simply provides some delegate methods to give UI Scripting the variable information such as a description for an object. This is separate from enabling the UI Scripting services of Mac OS X.

There is no way to get around asking for a username and password to turn on Accessibility (UI Scripting), but if you just want these features supported in your app, that is a separate matter entirely.
 

ruhi

macrumors member
Original poster
Jun 17, 2009
70
0
Prevent Authorization prompt

ya i want this feature in my application only for not showing that prompt from password and user name. i just want to make my application trusted.

But it should not give any prompt..

Thanks,
Ruhi
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
You either need to use Authorization Services, as mentioned in this thread:
https://forums.macrumors.com/threads/755864/

Otherwise you can't perform anything with escalated privileges, so you'll just need to request that the user enable the appropriate options. There is a security model for a reason, and you shouldn't try to break it. Your app is not special, it needs to behave like other OS X apps, and that means asking for permission and authorization to do privileged tasks. If any app can just run as root/with elevated privileges, it's a pretty short trip to an application ruining your system.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.