Name: Anonymous 2008-01-22 18:24
How would I make my program check if it was root?
export USER=root' and, if the rest of the program is just as stupid, possibly cause some sort of security breach. It would also break with `su -p', `sudo' (with some sort of moronic configuration that keeps the value of $USER), or any number of programs that call `seteuid()' without updating the environment.
$ env USER=root ./\>\>10\'s\ shitty\ program
you are root
$#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
int main(){
puts(
strcmp(getpwuid(geteuid())->pw_name, "root") ?
"not running as root"
: "running as root"
);
return 0;
}