Requesting Superuser

Regan Heath regan at netmail.co.nz
Tue Oct 2 02:52:22 PDT 2007


BCS wrote:
> Jesse Phillips wrote:
>> On Mon, 01 Oct 2007 15:33:18 -0700, BCS wrote:
>>
>>
>>> Jesse Phillips wrote:
>>>
>>>> As a Linux programmer it can be important to have a program run with
>>>> superuser privileges. I am trying to figure out the best way to either
>>>> become a super user by asking for a password, or simply checking if it
>>>> is run as a superuser.
>>>>
>>>> I have been looking at how to do this in C and found information on
>>>> suser () which seems to be for FreeBSD.
>>>> http://www.gsp.com/cgi-bin/man.cgi?section=9&topic=suser
>>>>
>>>> I was also reading some stuff on secure programming which said not to
>>>> use system() because it invokes the shell, that's fine but is it really
>>>> a problem?
>>>> http://www.onlamp.com/pub/a/onlamp/excerpt/PUIS3_chap16/index1.html
>>>>
>>>> Any good links or search queries would be great.
>>>>
>>>> Thanks,
>>>> Jesse Phillips
>>>
>>>
>>> Are you looking for D specific stuff? Under Unix I would expect that
>>> superuser related stuff will be the same as under C. As such I expect
>>> that this NG wouldn't have any specific expertices in that. You might
>>> get lucky and find someone who knowns (these guys have quite a range of
>>> knowledge) but here is not the first place I'd look.
>>
>>
>> Well, I was hoping for something D specific, but didn't think there 
>> would be. Phobos has a std.linux package but the docs don't say 
>> anything about what is in it, I guess I could look at the source.
> 
> failing anything else, figure out how to do it it C and then declare the 
> needed function declarations. In my experience POSIX stuff is easy to 
> translate.

I believe the POSIX routines are:
http://linux.die.net/man/2/getuid
http://linux.die.net/man/2/setuid

As mentioned by Nathan your exe would need an owner of root and the SUID 
bit in order to elevate itself to the root user with setuid.

In your case I think you just want getuid to check the uid is 0, or 
root.  Or perhaps geteuid (I'm not sure if this one is POSIX).

Regan


More information about the Digitalmars-d-learn mailing list