mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Pass whether or not system domain is being used back to framework
This avoids needing to do a file system check in InstallerConnection to determine if we need to connect to the system or user domain.
This commit is contained in:
1 parent
a79aa1690b
commit
467ffb15ca
19 files changed
+121
-129
No files matched your search
@@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, readonly) SUAppcastItem *appcastItem;
|
||||
@property (nonatomic, readonly) BOOL canSilentlyInstall;
|
||||
|
||||
@property (nonatomic) BOOL systemDomain;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -14,22 +14,30 @@
|
||||
|
||||
static NSString *SUAppcastItemKey = @"SUAppcastItem";
|
||||
static NSString *SUCanSilentlyInstallKey = @"SUCanSilentlyInstall";
|
||||
static NSString *SUSystemDomainKey = @"SUSystemDomain";
|
||||
|
||||
@implementation SPUInstallationInfo
|
||||
|
||||
@synthesize appcastItem = _appcastItem;
|
||||
@synthesize canSilentlyInstall = _canSilentlyInstall;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_appcastItem = appcastItem;
|
||||
_canSilentlyInstall = canSilentlyInstall;
|
||||
_systemDomain = systemDomain;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall
|
||||
{
|
||||
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:NO];
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
SUAppcastItem *appcastItem = [decoder decodeObjectOfClass:[SUAppcastItem class] forKey:SUAppcastItemKey];
|
||||
@@ -38,13 +46,15 @@ static NSString *SUCanSilentlyInstallKey = @"SUCanSilentlyInstall";
|
||||
}
|
||||
|
||||
BOOL canSilentlyInstall = [decoder decodeBoolForKey:SUCanSilentlyInstallKey];
|
||||
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall];
|
||||
BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey];
|
||||
return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.appcastItem forKey:SUAppcastItemKey];
|
||||
[coder encodeBool:self.canSilentlyInstall forKey:SUCanSilentlyInstallKey];
|
||||
[coder encodeBool:self.systemDomain forKey:SUSystemDomainKey];
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
#import "SUInstallerConnection.h"
|
||||
#import "SPUSystemAuthorization.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
@@ -61,9 +60,9 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K
|
||||
[self enableAutomaticTermination];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
NSXPCConnectionOptions options = SPUNeedsSystemAuthorizationAccess(hostPath, installationType) ? NSXPCConnectionPrivileged : 0;
|
||||
NSXPCConnectionOptions options = systemDomain ? NSXPCConnectionPrivileged : 0;
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options];
|
||||
|
||||
connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler;
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType;
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName hostPath:hostPath installationType:installationType];
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#import "SUFileManager.h"
|
||||
#import "SULog.h"
|
||||
#import "SPUMessageTypes.h"
|
||||
#import "SPUSystemAuthorization.h"
|
||||
#import "SUBundleIcon.h"
|
||||
#import "SPULocalCacheDirectory.h"
|
||||
#import "SPUInstallationType.h"
|
||||
@@ -281,8 +280,50 @@
|
||||
return resolvedAuxiliaryToolURL.path;
|
||||
}
|
||||
|
||||
static BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType)
|
||||
{
|
||||
BOOL needsAuthorization;
|
||||
if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
needsAuthorization = YES;
|
||||
} else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
needsAuthorization = NO;
|
||||
} else {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL hasWritability = [fileManager isWritableFileAtPath:path] && [fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
|
||||
if (!hasWritability) {
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
// Just because we have writability access does not mean we can set the correct owner/group
|
||||
// Test if we can set the owner/group on a temporarily created file
|
||||
// If we can, then we can probably perform an update without authorization
|
||||
|
||||
NSString *tempFilename = @"permission_test" ;
|
||||
|
||||
SUFileManager *suFileManager = [[SUFileManager alloc] init];
|
||||
NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL];
|
||||
|
||||
if (tempDirectoryURL == nil) {
|
||||
// I don't imagine this ever happening but in case it does, requesting authorization may be the better option
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename];
|
||||
if (![[NSData data] writeToURL:tempFileURL atomically:NO]) {
|
||||
// Obvious indicator we may need authorization
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
needsAuthorization = ![suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:[NSURL fileURLWithPath:path] error:NULL];
|
||||
}
|
||||
|
||||
[suFileManager removeItemAtURL:tempDirectoryURL error:NULL];
|
||||
}
|
||||
}
|
||||
}
|
||||
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 authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus))completionHandler
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
|
||||
@@ -290,19 +331,19 @@
|
||||
|
||||
if (needsSystemAuthorization && !allowingUpdaterInteraction) {
|
||||
SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher.");
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowingUpdaterInteraction && [installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher for performing an interactive type package installation.");
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
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);
|
||||
completionHandler(SUInstallerLauncherAuthorizeLater, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -317,7 +358,7 @@
|
||||
NSString *installerPath = [self pathForBundledTool:@""SPARKLE_RELAUNCH_TOOL_NAME extension:@"" inBundle:ourBundle];
|
||||
if (installerPath == nil) {
|
||||
SULog(SULogLevelError, @"Error: Cannot submit installer because the installer could not be located");
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -326,7 +367,7 @@
|
||||
|
||||
if (progressToolResourcePath == nil) {
|
||||
SULog(SULogLevelError, @"Error: Cannot submit progress tool because the progress tool could not be located");
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -342,7 +383,7 @@
|
||||
NSString *launcherCachePath = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootLauncherCachePath];
|
||||
if (launcherCachePath == nil) {
|
||||
SULog(SULogLevelError, @"Failed to create cache directory for progress tool in %@", rootLauncherCachePath);
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -352,7 +393,7 @@
|
||||
// SUFileManager is more reliable for copying files around
|
||||
if (![[[SUFileManager alloc] init] copyItemAtURL:[NSURL fileURLWithPath:progressToolResourcePath] toURL:[NSURL fileURLWithPath:progressToolPath] error:©Error]) {
|
||||
SULog(SULogLevelError, @"Failed to copy progress tool to cache: %@", copyError);
|
||||
completionHandler(SUInstallerLauncherFailure);
|
||||
completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,9 +411,9 @@
|
||||
}
|
||||
|
||||
if (installerStatus == SUInstallerLauncherCanceled) {
|
||||
completionHandler(installerStatus);
|
||||
completionHandler(installerStatus, needsSystemAuthorization);
|
||||
} else {
|
||||
completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure);
|
||||
completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure, needsSystemAuthorization);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
@protocol SUInstallerLauncherProtocol
|
||||
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus))completionHandler;
|
||||
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler;
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL requiresAuthorization))reply;
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
#import "SUInstallerStatus.h"
|
||||
#import "SPUSystemAuthorization.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
7205C4631E1306B500E370AE /* libxar.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E07681CA616A4001A286B /* libxar.tbd */; };
|
||||
7205C4641E1306BE00E370AE /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E076A1CA616B3001A286B /* libbz2.tbd */; };
|
||||
720767D31E2EE9C200F9A850 /* SUTouchBarForwardDeclarations.h in Headers */ = {isa = PBXBuildFile; fileRef = 720767D21E2EE9C200F9A850 /* SUTouchBarForwardDeclarations.h */; };
|
||||
720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B51D3D8AEE00D1BF90 /* SPUInstallationInfo.m */; };
|
||||
720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; };
|
||||
720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; };
|
||||
720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; };
|
||||
720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */ = {isa = PBXBuildFile; fileRef = 720E21791D0D00BF003A311C /* SPUUpdaterCycle.h */; };
|
||||
720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */ = {isa = PBXBuildFile; fileRef = 720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */; };
|
||||
@@ -139,7 +142,6 @@
|
||||
7214B8831D456C2400CB5CED /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; };
|
||||
7214B8841D456C9500CB5CED /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; };
|
||||
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; };
|
||||
721652621D3C44A100FD13D8 /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
721BC20E1D1CDE55002BC71E /* SPULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 721BC20C1D1CDE55002BC71E /* SPULocalCacheDirectory.h */; };
|
||||
721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; };
|
||||
721BC2101D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; };
|
||||
@@ -208,10 +210,6 @@
|
||||
724BB3A81D33461B005D534A /* SUXPCInstallerStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 724BB3A61D33461B005D534A /* SUXPCInstallerStatus.h */; };
|
||||
724BB3A91D33461B005D534A /* SUXPCInstallerStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3A71D33461B005D534A /* SUXPCInstallerStatus.m */; };
|
||||
724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3971D333832005D534A /* SUInstallerStatus.m */; };
|
||||
724BB3AF1D34828A005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
724BB3B71D35ABA8005D534A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; };
|
||||
724F76F91D6EAD0D00ECD062 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; };
|
||||
725264A91D5FBD9100CD6400 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; };
|
||||
@@ -337,7 +335,6 @@
|
||||
72A5D5B51D6929F80009E5AC /* SPUMessageTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B01D3D8AD500D1BF90 /* SPUMessageTypes.m */; };
|
||||
72A5D5B61D6929F80009E5AC /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; };
|
||||
72A5D5B71D6929F80009E5AC /* SPUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B51D3D8AEE00D1BF90 /* SPUInstallationInfo.m */; };
|
||||
72A5D5B81D6929F80009E5AC /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; };
|
||||
72A5D5B91D6929F80009E5AC /* SUAppcast.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FB9509C4F04600B25A18 /* SUAppcast.m */; };
|
||||
72A5D5BA1D6929F80009E5AC /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; };
|
||||
72A5D5BB1D6929F80009E5AC /* SPUURLDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B09CE61CE6BCBD0052EF9E /* SPUURLDownload.m */; };
|
||||
@@ -1198,8 +1195,6 @@
|
||||
724BB3A51D3338C8005D534A /* ConfigInstallerStatusDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerStatusDebug.xcconfig; sourceTree = "<group>"; };
|
||||
724BB3A61D33461B005D534A /* SUXPCInstallerStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUXPCInstallerStatus.h; sourceTree = "<group>"; };
|
||||
724BB3A71D33461B005D534A /* SUXPCInstallerStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUXPCInstallerStatus.m; sourceTree = "<group>"; };
|
||||
724BB3AB1D347EDE005D534A /* SPUSystemAuthorization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUSystemAuthorization.h; path = Sparkle/SPUSystemAuthorization.h; sourceTree = SOURCE_ROOT; };
|
||||
724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUSystemAuthorization.m; path = Sparkle/SPUSystemAuthorization.m; sourceTree = SOURCE_ROOT; };
|
||||
724BB3B51D35AAC3005D534A /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
|
||||
725602D31C83551C00DAA70E /* SUApplicationInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUApplicationInfo.h; sourceTree = "<group>"; };
|
||||
725602D41C83551C00DAA70E /* SUApplicationInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUApplicationInfo.m; sourceTree = "<group>"; };
|
||||
@@ -2225,8 +2220,6 @@
|
||||
7267E5B01D3D8AD500D1BF90 /* SPUMessageTypes.m */,
|
||||
726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */,
|
||||
726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */,
|
||||
724BB3AB1D347EDE005D534A /* SPUSystemAuthorization.h */,
|
||||
724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */,
|
||||
);
|
||||
name = IPC;
|
||||
path = Autoupdate;
|
||||
@@ -3395,13 +3388,15 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */,
|
||||
720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */,
|
||||
720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */,
|
||||
72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */,
|
||||
72D954831CBAD34F006F28BD /* main.m in Sources */,
|
||||
72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */,
|
||||
727F340E2605321D00020E85 /* SULog+NSError.m in Sources */,
|
||||
7267E5DC1D3D8F1E00D1BF90 /* SPUMessageTypes.m in Sources */,
|
||||
723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */,
|
||||
721652621D3C44A100FD13D8 /* SPUSystemAuthorization.m in Sources */,
|
||||
5AA89BA623FE276A0094DAB8 /* SUSignatures.m in Sources */,
|
||||
7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */,
|
||||
720595EF1D700568000572E8 /* SUApplicationInfo.m in Sources */,
|
||||
@@ -3421,7 +3416,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
724BB3731D31D0B7005D534A /* main.m in Sources */,
|
||||
724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3711D31D0B7005D534A /* SUInstallerConnection.m in Sources */,
|
||||
);
|
||||
@@ -3432,7 +3426,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
724BB39A1D333832005D534A /* main.m in Sources */,
|
||||
724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3981D333832005D534A /* SUInstallerStatus.m in Sources */,
|
||||
);
|
||||
@@ -3455,7 +3448,6 @@
|
||||
726E07B41CAF08D6001A286B /* main.m in Sources */,
|
||||
721D8A7B1D4963190032E472 /* SPULocalCacheDirectory.m in Sources */,
|
||||
7267E5E11D3D901600D1BF90 /* SPUMessageTypes.m in Sources */,
|
||||
724BB3AF1D34828A005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
5AA89BA523FE27660094DAB8 /* SUSignatures.m in Sources */,
|
||||
7214B8841D456C9500CB5CED /* SUBundleIcon.m in Sources */,
|
||||
726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */,
|
||||
@@ -3512,7 +3504,6 @@
|
||||
72A5D5CA1D6929F80009E5AC /* SPUProbingUpdateDriver.m in Sources */,
|
||||
72A5D5C91D6929F80009E5AC /* SPUScheduledUpdateDriver.m in Sources */,
|
||||
72A5D5B61D6929F80009E5AC /* SPUSecureCoding.m in Sources */,
|
||||
72A5D5B81D6929F80009E5AC /* SPUSystemAuthorization.m in Sources */,
|
||||
72A5D5CC1D6929F80009E5AC /* SPUUIBasedUpdateDriver.m in Sources */,
|
||||
72A5D5D61D6929F80009E5AC /* SPUUpdatePermissionRequest.m in Sources */,
|
||||
72A5D5D41D6929F80009E5AC /* SPUUpdater.m in Sources */,
|
||||
@@ -3623,7 +3614,6 @@
|
||||
726E075D1CA3A6D6001A286B /* SPUSecureCoding.m in Sources */,
|
||||
7246E0A41C83B685003B4E75 /* SPUStandardUpdaterController.m in Sources */,
|
||||
725CB95B1C7121830064365A /* SPUStandardUserDriver.m in Sources */,
|
||||
724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */,
|
||||
72B767DB1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.m in Sources */,
|
||||
72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */,
|
||||
|
||||
+15
-2
@@ -19,6 +19,8 @@
|
||||
#import "SUErrors.h"
|
||||
#import "SUNormalization.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SPUSecureCoding.h"
|
||||
#import "SPUInstallationInfo.h"
|
||||
|
||||
/*!
|
||||
* Terminate the application after a delay from launching the new update to avoid OS activation issues
|
||||
@@ -37,6 +39,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@property (nonatomic, readonly) SUHost *oldHost;
|
||||
@property (nonatomic, readonly) BOOL shouldRelaunchHostBundle;
|
||||
@property (nonatomic, readonly) NSString *oldHostBundlePath;
|
||||
@property (nonatomic, readonly) BOOL systemDomain;
|
||||
@property (nonatomic) StatusInfo *statusInfo;
|
||||
@property (nonatomic) BOOL submittedLauncherJob;
|
||||
@property (nonatomic) BOOL willTerminate;
|
||||
@@ -58,6 +61,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@synthesize oldHost = _oldHost;
|
||||
@synthesize shouldRelaunchHostBundle = _shouldRelaunchHostBundle;
|
||||
@synthesize oldHostBundlePath = _oldHostBundlePath;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
@synthesize statusInfo = _statusInfo;
|
||||
@synthesize submittedLauncherJob = _submittedLauncherJob;
|
||||
@synthesize willTerminate = _willTerminate;
|
||||
@@ -104,6 +108,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
// nor have a model where a process that runs at the highest level (the installer can run as root) tries to connect to a user level agent or process
|
||||
BOOL systemDomain = arguments[2].boolValue;
|
||||
NSXPCConnectionOptions connectionOptions = systemDomain ? NSXPCConnectionPrivileged : 0;
|
||||
|
||||
_systemDomain = systemDomain;
|
||||
_connection = [[NSXPCConnection alloc] initWithMachServiceName:SPUProgressAgentServiceNameForBundleIdentifier(hostBundleIdentifier) options:connectionOptions];
|
||||
|
||||
_statusInfo = [[StatusInfo alloc] initWithHostBundleIdentifier:hostBundleIdentifier];
|
||||
@@ -264,8 +270,15 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)registerInstallationInfoData:(NSData *)installationInfoData
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.statusInfo.installationInfoData == nil) {
|
||||
self.statusInfo.installationInfoData = installationInfoData;
|
||||
if (self.statusInfo.installationInfoData == nil && installationInfoData != nil) {
|
||||
SPUInstallationInfo *installationInfo = (SPUInstallationInfo *)SPUUnarchiveRootObjectSecurely(installationInfoData, [SPUInstallationInfo class]);
|
||||
|
||||
if (installationInfo != nil) {
|
||||
installationInfo.systemDomain = self.systemDomain;
|
||||
self.statusInfo.installationInfoData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Error: Failed to decode initial installation info from installer: %@", installationInfoData);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SPUBasicUpdateDriverDelegate <NSObject>
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate;
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain;
|
||||
|
||||
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error;
|
||||
|
||||
|
||||
Vendored
+11
-6
@@ -79,7 +79,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem
|
||||
- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem systemDomain:(NSNumber * _Nullable)systemDomain
|
||||
{
|
||||
if (updateItem == nil) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]];
|
||||
@@ -88,7 +88,7 @@
|
||||
[self notifyFinishLoadingAppcast];
|
||||
|
||||
SUAppcastItem *nonNullUpdateItem = updateItem;
|
||||
[self didFindValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO];
|
||||
[self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO systemDomain:systemDomain];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
assert(hostBundleIdentifier != nil);
|
||||
[SPUProbeInstallStatus probeInstallerUpdateItemForHostBundleIdentifier:hostBundleIdentifier completion:^(SPUInstallationInfo * _Nullable installationInfo) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyResumableUpdateItem:installationInfo.appcastItem];
|
||||
[self notifyResumableUpdateItem:installationInfo.appcastItem systemDomain:@(installationInfo.systemDomain)];
|
||||
});
|
||||
}];
|
||||
}
|
||||
@@ -109,7 +109,7 @@
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
|
||||
[self notifyResumableUpdateItem:resumableUpdate.updateItem];
|
||||
[self notifyResumableUpdateItem:resumableUpdate.updateItem systemDomain:nil];
|
||||
}
|
||||
|
||||
- (SUAppcastItem *)nonDeltaUpdateItem
|
||||
@@ -142,7 +142,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain
|
||||
{
|
||||
if (!self.aborted) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||
@@ -153,10 +153,15 @@
|
||||
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
|
||||
}
|
||||
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate systemDomain:systemDomain];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
{
|
||||
[self notifyFoundValidUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate systemDomain:nil];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult
|
||||
{
|
||||
if (!self.aborted) {
|
||||
|
||||
Vendored
+3
-2
@@ -145,12 +145,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
|
||||
if (self.resumingInstallingUpdate) {
|
||||
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem];
|
||||
assert(systemDomain != nil);
|
||||
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue];
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate];
|
||||
} else {
|
||||
if (!self.preventsInstallerInteraction) {
|
||||
|
||||
Vendored
+1
-1
@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id<SPUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SPUInstallerDriverDelegate>)delegate;
|
||||
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem;
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem systemDomain:(BOOL)systemDomain;
|
||||
|
||||
- (void)checkIfApplicationInstallationRequiresAuthorizationWithReply:(void (^)(BOOL requiresAuthorization))reply;
|
||||
|
||||
|
||||
Vendored
+8
-9
@@ -54,6 +54,8 @@
|
||||
@property (nonatomic, weak, readonly) id<SPUUpdaterDelegate> updaterDelegate;
|
||||
@property (nonatomic) BOOL willRelaunch;
|
||||
|
||||
@property (nonatomic) BOOL systemDomain;
|
||||
|
||||
@property (nonatomic) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, copy) NSString *temporaryDirectory;
|
||||
@@ -77,6 +79,7 @@
|
||||
@synthesize updater = _updater;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize willRelaunch = _willRelaunch;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize temporaryDirectory = _temporaryDirectory;
|
||||
@@ -137,7 +140,7 @@
|
||||
NSString *installationType = self.updateItem.installationType;
|
||||
assert(installationType != nil);
|
||||
|
||||
[self.installerConnection setServiceName:serviceName hostPath:self.host.bundlePath installationType:installationType];
|
||||
[self.installerConnection setServiceName:serviceName systemDomain:self.systemDomain];
|
||||
|
||||
[self sendInstallationData];
|
||||
}
|
||||
@@ -160,9 +163,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
self.systemDomain = systemDomain;
|
||||
}
|
||||
|
||||
- (void)sendInstallationData
|
||||
@@ -433,7 +437,7 @@
|
||||
|
||||
// The installer launcher could be in a XPC service, so we don't want to do localization in there
|
||||
NSString *authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants to update.", nil), self.host.name];
|
||||
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result) {
|
||||
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result, BOOL systemDomain) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
retrievedLaunchStatus = YES;
|
||||
[launcherConnection invalidate];
|
||||
@@ -450,6 +454,7 @@
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationAuthorizeLaterError userInfo:nil]);
|
||||
break;
|
||||
case SUInstallerLauncherSuccess:
|
||||
self.systemDomain = systemDomain;
|
||||
[self setUpConnection];
|
||||
completionHandler(nil);
|
||||
break;
|
||||
@@ -463,12 +468,6 @@
|
||||
return (!self.updaterDelegate || ![self.updaterDelegate respondsToSelector:@selector((updaterShouldRelaunchApplication:))] || [self.updaterDelegate updaterShouldRelaunchApplication:self.updater]);
|
||||
}
|
||||
|
||||
// Only implemented due to backwards compability reasons; see -installWithToolAndRelaunch:displayingUserInterface: below
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
[self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch];
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
Vendored
+1
-1
@@ -54,7 +54,7 @@
|
||||
[self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock];
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate systemDomain:(NSNumber * _Nullable)__unused systemDomain
|
||||
{
|
||||
// Stop as soon as we have an answer
|
||||
[self abortUpdate];
|
||||
|
||||
Vendored
+3
@@ -8,6 +8,9 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// If we are using XPC without using XPC Services, our custom classes will not be (de)serialized automatically,
|
||||
// hence needing functions to archive/unarchive NSSecureCoding objects.
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSData * _Nullable SPUArchiveRootObjectSecurely(id<NSSecureCoding> rootObject);
|
||||
|
||||
Vendored
-15
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// SPUSystemAuthorization.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/11/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
-55
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// SPUSystemAuthorization.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 7/11/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUSystemAuthorization.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUFileManager.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType)
|
||||
{
|
||||
BOOL needsAuthorization;
|
||||
if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
needsAuthorization = YES;
|
||||
} else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
needsAuthorization = NO;
|
||||
} else {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL hasWritability = [fileManager isWritableFileAtPath:path] && [fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
|
||||
if (!hasWritability) {
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
// Just because we have writability access does not mean we can set the correct owner/group
|
||||
// Test if we can set the owner/group on a temporarily created file
|
||||
// If we can, then we can probably perform an update without authorization
|
||||
|
||||
NSString *tempFilename = @"permission_test" ;
|
||||
|
||||
SUFileManager *suFileManager = [[SUFileManager alloc] init];
|
||||
NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL];
|
||||
|
||||
if (tempDirectoryURL == nil) {
|
||||
// I don't imagine this ever happening but in case it does, requesting authorization may be the better option
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename];
|
||||
if (![[NSData data] writeToURL:tempFileURL atomically:NO]) {
|
||||
// Obvious indicator we may need authorization
|
||||
needsAuthorization = YES;
|
||||
} else {
|
||||
needsAuthorization = ![suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:[NSURL fileURLWithPath:path] error:NULL];
|
||||
}
|
||||
|
||||
[suFileManager removeItemAtURL:tempDirectoryURL error:NULL];
|
||||
}
|
||||
}
|
||||
}
|
||||
return needsAuthorization;
|
||||
}
|
||||
Reference in new issue
Block a user