Forum > General

How to get root permissions MAC OS X


Hi all,

I have created two executables: a Daemon, nammed D and a Program nammed P.

When I run P for the first time, it has to initialize the configuration needed by D, that is:
1. create D.plist in /system/library/launchd/
2. launch D using launchctl to avoid the need of reboot
3. Terminate P which will be relaunched by D

Then, every time the mac reboot, D will be launched as Daemon and will launch P. That's all.

So, I think (but maybe I'm wrong ?) that P has to be launched as root for the first time because it needs to write a D.plist in /system/library/launchd/

The question is: How I can progammatically request root rights for P when I run it for the first time ?


i will tell u how i do it in linux

when i package my programme i make the main files (P,D,.....)
in the path let us say

--- Code: ---/usr/share/{application dir}
--- End code ---

and then write a small bash script to start my programe in root privilege and i but it in the path

--- Code: ---/usr/bin
--- End code ---
and this is the default path for Linux exec files

the script will be like that

in gnome desktop i use gksu

--- Code: ---#!/bin/bash
gksu /usr/share/{ap-plication dir}/P

--- End code ---

or use kdesu for kde desktop

--- Code: ---#!/bin/bash
kdesu /usr/share/{application dir}/P

--- End code ---

so u may have something similar in MAC OS X

There is a command sudo on MAC OS X. But you can not use it if you are a standard user and  my application has to be deployed by any user...

I come from "windows" world.   ::)

In this environment, you can ask for admin privilege. In this case, a popup windows alerts the user and he chooses to let or not the programm running with admin (root) privileges.

As I'm porting a windows application to Mac OS X, I also would keep the code as near as possible from the original. I'll have to maintain the two versions.


Finally, I think I can do it while deploying with PackageMaker : The package runs as admin and ask user to provide his password. This way I can put my plist in right place with right permissions and so on. But I'm still interested in knowing how PackageMaker does.


[0] Message Index

Go to full version