Re: Issue with running a process as root
Re: Issue with running a process as root
- Subject: Re: Issue with running a process as root
- From: Alastair Houghton <email@hidden>
- Date: Wed, 8 Aug 2007 12:24:52 +0100
On 8 Aug 2007, at 10:46, Saritha G wrote:
When I am executing the process without root privileges folder is
created with read, write and execute privileges and owner as
current user. But When I execute the process with root privileges
using authorizationExecuteWithPrivileges() folder is created as
read only and with owner as System.
Ah, OK, I think we're getting somewhere :-)
This process that you're running is doing the creating, right? Well,
when you do that, it will be running as root, so you'd expect it to
create the folder with different permissions than it would otherwise.
The solution is to do
seteuid(getuid());
which will change the effective user ID from root to the real user
ID, before creating your directory. If you need to switch back to
root again afterwards, just do
seteuid(0);
(Or, perhaps more cleanly, you can save the original effective UID in
a variable and change back to that explicitly. That approach works
if you need your program to run as a particular non-root user as well.)
Alternatively, if you have no need to switch back, you get just do
setuid(getuid());
which will drop the privileges permanently.
(BTW, this isn't a Cocoa question.)
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden