How can I pre-authorize authopen?
Posted
by Georg
on Stack Overflow
See other posts from Stack Overflow
or by Georg
Published on 2009-09-22T14:02:56Z
Indexed on
2010/06/13
20:02 UTC
Read the original article
Hit count: 506
I'm using authopen inside one of my programs to modify files owned by root. As can be seen in the screenshot below authopen asks for a admin password. What I'd like to achieve is that the dialog shows my app's name and then passes the authorization to authopen.

Code
Launching authopen which returns an authorized file descriptor.
int pipe[2];
socketpair(AF_UNIX, SOCK_STREAM, 0, pipe);
if (fork() == 0) { // child
// close parent's pipe
close(pipe[0]);
dup2(pipe[1], STDOUT_FILENO);
const char *authopenPath = "/usr/libexec/authopen";
execl(authopenPath,
authopenPath,
"-stdoutpipe",
[self.device.devicePath fileSystemRepresentation],
NULL);
NSLog(@"Fatal error, quitting.");
exit(-1);
}
// parent
// close childs's pipe
close(pipe[1]);
// get file descriptor through sockets
I'd really like not to use AuthorizationExecuteWithPrivileges because then I'd have to get more rights than I want to.
© Stack Overflow or respective owner