Recent

Author Topic: How to get root permissions MAC OS X  (Read 8735 times)

sinfoni

  • Jr. Member
  • **
  • Posts: 56
How to get root permissions MAC OS X
« on: May 18, 2010, 07:13:37 am »
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 ?

Thanks
André.

a.atalla

  • Jr. Member
  • **
  • Posts: 82
Re: How to get root permissions MAC OS X
« Reply #1 on: May 18, 2010, 10:38:56 am »
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: [Select]
/usr/share/{application dir}
and then write a small bash script to start my programe in root privilege and i but it in the path

Code: [Select]
/usr/binand this is the default path for Linux exec files

the script will be like that

in gnome desktop i use gksu
Code: [Select]
#!/bin/bash
gksu /usr/share/{ap-plication dir}/P

or use kdesu for kde desktop
Code: [Select]
#!/bin/bash
kdesu /usr/share/{application dir}/P

so u may have something similar in MAC OS X
Lazarus 1.0.8 | FPC 2.6.2 x64  | Arch Linux x64 | Windows 7-x86

sinfoni

  • Jr. Member
  • **
  • Posts: 56
Re: How to get root permissions MAC OS X
« Reply #2 on: May 18, 2010, 12:19:30 pm »
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.

  

sinfoni

  • Jr. Member
  • **
  • Posts: 56
Re: How to get root permissions MAC OS X
« Reply #3 on: May 19, 2010, 02:27:12 am »
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.

 

TinyPortal © 2005-2018