Skip to content

Commit c494dde

Browse files
author
Stephen A Pohl
committed
Bug 1728167: Add ability for standard users to install from a DMG through elevation. r=mstange,application-update-reviewers,bytesized
Differential Revision: https://phabricator.services.mozilla.com/D123899
1 parent 86fc7a1 commit c494dde

File tree

6 files changed

+992
-847
lines changed

6 files changed

+992
-847
lines changed

toolkit/mozapps/update/updater/launchchild_osx.mm

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,59 @@ void SetGroupOwnershipAndPermissions(const char* aAppBundle) {
450450
}
451451
}
452452
}
453+
454+
#if !defined(MAC_OS_X_VERSION_10_13) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_13
455+
@interface NSTask (NSTask10_13)
456+
@property(copy) NSURL* executableURL NS_AVAILABLE_MAC(10_13);
457+
@property(copy) NSArray<NSString*>* arguments;
458+
- (BOOL)launchAndReturnError:(NSError**)error NS_AVAILABLE_MAC(10_13);
459+
@end
460+
#endif
461+
462+
/**
463+
* Helper to launch macOS tasks via NSTask.
464+
*/
465+
static void LaunchTask(NSString* aPath, NSArray* aArguments) {
466+
if (@available(macOS 10.13, *)) {
467+
NSTask* task = [[NSTask alloc] init];
468+
[task setExecutableURL:[NSURL fileURLWithPath:aPath]];
469+
if (aArguments) {
470+
[task setArguments:aArguments];
471+
}
472+
[task launchAndReturnError:nil];
473+
[task release];
474+
} else {
475+
NSArray* arguments = aArguments;
476+
if (!arguments) {
477+
arguments = @[];
478+
}
479+
[NSTask launchedTaskWithLaunchPath:aPath arguments:arguments];
480+
}
481+
}
482+
483+
static void RegisterAppWithLaunchServices(NSString* aBundlePath) {
484+
NSArray* arguments = @[ @"-f", aBundlePath ];
485+
LaunchTask(@"/System/Library/Frameworks/CoreServices.framework/Frameworks/"
486+
@"LaunchServices.framework/Support/lsregister",
487+
arguments);
488+
}
489+
490+
static void StripQuarantineBit(NSString* aBundlePath) {
491+
NSArray* arguments = @[ @"-d", @"com.apple.quarantine", aBundlePath ];
492+
LaunchTask(@"/usr/bin/xattr", arguments);
493+
}
494+
495+
bool PerformInstallationFromDMG(int argc, char** argv) {
496+
MacAutoreleasePool pool;
497+
if (argc < 4) {
498+
return false;
499+
}
500+
NSString* bundlePath = [NSString stringWithUTF8String:argv[2]];
501+
NSString* destPath = [NSString stringWithUTF8String:argv[3]];
502+
if ([[NSFileManager defaultManager] copyItemAtPath:bundlePath toPath:destPath error:nil]) {
503+
RegisterAppWithLaunchServices(destPath);
504+
StripQuarantineBit(destPath);
505+
return true;
506+
}
507+
return false;
508+
}

0 commit comments

Comments
 (0)