mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
The installer can now inherit privileges from the updater, which inherits privileges from the process that spawns the updater. As such, we can now run the updater & installer as root, and no authorization dialog can prompt up. The installer now must abort or install if the target app has terminated. Zombie processes will no longer stay around. Because the root user has no trash directory, we ignore logging the error if it was not found. We also avoid invoking mdimport which fails as root on the installed app. mdimport may have been used before for updating mdimporter files, however, it should be the developer's responsibility to ensure their mdimporter files have an updated date stamp, which will work if a user updates an app manually. Other than that, we already touch the app to register it with LaunchServices, so that should suffice.
64 lines
3.1 KiB
Objective-C
64 lines
3.1 KiB
Objective-C
//
|
|
// SUInstallerLauncher.m
|
|
// InstallerLauncher
|
|
//
|
|
// Created by Mayur Pawashe on 4/1/16.
|
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
#import "SUInstallerLauncher.h"
|
|
#import "SUFileManager.h"
|
|
#import "SULog.h"
|
|
#import <AppKit/AppKit.h>
|
|
|
|
@implementation SUInstallerLauncher
|
|
|
|
- (void)launchInstallerAtPath:(NSString *)installerPath withHostBundleIdentifier:(NSString *)hostBundleIdentifier inheritingPrivileges:(BOOL)inheritingPrivileges completion:(void (^)(BOOL success))completionHandler
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
NSError *quarantineError = nil;
|
|
SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO];
|
|
|
|
if (![fileManager releaseItemFromQuarantineAtRootURL:[NSURL fileURLWithPath:installerPath] error:&quarantineError]) {
|
|
// This may or may not be a fatal error depending on if the process is sandboxed or not
|
|
SULog(@"Failed to release quarantine on installer at %@ with error %@", installerPath, quarantineError);
|
|
}
|
|
|
|
NSArray *arguments = @[hostBundleIdentifier, @(inheritingPrivileges).stringValue];
|
|
|
|
if (!inheritingPrivileges) {
|
|
// This new process does not inherit privileges because it's being launched via LaunchServices
|
|
// This allows the installer app to make authorization requests for example from a non-sandboxed XPC service
|
|
NSError *launchError = nil;
|
|
NSRunningApplication *runningApplication = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:installerPath] options:(NSWorkspaceLaunchOptions)(NSWorkspaceLaunchDefault | NSWorkspaceLaunchNewInstance) configuration:@{NSWorkspaceLaunchConfigurationArguments : arguments} error:&launchError];
|
|
|
|
if (runningApplication == nil) {
|
|
SULog(@"Failed to launch %@ app with error: %@", @SPARKLE_RELAUNCH_TOOL_NAME, launchError);
|
|
}
|
|
|
|
completionHandler(runningApplication != nil);
|
|
} else {
|
|
// This new process inherits privileges and thus will not use the authorization reference API, nor request a dialog for authorization
|
|
// If we have root permissions, so will this new process
|
|
// The reason I don't create a NSBundle to locate the executable is because I worry about NSBundle caching and if we enter here multiple times
|
|
NSString *executablePath = [[[installerPath stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:@"MacOS"] stringByAppendingPathComponent:@SPARKLE_RELAUNCH_TOOL_NAME];
|
|
|
|
NSTask *task = [[NSTask alloc] init];
|
|
task.launchPath = executablePath;
|
|
task.arguments = arguments;
|
|
|
|
BOOL success = NO;
|
|
@try {
|
|
[task launch];
|
|
success = YES;
|
|
} @catch (NSException *exception) {
|
|
SULog(@"Failed to launch %@ app with exception: %@", @SPARKLE_RELAUNCH_TOOL_NAME, exception);
|
|
}
|
|
|
|
completionHandler(success);
|
|
}
|
|
});
|
|
}
|
|
|
|
@end
|