[launchd-dev] SMJobBless & secure launched helper tool

Eric Gorr mailist at ericgorr.net
Thu Oct 13 11:19:18 PDT 2011


If anyone is interested, this (probably) turned out to be a bug and one has been filed. rdar://10280469

The way the system currently works is that it will ask for an admin password every time regardless of whether or not the SMJobBless function needs to install the helper tool or not. The bug is (probably) that a admin password request should not be made if the helper tool does not need to be installed (for example, it is already installed and has the same version as the one in the app bundle).

So, what this means is that the determination of whether or not the helper tool needs to be installed needs to be made before a call to SMJobBless and SMJobBless should only be called if it is already known the helper tool needs to be installed.

In my case, I only need to check whether the tool is installed (SMJobCopyDictionary handles this) and, if the tool is installed, whether or not it's version is older then the version of the tool in my app bundle.

Some (incomplete) code to check whether the tool is installed and what the versions are is below. 

There is another alternative to do a version check of the helper tool which is for the helper tool to receive a request for it's version and for it to send a version reply back. Personally, I like the method below, but wanted to mention this alternative as it may be the best path in some situations.





On Oct 3, 2011, at 10:13 AM, Eric Gorr wrote:

> ----------
> VVVVVVVVVV
> ----------
> NSDictionary* installedHelperJobData;
> 
> installedHelperJobData  = (NSDictionary*)SMJobCopyDictionary( kSMDomainSystemLaunchd, (CFStringRef)@"com.apple.bsd.SMJobBlessHelper" );
> 
> NSString*       installedPath           = [[installedHelperJobData objectForKey:@"ProgramArguments"] objectAtIndex:0];
> NSURL*          installedPathURL        = [NSURL fileURLWithPath:installedPath];
> 
> NSDictionary*   installedInfoPlist      = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)installedPathURL );
> NSString*       installedBundleVersion  = [installedInfoPlist objectForKey:@"CFBundleVersion"];
> NSInteger       installedVersion        = [installedBundleVersion integerValue];
> 
> NSLog( @"installedVersion: %ld", (long)installedVersion );
> 
> NSBundle*       appBundle       = [NSBundle mainBundle];
> NSURL*          appBundleURL    = [appBundle bundleURL];
> 
> NSURL*          currentHelperToolURL    = [appBundleURL URLByAppendingPathComponent:@"Contents/Library/LaunchServices/com.apple.bsd.SMJobBlessHelper"];
> NSDictionary*   currentInfoPlist        = (NSDictionary*)CFBundleCopyInfoDictionaryForURL( (CFURLRef)currentHelperToolURL );
> NSString*       currentBundleVersion    = [currentInfoPlist objectForKey:@"CFBundleVersion"];
> NSInteger       currentVersion          = [currentBundleVersion integerValue];
> 
> NSLog( @"currentVersion: %ld", (long)currentVersion );
> ----------
> ^^^^^^^^^^
> ----------



More information about the launchd-dev mailing list