#UAC alternative prompt for MacOS

15 messages · Page 1 of 1 (latest)

agile sail
#

Hi there, I have a shell script, lets call it script.sh. I need to execute this script with sudo on UNIX. On windows, I used the runas (https://github.com/mitsuhiko/rust-runas) crate which prompts a UAC window on windows. On MacOS however, no such popup occurs, instead it asks tty, of which none exists when running the app, and so promptly crashes. Note, a popup does occur if I run the app through terminal.

Is there a library tauri recommends or another (better) way of doing this on MacOS to get this prompt?
Many thanks :)

woeful vigil
agile sail
#

yep i did try that, somehow it didnt seem to change anything

#

i might take a look at the sourcecode and maybe fork it

#

was just wondering if there was a simpler way to do it ahahah

#

but yeah good suggestion

woeful vigil
agile sail
#

hmm yeah good point lemme try that

#

okay, so it doesnt give a popup with running without a CLI, but when I run one it runs from one (like with openas on the executable), it gives a popup asking for a password

#

dunno why it wouldnt appear with running without the cli tho

#

heres the part in the library that calls for the popup, ive never heard of some of these libraries so idrk whats going on here but maybe itll provide some insight?

#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <Security/Authorization.h>
#include <sys/wait.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"


int rust_darwin_gui_runas(const char *prog, const char **argv)
{
    AuthorizationRef authref = 0;
    FILE *pipe = 0;

    // consider locking this, this would leak a bit of memory if called
    // concurrently really quickly
    if (AuthorizationCreate(0, kAuthorizationEmptyEnvironment,
                            kAuthorizationFlagDefaults,
                            &authref) != errAuthorizationSuccess) {
        return -1;
    }

    if (AuthorizationExecuteWithPrivileges(
            authref, prog, kAuthorizationFlagDefaults, argv, &pipe)
            != errAuthorizationSuccess) {
        AuthorizationFree(authref, kAuthorizationFlagDestroyRights);
        return -1;
    }

    int pid = fcntl(fileno(pipe), F_GETOWN, 0);
    int r, status;
    do {
        r = waitpid(pid, &status, 0);
    } while (r == -1 && errno == EINTR);

    AuthorizationFree(authref, kAuthorizationFlagDestroyRights);
    return status;
}

#pragma clang diagnostic pop
woeful vigil
#

yep saw that file too, but i've never seen the apis used there myself either

#

never thought i'd say that but this time i hoped to see some objc rust bindings usage

agile sail
#

honestly so true 🤣 its so hard to know what you're looking at with these libraries, ill take a look - tyvm for ur help