Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Loonix halp

Name: Anonymous 2008-01-22 18:24

How would I make my program check if it was root?

Name: Anonymous 2008-01-22 20:28

>>11
Wrong, wrong, wrong. The user could easily `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.

Name: Anonymous 2008-01-22 20:35

>>7
wrong. >>1 didn't say uid 0, he said root.

>>11
wrong.
$ env USER=root ./\>\>10\'s\ shitty\ program
you are root
$

OH SHI-

#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;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List