Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How can I detect the root user?

How can I detect the root user?
Thread Tools
Junior Member
Join Date: Aug 2000
Location: Montreal, QC, Canada
Status: Offline
Reply With Quote
Apr 5, 2002, 06:11 PM
 
I'm writing a small command line program for OSX in C. I want the program to behave slightly differently if I'm running it as the super user. Is there any sort of isroot() function?


Thanks for any help
     
Mac Enthusiast
Join Date: Sep 2000
Location: Cupertino, CA
Status: Offline
Reply With Quote
Apr 5, 2002, 07:15 PM
 
Originally posted by Octo:
<STRONG>I'm writing a small command line program for OSX in C. I want the program to behave slightly differently if I'm running it as the super user. Is there any sort of isroot() function?


Thanks for any help</STRONG>
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
if (getuid() == <font color = blue>0</font>)
{
if(geteuid() == <font color = blue>0</font>)
{
<font color = brown>//Root</font>
} else {
<font color = brown>//Root with droped priviledges (seteuid())</font>
}
} else {
if(geteuid() == <font color = blue>0</font>)
{
<font color = brown>//Normal user running a setuid root program</font>
} else {
<font color = brown>//Not root</font>
}
}
</font>[/code]

Louis
Louis Gerbarg
Darwin Developer
These are my views, and not the views of my employer.
     
Octo  (op)
Junior Member
Join Date: Aug 2000
Location: Montreal, QC, Canada
Status: Offline
Reply With Quote
Apr 9, 2002, 07:28 AM
 
Originally posted by lgerbarg:
<STRONG>

&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
if (getuid() == &lt;font color = blue&gt;0&lt;/font&gt; )
{
if(geteuid() == &lt;font color = blue&gt;0&lt;/font&gt; )
{
&lt;font color = brown&gt;//Root&lt;/font&gt;
} else {
&lt;font color = brown&gt;//Root with droped priviledges (seteuid())&lt;/font&gt;
}
} else {
if(geteuid() == &lt;font color = blue&gt;0&lt;/font&gt; )
{
&lt;font color = brown&gt;//Normal user running a setuid root program&lt;/font&gt;
} else {
&lt;font color = brown&gt;//Not root&lt;/font&gt;
}
}
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/BLOCKQUOTE&gt;

Louis</STRONG>
Excellent. Thank you very much, it works like a charm.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2