From fb206d9f71fda818212441e9b3a036acf28dec45 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Fri, 18 Jul 2014 13:03:31 -0600 Subject: [PATCH 1/7] Use the system-available quarantine string to get the quarantine metadata attribute. --- Sparkle/SUPlainInstallerInternals.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 09504b17..62ac5015 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -537,13 +537,14 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @implementation SUPlainInstaller (MMExtendedAttributes) -+ (int)removeXAttr:(const char *)name ++ (int)removeXAttr:(NSString *)name fromFile:(NSString *)file options:(int)options { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! const char *path = NULL; + const char *attr = [name cStringUsingEncoding:NSASCIIStringEncoding]; @try { path = [file fileSystemRepresentation]; } @@ -556,14 +557,14 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return -1; } - return removexattr(path, name, options); + return removexattr(path, attr, options); } + (void)releaseFromQuarantine:(NSString *)root { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! - const char *quarantineAttribute = "com.apple.quarantine"; + NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; const int removeXAttrOptions = XATTR_NOFOLLOW; [self removeXAttr:quarantineAttribute From cb19fe8864a7fc5ddabf01227fec9aa5232e0df7 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Fri, 18 Jul 2014 13:28:20 -0600 Subject: [PATCH 2/7] Use some 10.10-specific APIs to remove the quarantine attribute. --- Sparkle/SUPlainInstallerInternals.m | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 62ac5015..c929d36b 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -564,6 +564,28 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! + NSFileManager *manager = [NSFileManager defaultManager]; +#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 + if (&NSURLQuarantinePropertiesKey) { + NSURL *rootURL = [NSURL fileURLWithPath:root]; + [rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; + NSString *rootType = rootAttributes[NSFileType]; + + if (rootType == NSFileTypeDirectory) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; + + for (NSURL *file in directoryEnumerator) { + [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + } + } + } else { +#endif NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; const int removeXAttrOptions = XATTR_NOFOLLOW; @@ -573,13 +595,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Only recurse if it's actually a directory. Don't recurse into a // root-level symbolic link. - NSDictionary *rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:root error:nil]; + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; NSString *rootType = rootAttributes[NSFileType]; if (rootType == NSFileTypeDirectory) { // The NSDirectoryEnumerator will avoid recursing into any contained // symbolic links, so no further type checks are needed. - NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:root]; + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root]; NSString *file = nil; while ((file = [directoryEnumerator nextObject])) { [self removeXAttr:quarantineAttribute @@ -587,6 +609,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza options:removeXAttrOptions]; } } +#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 +} +#endif } @end From 5a3fd1e12a09c5ddc1eaa0f21908ae2b9adce1f8 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Fri, 18 Jul 2014 13:31:54 -0600 Subject: [PATCH 3/7] Indenting code. --- Sparkle/SUPlainInstallerInternals.m | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index c929d36b..3c6c1f65 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -586,31 +586,31 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza } } else { #endif - NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; - const int removeXAttrOptions = XATTR_NOFOLLOW; + NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; + const int removeXAttrOptions = XATTR_NOFOLLOW; - [self removeXAttr:quarantineAttribute - fromFile:root - options:removeXAttrOptions]; + [self removeXAttr:quarantineAttribute + fromFile:root + options:removeXAttrOptions]; - // Only recurse if it's actually a directory. Don't recurse into a - // root-level symbolic link. - NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; - NSString *rootType = rootAttributes[NSFileType]; + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; + NSString *rootType = rootAttributes[NSFileType]; - if (rootType == NSFileTypeDirectory) { - // The NSDirectoryEnumerator will avoid recursing into any contained - // symbolic links, so no further type checks are needed. - NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root]; - NSString *file = nil; - while ((file = [directoryEnumerator nextObject])) { - [self removeXAttr:quarantineAttribute - fromFile:[root stringByAppendingPathComponent:file] - options:removeXAttrOptions]; + if (rootType == NSFileTypeDirectory) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root]; + NSString *file = nil; + while ((file = [directoryEnumerator nextObject])) { + [self removeXAttr:quarantineAttribute + fromFile:[root stringByAppendingPathComponent:file] + options:removeXAttrOptions]; + } } - } #if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 -} + } #endif } From 591d7d0049a23adda3002d06891fe69b669cb0cf Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 19 Jul 2014 14:38:51 -0600 Subject: [PATCH 4/7] Better, forward-compatible way of looking up NSURLQuarantinePropertiesKey, as suggested by @jakepetroules --- Configurations/ConfigFramework.xcconfig | 1 + Configurations/ConfigRelaunch.xcconfig | 1 + Sparkle/SUPlainInstallerInternals.m | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Configurations/ConfigFramework.xcconfig b/Configurations/ConfigFramework.xcconfig index cedad035..a0528768 100644 --- a/Configurations/ConfigFramework.xcconfig +++ b/Configurations/ConfigFramework.xcconfig @@ -9,3 +9,4 @@ FRAMEWORK_VERSION = A INFOPLIST_FILE = Sparkle/Sparkle-Info.plist GCC_PREFIX_HEADER = Sparkle/Sparkle.pch SKIP_INSTALL = YES +OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey diff --git a/Configurations/ConfigRelaunch.xcconfig b/Configurations/ConfigRelaunch.xcconfig index 22507036..ee339f01 100644 --- a/Configurations/ConfigRelaunch.xcconfig +++ b/Configurations/ConfigRelaunch.xcconfig @@ -5,3 +5,4 @@ PRODUCT_NAME = $(FINISH_INSTALL_TOOL_NAME) SKIP_INSTALL = YES GCC_PREFIX_HEADER = Sparkle/Autoupdate/Autoupdate.pch ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon +OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 3c6c1f65..746f3037 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -23,6 +23,10 @@ #include #include +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 10100 +extern NSString *const NSURLQuarantinePropertiesKey WEAK_IMPORT_ATTRIBUTE; +#endif + static inline void PerformOnMainThreadSync(dispatch_block_t theBlock) { if ([NSThread isMainThread]) { @@ -565,7 +569,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! NSFileManager *manager = [NSFileManager defaultManager]; -#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 if (&NSURLQuarantinePropertiesKey) { NSURL *rootURL = [NSURL fileURLWithPath:root]; [rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; @@ -585,7 +588,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza } } } else { -#endif NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; const int removeXAttrOptions = XATTR_NOFOLLOW; @@ -609,9 +611,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza options:removeXAttrOptions]; } } -#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 } -#endif } @end From 578666e9e624bb289b8a1b937f6a1050217d1898 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 19 Jul 2014 14:44:06 -0600 Subject: [PATCH 5/7] Minor fix. --- Sparkle/SUPlainInstallerInternals.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 746f3037..12f8e1b1 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -23,7 +23,7 @@ #include #include -#if __MAC_OS_X_VERSION_MAX_ALLOWED < 10100 +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000 extern NSString *const NSURLQuarantinePropertiesKey WEAK_IMPORT_ATTRIBUTE; #endif From 32d4de464d47316c29f79a067c8244ac868e5540 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 19 Jul 2014 15:05:08 -0600 Subject: [PATCH 6/7] Don't use new code if specifically targeting OS versions that have the new API. --- Sparkle/SUPlainInstallerInternals.m | 41 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 12f8e1b1..9974cf43 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -569,25 +569,8 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! NSFileManager *manager = [NSFileManager defaultManager]; - if (&NSURLQuarantinePropertiesKey) { - NSURL *rootURL = [NSURL fileURLWithPath:root]; - [rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; - - // Only recurse if it's actually a directory. Don't recurse into a - // root-level symbolic link. - NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; - NSString *rootType = rootAttributes[NSFileType]; - - if (rootType == NSFileTypeDirectory) { - // The NSDirectoryEnumerator will avoid recursing into any contained - // symbolic links, so no further type checks are needed. - NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; - - for (NSURL *file in directoryEnumerator) { - [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; - } - } - } else { +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + if (!&NSURLQuarantinePropertiesKey) { NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; const int removeXAttrOptions = XATTR_NOFOLLOW; @@ -611,7 +594,27 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza options:removeXAttrOptions]; } } + return; } +#endif + NSURL *rootURL = [NSURL fileURLWithPath:root]; + [rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; + NSString *rootType = rootAttributes[NSFileType]; + + if (rootType == NSFileTypeDirectory) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; + + for (NSURL *file in directoryEnumerator) { + [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + } + } + return; } @end From b13b57e800fbb14d293cf1d622b855f901855445 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 19 Jul 2014 21:46:29 -0600 Subject: [PATCH 7/7] remove unnecessary return; --- Sparkle/SUPlainInstallerInternals.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 9974cf43..072b64b7 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -614,7 +614,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; } } - return; } @end