[SYSTEM]: How detecting if run as root ?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[SYSTEM]: How detecting if run as root ?

dtouzeau
Dear

I need to detect if the program is executed as root privileges on Linux
system.
Did somebody had developped a such function ??

Best regards.


--

David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6
FreePascal-Lazarus,perl,delphi,php icq:160018849
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: [SYSTEM]: How detecting if run as root ?

Andrew Haines
TOUZEAU DAVID wrote:
> Dear
>
> I need to detect if the program is executed as root privileges on Linux
> system.
> Did somebody had developped a such function ??
>
> Best regards.
>
>
Well you can try GetEnv('USER') = 'root'; or GetEnv('UID') = '0'; but
there may be better ways to check this.

Andrew
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: [SYSTEM]: How detecting if run as root ?

Pete Cervasio
On Wednesday 11 October 2006 19:37, Andrew Haines wrote:

> TOUZEAU DAVID wrote:
> > Dear
> >
> > I need to detect if the program is executed as root privileges on Linux
> > system.
> > Did somebody had developped a such function ??
> >
> > Best regards.
>
> Well you can try GetEnv('USER') = 'root'; or GetEnv('UID') = '0'; but
> there may be better ways to check this.

The better way would be to use the geteuid function in the libc unit, because
the environment variables may not be set (such as if they were explictly
unset or if the program is run from cron or the system startup scripts).  

See the getuid/geteuid man page for particulars.  And no, I am not saying
"RTFMP" spitefully.  :) :)

Best regards,
Pete C.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: [SYSTEM]: How detecting if run as root ?

Michalis Kamburelis
Pete Cervasio wrote:

> On Wednesday 11 October 2006 19:37, Andrew Haines wrote:
>> TOUZEAU DAVID wrote:
>>> Dear
>>>
>>> I need to detect if the program is executed as root privileges on Linux
>>> system.
>>> Did somebody had developped a such function ??
>>>
>>> Best regards.
>> Well you can try GetEnv('USER') = 'root'; or GetEnv('UID') = '0'; but
>> there may be better ways to check this.
>
> The better way would be to use the geteuid function in the libc unit, because
> the environment variables may not be set (such as if they were explictly
> unset or if the program is run from cron or the system startup scripts).  
>
> See the getuid/geteuid man page for particulars.  And no, I am not saying
> "RTFMP" spitefully.  :) :)
>

It would be even better to use FpGetEUid function from the BaseUnix
unit. See [http://www.freepascal.org/docs-html/rtl/baseunix/fpgeteuid.html].

Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: [SYSTEM]: How detecting if run as root ?

Pete Cervasio
On Wednesday 11 October 2006 20:44, Michalis Kamburelis wrote:
> Pete Cervasio wrote:
> > The better way would be to use the geteuid function in the libc unit,
>
> It would be even better to use FpGetEUid function from the BaseUnix
> unit. See
> [http://www.freepascal.org/docs-html/rtl/baseunix/fpgeteuid.html].

DOH!  Thanks for reminding me, Michalis.  I always forget about seeing if a
function is already in the RTL when doing things that I know are standard C
library functions.  Force of habit is my (bad) excuse. :)

Best regards,
Pete C.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: [SYSTEM]: How detecting if run as root ?

dtouzeau
Many thanks i found the function GetEUID i'll try it
 
http://www.cs.uwc.ac.za/~firstyear/manuals/doc/units/unitsse36.html#x53-41900012.3


Pete Cervasio a écrit :

> On Wednesday 11 October 2006 20:44, Michalis Kamburelis wrote:
>  
>> Pete Cervasio wrote:
>>    
>>> The better way would be to use the geteuid function in the libc unit,
>>>      
>> It would be even better to use FpGetEUid function from the BaseUnix
>> unit. See
>> [http://www.freepascal.org/docs-html/rtl/baseunix/fpgeteuid.html].
>>    
>
> DOH!  Thanks for reminding me, Michalis.  I always forget about seeing if a
> function is already in the RTL when doing things that I know are standard C
> library functions.  Force of habit is my (bad) excuse. :)
>
> Best regards,
> Pete C.
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>  

--

David Touzeau -------------------------- Linux Ubuntu Dapper 6.0.6
FreePascal-Lazarus,perl,delphi,php icq:160018849

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal