We help IT Professionals succeed at work.

How to get root(super user) privilege in the program in OS X

tllin asked
     Some functions in Mac OS x need the root privilege to run.
     Such as create a raw socket, use ioctl( ) to change the HOST IP address.
     How can I  transfer my privilege into root in the program.
     The default condition is that I know the system manager's user name and password.

Thanks in advanced.
Teieh Lin
Watch Question



Dear weed:

   Yes, I can use netinfo to enable root login.
   Can I have the root privilege in the c program using the admin's user name and password??
   Which function should I use. Is there any sample code or document to reference. Or the darwin open source code.



Sure you can run programs as root via the terminal. I think the command goes 'su < root password>'...Then navigate to the programs directory and 'open <appname>' without the .app extension.
Do you want to set the program up so that it runs as root under
Mac OS X?  If so, the standard (UNIX) way to do this is to make
root the owner of the executable and set the suid bit in the
protections.  You can do that with terminal commands, assuming
you are root.  The commands are chown root <filename> and
chmod +s <filename>.

Note that if the program is running as root it has lots of potential
for compromising your system.  You may want to check out the
setuid() call so that you can minimize the time the program is
running as root.

I think tath yuo must read man pages for "setuid". I hope tath will helpp you.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.