diff --git a/InstallerConnection/SUInstallerConnection.m b/InstallerConnection/SUInstallerConnection.m index b4f26932..9715bca8 100644 --- a/InstallerConnection/SUInstallerConnection.m +++ b/InstallerConnection/SUInstallerConnection.m @@ -60,7 +60,7 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K - (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType { - NSXPCConnectionOptions options = SUNeedsSystemAuthorizationAccess(hostPath, installationType, NULL) ? NSXPCConnectionPrivileged : 0; + NSXPCConnectionOptions options = SUNeedsSystemAuthorizationAccess(hostPath, installationType) ? NSXPCConnectionPrivileged : 0; NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options]; connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)]; diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index abe56f4a..5d95bd79 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -12,6 +12,7 @@ #import "SUMessageTypes.h" #import "SUSystemAuthorization.h" #import "SUBundleIcon.h" +#import #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -42,7 +43,7 @@ NSArray *arguments = @[executablePath, hostBundlePath, @(inSystemDomainForInstaller).stringValue]; -#warning support running under system domain if updater is running as root - this means we would have to try running job under a different user + // The progress tool can only be ran as the logged in user, not as root CFStringRef domain = kSMDomainUserLaunchd; NSString *label = [NSString stringWithFormat:@"%@-sparkle-progress", hostBundleIdentifier]; @@ -264,11 +265,10 @@ dispatch_async(dispatch_get_main_queue(), ^{ NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath]; - BOOL preflighted = NO; - BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, installationType, &preflighted); + BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, installationType); - // if we need to use the system domain and we aren't already root and we aren't allowed interaction, then try sometime later when interaction is allowed - if (needsSystemAuthorization && !preflighted && !allowingInteraction) { + // if we need to use the system domain and we aren't allowed interaction, then try sometime later when interaction is allowed + if (needsSystemAuthorization && !allowingInteraction) { completionHandler(SUAuthorizationReplyAuthorizeLater); } else { SUAuthorizationReply installerReply = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle authorizationPrompt:authorizationPrompt allowingInteraction:allowingInteraction inSystemDomain:needsSystemAuthorization]; diff --git a/Sparkle/SUSystemAuthorization.h b/Sparkle/SUSystemAuthorization.h index 6e9232ce..8833154c 100644 --- a/Sparkle/SUSystemAuthorization.h +++ b/Sparkle/SUSystemAuthorization.h @@ -7,10 +7,9 @@ // #import -#import NS_ASSUME_NONNULL_BEGIN -BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType, BOOL * _Nullable preflighted); +BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType); NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUSystemAuthorization.m b/Sparkle/SUSystemAuthorization.m index 0b5a87e7..4ca36d59 100644 --- a/Sparkle/SUSystemAuthorization.m +++ b/Sparkle/SUSystemAuthorization.m @@ -7,47 +7,12 @@ // #import "SUSystemAuthorization.h" -#import #import "SUInstallationType.h" -static BOOL SUPreflightSystemAuthorization(void) -{ - // This should almost always succeed, fail in unusual/rare cases - AuthorizationRef auth = NULL; - OSStatus createStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth); - if (createStatus != errAuthorizationSuccess) { - return NO; - } - - AuthorizationItem rightItems[] = { - { .name = kSMRightModifySystemDaemons, .valueLength = 0, .value = NULL, .flags = 0} - }; - - AuthorizationRights rights = { - .count = sizeof(rightItems) / sizeof(*rightItems), - .items = rightItems, - }; - - AuthorizationFlags flags = - (AuthorizationFlags)(kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize); - - // This will test if we can gain authorization for running utlities as root - OSStatus copyStatus = AuthorizationCopyRights(auth, &rights, kAuthorizationEmptyEnvironment, flags, NULL); - - AuthorizationFree(auth, kAuthorizationFlagDefaults); - - return (copyStatus == errAuthorizationSuccess); -} - -BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType, BOOL * _Nullable preflighted) +BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType) { BOOL result; - if (SUPreflightSystemAuthorization()) { - if (preflighted != NULL) { - *preflighted = YES; - } - result = YES; - } else if ([installationType isEqualToString:SUInstallationTypeGuidedPackage]) { + if ([installationType isEqualToString:SUInstallationTypeGuidedPackage]) { result = YES; } else if ([installationType isEqualToString:SUInstallationTypePackage]) { result = NO; diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index 5346cfa9..0c391e00 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -46,6 +46,11 @@ 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}, {DEFER_FLAG, no_argument, NULL, 0},