3

我正在尝试通过 AuthorizationExecuteWithPrivileges 执行卸载程序(用 AppleScript 编写)。在创建一个空的 auth ref 后,我正在设置我的权利,如下所示:

    char *tool = "/usr/bin/osascript";
    AuthorizationItem items = {kAuthorizationRightExecute, strlen(tool), tool, 0};
    AuthorizationRights rights = {sizeof(items)/sizeof(AuthorizationItem), &items};
    AuthorizationFlags flags = kAuthorizationFlagDefaults |
                               kAuthorizationFlagExtendRights |
                               kAuthorizationFlagPreAuthorize |
                               kAuthorizationFlagInteractionAllowed;
    status = AuthorizationCopyRights(authorizationRef, &rights, NULL, flags, NULL);

后来我打电话:

    status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, (char *const *)args, NULL);

在 Snow Leopard 上这很好用,但在 Leopard 上我在 syslog.log 中得到以下信息:

Apr 19 15:30:09 hostname /usr/bin/osascript[39226]: OpenScripting.framework - 'gdut' event blocked in process with mixed credentials (issetugid=0 uid=501 euid=0 gid=20 egid=20)
Apr 19 15:30:12: --- last message repeated 1 time ---
...
Apr 19 15:30:12 hostname [0x0-0x2e92e9].com.example.uninstaller[39219]: /var/folders/vm/vmkIi0nYG8mHMrllaXaTgk+++TI/-Tmp-/TestApp_tmpfiles/Uninstall.scpt: 
Apr 19 15:30:12 hostname [0x0-0x2e92e9].com.example.uninstaller[39219]: execution error: «constant afdmasup» doesn’t understand the «event earsffdr» message. (-1708)

在研究了几个小时后,我的第一个猜测是,Leopard 不知何故不想做我正在做的事情,因为它知道它处于 setuid 情况并阻止在 applescript 中询问用户特定事物的调用。

我对这一切都错了吗?我只想运行相当于“sudo /usr/bin/osascript ...”

编辑:

FWIW,导致“执行错误”的第一行是:

set userAppSupportPath to (POSIX path of (path to application support folder from user domain))

但是,即使使用空脚本(运行 argv,结束运行,仅此而已),我仍然会收到“gdut”消息。

4

1 回答 1

2

根据这个线程。http://forums.macosxhints.com/showthread.php?t=90952&page=3 似乎对 OS X 进行了安全更新,阻止通过 AppleScript 访问 setuid 根脚本。

我怀疑这种机制也会阻止您的代码。

不幸的是,我想这意味着这不是“按设计”工作的。

于 2010-06-11T21:01:40.540 回答