Disable root support & checking

Assume that the updater will be run as a logged in user.
The command line driver and progress app aren't completely root safe anyway, and running the progress app under a different user could be quite awkward from root
This commit is contained in:
Zorg committed 2016-07-26 19:16:38 -04:00
1 parent 9f4e44f919
commit 0ca688073b
5 files changed
+14 -45

No files matched your search

+1 -1
View File
@@ -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)];
+5 -5
View File
@@ -12,6 +12,7 @@
#import "SUMessageTypes.h"
#import "SUSystemAuthorization.h"
#import "SUBundleIcon.h"
#import <ServiceManagement/ServiceManagement.h>
#ifdef _APPKITDEFINES_H
#error This is a "core" class and should NOT import AppKit
@@ -42,7 +43,7 @@
NSArray<NSString *> *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];
+1 -2
View File
@@ -7,10 +7,9 @@
//
#import <Foundation/Foundation.h>
#import <ServiceManagement/SMLoginItem.h>
NS_ASSUME_NONNULL_BEGIN
BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType, BOOL * _Nullable preflighted);
BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType);
NS_ASSUME_NONNULL_END
+2 -37
View File
@@ -7,47 +7,12 @@
//
#import "SUSystemAuthorization.h"
#import <ServiceManagement/ServiceManagement.h>
#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;
+5
View File
@@ -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},