mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-23 04:34:27 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6b704ea55 | ||
|
|
77fc6ca681 | ||
|
|
46c22e2bbf | ||
|
|
92d7b9f68f | ||
|
|
6b6b6b2405 | ||
|
|
b854b01e6a | ||
|
|
61e16cf276 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
INSTALL_PATH = @loader_path/../Frameworks
|
||||
DYLIB_COMPATIBILITY_VERSION = 2.0
|
||||
DYLIB_CURRENT_VERSION = 2.0
|
||||
DYLIB_CURRENT_VERSION = 2.0.1
|
||||
PRODUCT_NAME = Sparkle
|
||||
WRAPPER_EXTENSION = framework
|
||||
FRAMEWORK_VERSION = A
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
|
||||
typedef enum _SUInstallSerciveTask
|
||||
{
|
||||
SUInstallServiceTaskCopyPath = 1LL,
|
||||
SUInstallServiceTaskLaunchTask = 2LL
|
||||
SUInstallServiceTaskCopyPath = 1LL,
|
||||
SUInstallServiceTaskAuthCopyPath = 2LL,
|
||||
SUInstallServiceTaskLaunchTask = 3LL
|
||||
} SUInstallServiceTask;
|
||||
|
||||
const char * SUInstallServiceTaskTypeKey = "task_type"; // int64_t
|
||||
|
||||
// SUInstallServiceTaskCopyPath keys
|
||||
// SUInstallServiceTaskCopyPath & SUInstallServiceTaskAuthCopyPath keys
|
||||
const char * SUInstallServiceSourcePathKey = "source_path"; // c-string
|
||||
const char * SUInstallServiceDestinationPathKey = "destination_path"; // c-string
|
||||
const char * SUInstallServiceTempNameKey = "tmp_name"; // c-string
|
||||
@@ -25,9 +26,14 @@ const char * SUInstallServiceTempNameKey = "tmp_name"; // c-string
|
||||
// SUInstallServiceTaskLaunchTask keys
|
||||
const char * SUInstallServiceLaunchTaksPathKey = "launch_task_path";
|
||||
const char * SUInstallServiceLaunchTaskArgumentsKey = "launch_task_arguments"; // xpc_array of c-strings
|
||||
const char * SUInstallServiceLaunchTaskEnvironmentKey = "launch_task_environment"; // xpc_dictionary with keys and values of c-strings
|
||||
const char * SUInstallServiceLaunchTaskCurrentDirKey = "launch_task_cur_dir"; // c-string
|
||||
const char * SUInstallServiceLaunchTaskInputDataKey = "launch_task_input_data"; // xpc_data
|
||||
const char * SUInstallServiceLaunchTaskReplyImmediatelyKey = "launch_task_reply_immediately"; // bool
|
||||
|
||||
// Reply keys
|
||||
const char * SUInstallServiceErrorCodeKey = "error_code"; // int64_t
|
||||
const char * SUInstallServiceErrorLocalizedDescriptionKey = "error_localized_description"; // c-string
|
||||
const char * SUInstallServiceLaunchTaskOutputDataKey = "launch_task_output_data"; // xpc_data
|
||||
|
||||
#endif
|
||||
@@ -8,9 +8,22 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface SUXPCInstaller : NSObject
|
||||
|
||||
+ (void)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp completionHandler:(void (^)(NSError *error))completionHandler;
|
||||
+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments completionHandler:(void (^)(void))completionHandler ;
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)outError;
|
||||
|
||||
+ (BOOL)copyPathContent:(NSString *)src toDirectory:(NSString *)dstDir error:(NSError **)outError; // dstDir will be created if absent
|
||||
|
||||
+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments completionHandler:(void (^)(void))completionHandler;
|
||||
|
||||
+ (void)launchTaskWithPath:(NSString *)launchPath
|
||||
arguments:(NSArray *)arguments
|
||||
environment:(NSDictionary *)environment
|
||||
currentDirectoryPath:(NSString *)currentDirPath
|
||||
inputData:(NSData *)inputData
|
||||
waitForTaskResult:(BOOL)waitForTaskResult
|
||||
waitUntilDone:(BOOL)waitUntilDone // for sync/async logic
|
||||
completionHandler:(void (^)(int result, NSData *outputData))completionHandler;
|
||||
|
||||
@end
|
||||
@@ -44,12 +44,12 @@
|
||||
return (serviceConnection);
|
||||
}
|
||||
|
||||
+ (void)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp completionHandler:(void (^)(NSError *error))completionHandler
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)outError
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskCopyPath);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskAuthCopyPath);
|
||||
|
||||
if (src)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceSourcePathKey, [src fileSystemRepresentation]);
|
||||
@@ -58,50 +58,212 @@
|
||||
if (tmp)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceTempNameKey, [tmp UTF8String]);
|
||||
|
||||
xpc_connection_send_message_with_reply(connection, message, dispatch_get_main_queue(), ^(xpc_object_t response) {
|
||||
if (NULL == completionHandler)
|
||||
return;
|
||||
__block BOOL xpcDidReply = NO;
|
||||
__block NSError *error = nil;
|
||||
|
||||
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
|
||||
xpc_connection_send_message_with_reply(connection, message, queue, ^(xpc_object_t response) {
|
||||
if (XPC_TYPE_ERROR == xpc_get_type(response))
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Internal XPC error."
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
else if (XPC_TYPE_DICTIONARY == xpc_get_type(response))
|
||||
{
|
||||
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
|
||||
if (errorString != NULL)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:[NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
}
|
||||
|
||||
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
|
||||
if (errorString != NULL)
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain
|
||||
code:SUXPCServiceError
|
||||
userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]
|
||||
forKey:NSLocalizedDescriptionKey]];
|
||||
completionHandler(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
completionHandler(nil);
|
||||
}
|
||||
xpcDidReply = YES;
|
||||
});
|
||||
|
||||
while (NO == xpcDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
|
||||
}
|
||||
|
||||
xpc_release(message);
|
||||
dispatch_release(queue);
|
||||
|
||||
[error autorelease];
|
||||
if (nil != error && NULL != outError)
|
||||
{
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return (nil == error);
|
||||
}
|
||||
|
||||
+ (BOOL)copyPathContent:(NSString *)src toDirectory:(NSString *)dstDir error:(NSError **)outError
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskCopyPath);
|
||||
|
||||
if (src)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceSourcePathKey, [src fileSystemRepresentation]);
|
||||
if (dstDir)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceDestinationPathKey, [dstDir fileSystemRepresentation]);
|
||||
|
||||
__block BOOL xpcDidReply = NO;
|
||||
__block NSError *error = nil;
|
||||
|
||||
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
|
||||
xpc_connection_send_message_with_reply(connection, message, queue, ^(xpc_object_t response) {
|
||||
if (XPC_TYPE_ERROR == xpc_get_type(response))
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Internal XPC error."
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
else if (XPC_TYPE_DICTIONARY == xpc_get_type(response))
|
||||
{
|
||||
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
|
||||
if (errorString != NULL)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:[NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
}
|
||||
|
||||
xpcDidReply = YES;
|
||||
});
|
||||
|
||||
while (NO == xpcDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
|
||||
}
|
||||
|
||||
xpc_release(message);
|
||||
dispatch_release(queue);
|
||||
|
||||
[error autorelease];
|
||||
if (nil != error && NULL != outError)
|
||||
{
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return (nil == error);
|
||||
}
|
||||
|
||||
+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments completionHandler:(void (^)(void))completionHandler
|
||||
{
|
||||
void (^handler)(int, NSData *) = completionHandler != nil ? ^(int r, NSData *d) { completionHandler(); } : nil;
|
||||
[self launchTaskWithPath:path
|
||||
arguments:arguments
|
||||
environment:nil
|
||||
currentDirectoryPath:nil
|
||||
inputData:nil
|
||||
waitForTaskResult:NO
|
||||
waitUntilDone:NO
|
||||
completionHandler:handler];
|
||||
}
|
||||
|
||||
+ (void)launchTaskWithPath:(NSString *)launchPath
|
||||
arguments:(NSArray *)arguments
|
||||
environment:(NSDictionary *)environment
|
||||
currentDirectoryPath:(NSString *)currentDirPath
|
||||
inputData:(NSData *)inputData
|
||||
waitForTaskResult:(BOOL)waitForTaskResult
|
||||
waitUntilDone:(BOOL)waitUntilDone
|
||||
completionHandler:(void (^)(int result, NSData *outputData))completionHandler
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskLaunchTask);
|
||||
|
||||
if (path)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceLaunchTaksPathKey, [path fileSystemRepresentation]);
|
||||
|
||||
xpc_object_t array = xpc_array_create(NULL, 0);
|
||||
for (id argument in arguments)
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskLaunchTask);
|
||||
|
||||
if ([launchPath length])
|
||||
{
|
||||
xpc_array_set_string(array, XPC_ARRAY_APPEND, [argument UTF8String]);
|
||||
}
|
||||
xpc_dictionary_set_value(message, SUInstallServiceLaunchTaskArgumentsKey, array);
|
||||
xpc_release(array);
|
||||
|
||||
xpc_dictionary_set_string(message, SUInstallServiceLaunchTaksPathKey, [launchPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ([arguments count])
|
||||
{
|
||||
xpc_object_t array = xpc_array_create(NULL, 0);
|
||||
for (NSString *argument in arguments)
|
||||
{
|
||||
if (![argument isKindOfClass:[NSString class]])
|
||||
argument = [argument description];
|
||||
|
||||
xpc_array_set_string(array, XPC_ARRAY_APPEND, [argument UTF8String]);
|
||||
}
|
||||
xpc_dictionary_set_value(message, SUInstallServiceLaunchTaskArgumentsKey, array);
|
||||
xpc_release(array);
|
||||
}
|
||||
|
||||
if ([environment count])
|
||||
{
|
||||
__block xpc_object_t dict = xpc_dictionary_create(NULL, NULL, 0);
|
||||
[environment enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
||||
NSString *xpc_key = [key isKindOfClass:[NSString class]] ? key : [key description];
|
||||
NSString *xpc_value = [obj isKindOfClass:[NSString class]] ? obj : [obj description];
|
||||
|
||||
xpc_dictionary_set_string(dict, [xpc_key UTF8String], [xpc_value UTF8String]);
|
||||
}];
|
||||
|
||||
xpc_dictionary_set_value(message, SUInstallServiceLaunchTaskEnvironmentKey, dict);
|
||||
xpc_release(dict);
|
||||
}
|
||||
|
||||
if ([currentDirPath length])
|
||||
{
|
||||
xpc_dictionary_set_string(message, SUInstallServiceLaunchTaskCurrentDirKey, [currentDirPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ([inputData length])
|
||||
{
|
||||
xpc_dictionary_set_data(message, SUInstallServiceLaunchTaskInputDataKey, [inputData bytes], [inputData length]);
|
||||
}
|
||||
|
||||
xpc_dictionary_set_bool(message, SUInstallServiceLaunchTaskReplyImmediatelyKey, waitForTaskResult ? false : true);
|
||||
|
||||
__block BOOL xpcTaskDidReply = NO;
|
||||
xpc_connection_send_message_with_reply(connection, message, dispatch_get_current_queue(), ^(xpc_object_t response) {
|
||||
int taskResult = 0;
|
||||
NSData *outputData = nil;
|
||||
|
||||
if (completionHandler != NULL)
|
||||
completionHandler();
|
||||
{
|
||||
xpc_type_t type = xpc_get_type(response);
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
taskResult = SUXPCServiceError;
|
||||
}
|
||||
else if (type == XPC_TYPE_DICTIONARY)
|
||||
{
|
||||
taskResult = (int)xpc_dictionary_get_int64(response, SUInstallServiceErrorCodeKey);
|
||||
|
||||
size_t bytesLen = 0;
|
||||
const void *bytes = xpc_dictionary_get_data(response, SUInstallServiceLaunchTaskOutputDataKey, &bytesLen);
|
||||
if (NULL != bytes)
|
||||
{
|
||||
outputData = [NSData dataWithBytes:bytes length:bytesLen];
|
||||
}
|
||||
}
|
||||
|
||||
completionHandler(taskResult, outputData);
|
||||
}
|
||||
|
||||
xpcTaskDidReply = YES;
|
||||
});
|
||||
xpc_release(message);
|
||||
|
||||
if (waitUntilDone)
|
||||
{
|
||||
while (NO == xpcTaskDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -13,8 +13,279 @@
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUInstallServiceConstants.h"
|
||||
#import "SULog.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
static void peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
static xpc_object_t SUSICopyPathContent(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *src = xpc_dictionary_get_string(message, SUInstallServiceSourcePathKey);
|
||||
const char *dst = xpc_dictionary_get_string(message, SUInstallServiceDestinationPathKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *sourcePath = src ? [manager stringWithFileSystemRepresentation:src length:strlen(src)] : nil;
|
||||
NSString *targetPath = dst ? [manager stringWithFileSystemRepresentation:dst length:strlen(dst)] : nil;
|
||||
|
||||
NSError *error = nil;
|
||||
do
|
||||
{
|
||||
if (nil == sourcePath)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Source path is absent." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
break;
|
||||
}
|
||||
|
||||
if (nil == targetPath)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Destination path is absent." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
break;
|
||||
}
|
||||
|
||||
NSArray *contents = nil;
|
||||
|
||||
BOOL isSrcDirectory = NO;
|
||||
BOOL isSrcExist = [manager fileExistsAtPath:sourcePath isDirectory:&isSrcDirectory];
|
||||
isSrcDirectory = isSrcDirectory && ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:sourcePath];
|
||||
if (isSrcExist && isSrcDirectory)
|
||||
{
|
||||
contents = [manager contentsOfDirectoryAtPath:sourcePath error:&error];
|
||||
}
|
||||
else if (isSrcExist)
|
||||
{
|
||||
contents = [NSArray arrayWithObject:@""];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Source does not exist on disk." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
|
||||
if (nil != error)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
BOOL isDstDirectory = NO;
|
||||
BOOL isDstExist = [manager fileExistsAtPath:targetPath isDirectory:&isDstDirectory];
|
||||
if (isSrcDirectory && (!isDstExist || !isDstDirectory))
|
||||
{
|
||||
if (isDstExist)
|
||||
[manager removeItemAtPath:targetPath error:&error];
|
||||
[manager createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
}
|
||||
else if (!isSrcDirectory)
|
||||
{
|
||||
if (isDstExist && !isDstDirectory)
|
||||
[manager removeItemAtPath:targetPath error:&error];
|
||||
[manager createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
}
|
||||
|
||||
if (nil != error)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
for (NSString *item in contents)
|
||||
{
|
||||
NSString *fromPath = [item length] ? [sourcePath stringByAppendingPathComponent:item] : sourcePath;
|
||||
NSString *toPath = [item length] ? [targetPath stringByAppendingPathComponent:item] : [targetPath stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
if (![manager isReadableFileAtPath:fromPath])
|
||||
{
|
||||
SULog(@"XPC Install Service: will skip \"%@\"", fromPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
SULog(@"XPC Install Service: will copy \"%@\" to \"%@\"", fromPath, toPath);
|
||||
|
||||
if ([manager fileExistsAtPath:toPath])
|
||||
[manager removeItemAtPath:toPath error:&error];
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (NO);
|
||||
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
if (nil != error)
|
||||
{
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)[error code]);
|
||||
const char *errorMsg = [[error localizedDescription] length] ? [[error localizedDescription] UTF8String] : "";
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, errorMsg);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static xpc_object_t SUISCopyPathWithAuthentication(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *src = xpc_dictionary_get_string(message, SUInstallServiceSourcePathKey);
|
||||
const char *dst = xpc_dictionary_get_string(message, SUInstallServiceDestinationPathKey);
|
||||
const char *tmp = xpc_dictionary_get_string(message, SUInstallServiceTempNameKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *relaunchPathToCopy = src ? [manager stringWithFileSystemRepresentation:src length:strlen(src)] : nil;
|
||||
NSString *targetPath = dst ? [manager stringWithFileSystemRepresentation:dst length:strlen(dst)] : nil;
|
||||
NSString *temporaryName = tmp ? [NSString stringWithUTF8String:tmp] : nil;
|
||||
NSError *error = nil;
|
||||
BOOL result = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:temporaryName error:&error];
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
if (!result && error != nil)
|
||||
{
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)[error code]);
|
||||
const char *errorMsg = [[error localizedDescription] length] ? [[error localizedDescription] UTF8String] : "";
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, errorMsg);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static xpc_object_t SUISLaunchTask(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *path = xpc_dictionary_get_string(message, SUInstallServiceLaunchTaksPathKey);
|
||||
NSString *launchPath = path ? [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)] : nil;
|
||||
|
||||
xpc_object_t array = xpc_dictionary_get_value(message, SUInstallServiceLaunchTaskArgumentsKey);
|
||||
NSArray *arguments = nil;
|
||||
if (NULL != array)
|
||||
{
|
||||
size_t count = xpc_array_get_count(array);
|
||||
NSMutableArray *mutableArgs = [NSMutableArray arrayWithCapacity:count];
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
[mutableArgs addObject:[NSString stringWithUTF8String:xpc_array_get_string(array, i)]];
|
||||
}
|
||||
|
||||
arguments = mutableArgs;
|
||||
}
|
||||
|
||||
xpc_object_t dict = xpc_dictionary_get_value(message, SUInstallServiceLaunchTaskEnvironmentKey);
|
||||
NSDictionary *environment = nil;
|
||||
if (NULL != dict)
|
||||
{
|
||||
size_t count = xpc_dictionary_get_count(dict);
|
||||
__block NSMutableDictionary *mutableEnv = [NSMutableDictionary dictionaryWithCapacity:count];
|
||||
|
||||
xpc_dictionary_apply(dict, ^bool(const char *key, xpc_object_t value) {
|
||||
NSString *envKey = [NSString stringWithUTF8String:key];
|
||||
NSString *envValue = [NSString stringWithUTF8String:value];
|
||||
[mutableEnv setObject:envValue forKey:envKey];
|
||||
return true;
|
||||
});
|
||||
|
||||
environment = mutableEnv;
|
||||
}
|
||||
|
||||
path = xpc_dictionary_get_string(message, SUInstallServiceLaunchTaskCurrentDirKey);
|
||||
NSString *currentDirPath = path ? [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)] : nil;
|
||||
|
||||
size_t bytesLen = 0;
|
||||
const void *bytes = xpc_dictionary_get_data(message, SUInstallServiceLaunchTaskInputDataKey, &bytesLen);
|
||||
NSData *inputData = bytes ? [NSData dataWithBytes:bytes length:bytesLen] : nil;
|
||||
|
||||
bool shouldReplyImmediatly = xpc_dictionary_get_bool(message, SUInstallServiceLaunchTaskReplyImmediatelyKey);
|
||||
|
||||
// prepare NSTask
|
||||
NSTask *task = [[[NSTask alloc] init] autorelease];
|
||||
NSPipe *inputPipe = [NSPipe pipe];
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
|
||||
[task setStandardInput:inputPipe];
|
||||
[task setStandardOutput:outputPipe];
|
||||
[task setStandardError:outputPipe];
|
||||
|
||||
if (launchPath != nil)
|
||||
[task setLaunchPath:launchPath];
|
||||
if ([arguments count])
|
||||
[task setArguments:arguments];
|
||||
if ([environment count])
|
||||
[task setEnvironment:environment];
|
||||
if (currentDirPath != nil)
|
||||
[task setCurrentDirectoryPath:currentDirPath];
|
||||
|
||||
__block NSData *outputData = nil;
|
||||
__block int taskResult = 0;
|
||||
__block BOOL isTaskRunning = YES;
|
||||
|
||||
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
NSArray *notificationObjects = nil;
|
||||
|
||||
if (!shouldReplyImmediatly)
|
||||
{
|
||||
id object1 = [notificationCenter addObserverForName:NSFileHandleReadToEndOfFileCompletionNotification
|
||||
object:[outputPipe fileHandleForReading]
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
outputData = [[[note userInfo] objectForKey:NSFileHandleNotificationDataItem] retain];
|
||||
isTaskRunning = NO;
|
||||
}];
|
||||
|
||||
id object2 = [notificationCenter addObserverForName:NSTaskDidTerminateNotification
|
||||
object:task
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
taskResult = [task terminationStatus];
|
||||
}];
|
||||
|
||||
notificationObjects = [NSArray arrayWithObjects:object1, object2, nil];
|
||||
}
|
||||
|
||||
[[outputPipe fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
|
||||
|
||||
@try
|
||||
{
|
||||
[task launch];
|
||||
|
||||
if ([inputData length])
|
||||
{
|
||||
[[inputPipe fileHandleForWriting] writeData:inputData];
|
||||
[[inputPipe fileHandleForWriting] closeFile];
|
||||
}
|
||||
|
||||
if (!shouldReplyImmediatly)
|
||||
{
|
||||
// loop until we are done receiving the data
|
||||
while (YES == isTaskRunning)
|
||||
{
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (...)
|
||||
{
|
||||
taskResult = SUXPCServiceError;
|
||||
}
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)taskResult);
|
||||
if (outputData != nil)
|
||||
{
|
||||
xpc_dictionary_set_data(reply, SUInstallServiceLaunchTaskOutputDataKey, [outputData bytes], [outputData length]);
|
||||
}
|
||||
|
||||
for (id object in notificationObjects)
|
||||
{
|
||||
[notificationCenter removeObserver:object];
|
||||
}
|
||||
[outputData release];
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static void peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
{
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
@@ -37,55 +308,28 @@ static void peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
// Handle the message.
|
||||
SUInstallServiceTask task = (SUInstallServiceTask)xpc_dictionary_get_int64(event, SUInstallServiceTaskTypeKey);
|
||||
|
||||
NSLog(@"XPC Installer: should start task with id = %lld", (int64_t)task);
|
||||
|
||||
xpc_object_t reply = NULL;
|
||||
|
||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||
switch (task)
|
||||
{
|
||||
case SUInstallServiceTaskCopyPath:
|
||||
{
|
||||
const char *src = xpc_dictionary_get_string(event, SUInstallServiceSourcePathKey);
|
||||
const char *dst = xpc_dictionary_get_string(event, SUInstallServiceDestinationPathKey);
|
||||
const char *tmp = xpc_dictionary_get_string(event, SUInstallServiceTempNameKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *relaunchPathToCopy = src ? [manager stringWithFileSystemRepresentation:src length:strlen(src)] : nil;
|
||||
NSString *targetPath = dst ? [manager stringWithFileSystemRepresentation:dst length:strlen(dst)] : nil;
|
||||
NSString *temporaryName = tmp ? [NSString stringWithUTF8String:tmp] : nil;
|
||||
NSError *error = nil;
|
||||
BOOL result = [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: temporaryName error: &error];
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(event);
|
||||
if (!result && error != nil)
|
||||
{
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, [error code]);
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, [[error localizedDescription] cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
}
|
||||
xpc_connection_send_message(peer, reply);
|
||||
xpc_release(reply);
|
||||
reply = SUSICopyPathContent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case SUInstallServiceTaskAuthCopyPath:
|
||||
{
|
||||
reply = SUISCopyPathWithAuthentication(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case SUInstallServiceTaskLaunchTask:
|
||||
{
|
||||
const char *path = xpc_dictionary_get_string(event, SUInstallServiceLaunchTaksPathKey);
|
||||
xpc_object_t array = xpc_dictionary_get_value(event, SUInstallServiceLaunchTaskArgumentsKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *relaunchToolPath = path ? [manager stringWithFileSystemRepresentation:path length:strlen(path)] : nil;;
|
||||
NSMutableArray *arguments = [NSMutableArray array];
|
||||
for (size_t i = 0; i < xpc_array_get_count(array); i++)
|
||||
{
|
||||
[arguments addObject:[NSString stringWithUTF8String:xpc_array_get_string(array, i)]];
|
||||
}
|
||||
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:arguments];
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(event);
|
||||
xpc_connection_send_message(peer, reply);
|
||||
xpc_release(reply);
|
||||
|
||||
reply = SUISLaunchTask(event);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -93,20 +337,26 @@ static void peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
{
|
||||
SULog(@"XPC Install Service: Unknown XPC service task %lld", (int64_t)task);
|
||||
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(event);
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)1);
|
||||
reply = xpc_dictionary_create_reply(event);
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)SUXPCServiceError);
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, "Unknown install cervice task.");
|
||||
xpc_connection_send_message(peer, reply);
|
||||
xpc_release(reply);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
[localPool release];
|
||||
|
||||
if (NULL == reply)
|
||||
{
|
||||
reply = xpc_dictionary_create_reply(event);
|
||||
}
|
||||
|
||||
xpc_connection_send_message(peer, reply);
|
||||
xpc_release(reply);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_handler(xpc_connection_t peer)
|
||||
static void event_handler(xpc_connection_t peer)
|
||||
{
|
||||
// By defaults, new connections will target the default dispatch
|
||||
// concurrent queue.
|
||||
|
||||
+4
-2
@@ -9,6 +9,8 @@
|
||||
#ifndef NTSYNCHRONOUSTASK_H
|
||||
#define NTSYNCHRONOUSTASK_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NTSynchronousTask : NSObject
|
||||
{
|
||||
@private
|
||||
@@ -23,9 +25,9 @@
|
||||
|
||||
// pass nil for directory if not needed
|
||||
// returns the result
|
||||
+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData;
|
||||
+ (int)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output:(NSData**)outData;
|
||||
|
||||
+(NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
|
||||
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
- (int)result;
|
||||
|
||||
+2
-6
@@ -6,12 +6,8 @@
|
||||
// Copyright 2005 Steve Gehrman. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
#import <AppKit/NSApplication.h>
|
||||
|
||||
@implementation NTSynchronousTask
|
||||
|
||||
@@ -232,7 +228,7 @@
|
||||
}
|
||||
|
||||
|
||||
+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData
|
||||
+ (int)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output:(NSData**)outData
|
||||
{
|
||||
// we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
+10
-2
@@ -1,11 +1,19 @@
|
||||
{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf200
|
||||
{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf210
|
||||
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
||||
{\colortbl;\red255\green255\blue255;\red38\green38\blue38;}
|
||||
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
|
||||
\deftab720
|
||||
\pard\pardeftab720
|
||||
|
||||
\f0\b\fs26 \cf2 Version 2.0\
|
||||
\f0\b\fs26 \cf2 Version 2.0.1:\
|
||||
\pard\pardeftab720\sl380
|
||||
|
||||
\b0 \cf2 \'96 Bug fixing for the application updates in Sandboxed environment.\
|
||||
\pard\pardeftab720
|
||||
\cf2 \
|
||||
\pard\pardeftab720
|
||||
|
||||
\b \cf2 Version 2.0:\
|
||||
\pard\pardeftab720\sl380
|
||||
|
||||
\b0 \cf2 \'96 Works correctly with Sandboxed environment\
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@
|
||||
if ([delegate respondsToSelector:@selector(appcast:willFetchURLRequest:)])
|
||||
[delegate appcast:self willFetchURLRequest:request];
|
||||
|
||||
if ([SUUpdater shouldUseXPCDownloader])
|
||||
if (SUShouldUseXPCDownloader())
|
||||
{
|
||||
download = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ static NSString * const kSUAutomaticUpdateParamName = @"autoupdate";
|
||||
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
|
||||
[self updateURLRequestIfNeeds:request];
|
||||
|
||||
if ([SUUpdater shouldUseXPCDownloader])
|
||||
if (SUShouldUseXPCDownloader())
|
||||
{
|
||||
[SUXPCURLDownload sendSynchronousRequest:request delegate:nil];
|
||||
}
|
||||
|
||||
+13
-13
@@ -202,7 +202,7 @@ NSArray *SUGetAllDevMateURLHosts(void)
|
||||
[request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"];
|
||||
[self updateURLRequestIfNeeds:request];
|
||||
|
||||
if ([SUUpdater shouldUseXPCDownloader])
|
||||
if (SUShouldUseXPCDownloader())
|
||||
download = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
|
||||
else
|
||||
download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
|
||||
@@ -210,7 +210,8 @@ NSArray *SUGetAllDevMateURLHosts(void)
|
||||
|
||||
- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name
|
||||
{
|
||||
if ([SUUpdater shouldUseXPCDownloader]) {
|
||||
if (SUShouldUseXPCDownloader())
|
||||
{
|
||||
// The downloader will determine a file name, somewhere within our sandbox.
|
||||
downloadPath = nil;
|
||||
[d setDestination:name allowOverwrite:YES];
|
||||
@@ -387,19 +388,16 @@ NSArray *SUGetAllDevMateURLHosts(void)
|
||||
#endif
|
||||
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
if( [SUUpdater shouldUseXPCInstaller] )
|
||||
BOOL copiedRelaunchTool = NO;
|
||||
if (SUShouldUseXPCInstaller())
|
||||
{
|
||||
[SUXPCInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil completionHandler:^(NSError *xpcError) {
|
||||
if (xpcError != nil)
|
||||
NSLog(@"Error during asynchronous XPC call to copyPath: %@", xpcError);
|
||||
[self finishRelaunchAfterSuccessfulCopying:(xpcError == nil) fromPath:relaunchPathToCopy toPath:targetPath relaunch:relaunch];
|
||||
}];
|
||||
copiedRelaunchTool = [SUXPCInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error];
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL copiedRelaunchTool = [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error];
|
||||
[self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath relaunch:relaunch];
|
||||
copiedRelaunchTool = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error];
|
||||
}
|
||||
[self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath relaunch:relaunch];
|
||||
}
|
||||
|
||||
- (void)finishRelaunchAfterSuccessfulCopying:(BOOL)copiedRelaunchTool fromPath:(NSString *)relaunchPathToCopy toPath:(NSString *)targetPath relaunch:(BOOL)relaunch
|
||||
@@ -428,13 +426,15 @@ NSArray *SUGetAllDevMateURLHosts(void)
|
||||
pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater];
|
||||
NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"];
|
||||
NSArray *arguments = [NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", nil];
|
||||
if( [SUUpdater shouldUseXPCInstaller] )
|
||||
[SUXPCInstaller launchTaskWithLaunchPath: relaunchToolPath arguments:arguments completionHandler:^{
|
||||
if (SUShouldUseXPCInstaller())
|
||||
{
|
||||
[SUXPCInstaller launchTaskWithLaunchPath:relaunchToolPath arguments:arguments completionHandler:^{
|
||||
[NSApp terminate:self];
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:arguments];
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:arguments];
|
||||
[NSApp terminate:self];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SUHost.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
|
||||
@implementation SUBinaryDeltaUnarchiver
|
||||
|
||||
|
||||
@@ -21,4 +21,7 @@
|
||||
|
||||
@end
|
||||
|
||||
FOUNDATION_EXTERN BOOL SUShouldUseXPCDownloader(void);
|
||||
FOUNDATION_EXTERN BOOL SUShouldUseXPCInstaller(void);
|
||||
|
||||
#endif
|
||||
@@ -189,3 +189,26 @@ finally:
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
BOOL SUShouldUseXPCDownloader(void)
|
||||
{
|
||||
if ([SUCodeSigningVerifier hostAppAllowsNetworkOutgoingConnections])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.download-service.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
BOOL SUShouldUseXPCInstaller(void)
|
||||
{
|
||||
if (![SUCodeSigningVerifier hostApplicationIsSandboxed])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.install-service.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
#import <Security/cssm.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
/* CDSA Specific */
|
||||
static CSSM_CSP_HANDLE cdsaInit( void );
|
||||
static void cdsaRelease( CSSM_CSP_HANDLE cspHandle );
|
||||
@@ -355,3 +358,5 @@ static Boolean su_copyBytesToData( CSSM_DATA_PTR data, CSSM_SIZE size, const uin
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
+143
-59
@@ -9,6 +9,8 @@
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUXPCInstaller.h"
|
||||
#import "SULog.h"
|
||||
#import <CoreServices/CoreServices.h>
|
||||
|
||||
@@ -22,13 +24,37 @@
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMG
|
||||
{
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSData *result = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:[NSArray arrayWithObjects: @"isencrypted", archivePath, nil] input:NULL];
|
||||
if([self isEncrypted:result] && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) {
|
||||
NSString *hdiutilPath = @"/usr/bin/hdiutil";
|
||||
NSArray *args = [NSArray arrayWithObjects: @"isencrypted", archivePath, nil];
|
||||
NSString *currentDirPath = @"/";
|
||||
__block NSData *result = nil;
|
||||
if (SUShouldUseXPCInstaller())
|
||||
{
|
||||
[SUXPCInstaller launchTaskWithPath:hdiutilPath
|
||||
arguments:args
|
||||
environment:nil
|
||||
currentDirectoryPath:currentDirPath
|
||||
inputData:nil
|
||||
waitForTaskResult:YES
|
||||
waitUntilDone:YES
|
||||
completionHandler:^(int resultCode, NSData *outputData) {
|
||||
result = [outputData copy];
|
||||
}];
|
||||
[result autorelease];
|
||||
}
|
||||
else
|
||||
{
|
||||
result = [NTSynchronousTask task:hdiutilPath directory:currentDirPath withArgs:args input:nil];
|
||||
}
|
||||
|
||||
if ([self isEncrypted:result] && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)])
|
||||
{
|
||||
[self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
[self extractDMGWithPassword:nil];
|
||||
}
|
||||
|
||||
@@ -38,7 +64,6 @@
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMGWithPassword:(NSString *)password
|
||||
{
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
BOOL mountedSuccessfully = NO;
|
||||
@@ -46,9 +71,7 @@
|
||||
SULog(@"Extracting %@ as a DMG", archivePath);
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPointName = nil;
|
||||
NSString *mountPoint = nil;
|
||||
FSRef tmpRef;
|
||||
do
|
||||
{
|
||||
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
||||
@@ -57,98 +80,139 @@
|
||||
CFStringRef uuidString = CFUUIDCreateString(NULL, uuid);
|
||||
if (uuidString)
|
||||
{
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:(NSString*)uuidString];
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:(NSString *)uuidString];
|
||||
CFRelease(uuidString);
|
||||
}
|
||||
CFRelease(uuid);
|
||||
}
|
||||
}
|
||||
while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL));
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:mountPoint]);
|
||||
|
||||
NSData *promptData = nil;
|
||||
if (password) {
|
||||
if ([password length])
|
||||
{
|
||||
NSString *data = [NSString stringWithFormat:@"%@\nyes\n", password];
|
||||
const char *bytes = [data cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
NSUInteger length = [data lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
promptData = [NSData dataWithBytes:bytes length:length];
|
||||
}
|
||||
else
|
||||
{
|
||||
promptData = [NSData dataWithBytes:"yes\n" length:4];
|
||||
}
|
||||
|
||||
BOOL shouldUseXPC = SUShouldUseXPCInstaller();
|
||||
|
||||
NSString *hdiutilPath = @"/usr/bin/hdiutil";
|
||||
NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen", nil];
|
||||
NSString *currentDirPath = @"/";
|
||||
|
||||
NSData *output = nil;
|
||||
NSInteger taskResult = -1;
|
||||
__block NSData *output = nil;
|
||||
__block NSInteger taskResult = -1;
|
||||
@try
|
||||
{
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
if (shouldUseXPC)
|
||||
{
|
||||
[SUXPCInstaller launchTaskWithPath:hdiutilPath
|
||||
arguments:arguments
|
||||
environment:nil
|
||||
currentDirectoryPath:currentDirPath
|
||||
inputData:promptData
|
||||
waitForTaskResult:YES
|
||||
waitUntilDone:YES
|
||||
completionHandler:^(int result, NSData *outputData) {
|
||||
taskResult = (NSInteger)result;
|
||||
output = [outputData copy];
|
||||
}];
|
||||
[output autorelease];
|
||||
}
|
||||
else
|
||||
{
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
[task run:hdiutilPath directory:currentDirPath withArgs:arguments input:promptData];
|
||||
|
||||
[task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData];
|
||||
|
||||
taskResult = [task result];
|
||||
output = [[[task output] copy] autorelease];
|
||||
[task release];
|
||||
taskResult = [task result];
|
||||
output = [[[task output] copy] autorelease];
|
||||
[task release];
|
||||
}
|
||||
}
|
||||
@catch (NSException *localException)
|
||||
{
|
||||
{
|
||||
SULog(@"Got DMG mount exception: %@ - %@", [localException name], [localException reason]);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
if (taskResult != 0)
|
||||
{
|
||||
NSString* resultStr = output ? [[[NSString alloc] initWithData: output encoding: NSUTF8StringEncoding] autorelease] : nil;
|
||||
if (password != nil && [resultStr rangeOfString:@"Authentication error"].location != NSNotFound && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) {
|
||||
NSString *resultStr = output ? [[[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] autorelease] : nil;
|
||||
if (password != nil &&
|
||||
[resultStr rangeOfString:@"Authentication error"].location != NSNotFound &&
|
||||
[delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)])
|
||||
{
|
||||
[self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO];
|
||||
goto finally;
|
||||
} else {
|
||||
SULog( @"hdiutil failed with code: %d data: <<%@>>", taskResult, resultStr );
|
||||
}
|
||||
else
|
||||
{
|
||||
SULog( @"hdiutil failed with code: %d data: <<%@>>", taskResult, resultStr);
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
mountedSuccessfully = YES;
|
||||
|
||||
// Now that we've mounted it, we need to copy out its contents.
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
|
||||
// On 10.7 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357).
|
||||
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
|
||||
NSError *error = nil;
|
||||
NSArray *contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error];
|
||||
if (error)
|
||||
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_6)
|
||||
{
|
||||
if (shouldUseXPC)
|
||||
{
|
||||
SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
NSEnumerator *contentsEnumerator = [contents objectEnumerator];
|
||||
NSString *item;
|
||||
while ((item = [contentsEnumerator nextObject]))
|
||||
{
|
||||
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
NSError *error = nil;
|
||||
[SUXPCInstaller copyPathContent:mountPoint
|
||||
toDirectory:[archivePath stringByDeletingLastPathComponent]
|
||||
error:&error];
|
||||
|
||||
// We skip any files in the DMG which are not readable.
|
||||
if (![manager isReadableFileAtPath:fromPath])
|
||||
continue;
|
||||
|
||||
SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath);
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
if (nil != error)
|
||||
{
|
||||
SULog(@"Couldn't copy item: %@ : %@", error, error.userInfo ? error.userInfo : @"");
|
||||
SULog(@"Couldn't copy volume content: %d - %@", [error code], [error localizedDescription]);
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// On 10.7 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357).
|
||||
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
|
||||
NSError *error = nil;
|
||||
NSArray *contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error];
|
||||
if (error)
|
||||
{
|
||||
SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
NSEnumerator *contentsEnumerator = [contents objectEnumerator];
|
||||
NSString *item = nil;
|
||||
while ((item = [contentsEnumerator nextObject]))
|
||||
{
|
||||
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
|
||||
// We skip any files in the DMG which are not readable.
|
||||
if (![manager isReadableFileAtPath:fromPath])
|
||||
continue;
|
||||
|
||||
SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath);
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
{
|
||||
SULog(@"Couldn't copy item: %@ : %@", error, error.userInfo ? error.userInfo : @"");
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FSRef srcRef, dstRef;
|
||||
OSStatus err;
|
||||
err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL);
|
||||
if (err != noErr) goto reportError;
|
||||
err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL);
|
||||
if (err != noErr) goto reportError;
|
||||
|
||||
err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors);
|
||||
if (err != noErr) goto reportError;
|
||||
else
|
||||
{
|
||||
SULog(@"This version of Sparkle don't support OS X version earlier than 10.6");
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
@@ -159,9 +223,29 @@ reportError:
|
||||
|
||||
finally:
|
||||
if (mountedSuccessfully)
|
||||
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]];
|
||||
{
|
||||
NSArray *args = [NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil];
|
||||
if (shouldUseXPC)
|
||||
{
|
||||
[SUXPCInstaller launchTaskWithPath:hdiutilPath
|
||||
arguments:args
|
||||
environment:nil
|
||||
currentDirectoryPath:nil
|
||||
inputData:nil
|
||||
waitForTaskResult:NO
|
||||
waitUntilDone:NO
|
||||
completionHandler:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSTask launchedTaskWithLaunchPath:hdiutilPath arguments:args];
|
||||
}
|
||||
}
|
||||
else
|
||||
SULog(@"Can't mount DMG %@",archivePath);
|
||||
{
|
||||
SULog(@"Can't mount DMG %@", archivePath);
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#import <dirent.h>
|
||||
#import <unistd.h>
|
||||
#import <sys/param.h>
|
||||
|
||||
#import <dlfcn.h>
|
||||
|
||||
@interface SUPlainInstaller (MMExtendedAttributes)
|
||||
// Removes the directory tree rooted at |root| from the file quarantine.
|
||||
@@ -55,15 +55,40 @@ static BOOL SUAuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authori
|
||||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL);
|
||||
BOOL returnValue = YES;
|
||||
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess)
|
||||
// Create func pointer to AuthorizationExecuteWithPrivileges in case it doesn't exist
|
||||
// in this version of MacOS
|
||||
static OSStatus (*_AuthExecuteWithPrivilegesFunc)(AuthorizationRef authorization,
|
||||
const char *pathToTool,
|
||||
AuthorizationFlags options,
|
||||
char * const *arguments,
|
||||
FILE **communicationsPipe) = NULL;
|
||||
|
||||
// Check to see if we have the correct function in our loaded libraries
|
||||
if (NULL == _AuthExecuteWithPrivilegesFunc)
|
||||
{
|
||||
// On 10.7, AuthorizationExecuteWithPrivileges is deprecated. We want
|
||||
// to still use it since there's no good alternative (without requiring
|
||||
// code signing). We'll look up the function through dyld and fail if
|
||||
// it is no longer accessible. If Apple removes the function entirely
|
||||
// this will fail gracefully. If they keep the function and throw some
|
||||
// sort of exception, this won't fail gracefully, but that's a risk
|
||||
// we'll have to take for now.
|
||||
// Pattern by Andy Kim from Potion Factory LLC
|
||||
_AuthExecuteWithPrivilegesFunc = dlsym(RTLD_DEFAULT, "AuthorizationExecuteWithPrivileges");
|
||||
}
|
||||
|
||||
if (NULL != _AuthExecuteWithPrivilegesFunc &&
|
||||
errAuthorizationSuccess == _AuthExecuteWithPrivilegesFunc(authorization, executablePath, options, (char* const*)arguments, NULL))
|
||||
{
|
||||
int status;
|
||||
int status = 0;
|
||||
pid_t pid = wait(&status);
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = NO;
|
||||
}
|
||||
|
||||
signal(SIGCHLD, oldSigChildHandler);
|
||||
return returnValue;
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@
|
||||
[delegate updateAlert:self willLoadReleaseNotesWithRequest:request];
|
||||
}
|
||||
|
||||
if ([SUUpdater shouldUseXPCDownloader])
|
||||
if (SUShouldUseXPCDownloader())
|
||||
{
|
||||
[releaseNotesDownloader release];
|
||||
releaseNotesDownloader = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
|
||||
|
||||
-20
@@ -554,26 +554,6 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
|
||||
- (id)delegate { return delegate; }
|
||||
- (NSBundle *)hostBundle { return [host bundle]; }
|
||||
|
||||
+ (BOOL)shouldUseXPCDownloader
|
||||
{
|
||||
if ([SUCodeSigningVerifier hostAppAllowsNetworkOutgoingConnections])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[[SUUpdater sharedUpdater] hostBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.download-service.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
+ (BOOL)shouldUseXPCInstaller
|
||||
{
|
||||
if (![SUCodeSigningVerifier hostApplicationIsSandboxed])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[[SUUpdater sharedUpdater] hostBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.install-service.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
#pragma mark - DevMate Interaction
|
||||
|
||||
- (NSArray *)devmateFeedParameters
|
||||
|
||||
+1
-3
@@ -7,12 +7,10 @@
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
|
||||
@interface SUUpdater (Private)
|
||||
|
||||
- (BOOL)mayUpdateAndRestart;
|
||||
|
||||
+ (BOOL)shouldUseXPCDownloader;
|
||||
+ (BOOL)shouldUseXPCInstaller;
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user