Re: Authorization.h
Re: Authorization.h
- Subject: Re: Authorization.h
- From: Peter Sichel <email@hidden>
- Date: Fri, 2 Nov 2001 09:00:05 -0500
At 1:06 AM -0800 11/2/01, Josh M. Hurd wrote:
How can I use the Security framework (Authorization.h) to
'executeWithPrivileges' a function or method call instead of an
executable?
I don't believe you can directly. You need to wrap your function
into an executable tool, or execute a tool that makes your application
SUID root so you can execute it with root privileges. I've written
a tool to do the latter. When the application is run for the
first time, it displays a dialog like this:
IPNetMonitorX First Run
You must have administrator privileges to complete
the installation process. Please re-launch the application
after authenticating.
If the user authenticates, the application launches a unix
tool to make itself SUID root (actually, it makes a small
OpenICMP applet root which it then invokes to open ICMP sockets
and pass them back using BSD descriptor passing). In general
you don't want your entire application to run as root all the
time so you should either isolate the privileged operations to
a small applet, or raise and lower privileges like this:
// Globals
uid_t gSaved_uid;
gid_t gSaved_gid;
int main(int argc, const char *argv[])
{
// flush user defaults before seteuid
[NSUserDefaults resetStandardUserDefaults];
// Since we may run as SUID root,
// save our UID and then turn off any special permissions
gSaved_uid = geteuid();
gSaved_gid = getegid();
setegid(getgid());
seteuid(getuid());
return NSApplicationMain(argc, argv);
}
Then within your method that needs privileges:
// raise permissions
setegid(gSaved_gid);
seteuid(gSaved_uid);
// get a raw socket
mSocket = Socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
// lower permissions
setegid(getgid());
seteuid(getuid());
Now for my question:
I have an application that used to AuthorizationExecuteWithPrivileges
a unix shell script, but this seems to have stopped working around the
time I installed Apple's 10.1 security update. If I replace the shell
script with an executable image, it runs fine. Is this by design,
or is there some special attribute one can apply to execute a shell
script with privileges?
Thanks,
- Peter Sichel
Sustainable Softworks
--