mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Test changing ownership/group to determine if authorization is needed
This will work correctly in scenarios where the app to update is in a temporary location for instance.
This commit is contained in:
1 parent
31d6d40112
commit
11cbecbeaa
2 files changed
+37
-5
No files matched your search
@@ -323,6 +323,8 @@
|
||||
72F94F5F1CC455B4002DEE68 /* org.sparkle-project.TemporaryDownloader.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 728638F31CAF5A5F00783084 /* org.sparkle-project.TemporaryDownloader.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
72F9EBE21D517E2F004AC8B6 /* SUUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EBE01D517E2F004AC8B6 /* SUUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */; };
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; };
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; };
|
||||
F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; };
|
||||
@@ -2663,6 +2665,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
724BB3731D31D0B7005D534A /* main.m in Sources */,
|
||||
724BB3711D31D0B7005D534A /* SUInstallerConnection.m in Sources */,
|
||||
@@ -2673,6 +2676,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
724BB39A1D333832005D534A /* main.m in Sources */,
|
||||
724BB3981D333832005D534A /* SUInstallerStatus.m in Sources */,
|
||||
|
||||
Vendored
+33
-5
@@ -8,17 +8,45 @@
|
||||
|
||||
#import "SPUSystemAuthorization.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUFileManager.h"
|
||||
|
||||
BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType)
|
||||
{
|
||||
BOOL result;
|
||||
BOOL needsAuthorization;
|
||||
if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
result = YES;
|
||||
needsAuthorization = YES;
|
||||
} else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
result = NO;
|
||||
needsAuthorization = NO;
|
||||
} else {
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
result = ![fileManager isWritableFileAtPath:path] || ![fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]];
|
||||
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 result;
|
||||
return needsAuthorization;
|
||||
}
|
||||
Reference in new issue
Block a user