我非常了解Privileged Helper工具以及部署它们的目的和技术。我也成功创建并安装了它们 - 但我找不到一个例子来说明如何简单地将文件复制到需要特殊权限的位置。我以为FSPathCopyObjectSync允许我实现这一点,although I discovered the method was deprecated, along with what appears to be every single file operation on Mac OSX。
这是我到目前为止所发现的:
•BetterAuthorizationSample(已弃用)
•SMJobBless(基本上什么都不做)
•Privileged Helper Example(不在下面安装命令行工具)
这是上例中的方法:
if (pFilename)
{
// Base command minus cert name and file namem is 76 characters, 1 for NULL
char* valCodeSignCmd = 0;
// asprintf allocates & never overflows
if (asprintf(&valCodeSignCmd, "codesign -v -R=\"certificate leaf[subject.CN] = \\\"%s\\\" and anchor apple generic\" \"%s\"", kSigningCertCommonName, pFilename) != -1)
{
if (system(valCodeSignCmd) == 0)
{
// Passed codesign validation
// OK to copy now - overwrite if present
OSStatus fsret = FSPathCopyObjectSync(pFilename, "/usr/local/bin", toolName, NULL, kFSFileOperationOverwrite);
if (fsret != noErr)
success = false;
}
// Clean up
free(valCodeSignCmd);
}
else
success = false;
}
史蒂夫·乔布斯的名字在这里发生了什么?