Run AppleScript with elevated privileges from Objective-C

I am trying to execute an uninstaller (written in AppleScript) through AuthorizationExecuteWithPrivileges. I create my rights after creating an empty authorization line like this:

    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);

Later I call:

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

On Snow Leopard, this works fine, but on Leopard I get the following in 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)

After studying this for several hours, I first assume that Leopard for some reason does not want to do what I am doing, because he knows about it in a setuid situation and blocks calls that ask about user-specific things in applescript.

Am I really doing all this wrong? I just want to run the equivalent of "sudo / usr / bin / osascript ..."

Edit:

FWIW, the first line that causes a "runtime error" is:

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

script ( argv, end run ) 'gdut'.

+3
1

. http://forums.macosxhints.com/showthread.php?t=90952&page=3 , OS X, setuid AppleScript.

, .

, , , " ".

+2

Source: https://habr.com/ru/post/1741845/


All Articles