diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index a863a98d..68e0389d 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -18,6 +18,8 @@ #import #import #import +#import + #include "AppKitPrevention.h" @@ -71,6 +73,8 @@ } } + // If we are running as the root user, there is no need to explicitly set the UserName / GroupName keys + // because we are submitting under the user domain, which should automatically use the the console user. NSMutableDictionary *jobDictionary = [[NSMutableDictionary alloc] init]; jobDictionary[@"Label"] = label; jobDictionary[@"ProgramArguments"] = arguments; @@ -101,7 +105,7 @@ return (submittedJob == true); } -- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain +- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier userName:(NSString *)userName homeDirectory:(NSString *)homeDirectory authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain rootUser:(BOOL)rootUser { SUFileManager *fileManager = [[SUFileManager alloc] init]; @@ -111,12 +115,6 @@ NSString *hostBundleIdentifier = hostBundle.bundleIdentifier; assert(hostBundleIdentifier != nil); - NSString *homeDirectory = NSHomeDirectory(); - assert(homeDirectory != nil); - - NSString *userName = NSUserName(); - assert(userName != nil); - // The first argument has to be the path to the program, and the second is a host identifier so that the installer knows what mach services to host // The third and forth arguments are for home directory and user name which only pkg installer scripts may need // We intentionally do not pass any more arguments. Anything else should be done via IPC. @@ -134,7 +132,7 @@ BOOL canceledAuthorization = NO; BOOL failedToUseSystemDomain = NO; - if (auth != NULL && systemDomain) { + if (auth != NULL && systemDomain && !rootUser) { // See Apple's 'EvenBetterAuthorizationSample' sample code and // https://developer.apple.com/library/mac/technotes/tn2095/_index.html#//apple_ref/doc/uid/DTS10003110-CH1-SECTION7 // We can set a custom right name for authenticating as an administrator @@ -368,38 +366,46 @@ BOOL SPUSystemNeedsAuthorizationAccessForBundlePath(NSString *bundlePath) return needsAuthorization; } -static BOOL SPUSystemNeedsAuthorizationAccess(NSString *path, NSString *installationType) +static BOOL SPUUsesSystemDomainForBundlePath(NSString *path, NSString *installationType, BOOL rootUser) { - BOOL needsAuthorization; - if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) { - needsAuthorization = YES; - } else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) { - needsAuthorization = NO; + if (!rootUser) { + if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) { + return YES; + } else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) { + return NO; + } else { + return SPUSystemNeedsAuthorizationAccessForBundlePath(path); + } } else { - needsAuthorization = SPUSystemNeedsAuthorizationAccessForBundlePath(path); + // If we are the root user we use the system domain even if we don't need escalated authorization. + // Note interactive package installations are not supported as root. + return YES; } - return needsAuthorization; } - // Note: do not pass untrusted information such as paths to the installer and progress agent tools, when we can find them ourselves here - (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler { dispatch_async(dispatch_get_main_queue(), ^{ - BOOL needsSystemAuthorization = SPUSystemNeedsAuthorizationAccess(hostBundlePath, installationType); + // We could do a sort of preflight Authorization test instead of testing if we are running as root, + // but I think this is not necessarily a better approach. We have to chown() the launcher cache directory later on, + // and that is not necessarily related to a preflight test. It's more related to being ran under a root / different user from the active GUI session + BOOL rootUser = (geteuid() == 0); + + BOOL inSystemDomain = SPUUsesSystemDomainForBundlePath(hostBundlePath, installationType, rootUser); NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath]; if (hostBundle == nil) { SULog(SULogLevelError, @"InstallerLauncher failed to create bundle at %@", hostBundlePath); SULog(SULogLevelError, @"Please make sure InstallerLauncher is not sandboxed and do not sign your app by passing --deep. Check: codesign -d --entitlements :- \"%@\"", NSBundle.mainBundle.bundlePath); SULog(SULogLevelError, @"More information regarding sandboxing: https://sparkle-project.org/documentation/sandboxing/"); - completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); return; } - // if we need to use the system domain and we aren't allowed interaction, then try sometime later when interaction is allowed - if (needsSystemAuthorization && !allowingDriverInteraction) { - completionHandler(SUInstallerLauncherAuthorizeLater, needsSystemAuthorization); + // if we need to use the system authorization from non-root and we aren't allowed interaction, then try sometime later when interaction is allowed + if (inSystemDomain && !rootUser && !allowingDriverInteraction) { + completionHandler(SUInstallerLauncherAuthorizeLater, inSystemDomain); return; } @@ -414,7 +420,7 @@ static BOOL SPUSystemNeedsAuthorizationAccess(NSString *path, NSString *installa NSString *installerPath = [self pathForBundledTool:@""SPARKLE_RELAUNCH_TOOL_NAME extension:@"" fromBundle:ourBundle]; if (installerPath == nil) { SULog(SULogLevelError, @"Error: Cannot submit installer because the installer could not be located"); - completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); return; } @@ -423,7 +429,7 @@ static BOOL SPUSystemNeedsAuthorizationAccess(NSString *path, NSString *installa if (progressToolResourcePath == nil) { SULog(SULogLevelError, @"Error: Cannot submit progress tool because the progress tool could not be located"); - completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); return; } @@ -439,25 +445,69 @@ static BOOL SPUSystemNeedsAuthorizationAccess(NSString *path, NSString *installa NSString *launcherCachePath = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootLauncherCachePath]; if (launcherCachePath == nil) { SULog(SULogLevelError, @"Failed to create cache directory for progress tool in %@", rootLauncherCachePath); - completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); return; } + SUFileManager *fileManager = [[SUFileManager alloc] init]; + + NSString *userName; + NSString *homeDirectory; + if (!rootUser) { + // Normal path + homeDirectory = NSHomeDirectory(); + assert(homeDirectory != nil); + + userName = NSUserName(); + assert(userName != nil); + } else { + // As the root user we need to obtain the user name and home directory reflecting + // the user's console session. + + uid_t uid = 0; + gid_t gid = 0; + CFStringRef userNameRef = SCDynamicStoreCopyConsoleUser(NULL, &uid, &gid); + if (userNameRef == NULL) { + SULog(SULogLevelError, @"Failed to retrieve user name from the console user"); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); + return; + } + + userName = (NSString *)CFBridgingRelease(userNameRef); + homeDirectory = NSHomeDirectoryForUser(userName); + if (homeDirectory == nil) { + SULog(SULogLevelError, @"Failed to retrieve home directory for user: %@", userName); + + completionHandler(SUInstallerLauncherFailure, inSystemDomain); + return; + } + + // Ensure the console user has ownership of the launcher cache directory + // Otherwise the updater may not launch and not be able to clean up itself + NSError *changeOwnerAndGroupError = nil; + if (![fileManager changeOwnerAndGroupOfItemAtURL:[NSURL fileURLWithPath:launcherCachePath] ownerID:uid groupID:gid error:&changeOwnerAndGroupError]) { + SULog(SULogLevelError, @"Failed to change owner and group for launcher cache directory: %@", changeOwnerAndGroupError); + + completionHandler(SUInstallerLauncherFailure, inSystemDomain); + return; + } + } + NSString *progressToolPath = [launcherCachePath stringByAppendingPathComponent:@""SPARKLE_INSTALLER_PROGRESS_TOOL_NAME@".app"]; NSError *copyError = nil; // SUFileManager is more reliable for copying files around - if (![[[SUFileManager alloc] init] copyItemAtURL:[NSURL fileURLWithPath:progressToolResourcePath] toURL:[NSURL fileURLWithPath:progressToolPath] error:©Error]) { + if (![fileManager copyItemAtURL:[NSURL fileURLWithPath:progressToolResourcePath] toURL:[NSURL fileURLWithPath:progressToolPath] error:©Error]) { SULog(SULogLevelError, @"Failed to copy progress tool to cache: %@", copyError); - completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(SUInstallerLauncherFailure, inSystemDomain); return; } - SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle updaterIdentifier:updaterIdentifier authorizationPrompt:authorizationPrompt inSystemDomain:needsSystemAuthorization]; + SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle updaterIdentifier:updaterIdentifier userName:userName homeDirectory:homeDirectory authorizationPrompt:authorizationPrompt inSystemDomain:inSystemDomain rootUser:rootUser]; BOOL submittedProgressTool = NO; if (installerStatus == SUInstallerLauncherSuccess) { - submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle inSystemDomainForInstaller:needsSystemAuthorization]; + submittedProgressTool = [self submitProgressToolAtPath:progressToolPath withHostBundle:hostBundle inSystemDomainForInstaller:inSystemDomain]; if (!submittedProgressTool) { SULog(SULogLevelError, @"Failed to submit progress tool job"); @@ -468,9 +518,9 @@ static BOOL SPUSystemNeedsAuthorizationAccess(NSString *path, NSString *installa } if (installerStatus == SUInstallerLauncherCanceled) { - completionHandler(installerStatus, needsSystemAuthorization); + completionHandler(installerStatus, inSystemDomain); } else { - completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure, needsSystemAuthorization); + completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure, inSystemDomain); } }); } diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 723ccf97..5e6f647f 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -18,6 +18,7 @@ #import "SPUResumableUpdate.h" #import "SPUAppcastItemState.h" #import "SUAppcastItem+Private.h" +#import "SPUInstallationType.h" #include "AppKitPrevention.h" @@ -139,21 +140,31 @@ - (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain resuming:(BOOL)resuming { if (!self.aborted) { - // If the update is not being resumed from a prior session, give the delegate a chance to bail - NSError *shouldNotProceedError = nil; - if (!resuming && [self.updaterDelegate respondsToSelector:@selector(updater:shouldProceedWithUpdate:updateCheck:error:)] && ![self.updaterDelegate updater:self.updater shouldProceedWithUpdate:updateItem updateCheck:self.updateCheck error:&shouldNotProceedError]) { - [self.delegate basicDriverIsRequestingAbortUpdateWithError:shouldNotProceedError]; - } else { - [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification - object:self.updater - userInfo:@{ SUUpdaterAppcastItemNotificationKey: updateItem }]; - - if ([self.updaterDelegate respondsToSelector:@selector((updater:didFindValidUpdate:))]) { - [self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem]; + if (!resuming) { + // interactive pkg based updates are not supported under root user + if ([updateItem.installationType isEqualToString:SPUInstallationTypeInteractivePackage] && geteuid() == 0) { + [self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationRootInteractiveError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Interactive based packages cannot be installed as the root user.", nil) }]]; + return; + } else { + // Give the delegate a chance to bail + + NSError *shouldNotProceedError = nil; + if ([self.updaterDelegate respondsToSelector:@selector(updater:shouldProceedWithUpdate:updateCheck:error:)] && ![self.updaterDelegate updater:self.updater shouldProceedWithUpdate:updateItem updateCheck:self.updateCheck error:&shouldNotProceedError]) { + [self.delegate basicDriverIsRequestingAbortUpdateWithError:shouldNotProceedError]; + return; + } } - - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } + + [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification + object:self.updater + userInfo:@{ SUUpdaterAppcastItemNotificationKey: updateItem }]; + + if ([self.updaterDelegate respondsToSelector:@selector((updater:didFindValidUpdate:))]) { + [self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem]; + } + + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index 21de6578..b1ff139e 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -73,6 +73,7 @@ typedef NS_ENUM(OSStatus, SUError) { SUInstallationAuthorizeLaterError = 4008, SUNotValidUpdateError = 4009, SUAgentInvalidationError = 4010, + SUInstallationRootInteractiveError = 4011, // API misuse errors. SUIncorrectAPIUsageError = 5000 diff --git a/Sparkle/SUFileManager.h b/Sparkle/SUFileManager.h index 73d42fec..ccfdee2c 100644 --- a/Sparkle/SUFileManager.h +++ b/Sparkle/SUFileManager.h @@ -108,6 +108,18 @@ NS_ASSUME_NONNULL_BEGIN */ - (BOOL)changeOwnerAndGroupOfItemAtRootURL:(NSURL *)targetURL toMatchURL:(NSURL *)matchURL error:(NSError **)error; +/** + Changes the owner and group ID of an item at a specified target URL + @param targetURL A URL pointing to the target item whose owner and group IDs to alter. The item at this URL must exist. + @param ownerID The new owner ID to set on the item. + @param groupID The new group ID to set on the item. + @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL. + @return YES if the target item's owner and group IDs have changed, otherwise NO along with a populated error object. + + Unlike -changeOwnerAndGroupOfItemAtRootURL:toMatchURL:error: this method does not recursively try to change the owner and group IDs if the target item is a directory. + */ +- (BOOL)changeOwnerAndGroupOfItemAtURL:(NSURL *)targetURL ownerID:(uid_t)ownerID groupID:(gid_t)groupID error:(NSError * __autoreleasing *)error; + /** * Updates the modification and access time of an item at a specified target URL to the current time * @param targetURL A URL pointing to the target item whose modification and access time to update. The item at this URL must exist. diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 4d91fa62..e0fa04ef 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -243,7 +243,7 @@ static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; return YES; } -- (BOOL)_changeOwnerAndGroupOfItemAtURL:(NSURL *)targetURL ownerID:(NSNumber *)ownerID groupID:(NSNumber *)groupID error:(NSError * __autoreleasing *)error +- (BOOL)changeOwnerAndGroupOfItemAtURL:(NSURL *)targetURL ownerID:(uid_t)ownerID groupID:(gid_t)groupID error:(NSError * __autoreleasing *)error { char path[PATH_MAX] = {0}; if (![targetURL.path getFileSystemRepresentation:path maxLength:sizeof(path)]) { @@ -262,12 +262,12 @@ static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; } // We use fchown instead of chown because the latter can follow symbolic links - BOOL success = (fchown(fileDescriptor, ownerID.unsignedIntValue, groupID.unsignedIntValue) == 0); + BOOL success = (fchown(fileDescriptor, ownerID, groupID) == 0); close(fileDescriptor); if (!success) { if (error != NULL) { - *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to change owner & group for %@ with owner ID %u and group ID %u.", targetURL.path.lastPathComponent, ownerID.unsignedIntValue, groupID.unsignedIntValue] }]; + *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to change owner & group for %@ with owner ID %u and group ID %u.", targetURL.path.lastPathComponent, ownerID, groupID] }]; } } @@ -341,14 +341,14 @@ static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; // If we can't change both the new owner & group, try to only change the owner // If this works, this is sufficient enough for performing the update NSNumber *groupIDToUse; - if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:groupID error:NULL]) { + if (![self changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID.unsignedIntValue groupID:groupID.unsignedIntValue error:NULL]) { if ((targetOwnerID != nil && [ownerID isEqualToNumber:targetOwnerID])) { // Assume they're the same even if we don't check every file recursively // Speeds up the common case like above return YES; } - if (![self _changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID groupID:targetGroupID error:error]) { + if (![self changeOwnerAndGroupOfItemAtURL:targetURL ownerID:ownerID.unsignedIntValue groupID:targetGroupID.unsignedIntValue error:error]) { return NO; } @@ -360,7 +360,7 @@ static char SUAppleQuarantineIdentifier[] = "com.apple.quarantine"; if (isTargetADirectory) { NSDirectoryEnumerator *directoryEnumerator = [_fileManager enumeratorAtURL:targetURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; for (NSURL *url in directoryEnumerator) { - if (![self _changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID groupID:groupIDToUse error:error]) { + if (![self changeOwnerAndGroupOfItemAtURL:url ownerID:ownerID.unsignedIntValue groupID:groupIDToUse.unsignedIntValue error:error]) { return NO; } } diff --git a/sparkle-cli/SPUCommandLineDriver.m b/sparkle-cli/SPUCommandLineDriver.m index 372e5005..7fff162e 100644 --- a/sparkle-cli/SPUCommandLineDriver.m +++ b/sparkle-cli/SPUCommandLineDriver.m @@ -25,7 +25,8 @@ typedef NS_ENUM(int, CLIErrorExitStatus) { CLIErrorExitStatusInstallerInteractionNotAllowed = 3, CLIErrorExitStatusUpdateNotFound = 4, CLIErrorExitStatusUpdateCancelledAuthorization = 5, - CLIErrorExitStatusUpdatePermissionRequested = 6 + CLIErrorExitStatusUpdatePermissionRequested = 6, + CLIErrorCodeCannotInstallInteractivePackageAsRoot = 7, }; @interface SPUCommandLineDriver () @@ -150,7 +151,7 @@ typedef NS_ENUM(int, CLIErrorExitStatus) { } if (error != NULL) { - *error = [NSError errorWithDomain:SPARKLE_CLI_ERROR_DOMAIN code:CLIErrorCodeCannotPerformCheck userInfo:@{ NSLocalizedDescriptionKey: @"A new update check cannot be performed because updating this bundle will require user authorization. Please use --interactive to allow this." }]; + *error = [NSError errorWithDomain:SPARKLE_CLI_ERROR_DOMAIN code:CLIErrorCodeCannotPerformCheck userInfo:@{ NSLocalizedDescriptionKey: @"A new update check cannot be performed because updating this bundle will require user authorization. Please use --interactive or run as root to allow this." }]; } return NO; @@ -176,12 +177,14 @@ typedef NS_ENUM(int, CLIErrorExitStatus) { return NO; } - if (!self.interactive && ![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) { - if (error != NULL) { - *error = [NSError errorWithDomain:SPARKLE_CLI_ERROR_DOMAIN code:CLIErrorCodeCannotInstallPackage userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A new package-based update has been found (%@), but installing it will require user authorization. Please use --interactive to allow this.", updateItem.versionString] }]; + if (!self.interactive && geteuid() != 0) { // applicable for non-root only + if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) { + // Any package based updates will require authorization and therefore interaction + if (error != NULL) { + *error = [NSError errorWithDomain:SPARKLE_CLI_ERROR_DOMAIN code:CLIErrorCodeCannotInstallPackage userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A new package-based update has been found (%@), but installing it will require user authorization. Please use --interactive to allow this.", updateItem.versionString] }]; + } + return NO; } - - return NO; } return YES; @@ -240,6 +243,9 @@ typedef NS_ENUM(int, CLIErrorExitStatus) { fprintf(stderr, "Update was cancelled.\n"); } exit(CLIErrorExitStatusUpdateCancelledAuthorization); + } else if (error.code == SUInstallationRootInteractiveError) { + fprintf(stderr, "%s\n", error.localizedDescription.UTF8String); + exit(CLIErrorCodeCannotInstallInteractivePackageAsRoot); } else { fprintf(stderr, "Error: Update has failed due to error %ld (%s). %s\n", (long)error.code, error.domain.UTF8String, error.localizedDescription.UTF8String); exit(EXIT_FAILURE); diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index ee9a3517..20d995ce 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -65,8 +65,12 @@ - (void)displayHTMLReleaseNotes:(NSData *)releaseNotes { // Note: this is the only API we rely on here that references AppKit - NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:nil]; - [self displayReleaseNotes:attributedString.string.UTF8String]; + // We shouldn't invoke it when the calling process is ran under root. + // If only there was an API to translated HTML -> text that didn't rely on AppKit.. + if (geteuid() != 0) { + NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:nil]; + [self displayReleaseNotes:attributedString.string.UTF8String]; + } } - (void)displayPlainTextReleaseNotes:(NSData *)releaseNotes encoding:(NSStringEncoding)encoding diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index 6631b053..540aa25b 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -33,7 +33,7 @@ static void printUsage(char **argv) fprintf(stderr, " To check if an update is available without installing, use --%s.\n\n", PROBE_FLAG); fprintf(stderr, " if no updates are available now, or if the last update check was recently\n (unless --%s is specified) then nothing is done.\n\n", CHECK_NOW_FLAG); fprintf(stderr, " If update permission is requested and --%s is not\n specified, then checking for updates is aborted.\n\n", GRANT_AUTOMATIC_CHECKING_FLAG); - fprintf(stderr, " Unless --%s is specified, this tool will not request for escalated\n authorization. Running as root is not supported.\n\n", INTERACTIVE_FLAG); + fprintf(stderr, " Unless --%s is specified, this tool will not request for escalated\n authorization. Alternatively, this tool can be run as root under an active user login\n session, which will not require (and disallow) interaction.\n\n", INTERACTIVE_FLAG); fprintf(stderr, " If --%s is specified, this tool will exit leaving a spawned process\n for finishing the installation after the target application terminates.\n\n", DEFER_FLAG); fprintf(stderr, " Please specify --%s if you intend to use this tool in an automated way.\n", USER_AGENT_NAME); fprintf(stderr, "Options:\n"); @@ -55,11 +55,6 @@ int main(int argc, char **argv) { @autoreleasepool { - if (geteuid() == 0) { - fprintf(stderr, "Error: Running as root is not supported\n"); - return EXIT_FAILURE; - } - struct option longOptions[] = { {APPLICATION_FLAG, required_argument, NULL, 0}, {CHANNELS_FLAG, required_argument, NULL, 0}, @@ -176,6 +171,11 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + if (interactive && geteuid() == 0) { + fprintf(stderr, "Error: --%s is not supported when running as root\n", INTERACTIVE_FLAG); + return EXIT_FAILURE; + } + SUUpdatePermissionResponse *updatePermissionResponse = nil; if (grantAutomaticChecking) { updatePermissionResponse = [[SUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:YES sendSystemProfile:sendProfile];