Objective c 在没有Apple开发者证书的情况下请求用户提升权限并提升应用程序
显然,从10.7开始,Objective c 在没有Apple开发者证书的情况下请求用户提升权限并提升应用程序,objective-c,macos,osx-mavericks,osx-yosemite,Objective C,Macos,Osx Mavericks,Osx Yosemite,显然,从10.7开始,AuthorizationExecuteWithPrivileges已被弃用。我在此收集的信息的一般要点似乎建议使用ServiceManagement.framework的smjobbles()函数部署助手应用程序 但我的理解是,这需要从苹果公司购买开发者证书来对我的应用程序和助手进程进行代码签名,否则这将不起作用。这是正确的吗 我最初使用AuthorizationExecuteWithPrivileges向用户请求提升的权限,因为访问另一个正在运行的进程需要这些权限。如果
AuthorizationExecuteWithPrivileges
已被弃用。我在此收集的信息的一般要点似乎建议使用ServiceManagement.framework
的smjobbles()
函数部署助手应用程序
但我的理解是,这需要从苹果公司购买开发者证书来对我的应用程序和助手进程进行代码签名,否则这将不起作用。这是正确的吗
我最初使用AuthorizationExecuteWithPrivileges
向用户请求提升的权限,因为访问另一个正在运行的进程需要这些权限。如果没有这些,我的应用程序就不能像它打算使用的非官方插件那样工作。代码签名方式真的是唯一的出路吗?我试图避免购买开发者证书,因为它的成本太高了
是否有人找到了其他方法以提升权限(当然是用户权限)重新启动应用程序
代码签名方式真的是唯一的出路吗
据我所知,除了授权ExecuteWithPrivileges
,没有安全的替代方案
它在约塞米蒂山下仍然运作良好。还没试过El Capitan
如果以后电话不响,你可以试试看
我试图避免购买开发者证书,因为它的成本太高了
如果有帮助的话,代码签名证书将有效几年
我很确定我的开发者帐户已经失效,没有任何问题
因此,基本上每五年99美元。有代码来逃避路径和参数:
- (BOOL)runProcessAsAdministrator:(NSString*)scriptPath
withArguments:(NSArray*)arguments
output:(NSString**)output
errorDescription:(NSString**)errorDescription {
//Check path.
if (![scriptPath hasPrefix:@"/"]) {
@throw [NSException exceptionWithName:
NSInvalidArgumentException reason:@"Absolute path required." userInfo:nil];
}
//Define script.
static NSAppleScript* appleScript = nil;
if (!appleScript) {
appleScript = [[NSAppleScript alloc] initWithSource:
@"on run commandWithArguments\n"
" activate\n"
" repeat with currentArgument in commandWithArguments\n"
" set contents of currentArgument to quoted form of currentArgument\n"
" end repeat\n"
" set AppleScript's text item delimiters to space\n"
" return do shell script (commandWithArguments as text) with administrator privileges\n"
"end run"];
}
//Set command.
NSAppleEventDescriptor* commandWithArguments = [NSAppleEventDescriptor listDescriptor];
[commandWithArguments insertDescriptor:
[NSAppleEventDescriptor descriptorWithString:scriptPath] atIndex:0];
//Set arguments.
for (NSString* currentArgument in arguments) {
[commandWithArguments insertDescriptor:
[NSAppleEventDescriptor descriptorWithString:currentArgument] atIndex:0];
}
//Create target & event.
ProcessSerialNumber processSerial = {0, kCurrentProcess};
NSAppleEventDescriptor* scriptTarget =
[NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber bytes:&processSerial length:sizeof(ProcessSerialNumber)];
NSAppleEventDescriptor* scriptEvent =
[NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass
eventID:kAEOpenApplication
targetDescriptor:scriptTarget
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
[scriptEvent setParamDescriptor:commandWithArguments forKeyword:keyDirectObject];
//Run script.
NSDictionary* errorInfo = [NSDictionary dictionary];
NSAppleEventDescriptor* eventResult = [appleScript executeAppleEvent:scriptEvent error:&errorInfo];
//Success?
if (!eventResult) {
if (errorDescription)
*errorDescription = [errorInfo objectForKey:NSAppleScriptErrorMessage];
return NO;
} else {
if (output)
*output = [eventResult stringValue];
return YES;
}
}
更新
在约塞米蒂,do shell脚本
只调用AuthorizationExecuteWithPrivileges
中嵌入的StandardAdditions.osax
可以想象,当AuthorizationExecuteWithPrivileges
执行时,用于do shell脚本的具有管理员权限的选项将消失
就我个人而言,我会继续直接调用AuthorizationExecuteWithPrivileges
do shell脚本
具有自动执行的优点。这需要一点AuthorizationExecuteWithPrivileges
我仍在寻找是否有不需要代码签名/从苹果购买许可证的选项,但感谢您提供了一个关于如何在“最坏情况”下优雅失败的示例!有趣的是,看看那里是如何处理的@你可能已经看过了,但是。如果你走这条路,请确保使用引用表单
to。谢谢@null,我不完全确定使用它以提升权限重新启动应用程序的可行性。这并不理想,因为这是一种骇人的applescript方法——但如果它起作用,它就起作用了。我会试试看,祈祷好运。@loco抱歉,完全错过了你问题的“重新启动”部分。要做到这一点。所以类似于使用管理员权限执行shell脚本(commandWithArguments作为文本)和“&>/dev/null&”。我相信您已经调查了以root用户身份启动GUI应用程序的所有影响——今天我只是第一次使用它。