mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Added custom prompt text when asking for admin rights.
This commit is contained in:
1 parent
65d7c38ab6
commit
67a7bc3d62
4 files changed
+91
-45
No files matched your search
@@ -0,0 +1,11 @@
|
||||
//
|
||||
// install_service.pch
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 4/25/14.
|
||||
//
|
||||
//
|
||||
|
||||
#define SPARKLE_BUNDLE [NSBundle mainBundle]
|
||||
#define SULocalizedString(key,comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", SPARKLE_BUNDLE, comment)
|
||||
|
||||
+72
-45
@@ -48,7 +48,7 @@
|
||||
|
||||
// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan!
|
||||
|
||||
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments)
|
||||
static BOOL SUAuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments)
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
@@ -69,6 +69,58 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static void SUAuthorizationRelease(AuthorizationRef authorization)
|
||||
{
|
||||
if (NULL == authorization)
|
||||
return;
|
||||
|
||||
AuthorizationFree(authorization, kAuthorizationFlagDefaults);
|
||||
}
|
||||
|
||||
static AuthorizationRef SUAuthorizationCreate(OSStatus *outStatus)
|
||||
{
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while (errAuthorizationDenied == authStat)
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
|
||||
}
|
||||
|
||||
if (errAuthorizationSuccess == authStat)
|
||||
{
|
||||
AuthorizationFlags theFlags = kAuthorizationFlagDefaults | kAuthorizationFlagPreAuthorize | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
|
||||
|
||||
AuthorizationItem rightsItems = {kAuthorizationRightExecute, 0, NULL, 0};
|
||||
AuthorizationRights authRights = {1, &rightsItems};
|
||||
|
||||
AuthorizationItem envItems[1];
|
||||
|
||||
envItems[0].name = kAuthorizationEnvironmentPrompt;
|
||||
envItems[0].value = (void *)[SULocalizedString(@"The update requires administrative permissions to be completed.", nil) cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
envItems[0].valueLength = strlen((const char *)envItems[0].value);
|
||||
envItems[0].flags = 0;
|
||||
|
||||
AuthorizationEnvironment environment;
|
||||
environment.count = sizeof(envItems) / sizeof(AuthorizationItem);
|
||||
environment.items = envItems;
|
||||
|
||||
authStat = AuthorizationCopyRights(auth, &authRights, &environment, theFlags, NULL);
|
||||
}
|
||||
|
||||
if (errAuthorizationSuccess != authStat)
|
||||
{
|
||||
SUAuthorizationRelease(auth);
|
||||
auth = NULL;
|
||||
}
|
||||
|
||||
if (NULL != outStatus)
|
||||
{
|
||||
*outStatus = authStat;
|
||||
}
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
@implementation SUPlainInstaller (Internals)
|
||||
|
||||
+ (NSString *)temporaryNameForPath:(NSString *)path
|
||||
@@ -176,17 +228,10 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
}
|
||||
}
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while (authStat == errAuthorizationDenied) {
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
AuthorizationRef auth = SUAuthorizationCreate(NULL);
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess) {
|
||||
if (NULL != auth)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
@@ -209,7 +254,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res ) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char* coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
if( !res )
|
||||
SULog( @"chown -R %s %s failed.", uidgid, srcPath );
|
||||
}
|
||||
@@ -218,7 +263,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res && haveDst ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog( @"rm failed" );
|
||||
}
|
||||
@@ -226,7 +271,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res && haveDst ) // Move old exe to tmp path.
|
||||
{
|
||||
const char* mvParams[] = { "-f", dstPath, tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
if( !res )
|
||||
SULog( @"mv 1 failed" );
|
||||
}
|
||||
@@ -234,7 +279,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res ) // Move new exe to old exe's path.
|
||||
{
|
||||
const char* mvParams2[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams2 );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams2 );
|
||||
if( !res )
|
||||
SULog( @"mv 2 failed" );
|
||||
}
|
||||
@@ -242,10 +287,10 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
// if( res && haveDst /*&& !foundTrash*/ ) // If we managed to put the old exe in the trash, leave it there for the user to delete or recover.
|
||||
// { // ... Otherwise we better delete it, wouldn't want dozens of old versions lying around next to the new one.
|
||||
// const char* rmParams2[] = { "-rf", tmpPath, NULL };
|
||||
// res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams2 );
|
||||
// res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams2 );
|
||||
// }
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
SUAuthorizationRelease(auth);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
@@ -289,18 +334,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
struct stat dstSB;
|
||||
stat(dstContainerPath, &dstSB);
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
AuthorizationRef auth = SUAuthorizationCreate(NULL);
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
if (NULL != auth)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
@@ -311,7 +347,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res ) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char* coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
if( !res )
|
||||
SULog(@"Can't set permissions");
|
||||
}
|
||||
@@ -320,7 +356,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res && haveDst ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
@@ -328,12 +364,12 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
if( res ) // Move!.
|
||||
{
|
||||
const char* mvParams[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
if( !res )
|
||||
SULog(@"Can't move source file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
SUAuthorizationRelease(auth);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
@@ -358,30 +394,21 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
|
||||
const char* srcPath = [src fileSystemRepresentation];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
AuthorizationRef auth = SUAuthorizationCreate(NULL);
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
if (NULL != auth)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
if( res ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
res = SUAuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
SUAuthorizationRelease(auth);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
03B5E64B15D39CD90038BB67 /* SUXPCURLDownload.h in Headers */ = {isa = PBXBuildFile; fileRef = 03B5E64915D39CD90038BB67 /* SUXPCURLDownload.h */; };
|
||||
03B5E65A15D3DC3C0038BB67 /* com.andymatuschak.Sparkle.download-service.xpc in CopyFiles */ = {isa = PBXBuildFile; fileRef = 03B5E63A15D399500038BB67 /* com.andymatuschak.Sparkle.download-service.xpc */; };
|
||||
03B5E65B15D3E0490038BB67 /* SUXPCURLDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B5E64A15D39CD90038BB67 /* SUXPCURLDownload.m */; };
|
||||
3330768F190A5CB8005602B2 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; };
|
||||
33D081831888446F00394A94 /* libDMCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D081821888446E00394A94 /* libDMCore.a */; };
|
||||
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
525A2790133D6AE900FD8D70 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; };
|
||||
@@ -247,6 +248,7 @@
|
||||
0867D69BFE84028FC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
3329F06D18FBFBA800556010 /* ResourceRules.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ResourceRules.plist; sourceTree = "<group>"; };
|
||||
33307690190A5D8B005602B2 /* install_service.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = install_service.pch; sourceTree = "<group>"; };
|
||||
33D081821888446E00394A94 /* libDMCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libDMCore.a; path = External/libDMCore.a; sourceTree = "<group>"; };
|
||||
3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = "<group>"; };
|
||||
525A278F133D6AE900FD8D70 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
@@ -876,6 +878,7 @@
|
||||
8B887B801517F8B4000BB292 /* Service */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
33307690190A5D8B005602B2 /* install_service.pch */,
|
||||
8B887B8D15180767000BB292 /* install_service.m */,
|
||||
8B887B8F15180773000BB292 /* SandboxService.plist */,
|
||||
);
|
||||
@@ -1214,6 +1217,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
3330768F190A5CB8005602B2 /* Sparkle.strings in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1903,6 +1907,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 8B887B711517F447000BB292 /* ConfigServiceDebug.xcconfig */;
|
||||
buildSettings = {
|
||||
GCC_PREFIX_HEADER = "Installation XPC Service/install_service.pch";
|
||||
INFOPLIST_FILE = "Installation XPC Service/SandboxService.plist";
|
||||
PRODUCT_NAME = "com.andymatuschak.Sparkle.install-service";
|
||||
};
|
||||
@@ -1912,6 +1917,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 8B887B721517F447000BB292 /* ConfigServiceRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
GCC_PREFIX_HEADER = "Installation XPC Service/install_service.pch";
|
||||
INFOPLIST_FILE = "Installation XPC Service/SandboxService.plist";
|
||||
PRODUCT_NAME = "com.andymatuschak.Sparkle.install-service";
|
||||
};
|
||||
@@ -1921,6 +1927,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 8B887B721517F447000BB292 /* ConfigServiceRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
GCC_PREFIX_HEADER = "Installation XPC Service/install_service.pch";
|
||||
INFOPLIST_FILE = "Installation XPC Service/SandboxService.plist";
|
||||
PRODUCT_NAME = "com.andymatuschak.Sparkle.install-service";
|
||||
};
|
||||
@@ -1997,6 +2004,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 8B887B721517F447000BB292 /* ConfigServiceRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
GCC_PREFIX_HEADER = "Installation XPC Service/install_service.pch";
|
||||
INFOPLIST_FILE = "Installation XPC Service/SandboxService.plist";
|
||||
PRODUCT_NAME = "com.andymatuschak.Sparkle.install-service";
|
||||
};
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user