====== setUID ====== ===== SetUid C source ===== #include #include #include #include int main(void) { int current_uid = getuid(); printf("My UID is: %d. My GID is: %dn\n", current_uid, getgid()); system("/usr/bin/id"); if (setuid(0)) { perror("setuid"); return 1; } //I am now root! printf("\nMy UID is: %d. My GID is: %dn\n", getuid(), getgid()); system("/usr/bin/id"); //Time to drop back to regular user privileges setuid(current_uid); printf("\nMy UID is: %d. My GID is: %dn\n", getuid(), getgid()); system("/usr/bin/id"); return 0; } ===== Compile and chmod ===== gcc -o setuidtest setuidtest.c chmod u+s setuidtest ===== Read from stdin ===== char buf[1]; while(read(0, buf, sizeof(buf))>0) { // read() here read from stdin charachter by character // the buf[0] contains the character got by read() .... }