PDA

View Full Version : Get current user in C/C++?



Kimm
May 3rd, 2005, 03:54 PM
I am writing an application that would need root permission, I only want the program to ask for the password if you are not logged in as root however, so, I am woundering if there is any way that I can know what user is logged in?

HungSquirrel
May 3rd, 2005, 04:08 PM
If there's a way to execute shell commands from C, you could have your program execute the whoami Unix command. There's probably a much better way to do this, though.

Edit: Scroll down to the C on *Nix post at this link.
http://lineman.net/node/271

lao_V
May 3rd, 2005, 04:13 PM
you can check to see if the userid is 0 or not. something like:


if [ -eq $UID 0]

Kimm
May 3rd, 2005, 04:35 PM
HungSquirrel, that C on *Nix post worked perfectly ^^ thank you!

lao_V, I dont quite understand what you mean... is that C code??

Teren
May 3rd, 2005, 04:56 PM
HungSquirrel, that C on *Nix post worked perfectly ^^ thank you!

lao_V, I dont quite understand what you mean... is that C code??
That's SH

Kimm
May 3rd, 2005, 07:55 PM
oh, I see, I never realy use SH...